diff --git a/controllers/awsmachine_controller_unit_test.go b/controllers/awsmachine_controller_unit_test.go index d0505df8b6..44e7ef3058 100644 --- a/controllers/awsmachine_controller_unit_test.go +++ b/controllers/awsmachine_controller_unit_test.go @@ -1325,6 +1325,8 @@ func TestAWSMachineReconciler(t *testing.T) { ID: "myMachine", State: infrav1.InstanceStatePending, } + + //nolint:gosec presigned := "https://cluster-api-aws.s3.us-west-2.amazonaws.com/bootstrap-data.yaml?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA3SGQVQG7FGA6KKA6%2F20221104%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20221104T140227Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=b228dbec8c1008c80c162e1210e4503dceead1e4d4751b4d9787314fd6da4d55" objectStoreSvc.EXPECT().Create(gomock.Any(), gomock.Any()).Return(presigned, nil).Times(1) diff --git a/controlplane/eks/api/v1beta2/awsmanagedcontrolplane_webhook_test.go b/controlplane/eks/api/v1beta2/awsmanagedcontrolplane_webhook_test.go index 6fe2eb1b84..6de7c6fcc8 100644 --- a/controlplane/eks/api/v1beta2/awsmanagedcontrolplane_webhook_test.go +++ b/controlplane/eks/api/v1beta2/awsmanagedcontrolplane_webhook_test.go @@ -330,7 +330,7 @@ func TestWebhookCreate(t *testing.T) { }, } if tc.eksVersion != "" { - mcp.Spec.Version = &tc.eksVersion + mcp.Spec.Version = aws.String(tc.eksVersion) } if tc.hasAddons { testAddons := []Addon{ @@ -363,7 +363,7 @@ func TestWebhookCreate(t *testing.T) { func TestWebhookCreateIPv6Details(t *testing.T) { tests := []struct { name string - addons []Addon + addons *[]Addon kubeVersion string networkSpec infrav1.NetworkSpec err string @@ -391,7 +391,7 @@ func TestWebhookCreateIPv6Details(t *testing.T) { { name: "ipv6 with addons but cni version is lower than supported version", kubeVersion: "v1.22", - addons: []Addon{ + addons: &[]Addon{ { Name: vpcCniAddon, Version: "1.9.3", @@ -407,7 +407,7 @@ func TestWebhookCreateIPv6Details(t *testing.T) { { name: "ipv6 with addons and correct cni and cluster version", kubeVersion: "v1.22", - addons: []Addon{ + addons: &[]Addon{ { Name: vpcCniAddon, Version: "1.11.0", @@ -484,9 +484,9 @@ func TestWebhookCreateIPv6Details(t *testing.T) { }, Spec: AWSManagedControlPlaneSpec{ EKSClusterName: "test-cluster", - Addons: &tc.addons, + Addons: tc.addons, NetworkSpec: tc.networkSpec, - Version: &tc.kubeVersion, + Version: aws.String(tc.kubeVersion), }, } err := testEnv.Create(ctx, mcp) @@ -779,7 +779,7 @@ func TestValidatingWebhookCreateSecondaryCidr(t *testing.T) { }, } if tc.cidrRange != "" { - mcp.Spec.SecondaryCidrBlock = &tc.cidrRange + mcp.Spec.SecondaryCidrBlock = aws.String(tc.cidrRange) } warn, err := mcp.ValidateCreate() @@ -844,7 +844,7 @@ func TestValidatingWebhookUpdateSecondaryCidr(t *testing.T) { newMCP := &AWSManagedControlPlane{ Spec: AWSManagedControlPlaneSpec{ EKSClusterName: "default_cluster1", - SecondaryCidrBlock: &tc.cidrRange, + SecondaryCidrBlock: aws.String(tc.cidrRange), }, } oldMCP := &AWSManagedControlPlane{ diff --git a/hack/tools/Makefile b/hack/tools/Makefile index 9538907731..c530239c9b 100644 --- a/hack/tools/Makefile +++ b/hack/tools/Makefile @@ -45,7 +45,7 @@ ifeq ($(OS), windows) MDBOOK_EXTRACT_COMMAND := unzip -d /tmp endif -GOLANGCI_LINT_VERSION := v1.53.3 +GOLANGCI_LINT_VERSION := v1.55.2 ## -------------------------------------- ## Tooling Binaries ## -------------------------------------- diff --git a/pkg/cloud/interfaces.go b/pkg/cloud/interfaces.go index 2d68b2d7aa..a7f6609bdc 100644 --- a/pkg/cloud/interfaces.go +++ b/pkg/cloud/interfaces.go @@ -30,7 +30,7 @@ import ( // Session represents an AWS session. type Session interface { Session() awsclient.ConfigProvider - ServiceLimiter(string) *throttle.ServiceLimiter + ServiceLimiter(service string) *throttle.ServiceLimiter } // ScopeUsage is used to indicate which controller is using a scope. diff --git a/pkg/cloud/services/ec2/instances_test.go b/pkg/cloud/services/ec2/instances_test.go index a55f9ac5a5..946c4089e7 100644 --- a/pkg/cloud/services/ec2/instances_test.go +++ b/pkg/cloud/services/ec2/instances_test.go @@ -196,7 +196,7 @@ func TestInstanceIfExists(t *testing.T) { s := NewService(scope) s.EC2Client = ec2Mock - instance, err := s.InstanceIfExists(&tc.instanceID) + instance, err := s.InstanceIfExists(aws.String(tc.instanceID)) tc.check(instance, err) }) } @@ -298,7 +298,7 @@ func TestCreateInstance(t *testing.T) { testcases := []struct { name string - machine clusterv1.Machine + machine *clusterv1.Machine machineConfig *infrav1.AWSMachineSpec awsCluster *infrav1.AWSCluster expect func(m *mocks.MockEC2APIMockRecorder) @@ -306,7 +306,7 @@ func TestCreateInstance(t *testing.T) { }{ { name: "simple", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -419,7 +419,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with availability zone", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -550,7 +550,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with ImageLookupOrg specified at the machine level", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -700,7 +700,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with ImageLookupOrg specified at the cluster-level", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -850,7 +850,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "AWSMachine ImageLookupOrg overrides AWSCluster ImageLookupOrg", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -1001,7 +1001,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "subnet filter and failureDomain defined", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -1129,7 +1129,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with subnet ID that belongs to Cluster", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -1256,7 +1256,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with subnet ID that does not exist", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -1349,7 +1349,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with subnet ID that does not belong to Cluster", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -1475,7 +1475,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "subnet id and failureDomain don't match", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -1573,7 +1573,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "public IP true and failureDomain doesn't have public subnet", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -1656,7 +1656,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "public IP true and public subnet ID given", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -1786,7 +1786,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "public IP true and private subnet ID given", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -1885,7 +1885,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "both public IP and subnet filter defined", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -2023,7 +2023,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "public IP true and public subnet exists", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -2141,7 +2141,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "public IP true and no public subnet exists", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -2224,7 +2224,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with multiple block device mappings", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -2347,7 +2347,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with dedicated tenancy cloud-config", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, Namespace: "default", @@ -2503,7 +2503,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with custom placement group cloud-config", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, Namespace: "default", @@ -2659,7 +2659,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "with dedicated tenancy and placement group ignition", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, Namespace: "default", @@ -2819,7 +2819,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "expect the default SSH key when none is provided", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -2948,7 +2948,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "expect to use the cluster level ssh key name when no machine key name is provided", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -3078,7 +3078,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "expect to use the machine level ssh key name when both cluster and machine key names are provided", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -3209,7 +3209,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "expect ssh key to be unset when cluster key name is empty string and machine key name is nil", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -3337,7 +3337,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "expect ssh key to be unset when cluster key name is empty string and machine key name is empty string", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -3465,7 +3465,7 @@ func TestCreateInstance(t *testing.T) { }, { name: "expect ssh key to be unset when cluster key name is nil and machine key name is empty string", - machine: clusterv1.Machine{ + machine: &clusterv1.Machine{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{"set": "node"}, }, @@ -3620,7 +3620,7 @@ func TestCreateInstance(t *testing.T) { }, } - machine := &tc.machine + machine := tc.machine awsMachine := &infrav1.AWSMachine{ ObjectMeta: metav1.ObjectMeta{ diff --git a/pkg/cloud/services/elb/loadbalancer.go b/pkg/cloud/services/elb/loadbalancer.go index 40228eb805..a4a322324c 100644 --- a/pkg/cloud/services/elb/loadbalancer.go +++ b/pkg/cloud/services/elb/loadbalancer.go @@ -19,6 +19,7 @@ package elb import ( "context" "fmt" + "strconv" "strings" "time" @@ -186,7 +187,7 @@ func (s *Service) getAPIServerLBSpec(elbName string) (*infrav1.LoadBalancer, err VpcID: s.scope.VPC().ID, HealthCheck: &infrav1.TargetGroupHealthCheck{ Protocol: aws.String(string(additionalListeners.Protocol)), - Port: aws.String(fmt.Sprintf("%d", additionalListeners.Port)), + Port: aws.String(strconv.FormatInt(additionalListeners.Port, 10)), }, }, }) @@ -198,7 +199,8 @@ func (s *Service) getAPIServerLBSpec(elbName string) (*infrav1.LoadBalancer, err } if s.scope.ControlPlaneLoadBalancer() != nil { - res.ELBAttributes[infrav1.LoadBalancerAttributeEnableLoadBalancingCrossZone] = aws.String(fmt.Sprintf("%t", s.scope.ControlPlaneLoadBalancer().CrossZoneLoadBalancing)) + isCrossZoneLB := s.scope.ControlPlaneLoadBalancer().CrossZoneLoadBalancing + res.ELBAttributes[infrav1.LoadBalancerAttributeEnableLoadBalancingCrossZone] = aws.String(strconv.FormatBool(isCrossZoneLB)) } res.Tags = infrav1.Build(infrav1.BuildParams{ diff --git a/pkg/cloud/services/elb/loadbalancer_test.go b/pkg/cloud/services/elb/loadbalancer_test.go index 34704bc484..fcaf347fbd 100644 --- a/pkg/cloud/services/elb/loadbalancer_test.go +++ b/pkg/cloud/services/elb/loadbalancer_test.go @@ -46,12 +46,12 @@ import ( func TestELBName(t *testing.T) { tests := []struct { name string - awsCluster infrav1.AWSCluster + awsCluster *infrav1.AWSCluster expected string }{ { name: "name is not defined by user, so generate the default", - awsCluster: infrav1.AWSCluster{ + awsCluster: &infrav1.AWSCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: metav1.NamespaceDefault, @@ -61,7 +61,7 @@ func TestELBName(t *testing.T) { }, { name: "name is defined by user, so use it", - awsCluster: infrav1.AWSCluster{ + awsCluster: &infrav1.AWSCluster{ ObjectMeta: metav1.ObjectMeta{ Name: "example", Namespace: metav1.NamespaceDefault, @@ -89,7 +89,7 @@ func TestELBName(t *testing.T) { Namespace: tt.awsCluster.Namespace, }, }, - AWSCluster: &tt.awsCluster, + AWSCluster: tt.awsCluster, }) if err != nil { t.Fatalf("failed to create scope: %s", err) diff --git a/test/e2e/shared/defaults.go b/test/e2e/shared/defaults.go index 5342a5cfc7..c67c5538a5 100644 --- a/test/e2e/shared/defaults.go +++ b/test/e2e/shared/defaults.go @@ -70,6 +70,7 @@ const ( PostCSIKubernetesVer = "POST_1_23_KUBERNETES_VERSION" EFSSupport = "efs-support" IntreeCloudProvider = "intree-cloud-provider" + MultiTenancy = "MULTI_TENANCY_" ) var ResourceQuotaFilePath = "/tmp/capa-e2e-resource-usage.lock" @@ -84,15 +85,15 @@ var ( type MultitenancyRole string func (m MultitenancyRole) EnvVarARN() string { - return "MULTI_TENANCY_" + strings.ToUpper(string(m)) + "_ROLE_ARN" + return MultiTenancy + strings.ToUpper(string(m)) + "_ROLE_ARN" } func (m MultitenancyRole) EnvVarName() string { - return "MULTI_TENANCY_" + strings.ToUpper(string(m)) + "_ROLE_NAME" + return MultiTenancy + strings.ToUpper(string(m)) + "_ROLE_NAME" } func (m MultitenancyRole) EnvVarIdentity() string { - return "MULTI_TENANCY_" + strings.ToUpper(string(m)) + "_IDENTITY_NAME" + return MultiTenancy + strings.ToUpper(string(m)) + "_IDENTITY_NAME" } func (m MultitenancyRole) IdentityName() string { diff --git a/test/e2e/suites/unmanaged/unmanaged_functional_test.go b/test/e2e/suites/unmanaged/unmanaged_functional_test.go index 5237f8d274..203b3fc34c 100644 --- a/test/e2e/suites/unmanaged/unmanaged_functional_test.go +++ b/test/e2e/suites/unmanaged/unmanaged_functional_test.go @@ -47,6 +47,8 @@ import ( "sigs.k8s.io/cluster-api/util/conditions" ) +const TestSvc = "test-svc-" + var _ = ginkgo.Context("[unmanaged] [functional]", func() { var ( ctx context.Context @@ -334,7 +336,7 @@ var _ = ginkgo.Context("[unmanaged] [functional]", func() { }, e2eCtx.E2EConfig.GetIntervals(specName, "wait-contolplane-upgrade")...) ginkgo.By("Creating the LB service") - lbServiceName := "test-svc-" + util.RandomString(6) + lbServiceName := TestSvc + util.RandomString(6) elbName := createLBService(metav1.NamespaceDefault, lbServiceName, clusterClient) verifyElbExists(elbName, true) @@ -404,7 +406,7 @@ var _ = ginkgo.Context("[unmanaged] [functional]", func() { }, e2eCtx.E2EConfig.GetIntervals(specName, "wait-contolplane-upgrade")...) ginkgo.By("Creating the LB service") - lbServiceName := "test-svc-" + util.RandomString(6) + lbServiceName := TestSvc + util.RandomString(6) elbName := createLBService(metav1.NamespaceDefault, lbServiceName, clusterClient) verifyElbExists(elbName, true) @@ -474,7 +476,7 @@ var _ = ginkgo.Context("[unmanaged] [functional]", func() { }, e2eCtx.E2EConfig.GetIntervals(specName, "wait-contolplane-upgrade")...) ginkgo.By("Creating the LB service") - lbServiceName := "test-svc-" + util.RandomString(6) + lbServiceName := TestSvc + util.RandomString(6) elbName := createLBService(metav1.NamespaceDefault, lbServiceName, clusterClient) verifyElbExists(elbName, true)