Skip to content

Add ClusterNamespace Annotations to Worker Nodes #1924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/admission/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ func (ad *admissionData) defaultAndValidateMachineSpec(ctx context.Context, spec
}
}

// For KubeVirt we need to initialize the annotations for MachineDeployment, to enable setting of the needed annotations.
if providerConfig.CloudProvider == providerconfig.CloudProviderKubeVirt {
if spec.Annotations == nil {
spec.Annotations = make(map[string]string)
}
}

configResolver := configvar.NewResolver(ctx, ad.workerClient)
prov, err := cloudprovider.ForProvider(providerConfig.CloudProvider, configResolver)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/cloudprovider/provider/kubevirt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ const (
// node affinity constraints on a PersistentVolume.
topologyRegionKey = "topology.kubernetes.io/region"
topologyZoneKey = "topology.kubernetes.io/zone"
// clusterNamespace represents the infra cluster namespace, where KubeVirt resources are created.
clusterNamespace = "cluster.x-k8s.io/cluster-namespace"
)

type provider struct {
Expand Down Expand Up @@ -674,6 +676,13 @@ func (p *provider) AddDefaults(_ *zap.SugaredLogger, spec clusterv1alpha1.Machin
return spec, err
}

annotations := spec.Annotations
if annotations == nil {
annotations = make(map[string]string)
}

annotations[clusterNamespace] = c.Namespace
spec.Annotations = annotations
if err := appendTopologiesLabels(context.TODO(), c, spec.Labels); err != nil {
return spec, err
}
Expand Down