Skip to content

Commit 964f505

Browse files
authored
Merge pull request #2893 from devspace-sh/fix-415-server-side-apply
fix remote buildkit error: [415: Unsupported Media Type]
2 parents e873c8f + 8d05efe commit 964f505

File tree

13 files changed

+45
-20
lines changed

13 files changed

+45
-20
lines changed

cmd/cleanup/images.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cleanup
22

33
import (
44
"context"
5+
56
"github.com/loft-sh/devspace/pkg/devspace/docker"
67

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

7879
config := configInterface.Config()
79-
if config.Images == nil || len(config.Images) == 0 {
80+
if len(config.Images) == 0 {
8081
log.Done("No images found in config to delete")
8182
return nil
8283
}

cmd/list/ports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (cmd *portsCmd) RunListPort(f factory.Factory, cobraCmd *cobra.Command, arg
6868
config := configInterface.Config()
6969
portForwards := make([][]string, 0)
7070
for _, dev := range config.Dev {
71-
if dev.Ports == nil || len(dev.Ports) == 0 {
71+
if len(dev.Ports) == 0 {
7272
continue
7373
}
7474
selector := ""

cmd/list/sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package list
22

33
import (
44
"context"
5+
56
"github.com/loft-sh/devspace/cmd/flags"
67
"github.com/loft-sh/devspace/pkg/util/factory"
78
"github.com/loft-sh/devspace/pkg/util/log"
@@ -57,7 +58,7 @@ func (cmd *syncCmd) RunListSync(f factory.Factory, cobraCmd *cobra.Command, args
5758
syncPaths := make([][]string, 0)
5859

5960
for _, dev := range config.Dev {
60-
if dev.Sync == nil || len(dev.Sync) == 0 {
61+
if len(dev.Sync) == 0 {
6162
logger.Info("No sync paths are configured.")
6263
return nil
6364
}

e2e/tests/sync/sync.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,9 @@ var _ = DevSpaceDescribe("sync", func() {
596596
defer ginkgo.GinkgoRecover()
597597
defer waitGroup.Done()
598598
err = syncCmd.Run(f)
599-
framework.ExpectNoError(err)
599+
if !errors.Is(err, context.Canceled) {
600+
framework.ExpectNoError(err)
601+
}
600602
}()
601603

602604
// check that uploadExcludePaths folder was not synced

pkg/devspace/build/builder/custom/custom.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package custom
22

33
import (
44
"fmt"
5+
"io"
6+
"strings"
7+
58
"github.com/loft-sh/devspace/pkg/devspace/config/loader/variable/runtime"
69
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
710
"github.com/loft-sh/devspace/pkg/devspace/pipeline/engine"
811
"github.com/sirupsen/logrus"
9-
"io"
10-
"strings"
1112

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

4142
// ShouldRebuild implements interface
4243
func (b *Builder) ShouldRebuild(ctx devspacecontext.Context, forceRebuild bool) (bool, error) {
43-
if b.imageConf.Custom.OnChange == nil || len(b.imageConf.Custom.OnChange) == 0 {
44+
if len(b.imageConf.Custom.OnChange) == 0 {
4445
return true, nil
4546
}
4647

pkg/devspace/build/localregistry/deployment.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,21 @@ func (r *LocalRegistry) ensureDeployment(ctx devspacecontext.Context) (*appsv1.D
6363
if err != nil {
6464
return nil, err
6565
}
66-
return ctx.KubeClient().KubeClient().AppsV1().Deployments(r.Namespace).Apply(
66+
apply, err := ctx.KubeClient().KubeClient().AppsV1().Deployments(r.Namespace).Apply(
6767
ctx.Context(),
6868
applyConfiguration,
6969
metav1.ApplyOptions{
7070
FieldManager: ApplyFieldManager,
7171
Force: true,
7272
},
7373
)
74+
if kerrors.IsUnsupportedMediaType(err) {
75+
ctx.Log().Debugf("Server-side apply not available on the server for localRegistry deployment: (%v)", err)
76+
// Unsupport server-side apply, we use existing or created deployment
77+
return existing, nil
78+
}
79+
80+
return apply, err
7481
}
7582

7683
func (r *LocalRegistry) getDeployment() *appsv1.Deployment {

pkg/devspace/build/localregistry/service.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,21 @@ func (r *LocalRegistry) ensureService(ctx devspacecontext.Context) (*corev1.Serv
5050
if err != nil {
5151
return nil, err
5252
}
53-
54-
return ctx.KubeClient().KubeClient().CoreV1().Services(r.Namespace).Apply(
53+
apply, err := ctx.KubeClient().KubeClient().CoreV1().Services(r.Namespace).Apply(
5554
ctx.Context(),
5655
applyConfiguration,
5756
metav1.ApplyOptions{
5857
FieldManager: ApplyFieldManager,
5958
Force: true,
6059
},
6160
)
61+
if kerrors.IsUnsupportedMediaType(err) {
62+
ctx.Log().Debugf("Server-side apply not available on the server for localRegistry service: (%v)", err)
63+
// Unsupport server-side apply, we use existing or created service
64+
return existing, nil
65+
}
66+
67+
return apply, err
6268
}
6369

6470
func (r *LocalRegistry) getService() *corev1.Service {

pkg/devspace/build/localregistry/statefulset.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,21 @@ func (r *LocalRegistry) ensureStatefulset(ctx devspacecontext.Context) (*appsv1.
5959
if err != nil {
6060
return nil, err
6161
}
62-
return ctx.KubeClient().KubeClient().AppsV1().StatefulSets(r.Namespace).Apply(
62+
apply, err := ctx.KubeClient().KubeClient().AppsV1().StatefulSets(r.Namespace).Apply(
6363
ctx.Context(),
6464
applyConfiguration,
6565
metav1.ApplyOptions{
6666
FieldManager: ApplyFieldManager,
6767
Force: true,
6868
},
6969
)
70+
if kerrors.IsUnsupportedMediaType(err) {
71+
ctx.Log().Debugf("Server-side apply not available on the server for localRegistry statefulset: (%v)", err)
72+
// Unsupport server-side apply, we use existing or created statefulset
73+
return existing, nil
74+
}
75+
76+
return apply, err
7077
}
7178

7279
func (r *LocalRegistry) getStatefulSet() *appsv1.StatefulSet {

pkg/devspace/config/loader/loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (l *configLoader) LoadWithParser(ctx context.Context, localCache localcache
150150
var ok bool
151151
name, ok = data["name"].(string)
152152
if !ok {
153-
return nil, fmt.Errorf("name is missing in " + filepath.Base(l.absConfigPath))
153+
return nil, fmt.Errorf("name is missing in %s", filepath.Base(l.absConfigPath))
154154
}
155155
} else {
156156
data["name"] = options.OverrideName

pkg/devspace/deploy/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (c *controller) Deploy(ctx devspacecontext.Context, deployments []string, o
5959
return nil
6060
}
6161

62-
if config.Deployments != nil && len(config.Deployments) > 0 {
62+
if len(config.Deployments) > 0 {
6363
// Execute before deployments deploy hook
6464
err := hook.ExecuteHooks(ctx, nil, "before:"+event)
6565
if err != nil {

0 commit comments

Comments
 (0)