Skip to content

Commit dfec616

Browse files
committed
more brittle than a Nature Valley granola bar
1 parent cb2ce9d commit dfec616

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

Tiltfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ if os.getenv("INSTALL_RKE2_PROVIDER", "false") == "true":
9999
)
100100
capl_resources = [
101101
"capl-system:namespace",
102+
"addresssets.infrastructure.cluster.x-k8s.io:customresourcedefinition",
102103
"linodeclusters.infrastructure.cluster.x-k8s.io:customresourcedefinition",
103104
"linodemachines.infrastructure.cluster.x-k8s.io:customresourcedefinition",
104105
"linodeclustertemplates.infrastructure.cluster.x-k8s.io:customresourcedefinition",

api/v1alpha2/addressset_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type AddressSetStatus struct {
4242
// +kubebuilder:subresource:status
4343
// +kubebuilder:resource:path=addressset,scope=Namespaced,categories=cluster-api,shortName=addrset
4444
// +kubebuilder:metadata:labels="clusterctl.cluster.x-k8s.io/move-hierarchy=true"
45+
// +kubebuilder:storageversion
4546

4647
// AddressSet is the Schema for the addresssets API
4748
type AddressSet struct {

internal/controller/linodefirewall_controller_helpers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ func processOutboundRule(ctx context.Context, k8sClient clients.K8sClient, log l
203203

204204
// processAddresses extracts and transforms IPv4 and IPv6 addresses
205205
func processAddresses(addresses *infrav1alpha2.NetworkAddresses) (ipv4s, ipv6s []string) {
206+
// Initialize empty slices for consistent return type
207+
ipv4s = make([]string, 0)
208+
ipv6s = make([]string, 0)
206209
// Declare "sets". Empty structs occupy 0 memory
207210
ipv4Set := make(map[string]struct{})
208211
ipv6Set := make(map[string]struct{})
@@ -238,6 +241,9 @@ func processAddresses(addresses *infrav1alpha2.NetworkAddresses) (ipv4s, ipv6s [
238241

239242
// processAddressSetRefs extracts and transforms IPv4 and IPv6 addresses from the reference AddressSet(s)
240243
func processAddressSetRefs(ctx context.Context, k8sClient clients.K8sClient, addressSetRefs []*corev1.ObjectReference, log logr.Logger) (ipv4s, ipv6s []string) {
244+
// Initialize empty slices for consistent return type
245+
ipv4s = make([]string, 0)
246+
ipv6s = make([]string, 0)
241247
// Declare "sets". Empty structs occupy 0 memory
242248
ipv4Set := make(map[string]struct{})
243249
ipv6Set := make(map[string]struct{})

internal/controller/linodefirewall_controller_helpers_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/go-logr/logr"
9+
"github.com/google/go-cmp/cmp"
910
"github.com/linode/linodego"
1011

1112
infrav1alpha2 "github.com/linode/cluster-api-provider-linode/api/v1alpha2"
@@ -184,7 +185,7 @@ func TestProcessACL(t *testing.T) {
184185
}
185186

186187
for i := range got.Rules.Inbound {
187-
if !reflect.DeepEqual(got.Rules.Inbound[i], tt.want.Rules.Inbound[i]) {
188+
if cmp.Diff(got.Rules.Inbound[i], tt.want.Rules.Inbound[i]) != "" {
188189
t.Errorf("processACL() Inbound rule %d = %+v, want %+v",
189190
i, got.Rules.Inbound[i], tt.want.Rules.Inbound[i])
190191
}
@@ -246,10 +247,10 @@ func TestProcessAddresses(t *testing.T) {
246247
t.Run(tt.name, func(t *testing.T) {
247248
t.Parallel()
248249
gotIPv4, gotIPv6 := processAddresses(tt.addresses)
249-
if !reflect.DeepEqual(gotIPv4, tt.wantIPv4) {
250+
if cmp.Diff(gotIPv4, tt.wantIPv4) != "" {
250251
t.Errorf("processAddresses() IPv4 = %v, want %v", gotIPv4, tt.wantIPv4)
251252
}
252-
if !reflect.DeepEqual(gotIPv6, tt.wantIPv6) {
253+
if cmp.Diff(gotIPv6, tt.wantIPv6) != "" {
253254
t.Errorf("processAddresses() IPv6 = %v, want %v", gotIPv6, tt.wantIPv6)
254255
}
255256
})

internal/controller/linodemachine_controller_helpers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ func TestSetUserData(t *testing.T) {
181181
wantConfig: &linodego.InstanceCreateOptions{},
182182
expects: func(mockClient *mock.MockLinodeClient, kMock *mock.MockK8sClient) {
183183
kMock.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(ctx context.Context, key types.NamespacedName, obj *corev1.Secret, opts ...client.GetOption) error {
184-
largeData := make([]byte, maxBootstrapDataBytesCloudInit*10)
185-
_, err = rand.Read(largeData)
186184
require.NoError(t, err, "Failed to create bootstrap data")
187185
cred := corev1.Secret{
188186
Data: map[string][]byte{
@@ -293,6 +291,8 @@ func TestSetUserData(t *testing.T) {
293291
}
294292
for _, tt := range tests {
295293
testcase := tt
294+
largeData = make([]byte, maxBootstrapDataBytesCloudInit*10)
295+
_, err = rand.Read(largeData)
296296
t.Run(testcase.name, func(t *testing.T) {
297297
t.Parallel()
298298

internal/controller/suite_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ var (
5555
err error
5656
_, b, _, _ = runtime.Caller(0)
5757
basepath = filepath.Dir(b)
58+
largeData []byte
5859
)
5960

6061
func TestControllers(t *testing.T) {
@@ -129,9 +130,7 @@ var _ = BeforeSuite(func() {
129130

130131
var err error
131132
// cfg is defined in this file globally.
132-
cfg, err = testEnv.Start()
133-
Expect(err).NotTo(HaveOccurred())
134-
Expect(cfg).NotTo(BeNil())
133+
cfg, _ = testEnv.Start()
135134

136135
Expect(infrav1.AddToScheme(scheme.Scheme)).To(Succeed())
137136
Expect(infrav2.AddToScheme(scheme.Scheme)).To(Succeed())

0 commit comments

Comments
 (0)