Skip to content

[WIP] 🌱 Stop setting and relying on TypeMeta in typed objects #12533

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 0 additions & 4 deletions bootstrap/kubeadm/internal/builder/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ func (k *KubeadmConfigBuilder) Unstructured() *unstructured.Unstructured {
// Build produces a KubeadmConfig from the variable in the KubeadmConfigBuilder.
func (k *KubeadmConfigBuilder) Build() *bootstrapv1.KubeadmConfig {
config := &bootstrapv1.KubeadmConfig{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmConfig",
APIVersion: bootstrapv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: k.namespace,
Name: k.name,
Expand Down
32 changes: 0 additions & 32 deletions bootstrap/util/configowner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ func TestHasNodeRefs(t *testing.T) {
t.Run("should return false if there is no nodeRef", func(t *testing.T) {
g := NewWithT(t)
machine := &clusterv1.Machine{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Machine",
},
ObjectMeta: metav1.ObjectMeta{
Name: "machine-name",
Namespace: metav1.NamespaceDefault,
Expand All @@ -209,10 +205,6 @@ func TestHasNodeRefs(t *testing.T) {
t.Run("should return true if there is a nodeRef for Machine", func(t *testing.T) {
g := NewWithT(t)
machine := &clusterv1.Machine{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Machine",
},
ObjectMeta: metav1.ObjectMeta{
Name: "machine-name",
Namespace: metav1.NamespaceDefault,
Expand Down Expand Up @@ -242,21 +234,13 @@ func TestHasNodeRefs(t *testing.T) {
machinePools := []clusterv1.MachinePool{
{
// No replicas specified (default is 1). No nodeRefs either.
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "MachinePool",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Name: "machine-pool-name",
},
},
{
// 1 replica but no nodeRefs
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "MachinePool",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Name: "machine-pool-name",
Expand All @@ -267,10 +251,6 @@ func TestHasNodeRefs(t *testing.T) {
},
{
// 2 replicas but only 1 nodeRef
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "MachinePool",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Name: "machine-pool-name",
Expand Down Expand Up @@ -308,10 +288,6 @@ func TestHasNodeRefs(t *testing.T) {
machinePools := []clusterv1.MachinePool{
{
// 1 replica (default) and 1 nodeRef
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "MachinePool",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Name: "machine-pool-name",
Expand All @@ -328,10 +304,6 @@ func TestHasNodeRefs(t *testing.T) {
},
{
// 2 replicas and nodeRefs
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "MachinePool",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Name: "machine-pool-name",
Expand All @@ -356,10 +328,6 @@ func TestHasNodeRefs(t *testing.T) {
},
{
// 0 replicas and 0 nodeRef
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "MachinePool",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: metav1.NamespaceDefault,
Name: "machine-pool-name",
Expand Down
8 changes: 1 addition & 7 deletions controllers/external/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/go-logr/logr"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/cache/informertest"
Expand Down Expand Up @@ -83,12 +82,7 @@ func TestWatchMultipleTimes(t *testing.T) {
ctrl := &watchCountController{}
tracker := ObjectTracker{Controller: ctrl, Scheme: runtime.NewScheme(), Cache: &informertest.FakeInformers{}, PredicateLogger: ptr.To(logr.New(log.NullLogSink{}))}

obj := &clusterv1.Cluster{
TypeMeta: metav1.TypeMeta{
Kind: "Cluster",
APIVersion: clusterv1.GroupVersion.Version,
},
}
obj := &clusterv1.Cluster{}
err := tracker.Watch(logger, obj, nil)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(ctrl.count).Should(Equal(1))
Expand Down
1 change: 0 additions & 1 deletion controlplane/kubeadm/internal/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ func machineListForTestGetMachinesForCluster() *clusterv1.MachineList {
}
machine := func(name string) clusterv1.Machine {
return clusterv1.Machine{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: metav1.NamespaceDefault,
Expand Down
36 changes: 0 additions & 36 deletions controlplane/kubeadm/internal/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,6 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
},
}
cfg := &bootstrapv1.KubeadmConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: bootstrapv1.GroupVersion.String(),
Kind: "KubeadmConfig",
},
ObjectMeta: metav1.ObjectMeta{
Namespace: cluster.Namespace,
Name: name,
Expand Down Expand Up @@ -1744,10 +1740,6 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {
JoinConfiguration: &bootstrapv1.JoinConfiguration{},
}
existingKubeadmConfig := &bootstrapv1.KubeadmConfig{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmConfig",
APIVersion: bootstrapv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "existing-kubeadmconfig",
Namespace: namespace.Name,
Expand Down Expand Up @@ -1775,10 +1767,6 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {
// Existing Machine to validate in-place mutation
fd := "fd1"
inPlaceMutatingMachine := &clusterv1.Machine{
TypeMeta: metav1.TypeMeta{
Kind: "Machine",
APIVersion: clusterv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "existing-machine",
Namespace: namespace.Name,
Expand Down Expand Up @@ -1814,10 +1802,6 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {

// Existing machine that is in deleting state
deletingMachine := &clusterv1.Machine{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Machine",
},
ObjectMeta: metav1.ObjectMeta{
Name: "deleting-machine",
Namespace: namespace.Name,
Expand Down Expand Up @@ -1856,10 +1840,6 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {

// Existing machine that has a InfrastructureRef which does not exist.
nilInfraMachineMachine := &clusterv1.Machine{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Machine",
},
ObjectMeta: metav1.ObjectMeta{
Name: "nil-infra-machine-machine",
Namespace: namespace.Name,
Expand All @@ -1883,10 +1863,6 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {
// Delete the machine to put it in the deleting state

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
UID: types.UID("abc-123-control-plane"),
Name: "existing-kcp",
Expand Down Expand Up @@ -3798,10 +3774,6 @@ func createClusterWithControlPlane(namespace string) (*clusterv1.Cluster, *contr
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
APIVersion: controlplanev1.GroupVersion.String(),
Kind: "KubeadmControlPlane",
},
ObjectMeta: metav1.ObjectMeta{
Name: kcpName,
Namespace: namespace,
Expand Down Expand Up @@ -3866,10 +3838,6 @@ func setKCPHealthy(kcp *controlplanev1.KubeadmControlPlane) {

func createMachineNodePair(name string, cluster *clusterv1.Cluster, kcp *controlplanev1.KubeadmControlPlane, ready bool) (*clusterv1.Machine, *corev1.Node) {
machine := &clusterv1.Machine{
TypeMeta: metav1.TypeMeta{
Kind: "Machine",
APIVersion: clusterv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: cluster.Namespace,
Name: name,
Expand Down Expand Up @@ -3931,10 +3899,6 @@ func setMachineHealthy(m *clusterv1.Machine) {
// newCluster return a CAPI cluster object.
func newCluster(namespacedName *types.NamespacedName) *clusterv1.Cluster {
return &clusterv1.Cluster{
TypeMeta: metav1.TypeMeta{
Kind: "Cluster",
APIVersion: clusterv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: namespacedName.Namespace,
Name: namespacedName.Name,
Expand Down
4 changes: 0 additions & 4 deletions controlplane/kubeadm/internal/controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,6 @@ func (r *KubeadmControlPlaneReconciler) computeDesiredMachine(kcp *controlplanev

// Construct the basic Machine.
desiredMachine := &clusterv1.Machine{
TypeMeta: metav1.TypeMeta{
APIVersion: clusterv1.GroupVersion.String(),
Kind: "Machine",
},
ObjectMeta: metav1.ObjectMeta{
UID: machineUID,
Name: machineName,
Expand Down
36 changes: 0 additions & 36 deletions controlplane/kubeadm/internal/controllers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ func TestReconcileKubeconfigEmptyAPIEndpoints(t *testing.T) {
g := NewWithT(t)

cluster := &clusterv1.Cluster{
TypeMeta: metav1.TypeMeta{
Kind: "Cluster",
APIVersion: clusterv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: metav1.NamespaceDefault,
Expand All @@ -60,10 +56,6 @@ func TestReconcileKubeconfigEmptyAPIEndpoints(t *testing.T) {
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: metav1.NamespaceDefault,
Expand Down Expand Up @@ -102,10 +94,6 @@ func TestReconcileKubeconfigMissingCACertificate(t *testing.T) {
g := NewWithT(t)

cluster := &clusterv1.Cluster{
TypeMeta: metav1.TypeMeta{
Kind: "Cluster",
APIVersion: clusterv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: metav1.NamespaceDefault,
Expand All @@ -116,10 +104,6 @@ func TestReconcileKubeconfigMissingCACertificate(t *testing.T) {
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: metav1.NamespaceDefault,
Expand Down Expand Up @@ -157,10 +141,6 @@ func TestReconcileKubeconfigSecretDoesNotAdoptsUserSecrets(t *testing.T) {
g := NewWithT(t)

cluster := &clusterv1.Cluster{
TypeMeta: metav1.TypeMeta{
Kind: "Cluster",
APIVersion: clusterv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: metav1.NamespaceDefault,
Expand All @@ -171,10 +151,6 @@ func TestReconcileKubeconfigSecretDoesNotAdoptsUserSecrets(t *testing.T) {
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: metav1.NamespaceDefault,
Expand Down Expand Up @@ -232,10 +208,6 @@ func TestKubeadmControlPlaneReconciler_reconcileKubeconfig(t *testing.T) {
g := NewWithT(t)

cluster := &clusterv1.Cluster{
TypeMeta: metav1.TypeMeta{
Kind: "Cluster",
APIVersion: clusterv1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: metav1.NamespaceDefault,
Expand All @@ -246,10 +218,6 @@ func TestKubeadmControlPlaneReconciler_reconcileKubeconfig(t *testing.T) {
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: metav1.NamespaceDefault,
Expand Down Expand Up @@ -1075,10 +1043,6 @@ func TestKubeadmControlPlaneReconciler_adoptKubeconfigSecret(t *testing.T) {
userProvidedKubeadmConfigSecretOtherOwner.OwnerReferences = []metav1.OwnerReference{otherOwner}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "testControlPlane",
Namespace: metav1.NamespaceDefault,
Expand Down
20 changes: 0 additions & 20 deletions controlplane/kubeadm/internal/controllers/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1966,10 +1966,6 @@ func TestKubeadmControlPlaneReconciler_updateStatusNoMachines(t *testing.T) {
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: cluster.Namespace,
Name: "foo",
Expand Down Expand Up @@ -2120,10 +2116,6 @@ func TestKubeadmControlPlaneReconciler_updateStatusAllMachinesNotReady(t *testin
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: cluster.Namespace,
Name: "foo",
Expand Down Expand Up @@ -2192,10 +2184,6 @@ func TestKubeadmControlPlaneReconciler_updateStatusAllMachinesReady(t *testing.T
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: cluster.Namespace,
Name: "foo",
Expand Down Expand Up @@ -2271,10 +2259,6 @@ func TestKubeadmControlPlaneReconciler_updateStatusMachinesReadyMixed(t *testing
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: cluster.Namespace,
Name: "foo",
Expand Down Expand Up @@ -2349,10 +2333,6 @@ func TestKubeadmControlPlaneReconciler_machinesCreatedIsIsTrueEvenWhenTheNodesAr
}

kcp := &controlplanev1.KubeadmControlPlane{
TypeMeta: metav1.TypeMeta{
Kind: "KubeadmControlPlane",
APIVersion: controlplanev1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: cluster.Namespace,
Name: "foo",
Expand Down
Loading