Skip to content

Commit 32cfa90

Browse files
committed
fix: use Get instead of List to discover the namespace
Signed-off-by: Luca Di Maio <[email protected]>
1 parent e51af33 commit 32cfa90

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

pkg/devspace/build/localregistry/local_registry.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"k8s.io/apimachinery/pkg/util/wait"
1717
applyv1 "k8s.io/client-go/applyconfigurations/core/v1"
1818

19+
kerrors "k8s.io/apimachinery/pkg/api/errors"
20+
1921
"github.com/google/go-containerregistry/pkg/v1/remote"
2022
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
2123
"github.com/mgutz/ansi"
@@ -170,26 +172,24 @@ func (r *LocalRegistry) ensureNamespace(ctx devspacecontext.Context) error {
170172
// If localregistry namespace is the same as devspace, we don't have
171173
// anything to do.
172174
if r.Namespace == ctx.KubeClient().Namespace() {
175+
ctx.Log().Debugf("Namespace %s is the default Devspace namespace", r.Namespace)
173176
return nil
174177
}
175178

176-
// List all namespaces, this will already return an error in case of
177-
// user's permissions problems.
178-
namespaces, err := ctx.KubeClient().
179+
// Try to get the namespace we need
180+
_, err := ctx.KubeClient().
179181
KubeClient().
180182
CoreV1().
181183
Namespaces().
182-
List(ctx.Context(), metav1.ListOptions{})
183-
if err != nil {
184+
Get(ctx.Context(), r.Namespace, metav1.GetOptions{})
185+
// Ignore not found errors, but if we have any other type or error, report it
186+
if err != nil && !kerrors.IsNotFound(err) {
184187
return err
185188
}
186-
187-
// Check if the namespace already is there, if not we'll try to create it.
188-
for _, namespace := range namespaces.Items {
189-
if r.Namespace == namespace.Name {
190-
ctx.Log().Debugf("Namespace %s already exists, skipping creation", r.Namespace)
191-
return nil
192-
}
189+
// And if we don't have errors, it means the namespace already exists.
190+
if err == nil {
191+
ctx.Log().Debugf("Namespace %s already exists, skipping creation", r.Namespace)
192+
return nil
193193
}
194194

195195
ctx.Log().Debugf("Namespace %s doesn't exist, attempting creation", r.Namespace)

0 commit comments

Comments
 (0)