Skip to content

Commit

Permalink
remaining e2es + feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdeal committed Feb 26, 2025
1 parent f6198e2 commit 18d6949
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 65 deletions.
3 changes: 0 additions & 3 deletions pkg/controllers/nodeclaim/capacityreservation/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ func (c *Controller) Reconcile(ctx context.Context) (reconcile.Result, error) {
if err := c.kubeClient.List(ctx, ncs); err != nil {
return reconcile.Result{}, fmt.Errorf("listing nodeclaims, %w", err)
}
log.FromContext(ctx).WithValues("provider-ids", lo.Keys(providerIDsToCPNodeClaims), "nodeclaims", lo.Map(ncs.Items, func(nc karpv1.NodeClaim, _ int) string {
return nc.Name
})).Info("evaluating")
updatedNodeClaims := sets.New[string]()
var errs []error
for i := range ncs.Items {
Expand Down
12 changes: 0 additions & 12 deletions pkg/controllers/nodeclaim/capacityreservation/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,4 @@ var _ = Describe("Capacity Reservation NodeClaim Controller", func() {
Expect(node.Labels).To(HaveKeyWithValue(karpv1.CapacityTypeLabelKey, karpv1.CapacityTypeOnDemand))
Expect(node.Labels).ToNot(HaveKey(corecloudprovider.ReservationIDLabel))
})
It("should ignore nodeclaims which aren't registered", func() {
out := awsEnv.EC2API.DescribeInstancesBehavior.Output.Clone()
out.Reservations[0].Instances[0].CapacityReservationId = nil
awsEnv.EC2API.DescribeInstancesBehavior.Output.Set(out)
delete(nodeClaim.Labels, karpv1.NodeRegisteredLabelKey)

ExpectApplied(ctx, env.Client, nodeClaim)
ExpectSingletonReconciled(ctx, controller)
nodeClaim = ExpectExists(ctx, env.Client, nodeClaim)
Expect(nodeClaim.Labels).To(HaveKeyWithValue(karpv1.CapacityTypeLabelKey, karpv1.CapacityTypeReserved))
Expect(nodeClaim.Labels).To(HaveKeyWithValue(corecloudprovider.ReservationIDLabel, reservationID))
})
})
3 changes: 3 additions & 0 deletions pkg/providers/instancetype/offering/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func (p *DefaultProvider) InjectOfferings(
})
}

// NOTE: By making this copy one level deep, we can modify the offerings without mutating the results from previous
// GetInstanceTypes calls. This should still be done with caution - it is currently done here in the provider, and
// once in the instance provider (filterReservedInstanceTypes)
its = append(its, &cloudprovider.InstanceType{
Name: it.Name,
Requirements: it.Requirements,
Expand Down
12 changes: 8 additions & 4 deletions test/pkg/environment/aws/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func ExpectCapacityReservationCreated(
capacity int32,
endDate *time.Time,
tags map[string]string,
) (id string, cleanup func()) {
) string {
GinkgoHelper()
out, err := ec2api.CreateCapacityReservation(ctx, &ec2.CreateCapacityReservationInput{
InstanceCount: lo.ToPtr(capacity),
Expand All @@ -551,10 +551,14 @@ func ExpectCapacityReservationCreated(
}}, nil),
})
Expect(err).ToNot(HaveOccurred())
return lo.FromPtr(out.CapacityReservation.CapacityReservationId), func() {
GinkgoHelper()
return *out.CapacityReservation.CapacityReservationId
}

func ExpectCapacityReservationsCanceled(ctx context.Context, ec2api *ec2.Client, reservationIDs ...string) {
GinkgoHelper()
for _, id := range reservationIDs {
_, err := ec2api.CancelCapacityReservation(ctx, &ec2.CancelCapacityReservationInput{
CapacityReservationId: lo.ToPtr(*out.CapacityReservation.CapacityReservationId),
CapacityReservationId: &id,
})
Expect(err).ToNot(HaveOccurred())
}
Expand Down
Loading

0 comments on commit 18d6949

Please sign in to comment.