Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: added a test where there is no ips #7549

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pkg/providers/instance/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,40 @@
retrievedIDs := sets.New[string](lo.Map(instances, func(i *instance.Instance, _ int) string { return i.ID })...)
Expect(ids.Equal(retrievedIDs)).To(BeTrue())
})
It("should not consider subnet with no available IPs for instance creation", func() {
// Prepare the context, nodeClass, and nodeClaim as in the other tests
ExpectApplied(ctx, env.Client, nodeClaim, nodePool, nodeClass)
nodeClass = ExpectExists(ctx, env.Client, nodeClass)

awsEnv.EC2API.Subnets.Store(subnetID, ec2types.Subnet{

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.27.x)

awsEnv.EC2API.Subnets undefined (type *fake.EC2API has no field or method Subnets)

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.27.x)

undefined: subnetID

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.29.x)

awsEnv.EC2API.Subnets undefined (type *fake.EC2API has no field or method Subnets)

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.29.x)

undefined: subnetID

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.28.x)

awsEnv.EC2API.Subnets undefined (type *fake.EC2API has no field or method Subnets)

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.28.x)

undefined: subnetID

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.26.x)

awsEnv.EC2API.Subnets undefined (type *fake.EC2API has no field or method Subnets)

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.26.x)

undefined: subnetID

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.30.x)

awsEnv.EC2API.Subnets undefined (type *fake.EC2API has no field or method Subnets)

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.30.x)

undefined: subnetID

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.25.x)

awsEnv.EC2API.Subnets undefined (type *fake.EC2API has no field or method Subnets)

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.25.x)

undefined: subnetID

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.31.x)

awsEnv.EC2API.Subnets undefined (type *fake.EC2API has no field or method Subnets)

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.31.x)

undefined: subnetID

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci

awsEnv.EC2API.Subnets undefined (type *fake.EC2API has no field or method Subnets)

Check failure on line 213 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci

undefined: subnetID
SubnetId: aws.String(fake.subnetID),

Check failure on line 214 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.27.x)

undefined: fake.subnetID

Check failure on line 214 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.29.x)

undefined: fake.subnetID

Check failure on line 214 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.28.x)

undefined: fake.subnetID

Check failure on line 214 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.26.x)

undefined: fake.subnetID

Check failure on line 214 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.30.x)

undefined: fake.subnetID

Check failure on line 214 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.25.x)

undefined: fake.subnetID

Check failure on line 214 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.31.x)

undefined: fake.subnetID

Check failure on line 214 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci

undefined: fake.subnetID
AvailableIpAddressCount: aws.Int32(0), // 0 available IPs
AvailabilityZone: aws.String(fake.AvailabilityZone),

Check failure on line 216 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.27.x)

undefined: fake.AvailabilityZone

Check failure on line 216 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.29.x)

undefined: fake.AvailabilityZone

Check failure on line 216 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.28.x)

undefined: fake.AvailabilityZone

Check failure on line 216 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.26.x)

undefined: fake.AvailabilityZone

Check failure on line 216 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.30.x)

undefined: fake.AvailabilityZone

Check failure on line 216 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.25.x)

undefined: fake.AvailabilityZone

Check failure on line 216 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.31.x)

undefined: fake.AvailabilityZone

Check failure on line 216 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci

undefined: fake.AvailabilityZone
})

// Update the EC2 API mock to include this subnet
awsEnv.EC2API.DescribeSubnetsReturns = func(input *ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error) {

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.27.x)

awsEnv.EC2API.DescribeSubnetsReturns undefined (type *fake.EC2API has no field or method DescribeSubnetsReturns)

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.27.x)

undefined: ec2

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.29.x)

awsEnv.EC2API.DescribeSubnetsReturns undefined (type *fake.EC2API has no field or method DescribeSubnetsReturns)

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.29.x)

undefined: ec2

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.28.x)

awsEnv.EC2API.DescribeSubnetsReturns undefined (type *fake.EC2API has no field or method DescribeSubnetsReturns)

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.28.x)

undefined: ec2

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.26.x)

awsEnv.EC2API.DescribeSubnetsReturns undefined (type *fake.EC2API has no field or method DescribeSubnetsReturns)

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.26.x)

undefined: ec2

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.30.x)

awsEnv.EC2API.DescribeSubnetsReturns undefined (type *fake.EC2API has no field or method DescribeSubnetsReturns)

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.30.x)

undefined: ec2

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.25.x)

awsEnv.EC2API.DescribeSubnetsReturns undefined (type *fake.EC2API has no field or method DescribeSubnetsReturns)

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.25.x)

undefined: ec2

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.31.x)

awsEnv.EC2API.DescribeSubnetsReturns undefined (type *fake.EC2API has no field or method DescribeSubnetsReturns)

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.31.x)

undefined: ec2

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci

awsEnv.EC2API.DescribeSubnetsReturns undefined (type *fake.EC2API has no field or method DescribeSubnetsReturns)

Check failure on line 220 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci

undefined: ec2
return &ec2.DescribeSubnetsOutput{

Check failure on line 221 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.27.x)

undefined: ec2

Check failure on line 221 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.29.x)

undefined: ec2

Check failure on line 221 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.28.x)

undefined: ec2

Check failure on line 221 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.26.x)

undefined: ec2

Check failure on line 221 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.30.x)

undefined: ec2

Check failure on line 221 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.25.x)

undefined: ec2

Check failure on line 221 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.31.x)

undefined: ec2

Check failure on line 221 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci

undefined: ec2
Subnets: []ec2types.Subnet{
{
SubnetId: aws.String(fake.subnetID),

Check failure on line 224 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.27.x)

undefined: fake.subnetID

Check failure on line 224 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.29.x)

undefined: fake.subnetID

Check failure on line 224 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.28.x)

undefined: fake.subnetID

Check failure on line 224 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.26.x)

undefined: fake.subnetID

Check failure on line 224 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.30.x)

undefined: fake.subnetID

Check failure on line 224 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.25.x)

undefined: fake.subnetID

Check failure on line 224 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.31.x)

undefined: fake.subnetID

Check failure on line 224 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci

undefined: fake.subnetID
AvailableIpAddressCount: aws.Int32(0), // 0 available IPs
AvailabilityZone: aws.String(fake.AvailabilityZone),

Check failure on line 226 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.27.x)

undefined: fake.AvailabilityZone

Check failure on line 226 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.29.x)

undefined: fake.AvailabilityZone

Check failure on line 226 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.28.x)

undefined: fake.AvailabilityZone

Check failure on line 226 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.26.x)

undefined: fake.AvailabilityZone

Check failure on line 226 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.30.x)

undefined: fake.AvailabilityZone

Check failure on line 226 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.25.x)

undefined: fake.AvailabilityZone

Check failure on line 226 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci-test (1.31.x)

undefined: fake.AvailabilityZone

Check failure on line 226 in pkg/providers/instance/suite_test.go

View workflow job for this annotation

GitHub Actions / ci

undefined: fake.AvailabilityZone (typecheck)
},
},
}, nil
}

// Now we attempt to create instances
instanceTypes, err := cloudProvider.GetInstanceTypes(ctx, nodePool)
Expect(err).ToNot(HaveOccurred())

instanceTypes = lo.Filter(instanceTypes, func(i *corecloudprovider.InstanceType, _ int) bool { return i.Name == "m5.xlarge" })
instance, err := awsEnv.InstanceProvider.Create(ctx, nodeClass, nodeClaim, nil, instanceTypes)

// Assert that the instance was not created due to IP exhaustion
Expect(corecloudprovider.IsInsufficientCapacityError(err)).To(BeTrue())
Expect(instance).To(BeNil())
})

})
Loading