Skip to content

Commit e22e3f8

Browse files
committed
fix: ensure namespaces during dependencies resolution
Signed-off-by: Luca Di Maio <[email protected]>
1 parent fd90d46 commit e22e3f8

File tree

2 files changed

+16
-38
lines changed

2 files changed

+16
-38
lines changed

pkg/devspace/build/localregistry/local_registry.go

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import (
1414
corev1 "k8s.io/api/core/v1"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616
"k8s.io/apimachinery/pkg/util/wait"
17-
applyv1 "k8s.io/client-go/applyconfigurations/core/v1"
18-
19-
kerrors "k8s.io/apimachinery/pkg/api/errors"
2017

2118
"github.com/google/go-containerregistry/pkg/v1/remote"
2219
"github.com/loft-sh/devspace/pkg/devspace/kubectl"
@@ -176,41 +173,7 @@ func (r *LocalRegistry) ensureNamespace(ctx devspacecontext.Context) error {
176173
return nil
177174
}
178175

179-
// Try to get the namespace we need
180-
_, err := ctx.KubeClient().
181-
KubeClient().
182-
CoreV1().
183-
Namespaces().
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) {
187-
return err
188-
}
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
193-
}
194-
195-
ctx.Log().Debugf("Namespace %s doesn't exist, attempting creation", r.Namespace)
196-
applyConfiguration, err := applyv1.ExtractNamespace(&corev1.Namespace{
197-
ObjectMeta: metav1.ObjectMeta{
198-
Name: r.Namespace,
199-
},
200-
}, ApplyFieldManager)
201-
if err != nil {
202-
return err
203-
}
204-
205-
_, err = ctx.KubeClient().KubeClient().CoreV1().Namespaces().Apply(
206-
ctx.Context(),
207-
applyConfiguration,
208-
metav1.ApplyOptions{
209-
FieldManager: ApplyFieldManager,
210-
Force: true,
211-
},
212-
)
213-
return err
176+
return kubectl.EnsureNamespace(ctx.Context(), ctx.KubeClient(), r.Namespace, ctx.Log())
214177
}
215178

216179
func (r *LocalRegistry) SelectRegistryPod(ctx devspacecontext.Context) (*corev1.Pod, error) {

pkg/devspace/pipeline/pipeline.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ func (p *pipeline) StartNewDependencies(ctx devspacecontext.Context, dependencie
223223
continue
224224
}
225225

226+
err := ensureNamespace(ctx, dependency.DependencyConfig().Namespace)
227+
if err != nil {
228+
return errors.Wrapf(err, "cannot run dependency %s", dependency.Name())
229+
}
226230
deployDependencies = append(deployDependencies, dependency)
227231
}
228232

@@ -257,6 +261,17 @@ func (p *pipeline) StartNewDependencies(ctx devspacecontext.Context, dependencie
257261
return t.Wait()
258262
}
259263

264+
func ensureNamespace(ctx devspacecontext.Context, namespace string) error {
265+
// If localregistry namespace is the same as devspace, we don't have
266+
// anything to do.
267+
if namespace == ctx.KubeClient().Namespace() {
268+
ctx.Log().Debugf("Namespace %s is the default Devspace namespace", namespace)
269+
return nil
270+
}
271+
272+
return kubectl.EnsureNamespace(ctx.Context(), ctx.KubeClient(), namespace, ctx.Log())
273+
}
274+
260275
func waitForDependency(ctx context.Context, start types.Pipeline, dependencyName string, log log.Logger) {
261276
// get top level pipeline
262277
for start.Parent() != nil {

0 commit comments

Comments
 (0)