Skip to content
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

Bug 1787907: kubelet: switch to ObjectMeta.UID and initialize UUID #1469

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/controller/kubelet-config/kubelet_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/jsonmergepatch"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
coreclientsetv1 "k8s.io/client-go/kubernetes/typed/core/v1"
Expand Down Expand Up @@ -227,7 +228,7 @@ func (ctrl *Controller) cascadeDelete(cfg *mcfgv1.KubeletConfig) error {
return err
}
for _, mc := range mcs.Items {
if string(mc.GetUID()) == finalizerName || mc.GetName() == finalizerName {
if string(mc.ObjectMeta.GetUID()) == finalizerName || mc.GetName() == finalizerName {
err := ctrl.client.MachineconfigurationV1().MachineConfigs().Delete(mc.GetName(), &metav1.DeleteOptions{})
if err != nil && !macherrors.IsNotFound(err) {
return err
Expand Down Expand Up @@ -474,6 +475,7 @@ func (ctrl *Controller) syncKubeletConfig(key string) error {
if isNotFound {
ignConfig := ctrlcommon.NewIgnConfig()
mc = mtmpl.MachineConfigFromIgnConfig(role, managedKey, &ignConfig)
mc.ObjectMeta.UID = uuid.NewUUID()
}
mc.Spec.Config = createNewKubeletIgnition(cfgJSON)

Expand Down Expand Up @@ -556,15 +558,17 @@ func (ctrl *Controller) addFinalizerToKubeletConfig(kc *mcfgv1.KubeletConfig, mc
return err
}

uid := string(mc.ObjectMeta.GetUID())

// if the finalizer is already set then skip
for _, finalizerName := range newcfg.Finalizers {
if finalizerName == mc.Name || finalizerName == string(mc.GetUID()) {
if finalizerName == mc.Name || finalizerName == uid {
return nil
}
}

kcTmp := newcfg.DeepCopy()
kcTmp.Finalizers = append(kcTmp.Finalizers, string(mc.GetUID()))
kcTmp.ObjectMeta.Finalizers = append(kcTmp.ObjectMeta.Finalizers, uid)

modJSON, err := json.Marshal(kcTmp)
if err != nil {
Expand Down