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

🐛 machine: use correct APIVersion for KCP related exclude #11490

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
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(), KubeadmControlPlaneAPIVersion, []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