Skip to content

Commit 3bedfd0

Browse files
authored
Label Machine objects with configured OS (#924)
Signed-off-by: Artiom Diomin <[email protected]>
1 parent 1ba5d0c commit 3bedfd0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/admission/machines.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ func (ad *admissionData) mutateMachines(ar admissionv1.AdmissionRequest) (*admis
8888
common.SetKubeletFlags(&machine, map[common.KubeletFlags]string{
8989
common.ExternalCloudProviderKubeletFlag: fmt.Sprintf("%t", ad.nodeSettings.ExternalCloudProvider),
9090
})
91+
providerConfig, err := providerconfigtypes.GetConfig(machine.Spec.ProviderSpec)
92+
if err != nil {
93+
return nil, err
94+
}
95+
common.SetOSLabel(&machine, string(providerConfig.OperatingSystem))
9196
}
9297

9398
return createAdmissionResponse(machineOriginal, &machine)

pkg/apis/cluster/common/consts.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,17 @@ func GetKubeletFlags(metaobj metav1.Object) map[KubeletFlags]string {
193193
}
194194
return result
195195
}
196+
197+
const OperatingSystemLabelV1 = "v1.machine-controller.kubermatic.io/operating-system"
198+
199+
func SetOSLabel(metaobj metav1.Object, osName string) {
200+
lbs := metaobj.GetLabels()
201+
202+
if _, found := lbs[OperatingSystemLabelV1]; !found {
203+
if lbs == nil {
204+
lbs = map[string]string{}
205+
}
206+
lbs[OperatingSystemLabelV1] = osName
207+
metaobj.SetLabels(lbs)
208+
}
209+
}

0 commit comments

Comments
 (0)