Skip to content

Commit

Permalink
fix: default the manifest namespace if not set
Browse files Browse the repository at this point in the history
This seems to happen specifically for CRDs, regular Kubernetes resources
have some extra magic.

Fixes #6663

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Dec 22, 2022
1 parent 3c6cce5 commit 9a5f4c0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/app/machined/pkg/controllers/k8s/manifest_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/siderolabs/go-pointer"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -245,7 +246,13 @@ func (ctrl *ManifestApplyController) apply(ctx context.Context, logger *zap.Logg
}

var dr dynamic.ResourceInterface

if mapping.Scope.Name() == meta.RESTScopeNameNamespace {
// default the namespace if it's not set in the manifest
if obj.GetNamespace() == "" {
obj.SetNamespace(corev1.NamespaceDefault)
}

// namespaced resources should specify the namespace
dr = dyn.Resource(mapping.Resource).Namespace(obj.GetNamespace())
} else {
Expand Down

0 comments on commit 9a5f4c0

Please sign in to comment.