Skip to content

Commit

Permalink
machine: use correct APIVersion for KCP related exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Nov 28, 2024
1 parent 3b38f5d commit aaa2cbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 10 additions & 4 deletions internal/controllers/machine/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,17 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, s *scope) (ctrl.Result
return ctrl.Result{}, nil
}

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

// KubeadmControlPlanePreTerminateHookCleanupAnnotation inlined from KCP (we want to avoid importing the KCP API package).
KubeadmControlPlanePreTerminateHookCleanupAnnotation = clusterv1.PreTerminateDeleteHookAnnotationPrefix + "/kcp-cleanup"
)

func (r *Reconciler) isNodeDrainAllowed(m *clusterv1.Machine) bool {
if util.IsControlPlaneMachine(m) && util.HasOwner(m.GetOwnerReferences(), clusterv1.GroupVersion.String(), []string{"KubeadmControlPlane"}) {
// TODO(chrischdi) check why this does not work
if util.IsControlPlaneMachine(m) && util.HasOwner(m.GetOwnerReferences(), KubeadmControlPlaneAPIVersion, []string{"KubeadmControlPlane"}) {
if _, exists := m.Annotations[KubeadmControlPlanePreTerminateHookCleanupAnnotation]; !exists {
return false
}
Expand All @@ -658,7 +664,7 @@ func (r *Reconciler) isNodeDrainAllowed(m *clusterv1.Machine) bool {
// isNodeVolumeDetachingAllowed returns False if either ExcludeWaitForNodeVolumeDetachAnnotation annotation is set OR
// nodeVolumeDetachTimeoutExceeded timeout is exceeded, otherwise returns True.
func (r *Reconciler) isNodeVolumeDetachingAllowed(m *clusterv1.Machine) bool {
if util.IsControlPlaneMachine(m) && util.HasOwner(m.GetOwnerReferences(), clusterv1.GroupVersion.String(), []string{"KubeadmControlPlane"}) {
if util.IsControlPlaneMachine(m) && util.HasOwner(m.GetOwnerReferences(), "controlplane.cluster.x-k8s.io/v1beta1", []string{"KubeadmControlPlane"}) {
if _, exists := m.Annotations[KubeadmControlPlanePreTerminateHookCleanupAnnotation]; !exists {
return false
}
Expand Down
8 changes: 4 additions & 4 deletions internal/controllers/machine/machine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ func TestIsNodeDrainedAllowed(t *testing.T) {
Annotations: map[string]string{KubeadmControlPlanePreTerminateHookCleanupAnnotation: ""},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: clusterv1.GroupVersion.String(),
APIVersion: KubeadmControlPlaneAPIVersion,
Kind: "KubeadmControlPlane",
Name: "Foo",
},
Expand All @@ -1390,7 +1390,7 @@ func TestIsNodeDrainedAllowed(t *testing.T) {
Labels: map[string]string{clusterv1.MachineControlPlaneLabel: ""},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: clusterv1.GroupVersion.String(),
APIVersion: KubeadmControlPlaneAPIVersion,
Kind: "KubeadmControlPlane",
Name: "Foo",
},
Expand Down Expand Up @@ -1927,7 +1927,7 @@ func TestIsNodeVolumeDetachingAllowed(t *testing.T) {
Annotations: map[string]string{KubeadmControlPlanePreTerminateHookCleanupAnnotation: ""},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: clusterv1.GroupVersion.String(),
APIVersion: KubeadmControlPlaneAPIVersion,
Kind: "KubeadmControlPlane",
Name: "Foo",
},
Expand All @@ -1951,7 +1951,7 @@ func TestIsNodeVolumeDetachingAllowed(t *testing.T) {
Labels: map[string]string{clusterv1.MachineControlPlaneLabel: ""},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: clusterv1.GroupVersion.String(),
APIVersion: KubeadmControlPlaneAPIVersion,
Kind: "KubeadmControlPlane",
Name: "Foo",
},
Expand Down

0 comments on commit aaa2cbf

Please sign in to comment.