Skip to content

Commit

Permalink
Merge pull request #2893 from devspace-sh/fix-415-server-side-apply
Browse files Browse the repository at this point in the history
fix remote buildkit error: [415: Unsupported Media Type]
  • Loading branch information
lizardruss authored Sep 19, 2024
2 parents e873c8f + 8d05efe commit 964f505
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 20 deletions.
3 changes: 2 additions & 1 deletion cmd/cleanup/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cleanup

import (
"context"

"github.com/loft-sh/devspace/pkg/devspace/docker"

"github.com/loft-sh/devspace/cmd/flags"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (cmd *imagesCmd) RunCleanupImages(f factory.Factory, cobraCmd *cobra.Comman
}

config := configInterface.Config()
if config.Images == nil || len(config.Images) == 0 {
if len(config.Images) == 0 {
log.Done("No images found in config to delete")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/list/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (cmd *portsCmd) RunListPort(f factory.Factory, cobraCmd *cobra.Command, arg
config := configInterface.Config()
portForwards := make([][]string, 0)
for _, dev := range config.Dev {
if dev.Ports == nil || len(dev.Ports) == 0 {
if len(dev.Ports) == 0 {
continue
}
selector := ""
Expand Down
3 changes: 2 additions & 1 deletion cmd/list/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package list

import (
"context"

"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/pkg/util/factory"
"github.com/loft-sh/devspace/pkg/util/log"
Expand Down Expand Up @@ -57,7 +58,7 @@ func (cmd *syncCmd) RunListSync(f factory.Factory, cobraCmd *cobra.Command, args
syncPaths := make([][]string, 0)

for _, dev := range config.Dev {
if dev.Sync == nil || len(dev.Sync) == 0 {
if len(dev.Sync) == 0 {
logger.Info("No sync paths are configured.")
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion e2e/tests/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,9 @@ var _ = DevSpaceDescribe("sync", func() {
defer ginkgo.GinkgoRecover()
defer waitGroup.Done()
err = syncCmd.Run(f)
framework.ExpectNoError(err)
if !errors.Is(err, context.Canceled) {
framework.ExpectNoError(err)
}
}()

// check that uploadExcludePaths folder was not synced
Expand Down
7 changes: 4 additions & 3 deletions pkg/devspace/build/builder/custom/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package custom

import (
"fmt"
"io"
"strings"

"github.com/loft-sh/devspace/pkg/devspace/config/loader/variable/runtime"
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
"github.com/loft-sh/devspace/pkg/devspace/pipeline/engine"
"github.com/sirupsen/logrus"
"io"
"strings"

"github.com/bmatcuk/doublestar"
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
Expand Down Expand Up @@ -40,7 +41,7 @@ func NewBuilder(imageConf *latest.Image, imageTags []string) *Builder {

// ShouldRebuild implements interface
func (b *Builder) ShouldRebuild(ctx devspacecontext.Context, forceRebuild bool) (bool, error) {
if b.imageConf.Custom.OnChange == nil || len(b.imageConf.Custom.OnChange) == 0 {
if len(b.imageConf.Custom.OnChange) == 0 {
return true, nil
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/devspace/build/localregistry/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,21 @@ func (r *LocalRegistry) ensureDeployment(ctx devspacecontext.Context) (*appsv1.D
if err != nil {
return nil, err
}
return ctx.KubeClient().KubeClient().AppsV1().Deployments(r.Namespace).Apply(
apply, err := ctx.KubeClient().KubeClient().AppsV1().Deployments(r.Namespace).Apply(
ctx.Context(),
applyConfiguration,
metav1.ApplyOptions{
FieldManager: ApplyFieldManager,
Force: true,
},
)
if kerrors.IsUnsupportedMediaType(err) {
ctx.Log().Debugf("Server-side apply not available on the server for localRegistry deployment: (%v)", err)
// Unsupport server-side apply, we use existing or created deployment
return existing, nil
}

return apply, err
}

func (r *LocalRegistry) getDeployment() *appsv1.Deployment {
Expand Down
10 changes: 8 additions & 2 deletions pkg/devspace/build/localregistry/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,21 @@ func (r *LocalRegistry) ensureService(ctx devspacecontext.Context) (*corev1.Serv
if err != nil {
return nil, err
}

return ctx.KubeClient().KubeClient().CoreV1().Services(r.Namespace).Apply(
apply, err := ctx.KubeClient().KubeClient().CoreV1().Services(r.Namespace).Apply(
ctx.Context(),
applyConfiguration,
metav1.ApplyOptions{
FieldManager: ApplyFieldManager,
Force: true,
},
)
if kerrors.IsUnsupportedMediaType(err) {
ctx.Log().Debugf("Server-side apply not available on the server for localRegistry service: (%v)", err)
// Unsupport server-side apply, we use existing or created service
return existing, nil
}

return apply, err
}

func (r *LocalRegistry) getService() *corev1.Service {
Expand Down
9 changes: 8 additions & 1 deletion pkg/devspace/build/localregistry/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,21 @@ func (r *LocalRegistry) ensureStatefulset(ctx devspacecontext.Context) (*appsv1.
if err != nil {
return nil, err
}
return ctx.KubeClient().KubeClient().AppsV1().StatefulSets(r.Namespace).Apply(
apply, err := ctx.KubeClient().KubeClient().AppsV1().StatefulSets(r.Namespace).Apply(
ctx.Context(),
applyConfiguration,
metav1.ApplyOptions{
FieldManager: ApplyFieldManager,
Force: true,
},
)
if kerrors.IsUnsupportedMediaType(err) {
ctx.Log().Debugf("Server-side apply not available on the server for localRegistry statefulset: (%v)", err)
// Unsupport server-side apply, we use existing or created statefulset
return existing, nil
}

return apply, err
}

func (r *LocalRegistry) getStatefulSet() *appsv1.StatefulSet {
Expand Down
2 changes: 1 addition & 1 deletion pkg/devspace/config/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (l *configLoader) LoadWithParser(ctx context.Context, localCache localcache
var ok bool
name, ok = data["name"].(string)
if !ok {
return nil, fmt.Errorf("name is missing in " + filepath.Base(l.absConfigPath))
return nil, fmt.Errorf("name is missing in %s", filepath.Base(l.absConfigPath))
}
} else {
data["name"] = options.OverrideName
Expand Down
2 changes: 1 addition & 1 deletion pkg/devspace/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *controller) Deploy(ctx devspacecontext.Context, deployments []string, o
return nil
}

if config.Deployments != nil && len(config.Deployments) > 0 {
if len(config.Deployments) > 0 {
// Execute before deployments deploy hook
err := hook.ExecuteHooks(ctx, nil, "before:"+event)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions pkg/devspace/hook/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package hook
import (
"bytes"
"fmt"
"io"
"strings"
"time"

"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
"github.com/loft-sh/devspace/pkg/devspace/plugin"
Expand All @@ -13,10 +17,7 @@ import (
dockerterm "github.com/moby/term"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"io"
"k8s.io/apimachinery/pkg/labels"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -105,7 +106,7 @@ func executeSingle(ctx devspacecontext.Context, extraEnv map[string]string, even
}

c := config.Config()
if c.Hooks != nil && len(c.Hooks) > 0 {
if len(c.Hooks) > 0 {
hooksToExecute := []*latest.HookConfig{}

// Gather all hooks we should execute
Expand Down
3 changes: 1 addition & 2 deletions pkg/devspace/kubectl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ import (
"github.com/loft-sh/devspace/pkg/util/log"
"github.com/loft-sh/devspace/pkg/util/survey"
"github.com/loft-sh/devspace/pkg/util/terminal"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/mgutz/ansi"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
k8sv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/log/file_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (f *fileLogger) Debugf(format string, args ...interface{}) {
return
}

f.logger.Debugf(f.addPrefixes(stripEscapeSequences(fmt.Sprintf(format, args...))))
f.logger.Debug(f.addPrefixes(stripEscapeSequences(fmt.Sprintf(format, args...))))
}

func (f *fileLogger) Info(args ...interface{}) {
Expand Down

0 comments on commit 964f505

Please sign in to comment.