From 880be0a67f69fbc75ade1a345a4c4ba3d9a6c9ed Mon Sep 17 00:00:00 2001 From: Daniel Lipovetsky Date: Thu, 24 Oct 2024 12:15:47 -0700 Subject: [PATCH 1/2] Make builder package public, moving it from internal/test/builder to util/test/builder --- Makefile | 6 +- ...ubeadmconfig_controller_reconciler_test.go | 2 +- .../kubeadmconfig_controller_test.go | 5 +- .../client/cluster/objectgraph_test.go | 6 +- cmd/clusterctl/internal/test/fake_objects.go | 2 +- .../internal/controllers/controller_test.go | 5 +- .../internal/controllers/upgrade_test.go | 8 +- docs/book/src/developer/core/testing.md | 2 +- .../machinepool_controller_phases_test.go | 2 +- .../machinepool_controller_test.go | 2 +- .../desiredstate/desired_state_test.go | 11 +- exp/topology/scope/blueprint_test.go | 2 +- exp/topology/scope/state_test.go | 2 +- .../cluster/cluster_controller_phases_test.go | 2 +- .../cluster/cluster_controller_test.go | 2 +- .../clusterclass_controller_test.go | 40 +- .../machine_controller_noderef_test.go | 2 +- .../machine/machine_controller_phases_test.go | 2 +- .../machine/machine_controller_test.go | 5 +- .../machinedeployment_controller_test.go | 2 +- .../machinehealthcheck_controller_test.go | 2 +- .../machineset/machineset_controller_test.go | 21 +- .../machineset/machineset_preflight_test.go | 2 +- .../topology/cluster/blueprint_test.go | 5 +- .../cluster/cluster_controller_test.go | 9 +- .../topology/cluster/conditions_test.go | 2 +- .../topology/cluster/current_state_test.go | 8 +- .../topology/cluster/patches/engine_test.go | 17 +- .../patches/variables/variables_test.go | 2 +- .../topology/cluster/reconcile_state_test.go | 52 ++- .../serversidepathhelper_test.go | 2 +- .../twowayspatchhelper_test.go | 2 +- .../controllers/topology/cluster/util_test.go | 2 +- .../machinedeployment_controller_test.go | 2 +- .../machineset/machineset_controller_test.go | 2 +- .../topology/machineset/util_test.go | 2 +- internal/test/envtest/environment.go | 20 +- internal/topology/check/compatibility_test.go | 2 +- internal/topology/check/upgrade_test.go | 11 +- internal/util/ssa/patch_test.go | 2 +- internal/webhooks/cluster_test.go | 437 ++++++++++-------- internal/webhooks/clusterclass_test.go | 27 +- internal/webhooks/patch_validation_test.go | 17 +- internal/webhooks/test/clusterclass_test.go | 2 +- util/conditions/v1beta2/aggregate_test.go | 2 +- util/conditions/v1beta2/getter_test.go | 2 +- util/conditions/v1beta2/mirror_test.go | 2 +- util/conditions/v1beta2/patch_test.go | 2 +- util/conditions/v1beta2/setter_test.go | 2 +- util/conditions/v1beta2/summary_test.go | 26 +- util/patch/patch_test.go | 2 +- util/patch/utils_test.go | 2 +- util/paused/paused_test.go | 2 +- {internal => util}/test/builder/bootstrap.go | 0 {internal => util}/test/builder/builders.go | 0 .../test/builder/controlplane.go | 0 .../crd/test.cluster.x-k8s.io_phase0obj.yaml | 0 .../crd/test.cluster.x-k8s.io_phase1obj.yaml | 0 .../crd/test.cluster.x-k8s.io_phase2obj.yaml | 0 .../crd/test.cluster.x-k8s.io_phase3obj.yaml | 0 {internal => util}/test/builder/crds.go | 0 {internal => util}/test/builder/doc.go | 0 .../test/builder/infrastructure.go | 0 .../test/builder/remediation.go | 0 .../test/builder/v1beta2_transition.go | 0 .../test/builder/zz_generated.deepcopy.go | 0 66 files changed, 441 insertions(+), 361 deletions(-) rename {internal => util}/test/builder/bootstrap.go (100%) rename {internal => util}/test/builder/builders.go (100%) rename {internal => util}/test/builder/controlplane.go (100%) rename {internal => util}/test/builder/crd/test.cluster.x-k8s.io_phase0obj.yaml (100%) rename {internal => util}/test/builder/crd/test.cluster.x-k8s.io_phase1obj.yaml (100%) rename {internal => util}/test/builder/crd/test.cluster.x-k8s.io_phase2obj.yaml (100%) rename {internal => util}/test/builder/crd/test.cluster.x-k8s.io_phase3obj.yaml (100%) rename {internal => util}/test/builder/crds.go (100%) rename {internal => util}/test/builder/doc.go (100%) rename {internal => util}/test/builder/infrastructure.go (100%) rename {internal => util}/test/builder/remediation.go (100%) rename {internal => util}/test/builder/v1beta2_transition.go (100%) rename {internal => util}/test/builder/zz_generated.deepcopy.go (100%) diff --git a/Makefile b/Makefile index ec9ad71d45cc..907a196cc53e 100644 --- a/Makefile +++ b/Makefile @@ -306,9 +306,9 @@ generate-manifests-core: $(CONTROLLER_GEN) $(KUSTOMIZE) ## Generate manifests e. output:crd:dir=./cmd/clusterctl/config/crd/bases $(KUSTOMIZE) build $(CLUSTERCTL_MANIFEST_DIR)/crd > $(CLUSTERCTL_MANIFEST_DIR)/manifest/clusterctl-api.yaml $(CONTROLLER_GEN) \ - paths=./internal/test/builder/... \ + paths=./util/test/builder/... \ crd:crdVersions=v1 \ - output:crd:dir=./internal/test/builder/crd + output:crd:dir=./util/test/builder/crd .PHONY: generate-manifests-kubeadm-bootstrap generate-manifests-kubeadm-bootstrap: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc. for kubeadm bootstrap @@ -398,7 +398,7 @@ generate-go-deepcopy-core: $(CONTROLLER_GEN) ## Generate deepcopy go code for co paths=./$(EXP_DIR)/runtime/hooks/api/... \ paths=./internal/runtime/test/... \ paths=./cmd/clusterctl/... \ - paths=./internal/test/builder/... + paths=./util/test/builder/... .PHONY: generate-go-deepcopy-kubeadm-bootstrap generate-go-deepcopy-kubeadm-bootstrap: $(CONTROLLER_GEN) ## Generate deepcopy go code for kubeadm bootstrap diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_reconciler_test.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_reconciler_test.go index 0021cb928784..340025c5f740 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_reconciler_test.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_reconciler_test.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestKubeadmConfigReconciler(t *testing.T) { diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go index c40c759aa005..f91682487ef0 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go @@ -42,12 +42,12 @@ import ( "sigs.k8s.io/cluster-api/controllers/clustercache" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/certs" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/patch" "sigs.k8s.io/cluster-api/util/secret" + "sigs.k8s.io/cluster-api/util/test/builder" utilyaml "sigs.k8s.io/cluster-api/util/yaml" ) @@ -213,7 +213,8 @@ func TestKubeadmConfigReconciler_TestSecretOwnerReferenceReconciliation(t *testi Name: machine.Name, UID: machine.UID, Controller: ptr.To(true), - }}) + }, + }) g.Expect(myclient.Update(ctx, actual)).To(Succeed()) _, err = k.Reconcile(ctx, request) diff --git a/cmd/clusterctl/client/cluster/objectgraph_test.go b/cmd/clusterctl/client/cluster/objectgraph_test.go index 258acda9d0eb..ebc2b1092e68 100644 --- a/cmd/clusterctl/client/cluster/objectgraph_test.go +++ b/cmd/clusterctl/client/cluster/objectgraph_test.go @@ -32,7 +32,7 @@ import ( clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3" "sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestObjectGraph_getDiscoveryTypeMetaList(t *testing.T) { @@ -1043,7 +1043,6 @@ var objectGraphsTests = []struct { }, want: wantGraph{ nodes: map[string]wantGraphItem{ - "infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericInfrastructureMachineTemplate, ns1/shared": { owners: []string{ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1", @@ -1638,7 +1637,6 @@ var objectGraphsTests = []struct { // We need to deduplicate objects here as the clusterclasses share objects and // setting up the test server panics if we try to create it with duplicate objects. return deduplicateObjects(objs) - }(), }, want: wantGraph{ @@ -1807,7 +1805,7 @@ func TestObjectGraph_DiscoveryByNamespace(t *testing.T) { namespace string objs []client.Object } - var tests = []struct { + tests := []struct { name string args args want wantGraph diff --git a/cmd/clusterctl/internal/test/fake_objects.go b/cmd/clusterctl/internal/test/fake_objects.go index 0299d67dd9c9..4fdb9a49897a 100644 --- a/cmd/clusterctl/internal/test/fake_objects.go +++ b/cmd/clusterctl/internal/test/fake_objects.go @@ -39,8 +39,8 @@ import ( fakeinfrastructure "sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test/providers/infrastructure" addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util" + "sigs.k8s.io/cluster-api/util/test/builder" ) type FakeCluster struct { diff --git a/controlplane/kubeadm/internal/controllers/controller_test.go b/controlplane/kubeadm/internal/controllers/controller_test.go index f10a3254270d..29f20b500319 100644 --- a/controlplane/kubeadm/internal/controllers/controller_test.go +++ b/controlplane/kubeadm/internal/controllers/controller_test.go @@ -54,7 +54,6 @@ import ( expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/internal/contract" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/internal/webhooks" "sigs.k8s.io/cluster-api/util" @@ -65,6 +64,7 @@ import ( "sigs.k8s.io/cluster-api/util/kubeconfig" "sigs.k8s.io/cluster-api/util/patch" "sigs.k8s.io/cluster-api/util/secret" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestClusterToKubeadmControlPlane(t *testing.T) { @@ -85,7 +85,8 @@ func TestClusterToKubeadmControlPlane(t *testing.T) { { NamespacedName: client.ObjectKey{ Namespace: cluster.Spec.ControlPlaneRef.Namespace, - Name: cluster.Spec.ControlPlaneRef.Name}, + Name: cluster.Spec.ControlPlaneRef.Name, + }, }, } diff --git a/controlplane/kubeadm/internal/controllers/upgrade_test.go b/controlplane/kubeadm/internal/controllers/upgrade_test.go index 6c4f39bee6ae..5e619ba1b29e 100644 --- a/controlplane/kubeadm/internal/controllers/upgrade_test.go +++ b/controlplane/kubeadm/internal/controllers/upgrade_test.go @@ -34,14 +34,16 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" "sigs.k8s.io/cluster-api/controlplane/kubeadm/internal" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/collections" + "sigs.k8s.io/cluster-api/util/test/builder" ) -const UpdatedVersion string = "v1.17.4" -const Host string = "nodomain.example.com" +const ( + UpdatedVersion string = "v1.17.4" + Host string = "nodomain.example.com" +) func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) { setup := func(t *testing.T, g *WithT) *corev1.Namespace { diff --git a/docs/book/src/developer/core/testing.md b/docs/book/src/developer/core/testing.md index 8e1ea1374c8b..87d38667bd47 100644 --- a/docs/book/src/developer/core/testing.md +++ b/docs/book/src/developer/core/testing.md @@ -73,7 +73,7 @@ easily readable, well documented and consistent across the code base. In light of continuing improving our practice around this ambitious goal, we are starting to introduce a shared set of: -- Builders (`sigs.k8s.io/cluster-api/internal/test/builder`), allowing to create test objects in a simple and consistent way. +- Builders (`sigs.k8s.io/cluster-api/util/test/builder`), allowing to create test objects in a simple and consistent way. - Matchers (`sigs.k8s.io/controller-runtime/pkg/envtest/komega`), improving how we write test assertions. Each contribution in growing this set of utilities or their adoption across the codebase is more than welcome! diff --git a/exp/internal/controllers/machinepool_controller_phases_test.go b/exp/internal/controllers/machinepool_controller_phases_test.go index 76860029fbbf..070a0ef923e2 100644 --- a/exp/internal/controllers/machinepool_controller_phases_test.go +++ b/exp/internal/controllers/machinepool_controller_phases_test.go @@ -39,10 +39,10 @@ import ( "sigs.k8s.io/cluster-api/controllers/external" externalfake "sigs.k8s.io/cluster-api/controllers/external/fake" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/util/kubeconfig" "sigs.k8s.io/cluster-api/util/labels/format" + "sigs.k8s.io/cluster-api/util/test/builder" ) const ( diff --git a/exp/internal/controllers/machinepool_controller_test.go b/exp/internal/controllers/machinepool_controller_test.go index c0c930afcb62..9b4cc6bd8b9c 100644 --- a/exp/internal/controllers/machinepool_controller_test.go +++ b/exp/internal/controllers/machinepool_controller_test.go @@ -43,9 +43,9 @@ import ( "sigs.k8s.io/cluster-api/controllers/external" externalfake "sigs.k8s.io/cluster-api/controllers/external/fake" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestMachinePoolFinalizer(t *testing.T) { diff --git a/exp/topology/desiredstate/desired_state_test.go b/exp/topology/desiredstate/desired_state_test.go index 8f8dcd758d84..d540f2f7b7a8 100644 --- a/exp/topology/desiredstate/desired_state_test.go +++ b/exp/topology/desiredstate/desired_state_test.go @@ -45,11 +45,11 @@ import ( "sigs.k8s.io/cluster-api/internal/contract" "sigs.k8s.io/cluster-api/internal/hooks" fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/topology/clustershim" "sigs.k8s.io/cluster-api/internal/topology/names" "sigs.k8s.io/cluster-api/internal/topology/ownerrefs" "sigs.k8s.io/cluster-api/util" + "sigs.k8s.io/cluster-api/util/test/builder" ) var ( @@ -1381,7 +1381,8 @@ func TestComputeMachineDeployment(t *testing.T) { MachineHealthCheck: &clusterv1.MachineHealthCheckClass{ UnhealthyConditions: unhealthyConditions, NodeStartupTimeout: &metav1.Duration{ - Duration: time.Duration(1)}, + Duration: time.Duration(1), + }, }, }, }, @@ -2906,7 +2907,8 @@ func Test_computeMachineHealthCheck(t *testing.T) { }, }, NodeStartupTimeout: &metav1.Duration{ - Duration: time.Duration(1)}, + Duration: time.Duration(1), + }, } selector := &metav1.LabelSelector{MatchLabels: map[string]string{ "foo": "bar", @@ -2950,7 +2952,8 @@ func Test_computeMachineHealthCheck(t *testing.T) { }, }, NodeStartupTimeout: &metav1.Duration{ - Duration: time.Duration(1)}, + Duration: time.Duration(1), + }, }, } diff --git a/exp/topology/scope/blueprint_test.go b/exp/topology/scope/blueprint_test.go index 66071316d996..c709223ced69 100644 --- a/exp/topology/scope/blueprint_test.go +++ b/exp/topology/scope/blueprint_test.go @@ -28,7 +28,7 @@ import ( "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestIsControlPlaneMachineHealthCheckEnabled(t *testing.T) { diff --git a/exp/topology/scope/state_test.go b/exp/topology/scope/state_test.go index 874610c7615a..4c923c143a2e 100644 --- a/exp/topology/scope/state_test.go +++ b/exp/topology/scope/state_test.go @@ -28,7 +28,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestMDUpgrading(t *testing.T) { diff --git a/internal/controllers/cluster/cluster_controller_phases_test.go b/internal/controllers/cluster/cluster_controller_phases_test.go index 41da2dbb05a0..e086ddb8b693 100644 --- a/internal/controllers/cluster/cluster_controller_phases_test.go +++ b/internal/controllers/cluster/cluster_controller_phases_test.go @@ -34,8 +34,8 @@ import ( "sigs.k8s.io/cluster-api/controllers/external" externalfake "sigs.k8s.io/cluster-api/controllers/external/fake" capierrors "sigs.k8s.io/cluster-api/errors" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util/conditions" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestClusterReconcilePhases(t *testing.T) { diff --git a/internal/controllers/cluster/cluster_controller_test.go b/internal/controllers/cluster/cluster_controller_test.go index 828dda74e8fe..b43903dd8ad4 100644 --- a/internal/controllers/cluster/cluster_controller_test.go +++ b/internal/controllers/cluster/cluster_controller_test.go @@ -33,11 +33,11 @@ import ( expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1" "sigs.k8s.io/cluster-api/feature" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" conditionsv1beta2 "sigs.k8s.io/cluster-api/util/conditions/v1beta2" "sigs.k8s.io/cluster-api/util/patch" + "sigs.k8s.io/cluster-api/util/test/builder" ) const ( diff --git a/internal/controllers/clusterclass/clusterclass_controller_test.go b/internal/controllers/clusterclass/clusterclass_controller_test.go index d51b73e55f49..2c000c092771 100644 --- a/internal/controllers/clusterclass/clusterclass_controller_test.go +++ b/internal/controllers/clusterclass/clusterclass_controller_test.go @@ -44,7 +44,7 @@ import ( runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "sigs.k8s.io/cluster-api/feature" fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestClusterClassReconciler_reconcile(t *testing.T) { @@ -211,6 +211,7 @@ func assertStatusVariables(actualClusterClass *clusterv1.ClusterClass) error { } return nil } + func assertInfrastructureClusterTemplate(ctx context.Context, actualClusterClass *clusterv1.ClusterClass, ns *corev1.Namespace) error { // Assert the infrastructure cluster template has the correct owner reference. actualInfraClusterTemplate := builder.InfrastructureClusterTemplate("", "").Build() @@ -538,7 +539,9 @@ func TestReconciler_reconcileVariables(t *testing.T) { Name: "patch1", External: &clusterv1.ExternalPatchDefinition{ DiscoverVariablesExtension: ptr.To("variables-one"), - }}}). + }, + }, + }). Build(), patchResponse: &runtimehooksv1.DiscoverVariablesResponse{ CommonResponse: runtimehooksv1.CommonResponse{ @@ -754,7 +757,9 @@ func TestReconciler_reconcileVariables(t *testing.T) { Name: "patch1", External: &clusterv1.ExternalPatchDefinition{ DiscoverVariablesExtension: ptr.To("variables-one"), - }}}). + }, + }, + }). Build(), patchResponse: &runtimehooksv1.DiscoverVariablesResponse{ CommonResponse: runtimehooksv1.CommonResponse{ @@ -792,7 +797,9 @@ func TestReconciler_reconcileVariables(t *testing.T) { Name: "patch1", External: &clusterv1.ExternalPatchDefinition{ DiscoverVariablesExtension: ptr.To("variables-one"), - }}}). + }, + }, + }). Build(), patchResponse: &runtimehooksv1.DiscoverVariablesResponse{ CommonResponse: runtimehooksv1.CommonResponse{ @@ -965,7 +972,9 @@ func TestReconciler_reconcileVariables(t *testing.T) { Name: "patch1", External: &clusterv1.ExternalPatchDefinition{ DiscoverVariablesExtension: ptr.To("variables-one"), - }}}). + }, + }, + }). Build(), patchResponse: &runtimehooksv1.DiscoverVariablesResponse{ CommonResponse: runtimehooksv1.CommonResponse{ @@ -1011,7 +1020,9 @@ func TestReconciler_reconcileVariables(t *testing.T) { Name: "patch1", External: &clusterv1.ExternalPatchDefinition{ DiscoverVariablesExtension: ptr.To("variables-one"), - }}}). + }, + }, + }). Build(), patchResponse: &runtimehooksv1.DiscoverVariablesResponse{ CommonResponse: runtimehooksv1.CommonResponse{ @@ -1062,7 +1073,9 @@ func TestReconciler_reconcileVariables(t *testing.T) { Name: "patch1", External: &clusterv1.ExternalPatchDefinition{ DiscoverVariablesExtension: ptr.To("variables-one"), - }}}). + }, + }, + }). Build(), patchResponse: &runtimehooksv1.DiscoverVariablesResponse{ CommonResponse: runtimehooksv1.CommonResponse{ @@ -1137,7 +1150,9 @@ func TestReconciler_reconcileVariables(t *testing.T) { Name: "patch1", External: &clusterv1.ExternalPatchDefinition{ DiscoverVariablesExtension: ptr.To("variables-one"), - }}}). + }, + }, + }). Build(), patchResponse: &runtimehooksv1.DiscoverVariablesResponse{ CommonResponse: runtimehooksv1.CommonResponse{ @@ -1258,18 +1273,21 @@ func TestReconciler_extensionConfigToClusterClass(t *testing.T) { // These ClusterClasses will be reconciled as they both reference the passed ExtensionConfig `runtime1`. onePatchClusterClass := builder.ClusterClass(metav1.NamespaceDefault, "cc1"). WithPatches([]clusterv1.ClusterClassPatch{ - {External: &clusterv1.ExternalPatchDefinition{DiscoverVariablesExtension: ptr.To("discover-variables.runtime1")}}}). + {External: &clusterv1.ExternalPatchDefinition{DiscoverVariablesExtension: ptr.To("discover-variables.runtime1")}}, + }). Build() twoPatchClusterClass := builder.ClusterClass(metav1.NamespaceDefault, "cc2"). WithPatches([]clusterv1.ClusterClassPatch{ {External: &clusterv1.ExternalPatchDefinition{DiscoverVariablesExtension: ptr.To("discover-variables.runtime1")}}, - {External: &clusterv1.ExternalPatchDefinition{DiscoverVariablesExtension: ptr.To("discover-variables.runtime2")}}}). + {External: &clusterv1.ExternalPatchDefinition{DiscoverVariablesExtension: ptr.To("discover-variables.runtime2")}}, + }). Build() // This ClusterClasses will not be reconciled as it does not reference the passed ExtensionConfig `runtime1`. notReconciledClusterClass := builder.ClusterClass(metav1.NamespaceDefault, "cc3"). WithPatches([]clusterv1.ClusterClassPatch{ - {External: &clusterv1.ExternalPatchDefinition{DiscoverVariablesExtension: ptr.To("discover-variables.other-runtime-class")}}}). + {External: &clusterv1.ExternalPatchDefinition{DiscoverVariablesExtension: ptr.To("discover-variables.other-runtime-class")}}, + }). Build() t.Run("test", func(t *testing.T) { diff --git a/internal/controllers/machine/machine_controller_noderef_test.go b/internal/controllers/machine/machine_controller_noderef_test.go index 69120237118e..c568cf35d03c 100644 --- a/internal/controllers/machine/machine_controller_noderef_test.go +++ b/internal/controllers/machine/machine_controller_noderef_test.go @@ -39,10 +39,10 @@ import ( "sigs.k8s.io/cluster-api/api/v1beta1/index" "sigs.k8s.io/cluster-api/controllers/clustercache" "sigs.k8s.io/cluster-api/controllers/remote" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/topology/ownerrefs" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/kubeconfig" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestReconcileNode(t *testing.T) { diff --git a/internal/controllers/machine/machine_controller_phases_test.go b/internal/controllers/machine/machine_controller_phases_test.go index f0ef20a03c21..635ffaa2fafd 100644 --- a/internal/controllers/machine/machine_controller_phases_test.go +++ b/internal/controllers/machine/machine_controller_phases_test.go @@ -34,7 +34,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" externalfake "sigs.k8s.io/cluster-api/controllers/external/fake" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func init() { diff --git a/internal/controllers/machine/machine_controller_test.go b/internal/controllers/machine/machine_controller_test.go index 3ceed73f8bdc..438cc7469766 100644 --- a/internal/controllers/machine/machine_controller_test.go +++ b/internal/controllers/machine/machine_controller_test.go @@ -44,12 +44,12 @@ import ( "sigs.k8s.io/cluster-api/controllers/clustercache" "sigs.k8s.io/cluster-api/controllers/external" externalfake "sigs.k8s.io/cluster-api/controllers/external/fake" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/util/cache" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/patch" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestWatches(t *testing.T) { @@ -1222,7 +1222,8 @@ func TestMachineConditions(t *testing.T) { tt.beforeFunc(bootstrap, infra, m) } - objs := []client.Object{&testCluster, m, node, + objs := []client.Object{ + &testCluster, m, node, builder.GenericInfrastructureMachineCRD.DeepCopy(), infra, builder.GenericBootstrapConfigCRD.DeepCopy(), bootstrap, } diff --git a/internal/controllers/machinedeployment/machinedeployment_controller_test.go b/internal/controllers/machinedeployment/machinedeployment_controller_test.go index f4faa52b631b..e18ff8ee4d67 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller_test.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller_test.go @@ -34,11 +34,11 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/patch" + "sigs.k8s.io/cluster-api/util/test/builder" ) const ( diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go index 9982a2143f9a..d7d1b449f4cc 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller_test.go @@ -45,12 +45,12 @@ import ( "sigs.k8s.io/cluster-api/api/v1beta1/index" "sigs.k8s.io/cluster-api/controllers/clustercache" capierrors "sigs.k8s.io/cluster-api/errors" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/webhooks" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2" "sigs.k8s.io/cluster-api/util/patch" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestMachineHealthCheck_Reconcile(t *testing.T) { diff --git a/internal/controllers/machineset/machineset_controller_test.go b/internal/controllers/machineset/machineset_controller_test.go index 246844e32529..1a62fba1f914 100644 --- a/internal/controllers/machineset/machineset_controller_test.go +++ b/internal/controllers/machineset/machineset_controller_test.go @@ -37,11 +37,11 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" "sigs.k8s.io/cluster-api/internal/contract" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/patch" + "sigs.k8s.io/cluster-api/util/test/builder" ) var _ reconcile.Reconciler = &Reconciler{} @@ -1013,16 +1013,17 @@ func TestMachineSetReconciler_updateStatusResizedCondition(t *testing.T) { { name: "MachineSet should have ResizedCondition=false on scale down", machineSet: newMachineSet("ms-scale-down", cluster.Name, int32(0)), - machines: []*clusterv1.Machine{{ - ObjectMeta: metav1.ObjectMeta{ - Name: "machine-a", - Namespace: metav1.NamespaceDefault, - Labels: map[string]string{ - clusterv1.ClusterNameLabel: cluster.Name, + machines: []*clusterv1.Machine{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "machine-a", + Namespace: metav1.NamespaceDefault, + Labels: map[string]string{ + clusterv1.ClusterNameLabel: cluster.Name, + }, }, }, }, - }, expectedReason: clusterv1.ScalingDownReason, expectedMessage: "Scaling down MachineSet to 0 replicas (actual 1)", }, @@ -1894,7 +1895,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) { } // Perform the second pass. - var allMachines = func() (res []*clusterv1.Machine) { + allMachines := func() (res []*clusterv1.Machine) { var machineList clusterv1.MachineList g.Expect(r.Client.List(ctx, &machineList)).To(Succeed()) for i := range machineList.Items { @@ -1914,7 +1915,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) { _, err = r.reconcileUnhealthyMachines(ctx, s) g.Expect(err).ToNot(HaveOccurred()) - var validateSecondPass = func(cleanFinalizer bool) { + validateSecondPass := func(cleanFinalizer bool) { t.Helper() for i := range unhealthyMachines { m := unhealthyMachines[i] diff --git a/internal/controllers/machineset/machineset_preflight_test.go b/internal/controllers/machineset/machineset_preflight_test.go index a098fc749182..811ddbe49aaa 100644 --- a/internal/controllers/machineset/machineset_preflight_test.go +++ b/internal/controllers/machineset/machineset_preflight_test.go @@ -32,7 +32,7 @@ import ( bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" "sigs.k8s.io/cluster-api/feature" "sigs.k8s.io/cluster-api/internal/contract" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestMachineSetReconciler_runPreflightChecks(t *testing.T) { diff --git a/internal/controllers/topology/cluster/blueprint_test.go b/internal/controllers/topology/cluster/blueprint_test.go index 14f1ccd027a0..7d7113d4f885 100644 --- a/internal/controllers/topology/cluster/blueprint_test.go +++ b/internal/controllers/topology/cluster/blueprint_test.go @@ -29,7 +29,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/exp/topology/scope" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestGetBlueprint(t *testing.T) { @@ -64,7 +64,8 @@ func TestGetBlueprint(t *testing.T) { Build() machineHealthCheck := &clusterv1.MachineHealthCheckClass{ NodeStartupTimeout: &metav1.Duration{ - Duration: time.Duration(1)}, + Duration: time.Duration(1), + }, } machineDeployment := builder.MachineDeploymentClass("workerclass1"). diff --git a/internal/controllers/topology/cluster/cluster_controller_test.go b/internal/controllers/topology/cluster/cluster_controller_test.go index 9e8d95bbf784..61fc1d8dd810 100644 --- a/internal/controllers/topology/cluster/cluster_controller_test.go +++ b/internal/controllers/topology/cluster/cluster_controller_test.go @@ -43,10 +43,10 @@ import ( "sigs.k8s.io/cluster-api/internal/contract" "sigs.k8s.io/cluster-api/internal/hooks" fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/kubeconfig" "sigs.k8s.io/cluster-api/util/patch" + "sigs.k8s.io/cluster-api/util/test/builder" ) var ( @@ -1376,7 +1376,8 @@ func TestReconciler_DefaultCluster(t *testing.T) { }, }, }, - }}...). + }, + }...). WithConditions(*conditions.TrueCondition(clusterv1.ClusterClassVariablesReconciledCondition)). Build(), initialCluster: clusterBuilder.DeepCopy(). @@ -1440,7 +1441,7 @@ func TestReconciler_DefaultCluster(t *testing.T) { APIReader: fakeClient, } // Ignore the error here as we expect the ClusterClass to fail in reconciliation as its references do not exist. - var _, _ = r.Reconcile(ctx, ctrl.Request{NamespacedName: client.ObjectKey{Name: tt.initialCluster.Name, Namespace: tt.initialCluster.Namespace}}) + _, _ = r.Reconcile(ctx, ctrl.Request{NamespacedName: client.ObjectKey{Name: tt.initialCluster.Name, Namespace: tt.initialCluster.Namespace}}) got := &clusterv1.Cluster{} g.Expect(fakeClient.Get(ctx, client.ObjectKey{Name: tt.initialCluster.Name, Namespace: tt.initialCluster.Namespace}, got)).To(Succeed()) // Compare the spec of the two clusters to ensure that variables are defaulted correctly. @@ -1561,7 +1562,7 @@ func TestReconciler_ValidateCluster(t *testing.T) { Client: fakeClient, APIReader: fakeClient, } - var _, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: client.ObjectKey{Name: tt.cluster.Name, Namespace: tt.cluster.Namespace}}) + _, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: client.ObjectKey{Name: tt.cluster.Name, Namespace: tt.cluster.Namespace}}) // Reconcile will always return an error here as the topology is incomplete. This test checks specifically for // validation errors. validationErrMessage := fmt.Sprintf("Cluster.cluster.x-k8s.io %q is invalid:", tt.cluster.Name) diff --git a/internal/controllers/topology/cluster/conditions_test.go b/internal/controllers/topology/cluster/conditions_test.go index d19f84e75275..2124fb1e6e8e 100644 --- a/internal/controllers/topology/cluster/conditions_test.go +++ b/internal/controllers/topology/cluster/conditions_test.go @@ -31,8 +31,8 @@ import ( expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "sigs.k8s.io/cluster-api/exp/topology/scope" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util/conditions" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestReconcileTopologyReconciledCondition(t *testing.T) { diff --git a/internal/controllers/topology/cluster/current_state_test.go b/internal/controllers/topology/cluster/current_state_test.go index d2fefcece368..6ba5584fa0ce 100644 --- a/internal/controllers/topology/cluster/current_state_test.go +++ b/internal/controllers/topology/cluster/current_state_test.go @@ -31,8 +31,8 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/exp/topology/scope" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/topology/selectors" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestGetCurrentState(t *testing.T) { @@ -458,9 +458,11 @@ func TestGetCurrentState(t *testing.T) { ControlPlane: &scope.ControlPlaneState{}, InfrastructureCluster: nil, MachineDeployments: map[string]*scope.MachineDeploymentState{ - "md1": {Object: machineDeployment, BootstrapTemplate: machineDeploymentBootstrap, InfrastructureMachineTemplate: machineDeploymentInfrastructure}}, + "md1": {Object: machineDeployment, BootstrapTemplate: machineDeploymentBootstrap, InfrastructureMachineTemplate: machineDeploymentInfrastructure}, + }, MachinePools: map[string]*scope.MachinePoolState{ - "mp1": {Object: machinePool, BootstrapObject: machinePoolBootstrap, InfrastructureMachinePoolObject: machinePoolInfrastructure}}, + "mp1": {Object: machinePool, BootstrapObject: machinePoolBootstrap, InfrastructureMachinePoolObject: machinePoolInfrastructure}, + }, }, }, { diff --git a/internal/controllers/topology/cluster/patches/engine_test.go b/internal/controllers/topology/cluster/patches/engine_test.go index 8f21c3ec4960..7cf6a06ab09c 100644 --- a/internal/controllers/topology/cluster/patches/engine_test.go +++ b/internal/controllers/topology/cluster/patches/engine_test.go @@ -39,7 +39,7 @@ import ( "sigs.k8s.io/cluster-api/exp/topology/scope" "sigs.k8s.io/cluster-api/feature" fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestApply(t *testing.T) { @@ -421,7 +421,8 @@ func TestApply(t *testing.T) { Patch: bytesPatch([]jsonPatchRFC6902{{ Op: "add", Path: "/spec/template/spec/resource", - Value: &apiextensionsv1.JSON{Raw: []byte(`"infraCluster"`)}}}), + Value: &apiextensionsv1.JSON{Raw: []byte(`"infraCluster"`)}, + }}), }, }, }, @@ -457,7 +458,8 @@ func TestApply(t *testing.T) { Patch: bytesPatch([]jsonPatchRFC6902{{ Op: "add", Path: "/spec/template/spec/resource", - Value: &apiextensionsv1.JSON{Raw: []byte(`"invalid-infraCluster"`)}}}), + Value: &apiextensionsv1.JSON{Raw: []byte(`"invalid-infraCluster"`)}, + }}), }, }, }, @@ -496,7 +498,8 @@ func TestApply(t *testing.T) { Patch: bytesPatch([]jsonPatchRFC6902{{ Op: "add", Path: "/spec/template/spec/resource", - Value: &apiextensionsv1.JSON{Raw: []byte(`"infraCluster"`)}}}), + Value: &apiextensionsv1.JSON{Raw: []byte(`"infraCluster"`)}, + }}), }, { UID: "1", @@ -504,7 +507,8 @@ func TestApply(t *testing.T) { Patch: bytesPatch([]jsonPatchRFC6902{{ Op: "add", Path: "/spec/template/spec/another", - Value: &apiextensionsv1.JSON{Raw: []byte(`"resource"`)}}}), + Value: &apiextensionsv1.JSON{Raw: []byte(`"resource"`)}, + }}), }, }, }, @@ -513,7 +517,8 @@ func TestApply(t *testing.T) { { UID: "2", PatchType: runtimehooksv1.JSONMergePatchType, - Patch: []byte(`{"spec":{"template":{"spec":{"resource": "controlPlane"}}}}`)}, + Patch: []byte(`{"spec":{"template":{"spec":{"resource": "controlPlane"}}}}`), + }, }, }, }, diff --git a/internal/controllers/topology/cluster/patches/variables/variables_test.go b/internal/controllers/topology/cluster/patches/variables/variables_test.go index d9c794620ce1..07ffa38d8c13 100644 --- a/internal/controllers/topology/cluster/patches/variables/variables_test.go +++ b/internal/controllers/topology/cluster/patches/variables/variables_test.go @@ -31,7 +31,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestGlobal(t *testing.T) { diff --git a/internal/controllers/topology/cluster/reconcile_state_test.go b/internal/controllers/topology/cluster/reconcile_state_test.go index f70a6e163637..ac0f2eae4fbd 100644 --- a/internal/controllers/topology/cluster/reconcile_state_test.go +++ b/internal/controllers/topology/cluster/reconcile_state_test.go @@ -50,20 +50,18 @@ import ( "sigs.k8s.io/cluster-api/internal/controllers/topology/cluster/structuredmerge" "sigs.k8s.io/cluster-api/internal/hooks" fakeruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client/fake" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/topology/clustershim" "sigs.k8s.io/cluster-api/internal/topology/names" "sigs.k8s.io/cluster-api/internal/topology/ownerrefs" "sigs.k8s.io/cluster-api/internal/topology/selectors" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/internal/webhooks" + "sigs.k8s.io/cluster-api/util/test/builder" ) -var ( - IgnoreNameGenerated = IgnorePaths{ - "metadata.name", - } -) +var IgnoreNameGenerated = IgnorePaths{ + "metadata.name", +} func TestReconcileShim(t *testing.T) { infrastructureCluster := builder.TestInfrastructureCluster(metav1.NamespaceDefault, "infrastructure-cluster1").Build() @@ -301,7 +299,6 @@ func TestReconcile_callAfterControlPlaneInitialized(t *testing.T) { } successResponse := &runtimehooksv1.AfterControlPlaneInitializedResponse{ - CommonResponse: runtimehooksv1.CommonResponse{ Status: runtimehooksv1.ResponseStatusSuccess, }, @@ -489,7 +486,6 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) { } successResponse := &runtimehooksv1.AfterClusterUpgradeResponse{ - CommonResponse: runtimehooksv1.CommonResponse{ Status: runtimehooksv1.ResponseStatusSuccess, }, @@ -789,7 +785,8 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) { }, ControlPlane: &scope.ControlPlaneState{ Object: controlPlaneObj, - }}, + }, + }, HookResponseTracker: scope.NewHookResponseTracker(), UpgradeTracker: func() *scope.UpgradeTracker { ut := scope.NewUpgradeTracker() @@ -826,7 +823,8 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) { }, ControlPlane: &scope.ControlPlaneState{ Object: controlPlaneObj, - }}, + }, + }, HookResponseTracker: scope.NewHookResponseTracker(), UpgradeTracker: func() *scope.UpgradeTracker { ut := scope.NewUpgradeTracker() @@ -863,7 +861,8 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) { }, ControlPlane: &scope.ControlPlaneState{ Object: controlPlaneObj, - }}, + }, + }, HookResponseTracker: scope.NewHookResponseTracker(), UpgradeTracker: func() *scope.UpgradeTracker { ut := scope.NewUpgradeTracker() @@ -900,7 +899,8 @@ func TestReconcile_callAfterClusterUpgrade(t *testing.T) { }, ControlPlane: &scope.ControlPlaneState{ Object: controlPlaneObj, - }}, + }, + }, HookResponseTracker: scope.NewHookResponseTracker(), UpgradeTracker: func() *scope.UpgradeTracker { ut := scope.NewUpgradeTracker() @@ -1774,7 +1774,8 @@ func TestReconcileControlPlaneMachineHealthCheck(t *testing.T) { desired: &scope.ControlPlaneState{ Object: controlPlane1.DeepCopy(), InfrastructureMachineTemplate: infrastructureMachineTemplate.DeepCopy(), - MachineHealthCheck: mhcBuilder.Build()}, + MachineHealthCheck: mhcBuilder.Build(), + }, want: mhcBuilder.DeepCopy(). Build(), }, @@ -1784,7 +1785,8 @@ func TestReconcileControlPlaneMachineHealthCheck(t *testing.T) { current: &scope.ControlPlaneState{ Object: controlPlane1.DeepCopy(), // Note this creation would be blocked by the validation Webhook. MHC with no MachineInfrastructure is not allowed. - MachineHealthCheck: mhcBuilder.Build()}, + MachineHealthCheck: mhcBuilder.Build(), + }, desired: &scope.ControlPlaneState{ Object: controlPlane1.DeepCopy(), // ControlPlane does not have defined MachineInfrastructure. @@ -1798,7 +1800,8 @@ func TestReconcileControlPlaneMachineHealthCheck(t *testing.T) { current: &scope.ControlPlaneState{ Object: controlPlane1.DeepCopy(), InfrastructureMachineTemplate: infrastructureMachineTemplate.DeepCopy(), - MachineHealthCheck: mhcBuilder.Build()}, + MachineHealthCheck: mhcBuilder.Build(), + }, desired: &scope.ControlPlaneState{ Object: controlPlane1.DeepCopy(), InfrastructureMachineTemplate: infrastructureMachineTemplate.DeepCopy(), @@ -1814,7 +1817,8 @@ func TestReconcileControlPlaneMachineHealthCheck(t *testing.T) { current: &scope.ControlPlaneState{ Object: controlPlane1.DeepCopy(), InfrastructureMachineTemplate: infrastructureMachineTemplate.DeepCopy(), - MachineHealthCheck: mhcBuilder.Build()}, + MachineHealthCheck: mhcBuilder.Build(), + }, desired: &scope.ControlPlaneState{ Object: controlPlane1.DeepCopy(), InfrastructureMachineTemplate: infrastructureMachineTemplate.DeepCopy(), @@ -3330,20 +3334,24 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) { mhcBuilder.DeepCopy().Build()), }, want: []*clusterv1.MachineHealthCheck{ - mhcBuilder.DeepCopy().Build()}, + mhcBuilder.DeepCopy().Build(), + }, }, { name: "Create a new MachineHealthCheck if the MachineDeployment is modified to include one", current: []*scope.MachineDeploymentState{ newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate, - nil)}, + nil), + }, // MHC is added in the desired state of the MachineDeployment desired: []*scope.MachineDeploymentState{ newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate, mhcBuilder.DeepCopy().Build()), }, want: []*clusterv1.MachineHealthCheck{ - mhcBuilder.DeepCopy().Build()}}, + mhcBuilder.DeepCopy().Build(), + }, + }, { name: "Update MachineHealthCheck spec adding a field if the spec adds a field", current: []*scope.MachineDeploymentState{ @@ -3352,11 +3360,13 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) { }, desired: []*scope.MachineDeploymentState{ newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate, - mhcBuilder.DeepCopy().WithMaxUnhealthy(&maxUnhealthy).Build())}, + mhcBuilder.DeepCopy().WithMaxUnhealthy(&maxUnhealthy).Build()), + }, want: []*clusterv1.MachineHealthCheck{ mhcBuilder.DeepCopy(). WithMaxUnhealthy(&maxUnhealthy). - Build()}, + Build(), + }, }, { name: "Update MachineHealthCheck spec removing a field if the spec removes a field", diff --git a/internal/controllers/topology/cluster/structuredmerge/serversidepathhelper_test.go b/internal/controllers/topology/cluster/structuredmerge/serversidepathhelper_test.go index a183dea774ef..bc36b202b037 100644 --- a/internal/controllers/topology/cluster/structuredmerge/serversidepathhelper_test.go +++ b/internal/controllers/topology/cluster/structuredmerge/serversidepathhelper_test.go @@ -41,9 +41,9 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/util/ssa" "sigs.k8s.io/cluster-api/util/patch" + "sigs.k8s.io/cluster-api/util/test/builder" ) // NOTE: This test ensures the ServerSideApply works as expected when the object is co-authored by other controllers. diff --git a/internal/controllers/topology/cluster/structuredmerge/twowayspatchhelper_test.go b/internal/controllers/topology/cluster/structuredmerge/twowayspatchhelper_test.go index fd35f0e99059..307ab29e84a3 100644 --- a/internal/controllers/topology/cluster/structuredmerge/twowayspatchhelper_test.go +++ b/internal/controllers/topology/cluster/structuredmerge/twowayspatchhelper_test.go @@ -25,7 +25,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/cluster-api/internal/contract" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestNewHelper(t *testing.T) { diff --git a/internal/controllers/topology/cluster/util_test.go b/internal/controllers/topology/cluster/util_test.go index 70e92e437f37..ee0c2acbd8b8 100644 --- a/internal/controllers/topology/cluster/util_test.go +++ b/internal/controllers/topology/cluster/util_test.go @@ -28,7 +28,7 @@ import ( . "sigs.k8s.io/controller-runtime/pkg/envtest/komega" "sigs.k8s.io/cluster-api/internal/contract" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestGetReference(t *testing.T) { diff --git a/internal/controllers/topology/machinedeployment/machinedeployment_controller_test.go b/internal/controllers/topology/machinedeployment/machinedeployment_controller_test.go index 43b2e88f0e17..1348c47f8957 100644 --- a/internal/controllers/topology/machinedeployment/machinedeployment_controller_test.go +++ b/internal/controllers/topology/machinedeployment/machinedeployment_controller_test.go @@ -30,8 +30,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestMachineDeploymentTopologyFinalizer(t *testing.T) { diff --git a/internal/controllers/topology/machineset/machineset_controller_test.go b/internal/controllers/topology/machineset/machineset_controller_test.go index f434c9535542..e86633319d7c 100644 --- a/internal/controllers/topology/machineset/machineset_controller_test.go +++ b/internal/controllers/topology/machineset/machineset_controller_test.go @@ -30,8 +30,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestMachineSetTopologyFinalizer(t *testing.T) { diff --git a/internal/controllers/topology/machineset/util_test.go b/internal/controllers/topology/machineset/util_test.go index 4a923026c8c4..af41855d0c79 100644 --- a/internal/controllers/topology/machineset/util_test.go +++ b/internal/controllers/topology/machineset/util_test.go @@ -25,7 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestCalculateTemplatesInUse(t *testing.T) { diff --git a/internal/test/envtest/environment.go b/internal/test/envtest/environment.go index 080659d9ffc4..9a67ffe375aa 100644 --- a/internal/test/envtest/environment.go +++ b/internal/test/envtest/environment.go @@ -65,10 +65,10 @@ import ( expipamwebhooks "sigs.k8s.io/cluster-api/exp/ipam/webhooks" runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1" expapiwebhooks "sigs.k8s.io/cluster-api/exp/webhooks" - "sigs.k8s.io/cluster-api/internal/test/builder" internalwebhooks "sigs.k8s.io/cluster-api/internal/webhooks" runtimewebhooks "sigs.k8s.io/cluster-api/internal/webhooks/runtime" "sigs.k8s.io/cluster-api/util/kubeconfig" + "sigs.k8s.io/cluster-api/util/test/builder" "sigs.k8s.io/cluster-api/version" "sigs.k8s.io/cluster-api/webhooks" ) @@ -161,7 +161,7 @@ func Run(ctx context.Context, input RunInput) int { config := kubeconfig.FromEnvTestConfig(env.Config, &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{Name: "test"}, }) - if err := os.WriteFile(kubeconfigPath, config, 0600); err != nil { + if err := os.WriteFile(kubeconfigPath, config, 0o600); err != nil { panic(errors.Wrapf(err, "failed to write the test env kubeconfig")) } } @@ -205,14 +205,12 @@ func Run(ctx context.Context, input RunInput) int { return code } -var ( - cacheSyncBackoff = wait.Backoff{ - Duration: 100 * time.Millisecond, - Factor: 1.5, - Steps: 8, - Jitter: 0.4, - } -) +var cacheSyncBackoff = wait.Backoff{ + Duration: 100 * time.Millisecond, + Factor: 1.5, + Steps: 8, + Jitter: 0.4, +} // Environment encapsulates a Kubernetes local test environment. type Environment struct { @@ -240,7 +238,7 @@ func newEnvironment(uncachedObjs ...client.Object) *Environment { filepath.Join(root, "config", "crd", "bases"), filepath.Join(root, "controlplane", "kubeadm", "config", "crd", "bases"), filepath.Join(root, "bootstrap", "kubeadm", "config", "crd", "bases"), - filepath.Join(root, "internal", "test", "builder", "crd"), + filepath.Join(root, "util", "test", "builder", "crd"), }, CRDs: []*apiextensionsv1.CustomResourceDefinition{ builder.GenericBootstrapConfigCRD.DeepCopy(), diff --git a/internal/topology/check/compatibility_test.go b/internal/topology/check/compatibility_test.go index a04636c4df9c..e66d4223f7eb 100644 --- a/internal/topology/check/compatibility_test.go +++ b/internal/topology/check/compatibility_test.go @@ -26,7 +26,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) type referencedObjectsCompatibilityTestCase struct { diff --git a/internal/topology/check/upgrade_test.go b/internal/topology/check/upgrade_test.go index 601343ef9c07..86ad2616038b 100644 --- a/internal/topology/check/upgrade_test.go +++ b/internal/topology/check/upgrade_test.go @@ -29,7 +29,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestIsMachineDeploymentUpgrading(t *testing.T) { @@ -138,7 +138,8 @@ func TestIsMachinePoolUpgrading(t *testing.T) { NodeRefs: []corev1.ObjectReference{ {Name: "node1"}, {Name: "node2"}, - }}). + }, + }). Build(), nodes: []*corev1.Node{ { @@ -166,7 +167,8 @@ func TestIsMachinePoolUpgrading(t *testing.T) { NodeRefs: []corev1.ObjectReference{ {Name: "node1"}, {Name: "node2"}, - }}). + }, + }). Build(), nodes: []*corev1.Node{ { @@ -191,7 +193,8 @@ func TestIsMachinePoolUpgrading(t *testing.T) { WithClusterName("cluster1"). WithVersion("v1.2.3"). WithStatus(expv1.MachinePoolStatus{ - NodeRefs: []corev1.ObjectReference{}}). + NodeRefs: []corev1.ObjectReference{}, + }). Build(), nodes: []*corev1.Node{}, want: false, diff --git a/internal/util/ssa/patch_test.go b/internal/util/ssa/patch_test.go index de27ffe9afb8..956bf9f32dc3 100644 --- a/internal/util/ssa/patch_test.go +++ b/internal/util/ssa/patch_test.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestPatch(t *testing.T) { diff --git a/internal/webhooks/cluster_test.go b/internal/webhooks/cluster_test.go index dccee66d87ab..6bfa7243787f 100644 --- a/internal/webhooks/cluster_test.go +++ b/internal/webhooks/cluster_test.go @@ -42,9 +42,9 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/webhooks/util" "sigs.k8s.io/cluster-api/util/conditions" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestClusterDefaultNamespaces(t *testing.T) { @@ -735,7 +735,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}, + }, + }, ).Build(), topology: builder.ClusterTopology(). WithVariables(clusterv1.ClusterVariable{ @@ -761,7 +762,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}).Build(), + }, + }).Build(), topology: builder.ClusterTopology(). WithVariables(clusterv1.ClusterVariable{ Name: "cpu", @@ -797,7 +799,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}).Build(), + }, + }).Build(), topology: builder.ClusterTopology(). WithVariables(clusterv1.ClusterVariable{ Name: "cpu", @@ -833,7 +836,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}).Build(), + }, + }).Build(), topology: builder.ClusterTopology(). WithVariables(clusterv1.ClusterVariable{ Name: "cpu", @@ -869,7 +873,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}).Build(), + }, + }).Build(), topology: builder.ClusterTopology(). WithClass("foo"). WithVersion("v1.19.1"). @@ -906,7 +911,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}).Build(), + }, + }).Build(), topology: builder.ClusterTopology(). WithClass("foo"). WithVersion("v1.19.1"). @@ -979,7 +985,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}).Build(), + }, + }).Build(), topology: builder.ClusterTopology(). WithClass("foo"). WithVersion("v1.19.1"). @@ -1046,7 +1053,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}).Build(), + }, + }).Build(), topology: builder.ClusterTopology(). WithClass("foo"). WithVersion("v1.19.1"). @@ -1119,7 +1127,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}).Build(), + }, + }).Build(), topology: builder.ClusterTopology(). WithClass("foo"). WithVersion("v1.19.1"). @@ -1218,7 +1227,8 @@ func TestClusterDefaultAndValidateVariables(t *testing.T) { }, }, }, - }}).Build(), + }, + }).Build(), topology: builder.ClusterTopology(). WithClass("foo"). WithVersion("v1.19.1"). @@ -1399,195 +1409,211 @@ func TestClusterFailOnMissingClassField(t *testing.T) { func TestClusterValidation(t *testing.T) { // NOTE: ClusterTopology feature flag is disabled by default, thus preventing to set Cluster.Topologies. - var ( - tests = []struct { - name string - in *clusterv1.Cluster - old *clusterv1.Cluster - expectErr bool - }{ - { - name: "should return error when cluster namespace and infrastructure ref namespace mismatch", - expectErr: true, - in: builder.Cluster("fooNamespace", "cluster1"). - WithInfrastructureCluster( - builder.InfrastructureClusterTemplate("barNamespace", "infra1").Build()). - WithControlPlane( - builder.ControlPlane("fooNamespace", "cp1").Build()). - Build(), - }, - { - name: "should return error when cluster namespace and controlPlane ref namespace mismatch", - expectErr: true, - in: builder.Cluster("fooNamespace", "cluster1"). - WithInfrastructureCluster( - builder.InfrastructureClusterTemplate("fooNamespace", "infra1").Build()). - WithControlPlane( - builder.ControlPlane("barNamespace", "cp1").Build()). - Build(), - }, - { - name: "should succeed when namespaces match", - expectErr: false, - in: builder.Cluster("fooNamespace", "cluster1"). - WithInfrastructureCluster( - builder.InfrastructureClusterTemplate("fooNamespace", "infra1").Build()). - WithControlPlane( - builder.ControlPlane("fooNamespace", "cp1").Build()). - Build(), - }, - { - name: "fails if topology is set but feature flag is disabled", - expectErr: true, - in: builder.Cluster("fooNamespace", "cluster1"). - WithInfrastructureCluster( - builder.InfrastructureClusterTemplate("fooNamespace", "infra1").Build()). - WithControlPlane( - builder.ControlPlane("fooNamespace", "cp1").Build()). - WithTopology(&clusterv1.Topology{}). - Build(), - }, - { - name: "pass with undefined CIDR ranges", - expectErr: false, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{}}, - Pods: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{}}, - }). - Build(), - }, - { - name: "pass with nil CIDR ranges", - expectErr: false, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ - CIDRBlocks: nil}, - Pods: &clusterv1.NetworkRanges{ - CIDRBlocks: nil}, - }). - Build(), - }, - { - name: "pass with valid IPv4 CIDR ranges", - expectErr: false, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{"10.10.10.10/24"}}, - Pods: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{"10.10.10.10/24"}}, - }). - Build(), - }, - { - name: "pass with valid IPv6 CIDR ranges", - expectErr: false, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64"}}, - Pods: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64"}}, - }). - Build(), - }, - { - name: "pass with valid dualstack CIDR ranges", - expectErr: false, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64", "10.10.10.10/24"}}, - Pods: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64", "10.10.10.10/24"}}, - }). - Build(), - }, - { - name: "pass if multiple CIDR ranges of IPv4 are passed", - expectErr: false, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{"10.10.10.10/24", "11.11.11.11/24"}}, - }). - Build(), - }, - { - name: "pass if multiple CIDR ranges of IPv6 are passed", - expectErr: false, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{"2002::1234:abcd:ffff:c0a8:101/64", "2004::1234:abcd:ffff:c0a8:101/64"}}, - }). - Build(), - }, - { - name: "pass if too many cidr ranges are specified in the clusterNetwork pods field", - expectErr: false, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Pods: &clusterv1.NetworkRanges{ - CIDRBlocks: []string{"10.10.10.10/24", "11.11.11.11/24", "12.12.12.12/24"}}}). - Build(), - }, - { - name: "fails if service cidr ranges are not valid", - expectErr: true, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Services: &clusterv1.NetworkRanges{ - // Invalid ranges: missing network suffix - CIDRBlocks: []string{"10.10.10.10", "11.11.11.11"}}}). - Build(), - }, - { - name: "fails if pod cidr ranges are not valid", - expectErr: true, - in: builder.Cluster("fooNamespace", "cluster1"). - WithClusterNetwork(&clusterv1.ClusterNetwork{ - Pods: &clusterv1.NetworkRanges{ - // Invalid ranges: missing network suffix - CIDRBlocks: []string{"10.10.10.10", "11.11.11.11"}}}). - Build(), - }, - { - name: "pass with name of under 63 characters", - expectErr: false, - in: builder.Cluster("fooNamespace", "short-name").Build(), - }, - { - name: "pass with _, -, . characters in name", - in: builder.Cluster("fooNamespace", "thisNameContains.A_Non-Alphanumeric").Build(), - expectErr: false, - }, - { - name: "fails if cluster name is longer than 63 characters", - in: builder.Cluster("fooNamespace", "thisNameIsReallyMuchLongerThanTheMaximumLengthOfSixtyThreeCharacters").Build(), - expectErr: true, - }, - { - name: "error when name starts with NonAlphanumeric character", - in: builder.Cluster("fooNamespace", "-thisNameStartsWithANonAlphanumeric").Build(), - expectErr: true, - }, - { - name: "error when name ends with NonAlphanumeric character", - in: builder.Cluster("fooNamespace", "thisNameEndsWithANonAlphanumeric.").Build(), - expectErr: true, - }, - { - name: "error when name contains invalid NonAlphanumeric character", - in: builder.Cluster("fooNamespace", "thisNameContainsInvalid!@NonAlphanumerics").Build(), - expectErr: true, - }, - } - ) + tests := []struct { + name string + in *clusterv1.Cluster + old *clusterv1.Cluster + expectErr bool + }{ + { + name: "should return error when cluster namespace and infrastructure ref namespace mismatch", + expectErr: true, + in: builder.Cluster("fooNamespace", "cluster1"). + WithInfrastructureCluster( + builder.InfrastructureClusterTemplate("barNamespace", "infra1").Build()). + WithControlPlane( + builder.ControlPlane("fooNamespace", "cp1").Build()). + Build(), + }, + { + name: "should return error when cluster namespace and controlPlane ref namespace mismatch", + expectErr: true, + in: builder.Cluster("fooNamespace", "cluster1"). + WithInfrastructureCluster( + builder.InfrastructureClusterTemplate("fooNamespace", "infra1").Build()). + WithControlPlane( + builder.ControlPlane("barNamespace", "cp1").Build()). + Build(), + }, + { + name: "should succeed when namespaces match", + expectErr: false, + in: builder.Cluster("fooNamespace", "cluster1"). + WithInfrastructureCluster( + builder.InfrastructureClusterTemplate("fooNamespace", "infra1").Build()). + WithControlPlane( + builder.ControlPlane("fooNamespace", "cp1").Build()). + Build(), + }, + { + name: "fails if topology is set but feature flag is disabled", + expectErr: true, + in: builder.Cluster("fooNamespace", "cluster1"). + WithInfrastructureCluster( + builder.InfrastructureClusterTemplate("fooNamespace", "infra1").Build()). + WithControlPlane( + builder.ControlPlane("fooNamespace", "cp1").Build()). + WithTopology(&clusterv1.Topology{}). + Build(), + }, + { + name: "pass with undefined CIDR ranges", + expectErr: false, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Services: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{}, + }, + Pods: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{}, + }, + }). + Build(), + }, + { + name: "pass with nil CIDR ranges", + expectErr: false, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Services: &clusterv1.NetworkRanges{ + CIDRBlocks: nil, + }, + Pods: &clusterv1.NetworkRanges{ + CIDRBlocks: nil, + }, + }). + Build(), + }, + { + name: "pass with valid IPv4 CIDR ranges", + expectErr: false, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Services: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{"10.10.10.10/24"}, + }, + Pods: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{"10.10.10.10/24"}, + }, + }). + Build(), + }, + { + name: "pass with valid IPv6 CIDR ranges", + expectErr: false, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Services: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64"}, + }, + Pods: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64"}, + }, + }). + Build(), + }, + { + name: "pass with valid dualstack CIDR ranges", + expectErr: false, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Services: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64", "10.10.10.10/24"}, + }, + Pods: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{"2004::1234:abcd:ffff:c0a8:101/64", "10.10.10.10/24"}, + }, + }). + Build(), + }, + { + name: "pass if multiple CIDR ranges of IPv4 are passed", + expectErr: false, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Services: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{"10.10.10.10/24", "11.11.11.11/24"}, + }, + }). + Build(), + }, + { + name: "pass if multiple CIDR ranges of IPv6 are passed", + expectErr: false, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Services: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{"2002::1234:abcd:ffff:c0a8:101/64", "2004::1234:abcd:ffff:c0a8:101/64"}, + }, + }). + Build(), + }, + { + name: "pass if too many cidr ranges are specified in the clusterNetwork pods field", + expectErr: false, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Pods: &clusterv1.NetworkRanges{ + CIDRBlocks: []string{"10.10.10.10/24", "11.11.11.11/24", "12.12.12.12/24"}, + }, + }). + Build(), + }, + { + name: "fails if service cidr ranges are not valid", + expectErr: true, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Services: &clusterv1.NetworkRanges{ + // Invalid ranges: missing network suffix + CIDRBlocks: []string{"10.10.10.10", "11.11.11.11"}, + }, + }). + Build(), + }, + { + name: "fails if pod cidr ranges are not valid", + expectErr: true, + in: builder.Cluster("fooNamespace", "cluster1"). + WithClusterNetwork(&clusterv1.ClusterNetwork{ + Pods: &clusterv1.NetworkRanges{ + // Invalid ranges: missing network suffix + CIDRBlocks: []string{"10.10.10.10", "11.11.11.11"}, + }, + }). + Build(), + }, + { + name: "pass with name of under 63 characters", + expectErr: false, + in: builder.Cluster("fooNamespace", "short-name").Build(), + }, + { + name: "pass with _, -, . characters in name", + in: builder.Cluster("fooNamespace", "thisNameContains.A_Non-Alphanumeric").Build(), + expectErr: false, + }, + { + name: "fails if cluster name is longer than 63 characters", + in: builder.Cluster("fooNamespace", "thisNameIsReallyMuchLongerThanTheMaximumLengthOfSixtyThreeCharacters").Build(), + expectErr: true, + }, + { + name: "error when name starts with NonAlphanumeric character", + in: builder.Cluster("fooNamespace", "-thisNameStartsWithANonAlphanumeric").Build(), + expectErr: true, + }, + { + name: "error when name ends with NonAlphanumeric character", + in: builder.Cluster("fooNamespace", "thisNameEndsWithANonAlphanumeric.").Build(), + expectErr: true, + }, + { + name: "error when name contains invalid NonAlphanumeric character", + in: builder.Cluster("fooNamespace", "thisNameContainsInvalid!@NonAlphanumerics").Build(), + expectErr: true, + }, + } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) @@ -3277,11 +3303,12 @@ func TestClusterClassPollingErrors(t *testing.T) { for _, cc := range tt.clusterClasses { objs = append(objs, cc) } - c := &Cluster{Client: fake.NewClientBuilder(). - WithInterceptorFuncs(tt.injectedErr). - WithScheme(fakeScheme). - WithObjects(objs...). - Build(), + c := &Cluster{ + Client: fake.NewClientBuilder(). + WithInterceptorFuncs(tt.injectedErr). + WithScheme(fakeScheme). + WithObjects(objs...). + Build(), } // Checks the return error. diff --git a/internal/webhooks/clusterclass_test.go b/internal/webhooks/clusterclass_test.go index a236550b370d..49b8928529ad 100644 --- a/internal/webhooks/clusterclass_test.go +++ b/internal/webhooks/clusterclass_test.go @@ -37,8 +37,8 @@ import ( "sigs.k8s.io/cluster-api/api/v1beta1/index" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/cluster-api/feature" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/internal/webhooks/util" + "sigs.k8s.io/cluster-api/util/test/builder" ) var ( @@ -264,7 +264,6 @@ func TestClusterClassValidation(t *testing.T) { old *clusterv1.ClusterClass expectErr bool }{ - /* CREATE Tests */ @@ -901,7 +900,9 @@ func TestClusterClassValidation(t *testing.T) { }, }, NodeStartupTimeout: &metav1.Duration{ - Duration: time.Duration(6000000000000)}}). + Duration: time.Duration(6000000000000), + }, + }). Build(), }, { @@ -915,7 +916,9 @@ func TestClusterClassValidation(t *testing.T) { // No ControlPlaneMachineInfrastructure makes this an invalid creation request. WithControlPlaneMachineHealthCheck(&clusterv1.MachineHealthCheckClass{ NodeStartupTimeout: &metav1.Duration{ - Duration: time.Duration(6000000000000)}}). + Duration: time.Duration(6000000000000), + }, + }). Build(), expectErr: true, }, @@ -932,7 +935,9 @@ func TestClusterClassValidation(t *testing.T) { Build()). WithControlPlaneMachineHealthCheck(&clusterv1.MachineHealthCheckClass{ NodeStartupTimeout: &metav1.Duration{ - Duration: time.Duration(6000000000000)}}). + Duration: time.Duration(6000000000000), + }, + }). Build(), expectErr: false, }, @@ -959,7 +964,9 @@ func TestClusterClassValidation(t *testing.T) { }, }, NodeStartupTimeout: &metav1.Duration{ - Duration: time.Duration(6000000000000)}}). + Duration: time.Duration(6000000000000), + }, + }). Build()). Build(), }, @@ -987,7 +994,9 @@ func TestClusterClassValidation(t *testing.T) { }, NodeStartupTimeout: &metav1.Duration{ // nodeStartupTimeout is too short here - 600ns. - Duration: time.Duration(600)}}). + Duration: time.Duration(600), + }, + }). Build()). Build(), expectErr: true, @@ -1008,7 +1017,9 @@ func TestClusterClassValidation(t *testing.T) { builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()). WithMachineHealthCheckClass(&clusterv1.MachineHealthCheckClass{ NodeStartupTimeout: &metav1.Duration{ - Duration: time.Duration(6000000000000)}}). + Duration: time.Duration(6000000000000), + }, + }). Build()). Build(), expectErr: false, diff --git a/internal/webhooks/patch_validation_test.go b/internal/webhooks/patch_validation_test.go index fa1525a69653..365e8dab5d76 100644 --- a/internal/webhooks/patch_validation_test.go +++ b/internal/webhooks/patch_validation_test.go @@ -29,7 +29,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/feature" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestValidatePatches(t *testing.T) { @@ -140,7 +140,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "", Definitions: []clusterv1.PatchDefinition{ @@ -194,7 +193,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -328,7 +326,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -371,7 +368,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -464,7 +460,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -518,7 +513,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -572,7 +566,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -626,7 +619,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -682,7 +674,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -722,7 +713,6 @@ func TestValidatePatches(t *testing.T) { }, }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -778,7 +768,6 @@ func TestValidatePatches(t *testing.T) { }, }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -818,7 +807,6 @@ func TestValidatePatches(t *testing.T) { }, }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -861,7 +849,6 @@ func TestValidatePatches(t *testing.T) { }, }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -904,7 +891,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ @@ -1353,7 +1339,6 @@ func TestValidatePatches(t *testing.T) { }, Patches: []clusterv1.ClusterClassPatch{ - { Name: "patch1", Definitions: []clusterv1.PatchDefinition{ diff --git a/internal/webhooks/test/clusterclass_test.go b/internal/webhooks/test/clusterclass_test.go index c27ce423fee8..5ba977b94055 100644 --- a/internal/webhooks/test/clusterclass_test.go +++ b/internal/webhooks/test/clusterclass_test.go @@ -27,7 +27,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/feature" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) const ( diff --git a/util/conditions/v1beta2/aggregate_test.go b/util/conditions/v1beta2/aggregate_test.go index 6ad88de809c0..5828aea6c316 100644 --- a/util/conditions/v1beta2/aggregate_test.go +++ b/util/conditions/v1beta2/aggregate_test.go @@ -24,7 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestAggregate(t *testing.T) { diff --git a/util/conditions/v1beta2/getter_test.go b/util/conditions/v1beta2/getter_test.go index b71875af7749..956aafb183c4 100644 --- a/util/conditions/v1beta2/getter_test.go +++ b/util/conditions/v1beta2/getter_test.go @@ -27,7 +27,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestGet(t *testing.T) { diff --git a/util/conditions/v1beta2/mirror_test.go b/util/conditions/v1beta2/mirror_test.go index 52af53ea162d..cdd82fc1a83d 100644 --- a/util/conditions/v1beta2/mirror_test.go +++ b/util/conditions/v1beta2/mirror_test.go @@ -22,7 +22,7 @@ import ( . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestMirrorStatusCondition(t *testing.T) { diff --git a/util/conditions/v1beta2/patch_test.go b/util/conditions/v1beta2/patch_test.go index b2e34f9f1757..64cb94d366e6 100644 --- a/util/conditions/v1beta2/patch_test.go +++ b/util/conditions/v1beta2/patch_test.go @@ -23,7 +23,7 @@ import ( . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestNewPatch(t *testing.T) { diff --git a/util/conditions/v1beta2/setter_test.go b/util/conditions/v1beta2/setter_test.go index 34266ff05b9a..208236a134b3 100644 --- a/util/conditions/v1beta2/setter_test.go +++ b/util/conditions/v1beta2/setter_test.go @@ -26,7 +26,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestSet(t *testing.T) { diff --git a/util/conditions/v1beta2/summary_test.go b/util/conditions/v1beta2/summary_test.go index f4455285d578..71cd0c336bcd 100644 --- a/util/conditions/v1beta2/summary_test.go +++ b/util/conditions/v1beta2/summary_test.go @@ -24,7 +24,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestSummary(t *testing.T) { @@ -217,7 +217,10 @@ func TestSummary(t *testing.T) { {Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C", Message: "Message-C"}, // issue }, conditionType: clusterv1.AvailableV1Beta2Condition, - options: []SummaryOption{ForConditionTypes{"A", "!C"}, NegativePolarityConditionTypes{"!C"}, IgnoreTypesIfMissing{"!C"}, + options: []SummaryOption{ + ForConditionTypes{"A", "!C"}, + NegativePolarityConditionTypes{"!C"}, + IgnoreTypesIfMissing{"!C"}, OverrideConditions{ { OwnerResource: ConditionOwnerInfo{ @@ -228,7 +231,8 @@ func TestSummary(t *testing.T) { Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C-additional", Message: "Message-C-additional", // issue }, }, - }}, // OverrideCondition replaces the same condition from the SourceObject + }, + }, // OverrideCondition replaces the same condition from the SourceObject want: &metav1.Condition{ Type: clusterv1.AvailableV1Beta2Condition, Status: metav1.ConditionFalse, // False because !C is an issue @@ -243,7 +247,10 @@ func TestSummary(t *testing.T) { {Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C", Message: "Message-C"}, // issue }, conditionType: clusterv1.AvailableV1Beta2Condition, - options: []SummaryOption{ForConditionTypes{"A", "!C"}, NegativePolarityConditionTypes{"!C"}, IgnoreTypesIfMissing{"!C"}, + options: []SummaryOption{ + ForConditionTypes{"A", "!C"}, + NegativePolarityConditionTypes{"!C"}, + IgnoreTypesIfMissing{"!C"}, OverrideConditions{ { OwnerResource: ConditionOwnerInfo{ @@ -263,7 +270,8 @@ func TestSummary(t *testing.T) { Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C-additional", Message: "Message-C-additional", // issue }, }, - }}, // OverrideCondition is specified multiple times + }, + }, // OverrideCondition is specified multiple times wantErr: true, }, { @@ -273,7 +281,10 @@ func TestSummary(t *testing.T) { // !C is missing in source object }, conditionType: clusterv1.AvailableV1Beta2Condition, - options: []SummaryOption{ForConditionTypes{"A", "!C"}, NegativePolarityConditionTypes{"!C"}, IgnoreTypesIfMissing{"!C"}, + options: []SummaryOption{ + ForConditionTypes{"A", "!C"}, + NegativePolarityConditionTypes{"!C"}, + IgnoreTypesIfMissing{"!C"}, OverrideConditions{ { OwnerResource: ConditionOwnerInfo{ @@ -284,7 +295,8 @@ func TestSummary(t *testing.T) { Type: "!C", Status: metav1.ConditionTrue, Reason: "Reason-C-additional", Message: "Message-C-additional", // issue }, }, - }}, + }, + }, wantErr: true, }, } diff --git a/util/patch/patch_test.go b/util/patch/patch_test.go index 00d1910acb68..23329819540c 100644 --- a/util/patch/patch_test.go +++ b/util/patch/patch_test.go @@ -31,10 +31,10 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/controllers/external" - "sigs.k8s.io/cluster-api/internal/test/builder" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestPatchHelper(t *testing.T) { diff --git a/util/patch/utils_test.go b/util/patch/utils_test.go index 76858c852a49..1af2a1039dd4 100644 --- a/util/patch/utils_test.go +++ b/util/patch/utils_test.go @@ -26,7 +26,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestToUnstructured(t *testing.T) { diff --git a/util/paused/paused_test.go b/util/paused/paused_test.go index 679a12105a13..ee32b9734e48 100644 --- a/util/paused/paused_test.go +++ b/util/paused/paused_test.go @@ -28,7 +28,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/fake" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/internal/test/builder" + "sigs.k8s.io/cluster-api/util/test/builder" ) func TestEnsurePausedCondition(t *testing.T) { diff --git a/internal/test/builder/bootstrap.go b/util/test/builder/bootstrap.go similarity index 100% rename from internal/test/builder/bootstrap.go rename to util/test/builder/bootstrap.go diff --git a/internal/test/builder/builders.go b/util/test/builder/builders.go similarity index 100% rename from internal/test/builder/builders.go rename to util/test/builder/builders.go diff --git a/internal/test/builder/controlplane.go b/util/test/builder/controlplane.go similarity index 100% rename from internal/test/builder/controlplane.go rename to util/test/builder/controlplane.go diff --git a/internal/test/builder/crd/test.cluster.x-k8s.io_phase0obj.yaml b/util/test/builder/crd/test.cluster.x-k8s.io_phase0obj.yaml similarity index 100% rename from internal/test/builder/crd/test.cluster.x-k8s.io_phase0obj.yaml rename to util/test/builder/crd/test.cluster.x-k8s.io_phase0obj.yaml diff --git a/internal/test/builder/crd/test.cluster.x-k8s.io_phase1obj.yaml b/util/test/builder/crd/test.cluster.x-k8s.io_phase1obj.yaml similarity index 100% rename from internal/test/builder/crd/test.cluster.x-k8s.io_phase1obj.yaml rename to util/test/builder/crd/test.cluster.x-k8s.io_phase1obj.yaml diff --git a/internal/test/builder/crd/test.cluster.x-k8s.io_phase2obj.yaml b/util/test/builder/crd/test.cluster.x-k8s.io_phase2obj.yaml similarity index 100% rename from internal/test/builder/crd/test.cluster.x-k8s.io_phase2obj.yaml rename to util/test/builder/crd/test.cluster.x-k8s.io_phase2obj.yaml diff --git a/internal/test/builder/crd/test.cluster.x-k8s.io_phase3obj.yaml b/util/test/builder/crd/test.cluster.x-k8s.io_phase3obj.yaml similarity index 100% rename from internal/test/builder/crd/test.cluster.x-k8s.io_phase3obj.yaml rename to util/test/builder/crd/test.cluster.x-k8s.io_phase3obj.yaml diff --git a/internal/test/builder/crds.go b/util/test/builder/crds.go similarity index 100% rename from internal/test/builder/crds.go rename to util/test/builder/crds.go diff --git a/internal/test/builder/doc.go b/util/test/builder/doc.go similarity index 100% rename from internal/test/builder/doc.go rename to util/test/builder/doc.go diff --git a/internal/test/builder/infrastructure.go b/util/test/builder/infrastructure.go similarity index 100% rename from internal/test/builder/infrastructure.go rename to util/test/builder/infrastructure.go diff --git a/internal/test/builder/remediation.go b/util/test/builder/remediation.go similarity index 100% rename from internal/test/builder/remediation.go rename to util/test/builder/remediation.go diff --git a/internal/test/builder/v1beta2_transition.go b/util/test/builder/v1beta2_transition.go similarity index 100% rename from internal/test/builder/v1beta2_transition.go rename to util/test/builder/v1beta2_transition.go diff --git a/internal/test/builder/zz_generated.deepcopy.go b/util/test/builder/zz_generated.deepcopy.go similarity index 100% rename from internal/test/builder/zz_generated.deepcopy.go rename to util/test/builder/zz_generated.deepcopy.go From febc6a9353d94959eac07a881b608b605b3f1e00 Mon Sep 17 00:00:00 2001 From: Daniel Lipovetsky Date: Wed, 30 Oct 2024 09:29:56 -0700 Subject: [PATCH 2/2] Explain purpose and compatibility guarantee of util/test/builder --- util/test/builder/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 util/test/builder/README.md diff --git a/util/test/builder/README.md b/util/test/builder/README.md new file mode 100644 index 000000000000..c8dd9c882290 --- /dev/null +++ b/util/test/builder/README.md @@ -0,0 +1,7 @@ +# "Generic" custom resource builder + +This package helps create custom resources definitions of "generic" Cluster API resources. For example, resources for a "generic" infra provider, such as InfraClusters, InfraMachines, InfraTemplates, etc. These resources are used for testing Cluster API controllers that reconcile resources created by different infrastructure, bootstrap, and control-plane providers. + +## Compatibility notice + +This package does not adhere to any compatibility guarantees. This package is meant to be used by tests only.