Skip to content

Commit 87581de

Browse files
authored
Merge pull request #11490 from chrischdi/pr-fix-machine-controller-kcp
🐛 machine: use correct APIVersion for KCP related exclude
2 parents 3b38f5d + 67017b7 commit 87581de

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

internal/controllers/machine/machine_controller.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,17 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, s *scope) (ctrl.Result
634634
return ctrl.Result{}, nil
635635
}
636636

637-
// KubeadmControlPlanePreTerminateHookCleanupAnnotation inlined from KCP (we want to avoid importing the KCP API package).
638-
const KubeadmControlPlanePreTerminateHookCleanupAnnotation = clusterv1.PreTerminateDeleteHookAnnotationPrefix + "/kcp-cleanup"
637+
const (
638+
// KubeadmControlPlaneAPIVersion inlined from KCP (we want to avoid importing the KCP API package).
639+
KubeadmControlPlaneAPIVersion = "controlplane.cluster.x-k8s.io/v1beta1"
640+
641+
// KubeadmControlPlanePreTerminateHookCleanupAnnotation inlined from KCP (we want to avoid importing the KCP API package).
642+
KubeadmControlPlanePreTerminateHookCleanupAnnotation = clusterv1.PreTerminateDeleteHookAnnotationPrefix + "/kcp-cleanup"
643+
)
639644

640645
func (r *Reconciler) isNodeDrainAllowed(m *clusterv1.Machine) bool {
641-
if util.IsControlPlaneMachine(m) && util.HasOwner(m.GetOwnerReferences(), clusterv1.GroupVersion.String(), []string{"KubeadmControlPlane"}) {
646+
// TODO(chrischdi) check why this does not work
647+
if util.IsControlPlaneMachine(m) && util.HasOwner(m.GetOwnerReferences(), KubeadmControlPlaneAPIVersion, []string{"KubeadmControlPlane"}) {
642648
if _, exists := m.Annotations[KubeadmControlPlanePreTerminateHookCleanupAnnotation]; !exists {
643649
return false
644650
}
@@ -658,7 +664,7 @@ func (r *Reconciler) isNodeDrainAllowed(m *clusterv1.Machine) bool {
658664
// isNodeVolumeDetachingAllowed returns False if either ExcludeWaitForNodeVolumeDetachAnnotation annotation is set OR
659665
// nodeVolumeDetachTimeoutExceeded timeout is exceeded, otherwise returns True.
660666
func (r *Reconciler) isNodeVolumeDetachingAllowed(m *clusterv1.Machine) bool {
661-
if util.IsControlPlaneMachine(m) && util.HasOwner(m.GetOwnerReferences(), clusterv1.GroupVersion.String(), []string{"KubeadmControlPlane"}) {
667+
if util.IsControlPlaneMachine(m) && util.HasOwner(m.GetOwnerReferences(), KubeadmControlPlaneAPIVersion, []string{"KubeadmControlPlane"}) {
662668
if _, exists := m.Annotations[KubeadmControlPlanePreTerminateHookCleanupAnnotation]; !exists {
663669
return false
664670
}

internal/controllers/machine/machine_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ func TestIsNodeDrainedAllowed(t *testing.T) {
13661366
Annotations: map[string]string{KubeadmControlPlanePreTerminateHookCleanupAnnotation: ""},
13671367
OwnerReferences: []metav1.OwnerReference{
13681368
{
1369-
APIVersion: clusterv1.GroupVersion.String(),
1369+
APIVersion: KubeadmControlPlaneAPIVersion,
13701370
Kind: "KubeadmControlPlane",
13711371
Name: "Foo",
13721372
},
@@ -1390,7 +1390,7 @@ func TestIsNodeDrainedAllowed(t *testing.T) {
13901390
Labels: map[string]string{clusterv1.MachineControlPlaneLabel: ""},
13911391
OwnerReferences: []metav1.OwnerReference{
13921392
{
1393-
APIVersion: clusterv1.GroupVersion.String(),
1393+
APIVersion: KubeadmControlPlaneAPIVersion,
13941394
Kind: "KubeadmControlPlane",
13951395
Name: "Foo",
13961396
},
@@ -1927,7 +1927,7 @@ func TestIsNodeVolumeDetachingAllowed(t *testing.T) {
19271927
Annotations: map[string]string{KubeadmControlPlanePreTerminateHookCleanupAnnotation: ""},
19281928
OwnerReferences: []metav1.OwnerReference{
19291929
{
1930-
APIVersion: clusterv1.GroupVersion.String(),
1930+
APIVersion: KubeadmControlPlaneAPIVersion,
19311931
Kind: "KubeadmControlPlane",
19321932
Name: "Foo",
19331933
},
@@ -1951,7 +1951,7 @@ func TestIsNodeVolumeDetachingAllowed(t *testing.T) {
19511951
Labels: map[string]string{clusterv1.MachineControlPlaneLabel: ""},
19521952
OwnerReferences: []metav1.OwnerReference{
19531953
{
1954-
APIVersion: clusterv1.GroupVersion.String(),
1954+
APIVersion: KubeadmControlPlaneAPIVersion,
19551955
Kind: "KubeadmControlPlane",
19561956
Name: "Foo",
19571957
},

0 commit comments

Comments
 (0)