Skip to content

Commit 8d05efe

Browse files
committed
refactor: code review feedback
Signed-off-by: Russell Centanni <russell.centanni@gmail.com>
1 parent d84d605 commit 8d05efe

File tree

5 files changed

+9
-22
lines changed

5 files changed

+9
-22
lines changed

pkg/devspace/build/localregistry/deployment.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
8-
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
98
"github.com/loft-sh/devspace/pkg/util/ptr"
109
appsv1 "k8s.io/api/apps/v1"
1110
corev1 "k8s.io/api/core/v1"
@@ -72,7 +71,7 @@ func (r *LocalRegistry) ensureDeployment(ctx devspacecontext.Context) (*appsv1.D
7271
Force: true,
7372
},
7473
)
75-
if err != nil && kubectl.IsIncompatibleServerError(err) {
74+
if kerrors.IsUnsupportedMediaType(err) {
7675
ctx.Log().Debugf("Server-side apply not available on the server for localRegistry deployment: (%v)", err)
7776
// Unsupport server-side apply, we use existing or created deployment
7877
return existing, nil

pkg/devspace/build/localregistry/service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
8-
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
98
corev1 "k8s.io/api/core/v1"
109
kerrors "k8s.io/apimachinery/pkg/api/errors"
1110
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -59,7 +58,7 @@ func (r *LocalRegistry) ensureService(ctx devspacecontext.Context) (*corev1.Serv
5958
Force: true,
6059
},
6160
)
62-
if err != nil && kubectl.IsIncompatibleServerError(err) {
61+
if kerrors.IsUnsupportedMediaType(err) {
6362
ctx.Log().Debugf("Server-side apply not available on the server for localRegistry service: (%v)", err)
6463
// Unsupport server-side apply, we use existing or created service
6564
return existing, nil

pkg/devspace/build/localregistry/statefulset.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"time"
66

77
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
8-
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
98
appsv1 "k8s.io/api/apps/v1"
109
corev1 "k8s.io/api/core/v1"
1110
kerrors "k8s.io/apimachinery/pkg/api/errors"
@@ -68,7 +67,7 @@ func (r *LocalRegistry) ensureStatefulset(ctx devspacecontext.Context) (*appsv1.
6867
Force: true,
6968
},
7069
)
71-
if err != nil && kubectl.IsIncompatibleServerError(err) {
70+
if kerrors.IsUnsupportedMediaType(err) {
7271
ctx.Log().Debugf("Server-side apply not available on the server for localRegistry statefulset: (%v)", err)
7372
// Unsupport server-side apply, we use existing or created statefulset
7473
return existing, nil

pkg/devspace/kubectl/client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ package kubectl
33
import (
44
"context"
55
"fmt"
6+
"io"
7+
"net/http"
8+
"os"
9+
"time"
10+
611
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
712
"github.com/loft-sh/devspace/pkg/devspace/kill"
813
"github.com/loft-sh/devspace/pkg/devspace/kubectl/util"
@@ -12,17 +17,12 @@ import (
1217
"github.com/loft-sh/devspace/pkg/util/log"
1318
"github.com/loft-sh/devspace/pkg/util/survey"
1419
"github.com/loft-sh/devspace/pkg/util/terminal"
15-
"io"
16-
"k8s.io/apimachinery/pkg/util/wait"
17-
"net/http"
18-
"os"
19-
"time"
20-
2120
"github.com/mgutz/ansi"
2221
"github.com/pkg/errors"
2322
"github.com/sirupsen/logrus"
2423
k8sv1 "k8s.io/api/core/v1"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/apimachinery/pkg/util/wait"
2626
"k8s.io/client-go/kubernetes"
2727
"k8s.io/client-go/rest"
2828
"k8s.io/client-go/tools/clientcmd"

pkg/devspace/kubectl/util.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,3 @@ 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-
}

0 commit comments

Comments
 (0)