Skip to content

Commit f773f4b

Browse files
Merge pull request #3094 from olucasfreitas/OCM-18910-lint
OCM-18910 | fix: Fix linter errors for #3093
2 parents 2ffb33a + 3551093 commit f773f4b

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

pkg/aws/client.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ type Client interface {
223223
ListPolicyVersions(policyArn string) ([]PolicyVersion, error)
224224
GetCallerIdentity() (*sts.GetCallerIdentityOutput, error)
225225
CheckIfMachinePoolHasDedicatedHost(instanceIDs []string) (bool, error)
226-
CreateStackWithParamsTags(ctx context.Context, cfTemplateBody, stackName string, stackParams, stackTags map[string]string) (*string, error)
226+
CreateStackWithParamsTags(ctx context.Context, cfTemplateBody, stackName string,
227+
stackParams, stackTags map[string]string) (*string, error)
227228
GetCFStack(ctx context.Context, stackName string) (*cftypes.Stack, error)
228229
DescribeCFStackResources(ctx context.Context, stackName string) (*[]cftypes.StackResource, error)
229230
DeleteCFStack(ctx context.Context, stackName string) error
@@ -559,7 +560,7 @@ func (c *awsClient) FetchPublicSubnetMap(subnets []ec2types.Subnet) (map[string]
559560
}
560561
if routeTablesResp == nil {
561562
return mapSubnetIdToPublic, fmt.Errorf(
562-
"No route table found for associated subnets '%s'",
563+
"no route table found for associated subnets '%s'",
563564
helper.SliceToSortedString(aws.ToStringSlice(subnetIds)),
564565
)
565566
}
@@ -823,7 +824,7 @@ func (c *awsClient) ValidateCredentials() (bool, error) {
823824
_, err := c.stsClient.GetCallerIdentity(context.Background(), &sts.GetCallerIdentityInput{})
824825
if err != nil {
825826
if strings.Contains(fmt.Sprintf("%s", err), "InvalidClientTokenId") {
826-
awsErr := fmt.Errorf("Invalid AWS Credentials: %s.\n For help configuring your credentials, see %s",
827+
awsErr := fmt.Errorf("invalid AWS Credentials: %s.\n For help configuring your credentials, see %s",
827828
err,
828829
"https://docs.openshift.com/rosa/rosa_install_access_delete_clusters/rosa_getting_started_iam/"+
829830
"rosa-config-aws-account.html#rosa-configuring-aws-account_rosa-config-aws-account")
@@ -1137,7 +1138,7 @@ func (c *awsClient) GetAvailabilityZoneType(availabilityZoneName string) (string
11371138
return "", err
11381139
}
11391140
if len(availabilityZones.AvailabilityZones) < 1 {
1140-
return "", fmt.Errorf("Failed to find availability zone '%s'", availabilityZoneName)
1141+
return "", fmt.Errorf("failed to find availability zone '%s'", availabilityZoneName)
11411142
}
11421143
return aws.ToString(availabilityZones.AvailabilityZones[0].ZoneType), nil
11431144
}
@@ -1435,7 +1436,8 @@ func (c *awsClient) ListServiceAccountRoles(clusterName string) ([]iamtypes.Role
14351436
}
14361437

14371438
for _, tag := range listTagsResult.Tags {
1438-
if aws.ToString(tag.Key) == iamserviceaccount.RoleTypeTagKey && aws.ToString(tag.Value) == iamserviceaccount.ServiceAccountRoleType {
1439+
if aws.ToString(tag.Key) == iamserviceaccount.RoleTypeTagKey &&
1440+
aws.ToString(tag.Value) == iamserviceaccount.ServiceAccountRoleType {
14391441
isServiceAccountRole = true
14401442
}
14411443
if aws.ToString(tag.Key) == iamserviceaccount.ClusterTagKey && aws.ToString(tag.Value) == clusterName {
@@ -1460,17 +1462,19 @@ func (c *awsClient) ListServiceAccountRoles(clusterName string) ([]iamtypes.Role
14601462
}
14611463

14621464
// GetServiceAccountRoleDetails gets detailed information about a service account role using existing methods
1463-
func (c *awsClient) GetServiceAccountRoleDetails(roleName string) (*iamtypes.Role, []iamtypes.AttachedPolicy, []string, error) {
1465+
func (c *awsClient) GetServiceAccountRoleDetails(roleName string) (
1466+
*iamtypes.Role, []iamtypes.AttachedPolicy, []string, error) {
14641467
// Use existing GetRoleByName method
14651468
role, err := c.GetRoleByName(roleName)
14661469
if err != nil {
14671470
return nil, nil, nil, fmt.Errorf("failed to get role %s: %w", roleName, err)
14681471
}
14691472

14701473
// Get attached managed policies
1471-
listAttachedPoliciesResult, err := c.iamClient.ListAttachedRolePolicies(context.Background(), &iam.ListAttachedRolePoliciesInput{
1472-
RoleName: aws.String(roleName),
1473-
})
1474+
listAttachedPoliciesResult, err := c.iamClient.ListAttachedRolePolicies(context.Background(),
1475+
&iam.ListAttachedRolePoliciesInput{
1476+
RoleName: aws.String(roleName),
1477+
})
14741478
if err != nil {
14751479
return nil, nil, nil, fmt.Errorf("failed to list attached policies for role %s: %w", roleName, err)
14761480
}

pkg/aws/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ var _ = Describe("Client", func() {
515515

516516
valid, err := client.ValidateCredentials()
517517
Expect(valid).To(BeFalse())
518-
Expect(err.Error()).To(ContainSubstring(
519-
"Invalid AWS Credentials: %s.\n For help configuring your credentials, see", errMsg))
518+
expectedErr := fmt.Sprintf("invalid AWS Credentials: %s.\n For help configuring your credentials, see", errMsg)
519+
Expect(err.Error()).To(ContainSubstring(expectedErr))
520520
})
521521

522522
It("Does not wrap other errors and returns false", func() {

pkg/machinepool/validation.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ func ValidateKubeletConfig(input interface{}) error {
1313
return validateCount(answers)
1414
}
1515

16-
return fmt.Errorf("Input for kubelet config flag is not valid")
16+
return fmt.Errorf("input for kubelet config flag is not valid")
1717
}
1818

1919
func validateCount[K any](kubeletConfigs []K) error {
2020
if len(kubeletConfigs) > 1 {
21-
return fmt.Errorf("Only a single kubelet config is supported for Machine Pools")
21+
return fmt.Errorf("only a single kubelet config is supported for Machine Pools")
2222
}
2323
return nil
2424
}
@@ -27,35 +27,35 @@ func validateEditInput(poolType string, autoscaling bool, minReplicas int, maxRe
2727
isReplicasSet bool, isAutoscalingSet bool, isMinReplicasSet bool, isMaxReplicasSet bool, id string) error {
2828

2929
if autoscaling && minReplicas < 0 && isMinReplicasSet {
30-
return fmt.Errorf("Min replicas must be a non-negative number when autoscaling is set")
30+
return fmt.Errorf("min replicas must be a non-negative number when autoscaling is set")
3131
}
3232

3333
if autoscaling && maxReplicas < 0 && isMaxReplicasSet {
34-
return fmt.Errorf("Max replicas must be a non-negative number when autoscaling is set")
34+
return fmt.Errorf("max replicas must be a non-negative number when autoscaling is set")
3535
}
3636

3737
if !autoscaling && replicas < 0 {
38-
return fmt.Errorf("Replicas must be a non-negative number")
38+
return fmt.Errorf("replicas must be a non-negative number")
3939
}
4040

4141
if autoscaling && isReplicasSet && isAutoscalingSet {
42-
return fmt.Errorf("Autoscaling enabled on %s pool '%s'. can't set replicas", poolType, id)
42+
return fmt.Errorf("autoscaling enabled on %s pool '%s'. can't set replicas", poolType, id)
4343
}
4444

4545
if autoscaling && isAutoscalingSet && maxReplicas < minReplicas {
46-
return fmt.Errorf("Max replicas must not be greater than min replicas when autoscaling is enabled")
46+
return fmt.Errorf("max replicas must not be greater than min replicas when autoscaling is enabled")
4747
}
4848

4949
if !autoscaling && (isMinReplicasSet || isMaxReplicasSet) {
50-
return fmt.Errorf("Autoscaling disabled on %s pool '%s'. can't set min or max replicas", poolType, id)
50+
return fmt.Errorf("autoscaling disabled on %s pool '%s'. can't set min or max replicas", poolType, id)
5151
}
5252

5353
return nil
5454
}
5555

5656
func validateCapacityReservationId(proposedId, nodepoolId, existingId string) error {
5757
if existingId != "" {
58-
return fmt.Errorf("Unable to change 'capacity-reservation-id' to '%s'. AWS NodePool '%s' already has a "+
58+
return fmt.Errorf("unable to change 'capacity-reservation-id' to '%s'. AWS NodePool '%s' already has a "+
5959
"Capacity Reservation ID: '%s'", proposedId, nodepoolId, existingId)
6060
}
6161
return nil

pkg/machinepool/validation_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var _ = Describe("MachinePool validation", func() {
1313
kubeletConfigs := []string{"foo", "bar"}
1414
err := ValidateKubeletConfig(kubeletConfigs)
1515
Expect(err).To(HaveOccurred())
16-
Expect(err.Error()).To(Equal("Only a single kubelet config is supported for Machine Pools"))
16+
Expect(err.Error()).To(Equal("only a single kubelet config is supported for Machine Pools"))
1717
})
1818

1919
It("Fails if customer requests more than 1 kubelet config via []core.OptionAnswer", func() {
@@ -29,7 +29,7 @@ var _ = Describe("MachinePool validation", func() {
2929
}
3030
err := ValidateKubeletConfig(kubeletConfigs)
3131
Expect(err).To(HaveOccurred())
32-
Expect(err.Error()).To(Equal("Only a single kubelet config is supported for Machine Pools"))
32+
Expect(err.Error()).To(Equal("only a single kubelet config is supported for Machine Pools"))
3333
})
3434

3535
It("Passes if a customer selects only a single kubelet config via []core.OptionAnswer", func() {
@@ -62,7 +62,7 @@ var _ = Describe("MachinePool validation", func() {
6262
It("Fails if the input is not a []string or []core.OptionAnswer", func() {
6363
err := ValidateKubeletConfig("foo")
6464
Expect(err).To(HaveOccurred())
65-
Expect(err.Error()).To(Equal("Input for kubelet config flag is not valid"))
65+
Expect(err.Error()).To(Equal("input for kubelet config flag is not valid"))
6666
})
6767
})
6868
Context("Validate edit machinepool options", func() {
@@ -116,7 +116,7 @@ var _ = Describe("MachinePool validation", func() {
116116
})
117117
It("Fails when capacity reservation ID is set", func() {
118118
Expect(validateCapacityReservationId("new-id", "aws-nodepool-1", "old-id").Error()).
119-
Should(ContainSubstring("Unable to change 'capacity-reservation-id' to 'new-id'. " +
119+
Should(ContainSubstring("unable to change 'capacity-reservation-id' to 'new-id'. " +
120120
"AWS NodePool 'aws-nodepool-1' already has a Capacity Reservation ID: 'old-id'"))
121121
})
122122
})

0 commit comments

Comments
 (0)