Skip to content

Commit

Permalink
more brittle than a Nature Valley granola bar
Browse files Browse the repository at this point in the history
  • Loading branch information
AshleyDumaine committed Nov 27, 2024
1 parent cb2ce9d commit dfec616
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha2/addressset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions internal/controller/linodefirewall_controller_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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{})
Expand Down
7 changes: 4 additions & 3 deletions internal/controller/linodefirewall_controller_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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])
}
Expand Down Expand Up @@ -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)
}
})
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/linodemachine_controller_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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()

Expand Down
5 changes: 2 additions & 3 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
err error
_, b, _, _ = runtime.Caller(0)
basepath = filepath.Dir(b)
largeData []byte
)

func TestControllers(t *testing.T) {
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit dfec616

Please sign in to comment.