Skip to content

Commit

Permalink
Address linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Cole committed Sep 21, 2023
1 parent 013cf14 commit 062a0bc
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 36 deletions.
1 change: 0 additions & 1 deletion pkg/apis/settings/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/apis/v1alpha5/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions pkg/controllers/nodeclass/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ func (c *Controller) resolveAMIs(ctx context.Context, nodeClass *v1beta1.EC2Node
func (c *Controller) resolveLicenses(ctx context.Context, nodeClass *v1beta1.EC2NodeClass) error {
licenses, err := c.licenseProvider.Get(ctx, nodeClass)
if err != nil {
// Errors from license provider should not interrupt the process
return nil
return err
}
nodeClass.Status.Licenses = licenses

Expand All @@ -181,8 +180,7 @@ func (c *Controller) resolveLicenses(ctx context.Context, nodeClass *v1beta1.EC2
func (c *Controller) resolveHostResourceGroups(ctx context.Context, nodeClass *v1beta1.EC2NodeClass) error {
result, err := c.hostResourceGroupProvider.Get(ctx, nodeClass)
if err != nil {
// Errors from host resource group provider should not interrupt the process
return nil
return err
}

nodeClass.Status.HostResourceGroup = result
Expand All @@ -193,8 +191,7 @@ func (c *Controller) resolveHostResourceGroups(ctx context.Context, nodeClass *v
func (c *Controller) resolvePlacementGroups(ctx context.Context, nodeClass *v1beta1.EC2NodeClass) error {
result, err := c.placementGroupProvider.Get(ctx, nodeClass)
if err != nil {
// Errors from placement group provider should not interrupt the process
return nil
return err
}
if result != nil {
nodeClass.Status.PlacementGroups = append(nodeClass.Status.PlacementGroups, *result.GroupArn)
Expand Down
3 changes: 1 addition & 2 deletions pkg/fake/lmapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type LicenseManagerAPI struct {
LicenseManagerBehaviour
}
type LicenseManagerBehaviour struct {
NextError AtomicError
NextError AtomicError
ListLicenseConfigurationsOutput AtomicPtr[licensemanager.ListLicenseConfigurationsOutput]
}

Expand All @@ -48,4 +48,3 @@ func (l *LicenseManagerAPI) ListLicenseConfigurations(_ aws.Context, _ *licensem
// fail if the test doesn't provide specific data which causes our pricing provider to use its static price list
return errors.New("no license data provided")
}

8 changes: 4 additions & 4 deletions pkg/fake/rgapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
)

var (
TEST_LICENSE_ARN = "arn:aws:license-manager:us-west-2:11111111111:license-configuration:lic-94ba36399bd98eaad808b0ffb1d1604b"
TEST_LICENSE_NAME = "test-license"
TestLicenseArn = "arn:aws:license-manager:us-west-2:11111111111:license-configuration:lic-94ba36399bd98eaad808b0ffb1d1604b"
TestLicenseName = "test-license"
)

type ResourceGroupsAPI struct {
Expand All @@ -43,11 +43,11 @@ func (r *ResourceGroupsAPI) Reset() {
r.ListGroupsOutput.Reset()
}

func (r *ResourceGroupsAPI) ListGroupsWithContext(_ aws.Context, input *resourcegroups.ListGroupsInput, opts ...request.Option) (*resourcegroups.ListGroupsOutput, error) {
func (r *ResourceGroupsAPI) ListGroupsWithContext(_ aws.Context, input *resourcegroups.ListGroupsInput, _ ...request.Option) (*resourcegroups.ListGroupsOutput, error) {
return r.ListGroupsBehavior.Invoke(input, func(input *resourcegroups.ListGroupsInput) (*resourcegroups.ListGroupsOutput, error) {
return &resourcegroups.ListGroupsOutput{
GroupIdentifiers: []*resourcegroups.GroupIdentifier{
{GroupArn: aws.String(TEST_LICENSE_ARN), GroupName: aws.String(TEST_LICENSE_NAME)},
{GroupArn: aws.String(TestLicenseArn), GroupName: aws.String(TestLicenseName)},
},
}, nil
})
Expand Down
20 changes: 9 additions & 11 deletions pkg/providers/amifamily/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ func (r Resolver) Resolve(ctx context.Context, nodeClass *v1beta1.EC2NodeClass,
if len(mappedAMIs) == 0 {
return nil, fmt.Errorf("no instance types satisfy requirements of amis %v", amis)
}
placement, err := r.resolvePlacement(ctx, nodeClass)
if err != nil {
return nil, err
}
var resolvedTemplates []*LaunchTemplate
for amiID, instanceTypes := range mappedAMIs {
maxPodsToInstanceTypes := lo.GroupBy(instanceTypes, func(instanceType *cloudprovider.InstanceType) int {
Expand Down Expand Up @@ -183,7 +179,7 @@ func (r Resolver) Resolve(ctx context.Context, nodeClass *v1beta1.EC2NodeClass,
AMIID: amiID,
InstanceTypes: instanceTypes,
Licenses: nodeClass.Status.Licenses,
Placement: placement,
Placement: r.resolvePlacement(nodeClass),
}
if len(resolved.BlockDeviceMappings) == 0 {
resolved.BlockDeviceMappings = amiFamily.DefaultBlockDeviceMappings()
Expand All @@ -197,21 +193,23 @@ func (r Resolver) Resolve(ctx context.Context, nodeClass *v1beta1.EC2NodeClass,
return resolvedTemplates, nil
}

func (r Resolver) resolvePlacement(ctx context.Context, nodeClass *v1beta1.EC2NodeClass) (*Placement, error) {
func (r Resolver) resolvePlacement(nodeClass *v1beta1.EC2NodeClass) *Placement {
var placement *Placement
hrg := nodeClass.Status.HostResourceGroup
pg := nodeClass.Status.PlacementGroups

if pg != nil {
if pg != nil || hrg != nil {
placement = &Placement{}
if len(pg) > 0 {
placement.PlacementGroup = pg[0]
}
}
if hrg != nil {
placement.HostResourceGroup = hrg.Name

if hrg != nil {
placement.HostResourceGroup = hrg.Name
}
}

return placement, nil
return placement
}

func GetAMIFamily(amiFamily *string, options *Options) AMIFamily {
Expand Down
6 changes: 3 additions & 3 deletions pkg/test/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewEnvironment(ctx context.Context, env *coretest.Environment) *Environment
ec2api := &fake.EC2API{}
ssmapi := &fake.SSMAPI{}
lmapi := &fake.LicenseManagerAPI{}
rgapi := &fake.ResourceGroupsAPI{}
rgapi := &fake.ResourceGroupsAPI{}

// cache
ec2Cache := cache.New(awscache.DefaultTTL, awscache.DefaultCleanupInterval)
Expand All @@ -103,8 +103,8 @@ func NewEnvironment(ctx context.Context, env *coretest.Environment) *Environment
versionProvider := version.NewProvider(env.KubernetesInterface, kubernetesVersionCache)
amiProvider := amifamily.NewProvider(versionProvider, ssmapi, ec2api, ec2Cache)
licenseProvider := license.NewProvider(lmapi.LicenseManagerAPI, licenseCache)
hostResourceGroupProvider := hostresourcegroup.NewProvider(rgapi, hostResourceGroupsCache)
placementGroupProvider := placementgroup.NewProvider(ec2api, placementGroupCache)
hostResourceGroupProvider := hostresourcegroup.NewProvider(rgapi, hostResourceGroupsCache)
placementGroupProvider := placementgroup.NewProvider(ec2api, placementGroupCache)

amiResolver := amifamily.New(amiProvider, licenseProvider, hostResourceGroupProvider, placementGroupProvider)
instanceTypesProvider := instancetype.NewProvider("", instanceTypeCache, ec2api, subnetProvider, unavailableOfferingsCache, pricingProvider)
Expand Down
12 changes: 6 additions & 6 deletions pkg/utils/nodeclass/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,13 @@ var _ = Describe("NodeClassUtils", func() {
Expect(convertedNodeTemplate.Status.Subnets).To(Equal(nodeTemplate.Status.Subnets))
Expect(convertedNodeTemplate.Status.AMIs).To(Equal(nodeTemplate.Status.AMIs))
})
It("should convert a AWSNodeTemplate with LicenseSelectors to a EC2NodeClass and back", func() {
nodeTemplate.Status.Licenses = []string{"test-license"}
nodeTemplate.Spec.LicenseSelector = map[string]string{"name": "test-license"}
It("should convert a AWSNodeTemplate with LicenseSelectors to a EC2NodeClass and back", func() {
nodeTemplate.Status.Licenses = []string{"test-license"}
nodeTemplate.Spec.LicenseSelector = map[string]string{"name": "test-license"}
convertedNodeTemplate := nodetemplateutil.New(nodeclassutil.New(nodeTemplate))
Expect(convertedNodeTemplate.Status.Licenses).To(Equal(nodeTemplate.Status.Licenses))
Expect(convertedNodeTemplate.Spec.LicenseSelector).To(Equal(nodeTemplate.Spec.LicenseSelector))
})
Expect(convertedNodeTemplate.Status.Licenses).To(Equal(nodeTemplate.Status.Licenses))
Expect(convertedNodeTemplate.Spec.LicenseSelector).To(Equal(nodeTemplate.Spec.LicenseSelector))
})
It("should retrieve a EC2NodeClass with a get call", func() {
nodeClass := test.EC2NodeClass()
ExpectApplied(ctx, env.Client, nodeClass)
Expand Down

0 comments on commit 062a0bc

Please sign in to comment.