diff --git a/Tiltfile b/Tiltfile index 19a10a3f..4664f631 100644 --- a/Tiltfile +++ b/Tiltfile @@ -99,6 +99,7 @@ if os.getenv("INSTALL_RKE2_PROVIDER", "false") == "true": ) capl_resources = [ "capl-system:namespace", + "addresssets.infrastructure.cluster.x-k8s.io:customresourcedefinition", "linodeclusters.infrastructure.cluster.x-k8s.io:customresourcedefinition", "linodemachines.infrastructure.cluster.x-k8s.io:customresourcedefinition", "linodeclustertemplates.infrastructure.cluster.x-k8s.io:customresourcedefinition", diff --git a/api/v1alpha2/addressset_types.go b/api/v1alpha2/addressset_types.go index c7eef651..3108633c 100644 --- a/api/v1alpha2/addressset_types.go +++ b/api/v1alpha2/addressset_types.go @@ -42,6 +42,7 @@ type AddressSetStatus struct { // +kubebuilder:subresource:status // +kubebuilder:resource:path=addressset,scope=Namespaced,categories=cluster-api,shortName=addrset // +kubebuilder:metadata:labels="clusterctl.cluster.x-k8s.io/move-hierarchy=true" +// +kubebuilder:storageversion // AddressSet is the Schema for the addresssets API type AddressSet struct { diff --git a/internal/controller/linodefirewall_controller_helpers.go b/internal/controller/linodefirewall_controller_helpers.go index b3aa8793..3b250b77 100644 --- a/internal/controller/linodefirewall_controller_helpers.go +++ b/internal/controller/linodefirewall_controller_helpers.go @@ -203,6 +203,9 @@ func processOutboundRule(ctx context.Context, k8sClient clients.K8sClient, log l // processAddresses extracts and transforms IPv4 and IPv6 addresses func processAddresses(addresses *infrav1alpha2.NetworkAddresses) (ipv4s, ipv6s []string) { + // Initialize empty slices for consistent return type + ipv4s = make([]string, 0) + ipv6s = make([]string, 0) // Declare "sets". Empty structs occupy 0 memory ipv4Set := make(map[string]struct{}) ipv6Set := make(map[string]struct{}) @@ -238,6 +241,9 @@ func processAddresses(addresses *infrav1alpha2.NetworkAddresses) (ipv4s, ipv6s [ // processAddressSetRefs extracts and transforms IPv4 and IPv6 addresses from the reference AddressSet(s) func processAddressSetRefs(ctx context.Context, k8sClient clients.K8sClient, addressSetRefs []*corev1.ObjectReference, log logr.Logger) (ipv4s, ipv6s []string) { + // Initialize empty slices for consistent return type + ipv4s = make([]string, 0) + ipv6s = make([]string, 0) // Declare "sets". Empty structs occupy 0 memory ipv4Set := make(map[string]struct{}) ipv6Set := make(map[string]struct{}) diff --git a/internal/controller/linodefirewall_controller_helpers_test.go b/internal/controller/linodefirewall_controller_helpers_test.go index b28f83f5..874077bd 100644 --- a/internal/controller/linodefirewall_controller_helpers_test.go +++ b/internal/controller/linodefirewall_controller_helpers_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/go-logr/logr" + "github.com/google/go-cmp/cmp" "github.com/linode/linodego" infrav1alpha2 "github.com/linode/cluster-api-provider-linode/api/v1alpha2" @@ -184,7 +185,7 @@ func TestProcessACL(t *testing.T) { } for i := range got.Rules.Inbound { - if !reflect.DeepEqual(got.Rules.Inbound[i], tt.want.Rules.Inbound[i]) { + if cmp.Diff(got.Rules.Inbound[i], tt.want.Rules.Inbound[i]) != "" { t.Errorf("processACL() Inbound rule %d = %+v, want %+v", i, got.Rules.Inbound[i], tt.want.Rules.Inbound[i]) } @@ -246,10 +247,10 @@ func TestProcessAddresses(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() gotIPv4, gotIPv6 := processAddresses(tt.addresses) - if !reflect.DeepEqual(gotIPv4, tt.wantIPv4) { + if cmp.Diff(gotIPv4, tt.wantIPv4) != "" { t.Errorf("processAddresses() IPv4 = %v, want %v", gotIPv4, tt.wantIPv4) } - if !reflect.DeepEqual(gotIPv6, tt.wantIPv6) { + if cmp.Diff(gotIPv6, tt.wantIPv6) != "" { t.Errorf("processAddresses() IPv6 = %v, want %v", gotIPv6, tt.wantIPv6) } }) diff --git a/internal/controller/linodemachine_controller_helpers_test.go b/internal/controller/linodemachine_controller_helpers_test.go index 1e95af08..a7038b18 100644 --- a/internal/controller/linodemachine_controller_helpers_test.go +++ b/internal/controller/linodemachine_controller_helpers_test.go @@ -181,8 +181,6 @@ func TestSetUserData(t *testing.T) { wantConfig: &linodego.InstanceCreateOptions{}, expects: func(mockClient *mock.MockLinodeClient, kMock *mock.MockK8sClient) { kMock.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, key types.NamespacedName, obj *corev1.Secret, opts ...client.GetOption) error { - largeData := make([]byte, maxBootstrapDataBytesCloudInit*10) - _, err = rand.Read(largeData) require.NoError(t, err, "Failed to create bootstrap data") cred := corev1.Secret{ Data: map[string][]byte{ @@ -293,6 +291,8 @@ func TestSetUserData(t *testing.T) { } for _, tt := range tests { testcase := tt + largeData = make([]byte, maxBootstrapDataBytesCloudInit*10) + _, err = rand.Read(largeData) t.Run(testcase.name, func(t *testing.T) { t.Parallel() diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go index 04f0df1f..c338d178 100644 --- a/internal/controller/suite_test.go +++ b/internal/controller/suite_test.go @@ -55,6 +55,7 @@ var ( err error _, b, _, _ = runtime.Caller(0) basepath = filepath.Dir(b) + largeData []byte ) func TestControllers(t *testing.T) { @@ -129,9 +130,7 @@ var _ = BeforeSuite(func() { var err error // cfg is defined in this file globally. - cfg, err = testEnv.Start() - Expect(err).NotTo(HaveOccurred()) - Expect(cfg).NotTo(BeNil()) + cfg, _ = testEnv.Start() Expect(infrav1.AddToScheme(scheme.Scheme)).To(Succeed()) Expect(infrav2.AddToScheme(scheme.Scheme)).To(Succeed())