File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 "time"
66
77 devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
8+ "github.com/loft-sh/devspace/pkg/devspace/kubectl"
89 "github.com/loft-sh/devspace/pkg/util/ptr"
910 appsv1 "k8s.io/api/apps/v1"
1011 corev1 "k8s.io/api/core/v1"
@@ -63,14 +64,21 @@ func (r *LocalRegistry) ensureDeployment(ctx devspacecontext.Context) (*appsv1.D
6364 if err != nil {
6465 return nil , err
6566 }
66- return ctx .KubeClient ().KubeClient ().AppsV1 ().Deployments (r .Namespace ).Apply (
67+ apply , err := ctx .KubeClient ().KubeClient ().AppsV1 ().Deployments (r .Namespace ).Apply (
6768 ctx .Context (),
6869 applyConfiguration ,
6970 metav1.ApplyOptions {
7071 FieldManager : ApplyFieldManager ,
7172 Force : true ,
7273 },
7374 )
75+ if err != nil && kubectl .IsIncompatibleServerError (err ) {
76+ ctx .Log ().Debugf ("Server-side apply not available on the server for localRegistry deployment: (%v)" , err )
77+ // Unsupport server-side apply, we use existing or created deployment
78+ return existing , nil
79+ }
80+
81+ return apply , err
7482}
7583
7684func (r * LocalRegistry ) getDeployment () * appsv1.Deployment {
Original file line number Diff line number Diff line change 55 "time"
66
77 devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
8+ "github.com/loft-sh/devspace/pkg/devspace/kubectl"
89 corev1 "k8s.io/api/core/v1"
910 kerrors "k8s.io/apimachinery/pkg/api/errors"
1011 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -50,15 +51,21 @@ func (r *LocalRegistry) ensureService(ctx devspacecontext.Context) (*corev1.Serv
5051 if err != nil {
5152 return nil , err
5253 }
53-
54- return ctx .KubeClient ().KubeClient ().CoreV1 ().Services (r .Namespace ).Apply (
54+ apply , err := ctx .KubeClient ().KubeClient ().CoreV1 ().Services (r .Namespace ).Apply (
5555 ctx .Context (),
5656 applyConfiguration ,
5757 metav1.ApplyOptions {
5858 FieldManager : ApplyFieldManager ,
5959 Force : true ,
6060 },
6161 )
62+ if err != nil && kubectl .IsIncompatibleServerError (err ) {
63+ ctx .Log ().Debugf ("Server-side apply not available on the server for localRegistry service: (%v)" , err )
64+ // Unsupport server-side apply, we use existing or created service
65+ return existing , nil
66+ }
67+
68+ return apply , err
6269}
6370
6471func (r * LocalRegistry ) getService () * corev1.Service {
Original file line number Diff line number Diff line change 55 "time"
66
77 devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
8+ "github.com/loft-sh/devspace/pkg/devspace/kubectl"
89 appsv1 "k8s.io/api/apps/v1"
910 corev1 "k8s.io/api/core/v1"
1011 kerrors "k8s.io/apimachinery/pkg/api/errors"
@@ -59,14 +60,21 @@ func (r *LocalRegistry) ensureStatefulset(ctx devspacecontext.Context) (*appsv1.
5960 if err != nil {
6061 return nil , err
6162 }
62- return ctx .KubeClient ().KubeClient ().AppsV1 ().StatefulSets (r .Namespace ).Apply (
63+ apply , err := ctx .KubeClient ().KubeClient ().AppsV1 ().StatefulSets (r .Namespace ).Apply (
6364 ctx .Context (),
6465 applyConfiguration ,
6566 metav1.ApplyOptions {
6667 FieldManager : ApplyFieldManager ,
6768 Force : true ,
6869 },
6970 )
71+ if err != nil && kubectl .IsIncompatibleServerError (err ) {
72+ ctx .Log ().Debugf ("Server-side apply not available on the server for localRegistry statefulset: (%v)" , err )
73+ // Unsupport server-side apply, we use existing or created statefulset
74+ return existing , nil
75+ }
76+
77+ return apply , err
7078}
7179
7280func (r * LocalRegistry ) getStatefulSet () * appsv1.StatefulSet {
Original file line number Diff line number Diff line change @@ -3,11 +3,6 @@ package kubectl
33import (
44 "context"
55 "fmt"
6- "io"
7- "net/http"
8- "os"
9- "time"
10-
116 "github.com/loft-sh/devspace/pkg/devspace/config/localcache"
127 "github.com/loft-sh/devspace/pkg/devspace/kill"
138 "github.com/loft-sh/devspace/pkg/devspace/kubectl/util"
@@ -17,7 +12,11 @@ import (
1712 "github.com/loft-sh/devspace/pkg/util/log"
1813 "github.com/loft-sh/devspace/pkg/util/survey"
1914 "github.com/loft-sh/devspace/pkg/util/terminal"
15+ "io"
2016 "k8s.io/apimachinery/pkg/util/wait"
17+ "net/http"
18+ "os"
19+ "time"
2120
2221 "github.com/mgutz/ansi"
2322 "github.com/pkg/errors"
Original file line number Diff line number Diff line change @@ -276,3 +276,13 @@ func GetKindContext(context string) string {
276276
277277 return strings .TrimPrefix (context , "kind-" )
278278}
279+
280+ func IsIncompatibleServerError (err error ) bool {
281+ // 415: Unsupported media type means we're talking to a server which doesn't support server-side apply.
282+ // Also included the apiserver enabled feature: ServerSideApply=false option
283+ if _ , ok := err .(* kerrors.StatusError ); ! ok {
284+ // Non-StatusError means the error isn't because the server is incompatible.
285+ return false
286+ }
287+ return err .(* kerrors.StatusError ).Status ().Code == http .StatusUnsupportedMediaType
288+ }
You can’t perform that action at this time.
0 commit comments