Repository: kubernetes-sigs/cluster-api
Pull request #9315 (2023-08-25 14:33:58)

:bug: Fix tilt-prepare leader-elect setting
Explicitly set `--leader-elect` to false instead of removing it when running tilt-prepare. This helps for providers which set leader-elect to true by default.

/area devtools


Patch:
diff --git a/docs/book/src/reference/versions.md b/docs/book/src/reference/versions.md
index 2d3e14426..6856cac39 100644
--- a/docs/book/src/reference/versions.md
+++ b/docs/book/src/reference/versions.md
@@ -143,9 +143,7 @@ The Kubeadm Control Plane requires the Kubeadm Bootstrap Provider.
 | v1.3 (v1beta1)       | v1.10.0                         |
 | >= v1.3.4 (v1beta1)  | v1.10.1                         |
 | v1.4 (v1beta1)       | v1.10.1                         |
-| >= v1.4.6 (v1beta1)  | v1.11.1                         |
 | v1.5 (v1beta1)       | v1.10.1                         |
-| >= v1.5.1 (v1beta1)  | v1.11.1                         |
 
 #### Kubernetes version specific notes
 
diff --git a/go.mod b/go.mod
index 4b1f12e92..d75a9bc7e 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ require (
 	github.com/Masterminds/sprig/v3 v3.2.3
 	github.com/adrg/xdg v0.4.0
 	github.com/blang/semver/v4 v4.0.0
-	github.com/coredns/corefile-migration v1.0.21
+	github.com/coredns/corefile-migration v1.0.20
 	github.com/davecgh/go-spew v1.1.1
 	github.com/docker/distribution v2.8.2+incompatible
 	github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46
diff --git a/go.sum b/go.sum
index 883dd7917..9b22c89d6 100644
--- a/go.sum
+++ b/go.sum
@@ -102,8 +102,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
 github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
 github.com/coredns/caddy v1.1.0 h1:ezvsPrT/tA/7pYDBZxu0cT0VmWk75AfIaf6GSYCNMf0=
 github.com/coredns/caddy v1.1.0/go.mod h1:A6ntJQlAWuQfFlsd9hvigKbo2WS0VUs2l1e2F+BawD4=
-github.com/coredns/corefile-migration v1.0.21 h1:W/DCETrHDiFo0Wj03EyMkaQ9fwsmSgqTCQDHpceaSsE=
-github.com/coredns/corefile-migration v1.0.21/go.mod h1:XnhgULOEouimnzgn0t4WPuFDN2/PJQcTxdWKC5eXNGE=
+github.com/coredns/corefile-migration v1.0.20 h1:MdOkT6F3ehju/n9tgxlGct8XAajOX2vN+wG7To4BWSI=
+github.com/coredns/corefile-migration v1.0.20/go.mod h1:XnhgULOEouimnzgn0t4WPuFDN2/PJQcTxdWKC5eXNGE=
 github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
 github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
 github.com/coreos/go-semver v0.1.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
diff --git a/hack/tools/go.mod b/hack/tools/go.mod
index 69687852e..bbe951e89 100644
--- a/hack/tools/go.mod
+++ b/hack/tools/go.mod
@@ -47,7 +47,7 @@ require (
 	github.com/cespare/xxhash/v2 v2.2.0 // indirect
 	github.com/cloudflare/circl v1.3.3 // indirect
 	github.com/coredns/caddy v1.1.0 // indirect
-	github.com/coredns/corefile-migration v1.0.21 // indirect
+	github.com/coredns/corefile-migration v1.0.20 // indirect
 	github.com/davecgh/go-spew v1.1.1 // indirect
 	github.com/docker/distribution v2.8.2+incompatible // indirect
 	github.com/docker/docker v24.0.5+incompatible // indirect
diff --git a/hack/tools/go.sum b/hack/tools/go.sum
index 4b8daa08a..eb0ea7caf 100644
--- a/hack/tools/go.sum
+++ b/hack/tools/go.sum
@@ -107,8 +107,8 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH
 github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
 github.com/coredns/caddy v1.1.0 h1:ezvsPrT/tA/7pYDBZxu0cT0VmWk75AfIaf6GSYCNMf0=
 github.com/coredns/caddy v1.1.0/go.mod h1:A6ntJQlAWuQfFlsd9hvigKbo2WS0VUs2l1e2F+BawD4=
-github.com/coredns/corefile-migration v1.0.21 h1:W/DCETrHDiFo0Wj03EyMkaQ9fwsmSgqTCQDHpceaSsE=
-github.com/coredns/corefile-migration v1.0.21/go.mod h1:XnhgULOEouimnzgn0t4WPuFDN2/PJQcTxdWKC5eXNGE=
+github.com/coredns/corefile-migration v1.0.20 h1:MdOkT6F3ehju/n9tgxlGct8XAajOX2vN+wG7To4BWSI=
+github.com/coredns/corefile-migration v1.0.20/go.mod h1:XnhgULOEouimnzgn0t4WPuFDN2/PJQcTxdWKC5eXNGE=
 github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
 github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
 github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
diff --git a/hack/tools/internal/tilt-prepare/main.go b/hack/tools/internal/tilt-prepare/main.go
index 277fa4710..8bf3f2973 100644
--- a/hack/tools/internal/tilt-prepare/main.go
+++ b/hack/tools/internal/tilt-prepare/main.go
@@ -806,7 +806,7 @@ func prepareWorkload(name, prefix, binaryName, containerName string, objs []unst
 				debugArgs := make([]string, 0, len(args))
 				for _, a := range args {
 					if a == "--leader-elect" || a == "--leader-elect=true" {
-						continue
+						a = "--leader-elect=false"
 					}
 					debugArgs = append(debugArgs, a)
 				}


Test patch:
diff --git a/test/framework/ownerreference_helpers.go b/test/framework/ownerreference_helpers.go
index 0b727891d..124037a17 100644
--- a/test/framework/ownerreference_helpers.go
+++ b/test/framework/ownerreference_helpers.go
@@ -30,7 +30,6 @@ import (
 	"k8s.io/apimachinery/pkg/runtime/schema"
 	"k8s.io/apimachinery/pkg/types"
 	kerrors "k8s.io/apimachinery/pkg/util/errors"
-	"k8s.io/utils/pointer"
 	"sigs.k8s.io/controller-runtime/pkg/client"
 
 	clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -134,12 +133,12 @@ var (
 	machineDeploymentKind  = "MachineDeployment"
 	machineHealthCheckKind = "MachineHealthCheck"
 
-	clusterOwner                = metav1.OwnerReference{Kind: clusterKind, APIVersion: coreGroupVersion}
-	clusterController           = metav1.OwnerReference{Kind: clusterKind, APIVersion: coreGroupVersion, Controller: pointer.Bool(true)}
-	clusterClassOwner           = metav1.OwnerReference{Kind: clusterClassKind, APIVersion: coreGroupVersion}
-	machineDeploymentController = metav1.OwnerReference{Kind: machineDeploymentKind, APIVersion: coreGroupVersion, Controller: pointer.Bool(true)}
-	machineSetController        = metav1.OwnerReference{Kind: machineSetKind, APIVersion: coreGroupVersion, Controller: pointer.Bool(true)}
-	machineController           = metav1.OwnerReference{Kind: machineKind, APIVersion: coreGroupVersion, Controller: pointer.Bool(true)}
+	clusterOwner                = simpleOwnerRef{kind: clusterKind, apiVersion: coreGroupVersion}
+	clusterController           = simpleOwnerRef{kind: clusterKind, apiVersion: coreGroupVersion, controller: true}
+	clusterClassOwner           = simpleOwnerRef{kind: clusterClassKind, apiVersion: coreGroupVersion}
+	machineDeploymentController = simpleOwnerRef{kind: machineDeploymentKind, apiVersion: coreGroupVersion, controller: true}
+	machineSetController        = simpleOwnerRef{kind: machineSetKind, apiVersion: coreGroupVersion, controller: true}
+	machineController           = simpleOwnerRef{kind: machineKind, apiVersion: coreGroupVersion, controller: true}
 )
 
 // CoreOwnerReferenceAssertion maps Cluster API core types to functions which return an error if the passed
@@ -169,7 +168,7 @@ var CoreOwnerReferenceAssertion = map[string]func([]metav1.OwnerReference) error
 	},
 	machineKind: func(owners []metav1.OwnerReference) error {
 		// Machines must be owned and controlled by a MachineSet or a KubeadmControlPlane, depending on if this Machine is part of a ControlPlane or not.
-		return HasOneOfExactOwners(owners, []metav1.OwnerReference{machineSetController}, []metav1.OwnerReference{kubeadmControlPlaneController})
+		return HasOneOfExactOwners(owners, []simpleOwnerRef{machineSetController}, []simpleOwnerRef{kubeadmControlPlaneController})
 	},
 	machineHealthCheckKind: func(owners []metav1.OwnerReference) error {
 		// MachineHealthChecks must be owned by the Cluster.
@@ -183,10 +182,10 @@ var (
 	clusterResourceSetBindingKind = "ClusterResourceSetBinding"
 	machinePoolKind               = "MachinePool"
 
-	machinePoolOwner      = metav1.OwnerReference{Kind: machinePoolKind, APIVersion: expv1.GroupVersion.String()}
-	machinePoolController = metav1.OwnerReference{Kind: machinePoolKind, APIVersion: expv1.GroupVersion.String(), Controller: pointer.Bool(true)}
+	machinePoolOwner      = simpleOwnerRef{kind: machinePoolKind, apiVersion: expv1.GroupVersion.String()}
+	machinePoolController = simpleOwnerRef{kind: machinePoolKind, apiVersion: expv1.GroupVersion.String(), controller: true}
 
-	clusterResourceSetOwner = metav1.OwnerReference{Kind: clusterResourceSetKind, APIVersion: addonsv1.GroupVersion.String()}
+	clusterResourceSetOwner = simpleOwnerRef{kind: clusterResourceSetKind, apiVersion: addonsv1.GroupVersion.String()}
 )
 
 // ExpOwnerReferenceAssertions maps experimental types to functions which return an error if the passed OwnerReferences
@@ -200,7 +199,7 @@ var ExpOwnerReferenceAssertions = map[string]func([]metav1.OwnerReference) error
 	},
 	// ClusterResourcesSetBinding has ClusterResourceSet set as owners on creation.
 	clusterResourceSetBindingKind: func(owners []metav1.OwnerReference) error {
-		return HasOneOfExactOwners(owners, []metav1.OwnerReference{clusterResourceSetOwner}, []metav1.OwnerReference{clusterResourceSetOwner, clusterResourceSetOwner})
+		return HasOneOfExactOwners(owners, []simpleOwnerRef{clusterResourceSetOwner}, []simpleOwnerRef{clusterResourceSetOwner, clusterResourceSetOwner})
 	},
 	// MachinePool must be owned by a Cluster.
 	machinePoolKind: func(owners []metav1.OwnerReference) error {
@@ -221,7 +220,7 @@ var (
 var KubernetesReferenceAssertions = map[string]func([]metav1.OwnerReference) error{
 	secretKind: func(owners []metav1.OwnerReference) error {
 		// Secrets for cluster certificates must be owned and controlled by the KubeadmControlPlane. The bootstrap secret should be owned and controlled by a KubeadmControlPlane.
-		return HasOneOfExactOwners(owners, []metav1.OwnerReference{kubeadmControlPlaneController}, []metav1.OwnerReference{kubeadmConfigController})
+		return HasOneOfExactOwners(owners, []simpleOwnerRef{kubeadmControlPlaneController}, []simpleOwnerRef{kubeadmConfigController})
 	},
 	configMapKind: func(owners []metav1.OwnerReference) error {
 		// The only configMaps considered here are those owned by a ClusterResourceSet.
@@ -236,7 +235,7 @@ var (
 
 	kubeadmControlPlaneGroupVersion = controlplanev1.GroupVersion.String()
 
-	kubeadmControlPlaneController = metav1.OwnerReference{Kind: kubeadmControlPlaneKind, APIVersion: kubeadmControlPlaneGroupVersion, Controller: pointer.Bool(true)}
+	kubeadmControlPlaneController = simpleOwnerRef{kind: kubeadmControlPlaneKind, apiVersion: kubeadmControlPlaneGroupVersion, controller: true}
 )
 
 // KubeadmControlPlaneOwnerReferenceAssertions maps Kubeadm control plane types to functions which return an error if the passed
@@ -260,7 +259,7 @@ var (
 	kubeadmConfigTemplateKind = "KubeadmConfigTemplate"
 
 	kubeadmConfigGroupVersion = bootstrapv1.GroupVersion.String()
-	kubeadmConfigController   = metav1.OwnerReference{Kind: kubeadmConfigKind, APIVersion: kubeadmConfigGroupVersion, Controller: pointer.Bool(true)}
+	kubeadmConfigController   = simpleOwnerRef{kind: kubeadmConfigKind, apiVersion: kubeadmConfigGroupVersion, controller: true}
 )
 
 // KubeadmBootstrapOwnerReferenceAssertions maps KubeadmBootstrap types to functions which return an error if the passed OwnerReferences
@@ -270,11 +269,11 @@ var (
 var KubeadmBootstrapOwnerReferenceAssertions = map[string]func([]metav1.OwnerReference) error{
 	kubeadmConfigKind: func(owners []metav1.OwnerReference) error {
 		// The KubeadmConfig must be owned and controlled by a Machine or MachinePool.
-		return HasOneOfExactOwners(owners, []metav1.OwnerReference{machineController}, []metav1.OwnerReference{machinePoolController})
+		return HasOneOfExactOwners(owners, []simpleOwnerRef{machineController}, []simpleOwnerRef{machinePoolController})
 	},
 	kubeadmConfigTemplateKind: func(owners []metav1.OwnerReference) error {
 		// The KubeadmConfigTemplate must be owned by a ClusterClass.
-		return HasOneOfExactOwners(owners, []metav1.OwnerReference{clusterOwner}, []metav1.OwnerReference{clusterClassOwner})
+		return HasOneOfExactOwners(owners, []simpleOwnerRef{clusterOwner}, []simpleOwnerRef{clusterClassOwner})
 	},
 }
 
@@ -299,7 +298,7 @@ var DockerInfraOwnerReferenceAssertions = map[string]func([]metav1.OwnerReferenc
 	dockerMachineTemplateKind: func(owners []metav1.OwnerReference) error {
 		// Base DockerMachineTemplates referenced in a ClusterClass must be owned by the ClusterClass.
 		// DockerMachineTemplates created for specific Clusters in the Topology controller must be owned by a Cluster.
-		return HasOneOfExactOwners(owners, []metav1.OwnerReference{clusterOwner}, []metav1.OwnerReference{clusterClassOwner})
+		return HasOneOfExactOwners(owners, []simpleOwnerRef{clusterOwner}, []simpleOwnerRef{clusterClassOwner})
 	},
 	dockerClusterKind: func(owners []metav1.OwnerReference) error {
 		// DockerCluster must be owned and controlled by a Cluster.
@@ -315,35 +314,48 @@ var DockerInfraOwnerReferenceAssertions = map[string]func([]metav1.OwnerReferenc
 	},
 }
 
-func HasExactOwners(gotOwners []metav1.OwnerReference, wantOwners ...metav1.OwnerReference) error {
-	wantComparable := []string{}
-	gotComparable := []string{}
-	for _, ref := range gotOwners {
-		gotComparable = append(gotComparable, ownerReferenceString(ref))
+// simpleOwnerRef is a simple representation of an ownerReference.
+type simpleOwnerRef struct {
+	kind       string
+	apiVersion string
+	controller bool
+}
+
+func (s simpleOwnerRef) String() string {
+	return fmt.Sprintf("%s/%s/%v", s.apiVersion, s.kind, s.controller)
+}
+
+func HasExactOwners(refList []metav1.OwnerReference, wantOwners ...simpleOwnerRef) error {
+	gotOwners := []simpleOwnerRef{}
+	if wantOwners == nil {
+		wantOwners = []simpleOwnerRef{}
 	}
-	for _, ref := range wantOwners {
-		wantComparable = append(wantComparable, ownerReferenceString(ref))
+	for _, ref := range refList {
+		simpleRef := simpleOwnerRef{
+			kind:       ref.Kind,
+			apiVersion: ref.APIVersion,
+		}
+		simpleRef.controller = true
+		if ref.Controller == nil || !*ref.Controller {
+			simpleRef.controller = false
+		}
+		gotOwners = append(gotOwners, simpleRef)
 	}
-	sort.Strings(gotComparable)
-	sort.Strings(wantComparable)
-
-	if !reflect.DeepEqual(gotComparable, wantComparable) {
+	sort.SliceStable(gotOwners, func(i int, j int) bool {
+		return gotOwners[i].String() > gotOwners[j].String()
+	})
+	sort.SliceStable(wantOwners, func(i int, j int) bool {
+		return wantOwners[i].String() > wantOwners[j].String()
+	})
+	if !reflect.DeepEqual(wantOwners, gotOwners) {
 		return fmt.Errorf("wanted %v, actual %v", wantOwners, gotOwners)
 	}
 	return nil
 }
 
-func ownerReferenceString(ref metav1.OwnerReference) string {
-	controller := false
-	if ref.Controller != nil && *ref.Controller {
-		controller = true
-	}
-	return fmt.Sprintf("%s/%s/%v", ref.APIVersion, ref.Kind, controller)
-}
-
 // HasOneOfExactOwners is a convenience approach for checking owner references on objects that can have different owner references depending on the cluster.
 // In a follow-up iteration we can make improvements to check owner references according to the specific use cases vs checking generically "oneOf".
-func HasOneOfExactOwners(refList []metav1.OwnerReference, possibleOwners ...[]metav1.OwnerReference) error {
+func HasOneOfExactOwners(refList []metav1.OwnerReference, possibleOwners ...[]simpleOwnerRef) error {
 	var allErrs []error
 	for _, wantOwner := range possibleOwners {
 		err := HasExactOwners(refList, wantOwner...)
diff --git a/test/go.mod b/test/go.mod
index 06546efff..a20dddbee 100644
--- a/test/go.mod
+++ b/test/go.mod
@@ -55,7 +55,7 @@ require (
 	github.com/cespare/xxhash/v2 v2.2.0 // indirect
 	github.com/cloudflare/circl v1.3.3 // indirect
 	github.com/coredns/caddy v1.1.0 // indirect
-	github.com/coredns/corefile-migration v1.0.21 // indirect
+	github.com/coredns/corefile-migration v1.0.20 // indirect
 	github.com/coreos/go-semver v0.3.1 // indirect
 	github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
 	github.com/coreos/go-systemd/v22 v22.5.0 // indirect
diff --git a/test/go.sum b/test/go.sum
index f0c985391..9e57d4dd7 100644
--- a/test/go.sum
+++ b/test/go.sum
@@ -112,8 +112,8 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH
 github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
 github.com/coredns/caddy v1.1.0 h1:ezvsPrT/tA/7pYDBZxu0cT0VmWk75AfIaf6GSYCNMf0=
 github.com/coredns/caddy v1.1.0/go.mod h1:A6ntJQlAWuQfFlsd9hvigKbo2WS0VUs2l1e2F+BawD4=
-github.com/coredns/corefile-migration v1.0.21 h1:W/DCETrHDiFo0Wj03EyMkaQ9fwsmSgqTCQDHpceaSsE=
-github.com/coredns/corefile-migration v1.0.21/go.mod h1:XnhgULOEouimnzgn0t4WPuFDN2/PJQcTxdWKC5eXNGE=
+github.com/coredns/corefile-migration v1.0.20 h1:MdOkT6F3ehju/n9tgxlGct8XAajOX2vN+wG7To4BWSI=
+github.com/coredns/corefile-migration v1.0.20/go.mod h1:XnhgULOEouimnzgn0t4WPuFDN2/PJQcTxdWKC5eXNGE=
 github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
 github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
 github.com/coreos/go-semver v0.1.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=