diff --git a/exp/internal/controllers/machinepool_controller_phases_test.go b/exp/internal/controllers/machinepool_controller_phases_test.go index 76860029fbbf..de1076b5cf6e 100644 --- a/exp/internal/controllers/machinepool_controller_phases_test.go +++ b/exp/internal/controllers/machinepool_controller_phases_test.go @@ -76,12 +76,14 @@ func TestReconcileMachinePoolPhases(t *testing.T) { APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, InfrastructureRef: corev1.ObjectReference{ APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachineTemplateKind, Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, }, @@ -795,6 +797,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, }, @@ -936,6 +939,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, DataSecretName: ptr.To("data"), }, @@ -1019,6 +1023,7 @@ func TestReconcileMachinePoolBootstrap(t *testing.T) { APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, DataSecretName: ptr.To("data"), }, @@ -1093,12 +1098,14 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, InfrastructureRef: corev1.ObjectReference{ APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachineTemplateKind, Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, }, @@ -1172,12 +1179,14 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, InfrastructureRef: corev1.ObjectReference{ APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachineTemplateKind, Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, }, @@ -1268,12 +1277,14 @@ func TestReconcileMachinePoolInfrastructure(t *testing.T) { APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, InfrastructureRef: corev1.ObjectReference{ APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachineTemplateKind, Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, }, @@ -1775,12 +1786,14 @@ func TestReconcileMachinePoolScaleToFromZero(t *testing.T) { APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "bootstrap-config1", + Namespace: ns.Name, }, }, InfrastructureRef: corev1.ObjectReference{ APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachineTemplateKind, Name: "infra-config1", + Namespace: ns.Name, }, }, }, @@ -2196,12 +2209,14 @@ func getMachinePool(replicas int, mpName, clusterName, nsName string) expv1.Mach APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.GenericBootstrapConfigKind, Name: "bootstrap-config1", + Namespace: nsName, }, }, InfrastructureRef: corev1.ObjectReference{ APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.GenericInfrastructureMachineKind, Name: "infra-config1", + Namespace: nsName, }, }, }, diff --git a/exp/internal/controllers/machinepool_controller_test.go b/exp/internal/controllers/machinepool_controller_test.go index c0c930afcb62..9706c877eea9 100644 --- a/exp/internal/controllers/machinepool_controller_test.go +++ b/exp/internal/controllers/machinepool_controller_test.go @@ -357,6 +357,7 @@ func TestReconcileMachinePoolRequest(t *testing.T) { APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachinePoolKind, Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, }, @@ -404,6 +405,7 @@ func TestReconcileMachinePoolRequest(t *testing.T) { APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachinePoolKind, Name: "infra-config1-already-deleted", // Use an InfrastructureMachinePool that doesn't exist, so reconcileDelete doesn't get stuck on deletion + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, NodeDeletionTimeout: &metav1.Duration{Duration: 10 * time.Minute}, @@ -466,6 +468,7 @@ func TestReconcileMachinePoolRequest(t *testing.T) { APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachinePoolKind, Name: "infra-config1-already-deleted", // Use an InfrastructureMachinePool that doesn't exist, so reconcileDelete doesn't get stuck on deletion + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, NodeDeletionTimeout: &metav1.Duration{Duration: 10 * time.Minute}, @@ -528,6 +531,7 @@ func TestReconcileMachinePoolRequest(t *testing.T) { APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachinePoolKind, Name: "infra-config1-already-deleted", // Use an InfrastructureMachinePool that doesn't exist, so reconcileDelete doesn't get stuck on deletion + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, NodeDeletionTimeout: &metav1.Duration{Duration: 10 * time.Second}, // timeout passed @@ -761,12 +765,14 @@ func TestReconcileMachinePoolDeleteExternal(t *testing.T) { APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachineTemplateKind, Name: "delete-infra", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{ ConfigRef: &corev1.ObjectReference{ APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "delete-bootstrap", + Namespace: metav1.NamespaceDefault, }, }, }, @@ -864,6 +870,7 @@ func TestRemoveMachinePoolFinalizerAfterDeleteReconcile(t *testing.T) { APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachineTemplateKind, Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, }, @@ -957,12 +964,14 @@ func TestMachinePoolConditions(t *testing.T) { APIVersion: builder.InfrastructureGroupVersion.String(), Kind: builder.TestInfrastructureMachineTemplateKind, Name: "infra1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{ ConfigRef: &corev1.ObjectReference{ APIVersion: builder.BootstrapGroupVersion.String(), Kind: builder.TestBootstrapConfigKind, Name: "bootstrap1", + Namespace: metav1.NamespaceDefault, }, }, }, diff --git a/internal/controllers/cluster/cluster_controller_phases_test.go b/internal/controllers/cluster/cluster_controller_phases_test.go index 41da2dbb05a0..947849bc3772 100644 --- a/internal/controllers/cluster/cluster_controller_phases_test.go +++ b/internal/controllers/cluster/cluster_controller_phases_test.go @@ -57,6 +57,7 @@ func TestClusterReconcilePhases(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "test", + Namespace: "test-namespace", }, }, } @@ -73,6 +74,7 @@ func TestClusterReconcilePhases(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "test", + Namespace: "test-namespace", }, }, } @@ -248,6 +250,7 @@ func TestClusterReconcilePhases(t *testing.T) { APIVersion: "controlplane.cluster.x-k8s.io/v1beta1", Kind: "GenericControlPlane", Name: "test", + Namespace: "test-namespace", }, }, } @@ -264,6 +267,7 @@ func TestClusterReconcilePhases(t *testing.T) { APIVersion: "controlplane.cluster.x-k8s.io/v1beta1", Kind: "GenericControlPlane", Name: "test", + Namespace: "test-namespace", }, }, } @@ -689,6 +693,7 @@ func TestClusterReconcilePhases_reconcileFailureDomains(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureCluster", Name: "test", + Namespace: "test-namespace", }, }, } diff --git a/internal/controllers/machine/machine_controller_noderef_test.go b/internal/controllers/machine/machine_controller_noderef_test.go index 69120237118e..1ef53d9750db 100644 --- a/internal/controllers/machine/machine_controller_noderef_test.go +++ b/internal/controllers/machine/machine_controller_noderef_test.go @@ -412,12 +412,14 @@ func TestNodeLabelSync(t *testing.T) { APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, InfrastructureRef: corev1.ObjectReference{ APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, } @@ -450,6 +452,8 @@ func TestNodeLabelSync(t *testing.T) { machine := defaultMachine.DeepCopy() machine.Namespace = ns.Name + machine.Spec.Bootstrap.ConfigRef.Namespace = ns.Name + machine.Spec.InfrastructureRef.Namespace = ns.Name machine.Spec.ProviderID = ptr.To(nodeProviderID) // Set Machine labels. diff --git a/internal/controllers/machine/machine_controller_phases_test.go b/internal/controllers/machine/machine_controller_phases_test.go index f0ef20a03c21..5b918f1aebeb 100644 --- a/internal/controllers/machine/machine_controller_phases_test.go +++ b/internal/controllers/machine/machine_controller_phases_test.go @@ -56,6 +56,7 @@ func TestReconcileBootstrap(t *testing.T) { APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, }, @@ -217,6 +218,7 @@ func TestReconcileBootstrap(t *testing.T) { APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, DataSecretName: ptr.To("secret-data"), }, @@ -261,6 +263,7 @@ func TestReconcileBootstrap(t *testing.T) { APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, DataSecretName: ptr.To("secret-data"), }, @@ -339,6 +342,7 @@ func TestReconcileInfrastructure(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, } @@ -619,6 +623,7 @@ func TestReconcileInfrastructure(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, ProviderID: ptr.To("test://something"), FailureDomain: ptr.To("something"), @@ -680,6 +685,7 @@ func TestReconcileInfrastructure(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, ProviderID: ptr.To("test://something"), FailureDomain: ptr.To("something"), @@ -741,6 +747,7 @@ func TestReconcileInfrastructure(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, Status: clusterv1.MachineStatus{ @@ -769,6 +776,7 @@ func TestReconcileInfrastructure(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, Status: clusterv1.MachineStatus{ @@ -799,6 +807,7 @@ func TestReconcileInfrastructure(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, Status: clusterv1.MachineStatus{ @@ -825,6 +834,7 @@ func TestReconcileInfrastructure(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, Status: clusterv1.MachineStatus{ diff --git a/internal/controllers/machine/machine_controller_status_test.go b/internal/controllers/machine/machine_controller_status_test.go index 25f7c0f5a3ef..866a0aa50049 100644 --- a/internal/controllers/machine/machine_controller_status_test.go +++ b/internal/controllers/machine/machine_controller_status_test.go @@ -49,6 +49,7 @@ func TestSetBootstrapReadyCondition(t *testing.T) { APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, }, @@ -268,6 +269,7 @@ func TestSetInfrastructureReadyCondition(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-machine1", + Namespace: metav1.NamespaceDefault, }, }, } @@ -582,6 +584,7 @@ func TestSetNodeHealthyAndReadyConditions(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-machine1", + Namespace: metav1.NamespaceDefault, }, }, } @@ -1747,12 +1750,14 @@ func TestReconcileMachinePhases(t *testing.T) { APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, InfrastructureRef: corev1.ObjectReference{ APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, }, } @@ -1801,6 +1806,8 @@ func TestReconcileMachinePhases(t *testing.T) { infraMachine.SetNamespace(ns.Name) machine := defaultMachine.DeepCopy() machine.Namespace = ns.Name + machine.Spec.InfrastructureRef.Namespace = ns.Name + machine.Spec.Bootstrap.ConfigRef.Namespace = ns.Name g.Expect(env.Create(ctx, cluster)).To(Succeed()) defaultKubeconfigSecret = kubeconfig.GenerateSecret(cluster, kubeconfig.FromEnvTestConfig(env.Config, cluster)) @@ -1853,6 +1860,8 @@ func TestReconcileMachinePhases(t *testing.T) { infraMachine.SetNamespace(ns.Name) machine := defaultMachine.DeepCopy() machine.Namespace = ns.Name + machine.Spec.InfrastructureRef.Namespace = ns.Name + machine.Spec.Bootstrap.ConfigRef.Namespace = ns.Name g.Expect(env.Create(ctx, cluster)).To(Succeed()) defaultKubeconfigSecret = kubeconfig.GenerateSecret(cluster, kubeconfig.FromEnvTestConfig(env.Config, cluster)) @@ -1896,6 +1905,8 @@ func TestReconcileMachinePhases(t *testing.T) { infraMachine.SetNamespace(ns.Name) machine := defaultMachine.DeepCopy() machine.Namespace = ns.Name + machine.Spec.InfrastructureRef.Namespace = ns.Name + machine.Spec.Bootstrap.ConfigRef.Namespace = ns.Name g.Expect(env.Create(ctx, cluster)).To(Succeed()) defaultKubeconfigSecret = kubeconfig.GenerateSecret(cluster, kubeconfig.FromEnvTestConfig(env.Config, cluster)) @@ -1956,6 +1967,8 @@ func TestReconcileMachinePhases(t *testing.T) { g.Expect(unstructured.SetNestedField(infraMachine.Object, "us-east-2a", "spec", "failureDomain")).To(Succeed()) machine := defaultMachine.DeepCopy() machine.Namespace = ns.Name + machine.Spec.InfrastructureRef.Namespace = ns.Name + machine.Spec.Bootstrap.ConfigRef.Namespace = ns.Name // Create Node. node := &corev1.Node{ @@ -2045,6 +2058,8 @@ func TestReconcileMachinePhases(t *testing.T) { g.Expect(unstructured.SetNestedField(infraMachine.Object, nodeProviderID, "spec", "providerID")).To(Succeed()) machine := defaultMachine.DeepCopy() machine.Namespace = ns.Name + machine.Spec.InfrastructureRef.Namespace = ns.Name + machine.Spec.Bootstrap.ConfigRef.Namespace = ns.Name // Create Node. node := &corev1.Node{ @@ -2123,6 +2138,8 @@ func TestReconcileMachinePhases(t *testing.T) { g.Expect(unstructured.SetNestedField(infraMachine.Object, nodeProviderID, "spec", "providerID")).To(Succeed()) machine := defaultMachine.DeepCopy() machine.Namespace = ns.Name + machine.Spec.InfrastructureRef.Namespace = ns.Name + machine.Spec.Bootstrap.ConfigRef.Namespace = ns.Name // Create Node. node := &corev1.Node{ @@ -2200,6 +2217,8 @@ func TestReconcileMachinePhases(t *testing.T) { g.Expect(unstructured.SetNestedField(infraMachine.Object, nodeProviderID, "spec", "providerID")).To(Succeed()) machine := defaultMachine.DeepCopy() machine.Namespace = ns.Name + machine.Spec.InfrastructureRef.Namespace = ns.Name + machine.Spec.Bootstrap.ConfigRef.Namespace = ns.Name // Set Machine ProviderID. machine.Spec.ProviderID = ptr.To(nodeProviderID) @@ -2262,6 +2281,8 @@ func TestReconcileMachinePhases(t *testing.T) { g.Expect(unstructured.SetNestedField(infraMachine.Object, nodeProviderID, "spec", "providerID")).To(Succeed()) machine := defaultMachine.DeepCopy() machine.Namespace = ns.Name + machine.Spec.InfrastructureRef.Namespace = ns.Name + machine.Spec.Bootstrap.ConfigRef.Namespace = ns.Name // Create Node. node := &corev1.Node{ diff --git a/internal/controllers/machine/machine_controller_test.go b/internal/controllers/machine/machine_controller_test.go index 3ceed73f8bdc..4b1b65c964df 100644 --- a/internal/controllers/machine/machine_controller_test.go +++ b/internal/controllers/machine/machine_controller_test.go @@ -152,12 +152,14 @@ func TestWatches(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: ns.Name, }, Bootstrap: clusterv1.Bootstrap{ ConfigRef: &corev1.ObjectReference{ APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config-machinereconcile", + Namespace: ns.Name, }, }, }, @@ -288,12 +290,14 @@ func TestWatchesDelete(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: ns.Name, }, Bootstrap: clusterv1.Bootstrap{ ConfigRef: &corev1.ObjectReference{ APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config-machinereconcile", + Namespace: ns.Name, }, }, }, @@ -438,12 +442,14 @@ func TestMachine_Reconcile(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: ns.Name, }, Bootstrap: clusterv1.Bootstrap{ ConfigRef: &corev1.ObjectReference{ APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config-machinereconcile", + Namespace: ns.Name, }, }, }, @@ -857,6 +863,7 @@ func TestReconcileRequest(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, }, @@ -886,6 +893,7 @@ func TestReconcileRequest(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, }, @@ -919,6 +927,7 @@ func TestReconcileRequest(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, }, @@ -1036,12 +1045,14 @@ func TestMachineConditions(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{ ConfigRef: &corev1.ObjectReference{ APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config1", + Namespace: metav1.NamespaceDefault, }, }, }, @@ -1282,6 +1293,7 @@ func TestRemoveMachineFinalizerAfterDeleteReconcile(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, }, @@ -2855,12 +2867,14 @@ func TestNodeToMachine(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: ns.Name, }, Bootstrap: clusterv1.Bootstrap{ ConfigRef: &corev1.ObjectReference{ APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfig", Name: "bootstrap-config-machinereconcile", + Namespace: ns.Name, }, }, }, @@ -3032,6 +3046,7 @@ func TestNodeDeletion(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, }, @@ -3228,6 +3243,7 @@ func TestNodeDeletionWithoutNodeRefFallback(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachine", Name: "infra-config1", + Namespace: metav1.NamespaceDefault, }, Bootstrap: clusterv1.Bootstrap{DataSecretName: ptr.To("data")}, ProviderID: ptr.To("test://id-1"), diff --git a/internal/controllers/machinedeployment/machinedeployment_controller_test.go b/internal/controllers/machinedeployment/machinedeployment_controller_test.go index f4faa52b631b..f1cf1cd9dcf1 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller_test.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller_test.go @@ -127,6 +127,7 @@ func TestMachineDeploymentReconciler(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachineTemplate", Name: "md-template", + Namespace: namespace.Name, }, Bootstrap: clusterv1.Bootstrap{ DataSecretName: ptr.To("data-secret-name"), @@ -310,6 +311,7 @@ func TestMachineDeploymentReconciler(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachineTemplate", Name: "md-template-2", + Namespace: namespace.Name, } modifyFunc = func(d *clusterv1.MachineDeployment) { d.Spec.Template.Spec.InfrastructureRef = infraTmpl2Ref } g.Expect(updateMachineDeployment(ctx, env, deployment, modifyFunc)).To(Succeed()) @@ -549,6 +551,7 @@ func TestMachineDeploymentReconciler_CleanUpManagedFieldsForSSAAdoption(t *testi APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachineTemplate", Name: "md-template", + Namespace: namespace.Name, }, Bootstrap: clusterv1.Bootstrap{ DataSecretName: ptr.To("data-secret-name"), @@ -619,6 +622,7 @@ func TestMachineDeploymentReconciler_CleanUpManagedFieldsForSSAAdoption(t *testi APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachineTemplate", Name: "md-template", + Namespace: testCluster.Namespace, }, Bootstrap: clusterv1.Bootstrap{ DataSecretName: ptr.To("data-secret-name"), diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go index 96b8560a8963..bdbbc8a837c5 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go @@ -689,6 +689,7 @@ func (r *Reconciler) getExternalRemediationRequest(ctx context.Context, m *clust APIVersion: m.Spec.RemediationTemplate.APIVersion, Kind: strings.TrimSuffix(m.Spec.RemediationTemplate.Kind, clusterv1.TemplateSuffix), Name: machineName, + Namespace: m.Namespace, } remediationReq, err := external.Get(ctx, r.Client, remediationRef, m.Namespace) if err != nil { diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go index 9982a2143f9a..c6dab1ccb05e 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go @@ -1328,6 +1328,7 @@ func TestMachineHealthCheck_Reconcile(t *testing.T) { APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachineTemplate", Name: infraTmpl.GetName(), + Namespace: mhc.Namespace, }, }, }, @@ -1536,6 +1537,7 @@ func TestMachineHealthCheck_Reconcile(t *testing.T) { APIVersion: builder.RemediationGroupVersion.String(), Kind: "GenericExternalRemediationTemplate", Name: infraRemediationTmpl.GetName(), + Namespace: cluster.Namespace, } mhc := newMachineHealthCheck(cluster.Namespace, cluster.Name) @@ -1690,6 +1692,7 @@ func TestMachineHealthCheck_Reconcile(t *testing.T) { APIVersion: builder.RemediationGroupVersion.String(), Kind: "GenericExternalRemediationTemplate", Name: infraRemediationTmpl.GetName(), + Namespace: ns.Name, } mhc := newMachineHealthCheck(cluster.Namespace, cluster.Name) @@ -2530,6 +2533,7 @@ func createMachinesWithNodes( APIVersion: infraMachine.GetAPIVersion(), Kind: infraMachine.GetKind(), Name: infraMachine.GetName(), + Namespace: infraMachine.GetNamespace(), } g.Expect(env.Create(ctx, machine)).To(Succeed()) fmt.Printf("machine created: %s\n", machine.GetName()) diff --git a/internal/controllers/machineset/machineset_controller_test.go b/internal/controllers/machineset/machineset_controller_test.go index 246844e32529..c19ba65b351e 100644 --- a/internal/controllers/machineset/machineset_controller_test.go +++ b/internal/controllers/machineset/machineset_controller_test.go @@ -105,12 +105,14 @@ func TestMachineSetReconciler(t *testing.T) { APIVersion: "bootstrap.cluster.x-k8s.io/v1beta1", Kind: "GenericBootstrapConfigTemplate", Name: "ms-template", + Namespace: namespace.Name, }, }, InfrastructureRef: corev1.ObjectReference{ APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1", Kind: "GenericInfrastructureMachineTemplate", Name: "ms-template", + Namespace: namespace.Name, }, NodeDrainTimeout: duration10m, NodeDeletionTimeout: duration10m,