Skip to content

Commit 7b143f8

Browse files
authored
Add ClusterNamespace Annotations to Worker Nodes (#1924) (#1926)
* add clusterNamespace annotations * initialize annotation (cherry picked from commit 7a93ac5) Signed-off-by: moadqassem <moad.qassem@gmail.com>
1 parent 6b5ac69 commit 7b143f8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/admission/machines.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ func (ad *admissionData) defaultAndValidateMachineSpec(ctx context.Context, spec
129129
}
130130
}
131131

132+
// For KubeVirt we need to initialize the annotations for MachineDeployment, to enable setting of the needed annotations.
133+
if providerConfig.CloudProvider == providerconfigtypes.CloudProviderKubeVirt {
134+
if spec.Annotations == nil {
135+
spec.Annotations = make(map[string]string)
136+
}
137+
}
138+
132139
skg := providerconfig.NewConfigVarResolver(ctx, ad.workerClient)
133140
prov, err := cloudprovider.ForProvider(providerConfig.CloudProvider, skg)
134141
if err != nil {

pkg/cloudprovider/provider/kubevirt/provider.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ const (
8181
// node affinity constraints on a PersistentVolume.
8282
topologyRegionKey = "topology.kubernetes.io/region"
8383
topologyZoneKey = "topology.kubernetes.io/zone"
84+
// clusterNamespace represents the infra cluster namespace, where KubeVirt resources are created.
85+
clusterNamespace = "cluster.x-k8s.io/cluster-namespace"
8486
)
8587

8688
type provider struct {
@@ -675,6 +677,13 @@ func (p *provider) AddDefaults(_ *zap.SugaredLogger, spec clusterv1alpha1.Machin
675677
return spec, err
676678
}
677679

680+
annotations := spec.Annotations
681+
if annotations == nil {
682+
annotations = make(map[string]string)
683+
}
684+
685+
annotations[clusterNamespace] = c.Namespace
686+
spec.Annotations = annotations
678687
if err := appendTopologiesLabels(context.TODO(), c, spec.Labels); err != nil {
679688
return spec, err
680689
}

0 commit comments

Comments
 (0)