From 080ade8776316f66c9310adc1c4e3b3dc3f9a4be Mon Sep 17 00:00:00 2001 From: Reed Schalo Date: Thu, 16 May 2024 11:02:20 -0700 Subject: [PATCH] create constraints on offerings --- kwok/cloudprovider/cloudprovider.go | 4 +- kwok/cloudprovider/helpers.go | 8 +- kwok/tools/gen_instance_types.go | 10 +- pkg/cloudprovider/fake/cloudprovider.go | 8 +- pkg/cloudprovider/fake/instancetype.go | 26 +- pkg/cloudprovider/types.go | 33 +- pkg/controllers/disruption/consolidation.go | 2 +- .../disruption/consolidation_test.go | 347 +++++++++--------- pkg/controllers/disruption/drift_test.go | 62 ++-- pkg/controllers/disruption/emptiness_test.go | 24 +- pkg/controllers/disruption/expiration_test.go | 62 ++-- pkg/controllers/disruption/helpers.go | 18 +- .../disruption/multinodeconsolidation.go | 3 +- .../disruption/orchestration/suite_test.go | 12 +- pkg/controllers/disruption/suite_test.go | 172 +++++---- .../scheduling/instance_selection_test.go | 189 +++++----- .../provisioning/scheduling/nodeclaim.go | 4 +- .../provisioning/scheduling/suite_test.go | 27 +- pkg/controllers/provisioning/suite_test.go | 10 +- pkg/test/helpers.go | 35 ++ 20 files changed, 544 insertions(+), 512 deletions(-) create mode 100644 pkg/test/helpers.go diff --git a/kwok/cloudprovider/cloudprovider.go b/kwok/cloudprovider/cloudprovider.go index 2f22f3dfdf..f7bc0331f2 100644 --- a/kwok/cloudprovider/cloudprovider.go +++ b/kwok/cloudprovider/cloudprovider.go @@ -207,8 +207,8 @@ func addInstanceLabels(labels map[string]string, instanceType *cloudprovider.Ins // Kwok has some scalability limitations. // Randomly add each new node to one of the pre-created kwokPartitions. ret[kwokPartitionLabelKey] = lo.Sample(KwokPartitions) - ret[v1beta1.CapacityTypeLabelKey] = offering.CapacityType - ret[v1.LabelTopologyZone] = offering.Zone + ret[v1beta1.CapacityTypeLabelKey] = offering.Constraints[v1beta1.CapacityTypeLabelKey] + ret[v1.LabelTopologyZone] = offering.Constraints[v1.LabelTopologyZone] ret[v1.LabelHostname] = nodeClaim.Name ret[kwokLabelKey] = kwokLabelValue diff --git a/kwok/cloudprovider/helpers.go b/kwok/cloudprovider/helpers.go index 079f02b46f..cab6a768a8 100644 --- a/kwok/cloudprovider/helpers.go +++ b/kwok/cloudprovider/helpers.go @@ -140,8 +140,12 @@ func newInstanceType(options InstanceTypeOptions) *cloudprovider.InstanceType { scheduling.NewRequirement(v1.LabelInstanceTypeStable, v1.NodeSelectorOpIn, options.Name), scheduling.NewRequirement(v1.LabelArchStable, v1.NodeSelectorOpIn, options.Architecture), scheduling.NewRequirement(v1.LabelOSStable, v1.NodeSelectorOpIn, osNames...), - scheduling.NewRequirement(v1.LabelTopologyZone, v1.NodeSelectorOpIn, lo.Map(options.Offerings.Available(), func(o cloudprovider.Offering, _ int) string { return o.Zone })...), - scheduling.NewRequirement(v1beta1.CapacityTypeLabelKey, v1.NodeSelectorOpIn, lo.Map(options.Offerings.Available(), func(o cloudprovider.Offering, _ int) string { return o.CapacityType })...), + scheduling.NewRequirement(v1.LabelTopologyZone, v1.NodeSelectorOpIn, lo.Map(options.Offerings.Available(), func(o cloudprovider.Offering, _ int) string { + return o.Constraints[v1.LabelTopologyZone] + })...), + scheduling.NewRequirement(v1beta1.CapacityTypeLabelKey, v1.NodeSelectorOpIn, lo.Map(options.Offerings.Available(), func(o cloudprovider.Offering, _ int) string { + return o.Constraints[v1beta1.CapacityTypeLabelKey] + })...), scheduling.NewRequirement(InstanceSizeLabelKey, v1.NodeSelectorOpIn, options.instanceTypeLabels[InstanceSizeLabelKey]), scheduling.NewRequirement(InstanceFamilyLabelKey, v1.NodeSelectorOpIn, options.instanceTypeLabels[InstanceFamilyLabelKey]), scheduling.NewRequirement(InstanceCPULabelKey, v1.NodeSelectorOpIn, options.instanceTypeLabels[InstanceCPULabelKey]), diff --git a/kwok/tools/gen_instance_types.go b/kwok/tools/gen_instance_types.go index 202448b354..93ab6426c7 100644 --- a/kwok/tools/gen_instance_types.go +++ b/kwok/tools/gen_instance_types.go @@ -93,10 +93,12 @@ func constructGenericInstanceTypes() []kwok.InstanceTypeOptions { for _, zone := range KwokZones { for _, ct := range []string{v1beta1.CapacityTypeSpot, v1beta1.CapacityTypeOnDemand} { opts.Offerings = append(opts.Offerings, cloudprovider.Offering{ - CapacityType: ct, - Zone: zone, - Price: lo.Ternary(ct == v1beta1.CapacityTypeSpot, price*.7, price), - Available: true, + Constraints: map[string]string{ + v1beta1.CapacityTypeLabelKey: ct, + v1.LabelTopologyZone: zone, + }, + Price: lo.Ternary(ct == v1beta1.CapacityTypeSpot, price*.7, price), + Available: true, }) } } diff --git a/pkg/cloudprovider/fake/cloudprovider.go b/pkg/cloudprovider/fake/cloudprovider.go index 72326d3b34..bd5938170b 100644 --- a/pkg/cloudprovider/fake/cloudprovider.go +++ b/pkg/cloudprovider/fake/cloudprovider.go @@ -128,11 +128,11 @@ func (c *CloudProvider) Create(ctx context.Context, nodeClaim *v1beta1.NodeClaim // Find Offering for _, o := range instanceType.Offerings.Available() { if reqs.Compatible(scheduling.NewRequirements( - scheduling.NewRequirement(v1.LabelTopologyZone, v1.NodeSelectorOpIn, o.Zone), - scheduling.NewRequirement(v1beta1.CapacityTypeLabelKey, v1.NodeSelectorOpIn, o.CapacityType), + scheduling.NewRequirement(v1.LabelTopologyZone, v1.NodeSelectorOpIn, o.Constraints[v1.LabelTopologyZone]), + scheduling.NewRequirement(v1beta1.CapacityTypeLabelKey, v1.NodeSelectorOpIn, o.Constraints[v1beta1.CapacityTypeLabelKey]), ), scheduling.AllowUndefinedWellKnownLabels) == nil { - labels[v1.LabelTopologyZone] = o.Zone - labels[v1beta1.CapacityTypeLabelKey] = o.CapacityType + labels[v1.LabelTopologyZone] = o.Constraints[v1.LabelTopologyZone] + labels[v1beta1.CapacityTypeLabelKey] = o.Constraints[v1beta1.CapacityTypeLabelKey] break } } diff --git a/pkg/cloudprovider/fake/instancetype.go b/pkg/cloudprovider/fake/instancetype.go index 97ab5f9808..8e593e14b5 100644 --- a/pkg/cloudprovider/fake/instancetype.go +++ b/pkg/cloudprovider/fake/instancetype.go @@ -29,6 +29,7 @@ import ( "sigs.k8s.io/karpenter/pkg/apis/v1beta1" "sigs.k8s.io/karpenter/pkg/cloudprovider" "sigs.k8s.io/karpenter/pkg/scheduling" + "sigs.k8s.io/karpenter/pkg/test" ) const ( @@ -66,11 +67,11 @@ func NewInstanceTypeWithCustomRequirement(options InstanceTypeOptions, customReq } if len(options.Offerings) == 0 { options.Offerings = []cloudprovider.Offering{ - {CapacityType: "spot", Zone: "test-zone-1", Price: PriceFromResources(options.Resources), Available: true}, - {CapacityType: "spot", Zone: "test-zone-2", Price: PriceFromResources(options.Resources), Available: true}, - {CapacityType: "on-demand", Zone: "test-zone-1", Price: PriceFromResources(options.Resources), Available: true}, - {CapacityType: "on-demand", Zone: "test-zone-2", Price: PriceFromResources(options.Resources), Available: true}, - {CapacityType: "on-demand", Zone: "test-zone-3", Price: PriceFromResources(options.Resources), Available: true}, + {Constraints: test.Constraints("spot", "test-zone-1"), Price: PriceFromResources(options.Resources), Available: true}, + {Constraints: test.Constraints("spot", "test-zone-2"), Price: PriceFromResources(options.Resources), Available: true}, + {Constraints: test.Constraints("on-demand", "test-zone-1"), Price: PriceFromResources(options.Resources), Available: true}, + {Constraints: test.Constraints("on-demand", "test-zone-2"), Price: PriceFromResources(options.Resources), Available: true}, + {Constraints: test.Constraints("on-demand", "test-zone-3"), Price: PriceFromResources(options.Resources), Available: true}, } } if len(options.Architecture) == 0 { @@ -83,8 +84,12 @@ func NewInstanceTypeWithCustomRequirement(options InstanceTypeOptions, customReq scheduling.NewRequirement(v1.LabelInstanceTypeStable, v1.NodeSelectorOpIn, options.Name), scheduling.NewRequirement(v1.LabelArchStable, v1.NodeSelectorOpIn, options.Architecture), scheduling.NewRequirement(v1.LabelOSStable, v1.NodeSelectorOpIn, sets.List(options.OperatingSystems)...), - scheduling.NewRequirement(v1.LabelTopologyZone, v1.NodeSelectorOpIn, lo.Map(options.Offerings.Available(), func(o cloudprovider.Offering, _ int) string { return o.Zone })...), - scheduling.NewRequirement(v1beta1.CapacityTypeLabelKey, v1.NodeSelectorOpIn, lo.Map(options.Offerings.Available(), func(o cloudprovider.Offering, _ int) string { return o.CapacityType })...), + scheduling.NewRequirement(v1.LabelTopologyZone, v1.NodeSelectorOpIn, lo.Map(options.Offerings.Available(), func(o cloudprovider.Offering, _ int) string { + return o.Constraints[v1.LabelTopologyZone] + })...), + scheduling.NewRequirement(v1beta1.CapacityTypeLabelKey, v1.NodeSelectorOpIn, lo.Map(options.Offerings.Available(), func(o cloudprovider.Offering, _ int) string { + return o.Constraints[v1beta1.CapacityTypeLabelKey] + })...), scheduling.NewRequirement(LabelInstanceSize, v1.NodeSelectorOpDoesNotExist), scheduling.NewRequirement(ExoticInstanceLabelKey, v1.NodeSelectorOpDoesNotExist), scheduling.NewRequirement(IntegerInstanceLabelKey, v1.NodeSelectorOpIn, fmt.Sprint(options.Resources.Cpu().Value())), @@ -135,10 +140,9 @@ func InstanceTypesAssorted() []*cloudprovider.InstanceType { price := PriceFromResources(opts.Resources) opts.Offerings = []cloudprovider.Offering{ { - CapacityType: ct, - Zone: zone, - Price: price, - Available: true, + Constraints: test.Constraints(ct, zone), + Price: price, + Available: true, }, } instanceTypes = append(instanceTypes, NewInstanceType(opts)) diff --git a/pkg/cloudprovider/types.go b/pkg/cloudprovider/types.go index a7bbab49d0..6ac6b2c8da 100644 --- a/pkg/cloudprovider/types.go +++ b/pkg/cloudprovider/types.go @@ -215,11 +215,11 @@ func (i InstanceTypeOverhead) Total() v1.ResourceList { } // An Offering describes where an InstanceType is available to be used, with the expectation that its properties -// may be tightly coupled (e.g. the availability of an instance type in some zone is scoped to a capacity type) +// may be tightly coupled (e.g. the availability of an instance type in some zone is scoped to a capacity type) and +// these properties are captured with labels in the Constraints map. v1beta1.CapacityTypeLabelKey is required. type Offering struct { - CapacityType string - Zone string - Price float64 + Constraints map[string]string + Price float64 // Available is added so that Offerings can return all offerings that have ever existed for an instance type, // so we can get historical pricing data for calculating savings in consolidation Available bool @@ -228,10 +228,18 @@ type Offering struct { type Offerings []Offering // Get gets the offering from an offering slice that matches the -// passed zone and capacity type -func (ofs Offerings) Get(ct, zone string) (Offering, bool) { +// passed zone, capacityType, and other constraints +func (ofs Offerings) Get(constraints map[string]string) (Offering, bool) { return lo.Find(ofs, func(of Offering) bool { - return of.CapacityType == ct && of.Zone == zone + match := false + for label, v := range of.Constraints { + fmt.Println("value: ", v, " and constraint label: ", label, " and constraint value: ", constraints[label]) + match = lo.Ternary(v == constraints[label], true, false) + } + fmt.Println("") + fmt.Println("match: ", match) + fmt.Println("") + return match }) } @@ -245,8 +253,15 @@ func (ofs Offerings) Available() Offerings { // Compatible returns the offerings based on the passed requirements func (ofs Offerings) Compatible(reqs scheduling.Requirements) Offerings { return lo.Filter(ofs, func(offering Offering, _ int) bool { - return (!reqs.Has(v1.LabelTopologyZone) || reqs.Get(v1.LabelTopologyZone).Has(offering.Zone)) && - (!reqs.Has(v1beta1.CapacityTypeLabelKey) || reqs.Get(v1beta1.CapacityTypeLabelKey).Has(offering.CapacityType)) + match := true + for label, v := range offering.Constraints { + match = (!reqs.Has(label) || reqs.Get(label).Has(v)) && match + } + fmt.Println("") + fmt.Println("") + fmt.Println("") + fmt.Println("match: ", match, " this of: ", offering, " with these reqs: ", reqs) + return match }) } diff --git a/pkg/controllers/disruption/consolidation.go b/pkg/controllers/disruption/consolidation.go index 70ffef1a93..038cfdf79e 100644 --- a/pkg/controllers/disruption/consolidation.go +++ b/pkg/controllers/disruption/consolidation.go @@ -291,7 +291,7 @@ func (c *consolidation) computeSpotToSpotConsolidation(ctx context.Context, cand func getCandidatePrices(candidates []*Candidate) (float64, error) { var price float64 for _, c := range candidates { - offering, ok := c.instanceType.Offerings.Get(c.capacityType, c.zone) + offering, ok := c.instanceType.Offerings.Get(c.StateNode.Labels()) if !ok { return 0.0, fmt.Errorf("unable to determine offering for %s/%s/%s", c.instanceType.Name, c.capacityType, c.zone) } diff --git a/pkg/controllers/disruption/consolidation_test.go b/pkg/controllers/disruption/consolidation_test.go index 3e5ffb8f80..d4dc4a3571 100644 --- a/pkg/controllers/disruption/consolidation_test.go +++ b/pkg/controllers/disruption/consolidation_test.go @@ -76,8 +76,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -89,8 +89,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -192,8 +192,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -406,8 +406,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -470,8 +470,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -534,8 +534,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -625,8 +625,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -716,8 +716,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -807,8 +807,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -857,8 +857,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -929,8 +929,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: largeCheapType.Name, - v1beta1.CapacityTypeLabelKey: largeCheapType.Offerings[0].CapacityType, - v1.LabelTopologyZone: largeCheapType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: largeCheapType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: largeCheapType.Offerings[0].Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -977,13 +977,13 @@ var _ = Describe("Consolidation", func() { // assign the nodeclaims to the least expensive offering so we don't get a replacement nodeClaim.Labels = lo.Assign(nodeClaim.Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) node.Labels = lo.Assign(node.Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) ds := test.DaemonSet() @@ -1033,13 +1033,13 @@ var _ = Describe("Consolidation", func() { // assign the nodeclaims to the least expensive offering so we don't get a replacement nodeClaim.Labels = lo.Assign(nodeClaim.Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) node.Labels = lo.Assign(node.Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) rs := test.ReplicaSet() @@ -1098,13 +1098,13 @@ var _ = Describe("Consolidation", func() { // assign the nodeclaims to the least expensive offering so we don't get a replacement nodeClaim.Labels = lo.Assign(nodeClaim.Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) node.Labels = lo.Assign(node.Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) ss := test.StatefulSet() @@ -1224,10 +1224,10 @@ var _ = Describe("Consolidation", func() { // Forcefully assign lowest possible instancePrice to make sure we have atleast one instance // that is lower than the current node. cloudProvider.InstanceTypes[0].Offerings[0].Price = 0.001 - cloudProvider.InstanceTypes[0].Offerings[0].CapacityType = v1beta1.CapacityTypeSpot + cloudProvider.InstanceTypes[0].Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey] = v1beta1.CapacityTypeSpot spotInstances = lo.Filter(cloudProvider.InstanceTypes, func(i *cloudprovider.InstanceType, _ int) bool { for _, o := range i.Offerings { - if o.CapacityType == v1beta1.CapacityTypeSpot { + if o.Constraints[v1beta1.CapacityTypeLabelKey] == v1beta1.CapacityTypeSpot { return true } } @@ -1242,15 +1242,15 @@ var _ = Describe("Consolidation", func() { spotNodeClaim.Labels = lo.Assign(spotNodeClaim.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpSpotOffering.Constraints[v1.LabelTopologyZone], }) spotNode.Labels = lo.Assign(spotNode.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpSpotOffering.Constraints[v1.LabelTopologyZone], }) rs := test.ReplicaSet() @@ -1346,14 +1346,14 @@ var _ = Describe("Consolidation", func() { // Forcefully assign lowest possible instancePrice to make sure we have atleast one instance // that is lower than the current node. cloudProvider.InstanceTypes[0].Offerings[0].Price = 0.001 - cloudProvider.InstanceTypes[0].Offerings[0].CapacityType = v1beta1.CapacityTypeSpot + cloudProvider.InstanceTypes[0].Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey] = v1beta1.CapacityTypeSpot // Also sort the cloud provider instances by pricing from low to high sort.Slice(cloudProvider.InstanceTypes, func(i, j int) bool { return cloudProvider.InstanceTypes[i].Offerings.Cheapest().Price < cloudProvider.InstanceTypes[j].Offerings.Cheapest().Price }) spotInstances = lo.Filter(cloudProvider.InstanceTypes, func(i *cloudprovider.InstanceType, _ int) bool { for _, o := range i.Offerings { - if o.CapacityType == v1beta1.CapacityTypeSpot { + if o.Constraints[v1beta1.CapacityTypeLabelKey] == v1beta1.CapacityTypeSpot { return true } } @@ -1365,15 +1365,15 @@ var _ = Describe("Consolidation", func() { spotNodeClaim.Labels = lo.Assign(spotNodeClaim.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: spotInstance.Name, - v1beta1.CapacityTypeLabelKey: spotOffering.CapacityType, - v1.LabelTopologyZone: spotOffering.Zone, + v1beta1.CapacityTypeLabelKey: spotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: spotOffering.Constraints[v1.LabelTopologyZone], }) spotNode.Labels = lo.Assign(spotNode.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: spotInstance.Name, - v1beta1.CapacityTypeLabelKey: spotOffering.CapacityType, - v1.LabelTopologyZone: spotOffering.Zone, + v1beta1.CapacityTypeLabelKey: spotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: spotOffering.Constraints[v1.LabelTopologyZone], }) rs := test.ReplicaSet() @@ -1418,7 +1418,7 @@ var _ = Describe("Consolidation", func() { // Fetch 18 spot instances spotInstances = lo.Slice(lo.Filter(cloudProvider.InstanceTypes, func(i *cloudprovider.InstanceType, _ int) bool { for _, o := range i.Offerings { - if o.CapacityType == v1beta1.CapacityTypeSpot { + if o.Constraints[v1beta1.CapacityTypeLabelKey] == v1beta1.CapacityTypeSpot { return true } } @@ -1454,15 +1454,15 @@ var _ = Describe("Consolidation", func() { spotNodeClaim.Labels = lo.Assign(spotNodeClaim.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) spotNode.Labels = lo.Assign(spotNode.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) rs := test.ReplicaSet() @@ -1543,7 +1543,7 @@ var _ = Describe("Consolidation", func() { // Fetch 18 spot instances spotInstances = lo.Slice(lo.Filter(cloudProvider.InstanceTypes, func(i *cloudprovider.InstanceType, _ int) bool { for _, o := range i.Offerings { - if o.CapacityType == v1beta1.CapacityTypeSpot { + if o.Constraints[v1beta1.CapacityTypeLabelKey] == v1beta1.CapacityTypeSpot { return true } } @@ -1579,15 +1579,15 @@ var _ = Describe("Consolidation", func() { spotNodeClaim.Labels = lo.Assign(spotNodeClaim.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) spotNode.Labels = lo.Assign(spotNode.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) rs := test.ReplicaSet() @@ -1668,7 +1668,7 @@ var _ = Describe("Consolidation", func() { // Fetch 18 spot instances spotInstances = lo.Slice(lo.Filter(cloudProvider.InstanceTypes, func(i *cloudprovider.InstanceType, _ int) bool { for _, o := range i.Offerings { - if o.CapacityType == v1beta1.CapacityTypeSpot { + if o.Constraints[v1beta1.CapacityTypeLabelKey] == v1beta1.CapacityTypeSpot { return true } } @@ -1704,15 +1704,15 @@ var _ = Describe("Consolidation", func() { spotNodeClaim.Labels = lo.Assign(spotNodeClaim.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) spotNode.Labels = lo.Assign(spotNode.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) rs := test.ReplicaSet() @@ -1807,29 +1807,29 @@ var _ = Describe("Consolidation", func() { spotNodeClaim.Labels = lo.Assign(spotNodeClaim.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) spotNode.Labels = lo.Assign(spotNode.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) nodeClaim.Labels = lo.Assign(spotNodeClaim.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveODInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveODInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveODInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveODInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveODInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) node.Labels = lo.Assign(spotNode.Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveODInstanceType.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveODInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: mostExpensiveODInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveODInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveODInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }) nodeClaim = lo.Ternary(spotToSpot, spotNodeClaim, nodeClaim) @@ -2196,8 +2196,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -2211,13 +2211,13 @@ var _ = Describe("Consolidation", func() { if spotToSpot { annotatedNodeClaim.Labels = lo.Assign(annotatedNodeClaim.Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) annotatedNode.Labels = lo.Assign(annotatedNode.Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) } @@ -2289,8 +2289,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -2304,13 +2304,13 @@ var _ = Describe("Consolidation", func() { if spotToSpot { annotatedNodeClaim.Labels = lo.Assign(annotatedNodeClaim.Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) annotatedNode.Labels = lo.Assign(annotatedNode.Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) } @@ -2379,8 +2379,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -2394,13 +2394,13 @@ var _ = Describe("Consolidation", func() { if spotToSpot { nodeClaim2.Labels = lo.Assign(nodeClaim2.Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) node2.Labels = lo.Assign(node2.Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) } // Block this pod from being disrupted with karpenter.sh/do-not-evict @@ -2471,8 +2471,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -2485,13 +2485,13 @@ var _ = Describe("Consolidation", func() { if spotToSpot { nodeClaim2.Labels = lo.Assign(nodeClaim2.Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) node2.Labels = lo.Assign(node2.Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) } // Block this pod from being disrupted with karpenter.sh/do-not-disrupt @@ -2534,10 +2534,9 @@ var _ = Describe("Consolidation", func() { Name: "current-on-demand", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 0.5, - Available: false, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 0.5, + Available: false, }, }, }) @@ -2545,22 +2544,19 @@ var _ = Describe("Consolidation", func() { Name: "potential-spot-replacement", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1a", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1a"), + Price: 1.0, + Available: true, }, { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1b", - Price: 0.2, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1b"), + Price: 0.2, + Available: true, }, { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1c", - Price: 0.4, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1c"), + Price: 0.4, + Available: true, }, }, }) @@ -2591,8 +2587,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: currentInstance.Name, - v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].CapacityType, - v1.LabelTopologyZone: currentInstance.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: currentInstance.Offerings[0].Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -2625,10 +2621,9 @@ var _ = Describe("Consolidation", func() { Name: "current-on-demand", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 0.5, - Available: false, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 0.5, + Available: false, }, }, }) @@ -2636,28 +2631,24 @@ var _ = Describe("Consolidation", func() { Name: "on-demand-replacement", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 0.6, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 0.6, + Available: true, }, { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1b", - Price: 0.6, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1b"), + Price: 0.6, + Available: true, }, { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1b", - Price: 0.2, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1c"), + Price: 0.2, + Available: true, }, { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1c", - Price: 0.3, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1c"), + Price: 0.3, + Available: true, }, }, }) @@ -2700,8 +2691,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: currentInstance.Name, - v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].CapacityType, - v1.LabelTopologyZone: currentInstance.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: currentInstance.Offerings[0].Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -2740,8 +2731,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -3312,8 +3303,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: defaultInstanceType.Name, - v1beta1.CapacityTypeLabelKey: defaultInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: defaultInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: defaultInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: defaultInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -3341,8 +3332,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: smallInstanceType.Name, - v1beta1.CapacityTypeLabelKey: smallInstanceType.Offerings[0].CapacityType, - v1.LabelTopologyZone: smallInstanceType.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: smallInstanceType.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: smallInstanceType.Offerings[0].Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -3575,8 +3566,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -3636,23 +3627,23 @@ var _ = Describe("Consolidation", func() { // assign the nodeclaims to the least expensive offering so only one of them gets deleted nodeClaims[0].Labels = lo.Assign(nodeClaims[0].Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) nodes[0].Labels = lo.Assign(nodes[0].Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) nodeClaims[1].Labels = lo.Assign(nodeClaims[1].Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) nodes[1].Labels = lo.Assign(nodes[1].Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }) pods := test.Pods(3, test.PodOptions{ @@ -4153,8 +4144,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -4244,8 +4235,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -4332,8 +4323,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -4348,8 +4339,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -4420,13 +4411,13 @@ var _ = Describe("Consolidation", func() { // Change one of them to spot. nodeClaims[2].Labels = lo.Assign(nodeClaims[2].Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) nodes[2].Labels = lo.Assign(nodeClaims[2].Labels, map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveSpotInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveSpotOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveSpotOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveSpotOffering.Constraints[v1.LabelTopologyZone], }) // create our RS so we can link a pod to it rs := test.ReplicaSet() @@ -4499,23 +4490,23 @@ var _ = Describe("Consolidation", func() { // Make the nodeclaims the least expensive instance type and make them of the same type nodeClaims[0].Labels = lo.Assign(nodeClaims[0].Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpOffering.CapacityType, - v1.LabelTopologyZone: leastExpOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpOffering.Constraints[v1.LabelTopologyZone], }) nodes[0].Labels = lo.Assign(nodes[0].Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpOffering.CapacityType, - v1.LabelTopologyZone: leastExpOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpOffering.Constraints[v1.LabelTopologyZone], }) nodeClaims[1].Labels = lo.Assign(nodeClaims[1].Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpOffering.CapacityType, - v1.LabelTopologyZone: leastExpOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpOffering.Constraints[v1.LabelTopologyZone], }) nodes[1].Labels = lo.Assign(nodes[1].Labels, map[string]string{ v1.LabelInstanceTypeStable: leastExpInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpOffering.CapacityType, - v1.LabelTopologyZone: leastExpOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpOffering.Constraints[v1.LabelTopologyZone], }) ExpectApplied(ctx, env.Client, rs, pods[0], pods[1], pods[2], nodeClaims[0], nodes[0], nodeClaims[1], nodes[1], nodePool) ExpectMakeNodesInitialized(ctx, env.Client, nodes[0], nodes[1]) @@ -4812,8 +4803,8 @@ var _ = Describe("Consolidation", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -4892,7 +4883,7 @@ var _ = Describe("Consolidation", func() { v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelTopologyZone: "test-zone-1", v1.LabelInstanceTypeStable: testZone1Instance.Name, - v1beta1.CapacityTypeLabelKey: testZone1Instance.Offerings[0].CapacityType, + v1beta1.CapacityTypeLabelKey: testZone1Instance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], }, }, Status: v1beta1.NodeClaimStatus{ @@ -4902,23 +4893,23 @@ var _ = Describe("Consolidation", func() { nodeClaims[1].Labels = lo.Assign(nodeClaims[1].Labels, map[string]string{ v1.LabelTopologyZone: "test-zone-2", v1.LabelInstanceTypeStable: testZone2Instance.Name, - v1beta1.CapacityTypeLabelKey: testZone2Instance.Offerings[0].CapacityType, + v1beta1.CapacityTypeLabelKey: testZone2Instance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], }) nodes[1].Labels = lo.Assign(nodes[1].Labels, map[string]string{ v1.LabelTopologyZone: "test-zone-2", v1.LabelInstanceTypeStable: testZone2Instance.Name, - v1beta1.CapacityTypeLabelKey: testZone2Instance.Offerings[0].CapacityType, + v1beta1.CapacityTypeLabelKey: testZone2Instance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], }) nodeClaims[2].Labels = lo.Assign(nodeClaims[2].Labels, map[string]string{ v1.LabelTopologyZone: "test-zone-3", v1.LabelInstanceTypeStable: testZone3Instance.Name, - v1beta1.CapacityTypeLabelKey: testZone1Instance.Offerings[0].CapacityType, + v1beta1.CapacityTypeLabelKey: testZone1Instance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], }) nodes[2].Labels = lo.Assign(nodes[2].Labels, map[string]string{ v1.LabelTopologyZone: "test-zone-3", v1.LabelInstanceTypeStable: testZone3Instance.Name, - v1beta1.CapacityTypeLabelKey: testZone1Instance.Offerings[0].CapacityType, + v1beta1.CapacityTypeLabelKey: testZone1Instance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], }) oldNodeClaimNames = sets.New(nodeClaims[0].Name, nodeClaims[1].Name, nodeClaims[2].Name) }) @@ -5032,13 +5023,13 @@ var _ = Describe("Consolidation", func() { v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelTopologyZone: "test-zone-2", v1.LabelInstanceTypeStable: zone2Instance.Name, - v1beta1.CapacityTypeLabelKey: zone2Instance.Offerings[0].CapacityType, + v1beta1.CapacityTypeLabelKey: zone2Instance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], }) nodeClaims[1].Labels = lo.Assign(nodeClaims[1].Labels, map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelTopologyZone: "test-zone-2", v1.LabelInstanceTypeStable: zone2Instance.Name, - v1beta1.CapacityTypeLabelKey: zone2Instance.Offerings[0].CapacityType, + v1beta1.CapacityTypeLabelKey: zone2Instance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], }) ExpectApplied(ctx, env.Client, rs, pods[0], pods[1], pods[2], nodeClaims[0], nodes[0], nodeClaims[1], nodes[1], nodeClaims[2], nodes[2], nodePool) diff --git a/pkg/controllers/disruption/drift_test.go b/pkg/controllers/disruption/drift_test.go index 696e839016..d3f6bd081f 100644 --- a/pkg/controllers/disruption/drift_test.go +++ b/pkg/controllers/disruption/drift_test.go @@ -65,8 +65,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -139,8 +139,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -182,8 +182,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -225,8 +225,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -268,8 +268,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -364,8 +364,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -430,8 +430,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -517,8 +517,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -667,8 +667,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -807,10 +807,9 @@ var _ = Describe("Drift", func() { Name: "current-on-demand", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 0.5, - Available: false, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 0.5, + Available: false, }, }, }) @@ -818,10 +817,9 @@ var _ = Describe("Drift", func() { Name: "replacement-on-demand", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 0.3, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 0.3, + Available: true, }, }, Resources: map[v1.ResourceName]resource.Quantity{v1.ResourceCPU: resource.MustParse("3")}, @@ -859,14 +857,14 @@ var _ = Describe("Drift", func() { nodeClaim.Labels = lo.Assign(nodeClaim.Labels, map[string]string{ v1.LabelInstanceTypeStable: currentInstance.Name, - v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].CapacityType, - v1.LabelTopologyZone: currentInstance.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: currentInstance.Offerings[0].Constraints[v1.LabelTopologyZone], }) nodeClaim.Status.Allocatable = map[v1.ResourceName]resource.Quantity{v1.ResourceCPU: resource.MustParse("8")} node.Labels = lo.Assign(node.Labels, map[string]string{ v1.LabelInstanceTypeStable: currentInstance.Name, - v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].CapacityType, - v1.LabelTopologyZone: currentInstance.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: currentInstance.Offerings[0].Constraints[v1.LabelTopologyZone], }) node.Status.Allocatable = map[v1.ResourceName]resource.Quantity{v1.ResourceCPU: resource.MustParse("8")} @@ -932,8 +930,8 @@ var _ = Describe("Drift", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ diff --git a/pkg/controllers/disruption/emptiness_test.go b/pkg/controllers/disruption/emptiness_test.go index 9f440e7324..0ca838548c 100644 --- a/pkg/controllers/disruption/emptiness_test.go +++ b/pkg/controllers/disruption/emptiness_test.go @@ -61,8 +61,8 @@ var _ = Describe("Emptiness", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -149,8 +149,8 @@ var _ = Describe("Emptiness", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -195,8 +195,8 @@ var _ = Describe("Emptiness", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -241,8 +241,8 @@ var _ = Describe("Emptiness", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -309,8 +309,8 @@ var _ = Describe("Emptiness", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -379,8 +379,8 @@ var _ = Describe("Emptiness", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ diff --git a/pkg/controllers/disruption/expiration_test.go b/pkg/controllers/disruption/expiration_test.go index 0acedbcc51..c4c0915065 100644 --- a/pkg/controllers/disruption/expiration_test.go +++ b/pkg/controllers/disruption/expiration_test.go @@ -64,8 +64,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -139,8 +139,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -186,8 +186,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -233,8 +233,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -277,8 +277,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -372,8 +372,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -437,8 +437,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: np.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -576,8 +576,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -653,8 +653,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -721,8 +721,8 @@ var _ = Describe("Expiration", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -866,10 +866,9 @@ var _ = Describe("Expiration", func() { Name: "current-on-demand", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 0.5, - Available: false, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 0.5, + Available: false, }, }, }) @@ -877,10 +876,9 @@ var _ = Describe("Expiration", func() { Name: "replacement-on-demand", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 0.3, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 0.3, + Available: true, }, }, Resources: map[v1.ResourceName]resource.Quantity{v1.ResourceCPU: resource.MustParse("3")}, @@ -917,14 +915,14 @@ var _ = Describe("Expiration", func() { }) nodeClaim.Labels = lo.Assign(nodeClaim.Labels, map[string]string{ v1.LabelInstanceTypeStable: currentInstance.Name, - v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].CapacityType, - v1.LabelTopologyZone: currentInstance.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: currentInstance.Offerings[0].Constraints[v1.LabelTopologyZone], }) nodeClaim.Status.Allocatable = map[v1.ResourceName]resource.Quantity{v1.ResourceCPU: resource.MustParse("8")} node.Labels = lo.Assign(node.Labels, map[string]string{ v1.LabelInstanceTypeStable: currentInstance.Name, - v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].CapacityType, - v1.LabelTopologyZone: currentInstance.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: currentInstance.Offerings[0].Constraints[v1.LabelTopologyZone], }) node.Status.Allocatable = map[v1.ResourceName]resource.Quantity{v1.ResourceCPU: resource.MustParse("8")} diff --git a/pkg/controllers/disruption/helpers.go b/pkg/controllers/disruption/helpers.go index a3701f6e28..821cf75252 100644 --- a/pkg/controllers/disruption/helpers.go +++ b/pkg/controllers/disruption/helpers.go @@ -317,7 +317,14 @@ func worstLaunchPrice(ofs []cloudprovider.Offering, reqs scheduling.Requirements // We prefer to launch spot offerings, so we will get the worst price based on the node requirements if reqs.Get(v1beta1.CapacityTypeLabelKey).Has(v1beta1.CapacityTypeSpot) { spotOfferings := lo.Filter(ofs, func(of cloudprovider.Offering, _ int) bool { - return of.CapacityType == v1beta1.CapacityTypeSpot && reqs.Get(v1.LabelTopologyZone).Has(of.Zone) + if of.Constraints[v1beta1.CapacityTypeLabelKey] == v1beta1.CapacityTypeSpot { + match := false + for label, v := range of.Constraints { + match = lo.Ternary(reqs.Get(label).Has(v), true, false) + } + return match + } + return false }) if len(spotOfferings) > 0 { return lo.MaxBy(spotOfferings, func(of1, of2 cloudprovider.Offering) bool { @@ -327,7 +334,14 @@ func worstLaunchPrice(ofs []cloudprovider.Offering, reqs scheduling.Requirements } if reqs.Get(v1beta1.CapacityTypeLabelKey).Has(v1beta1.CapacityTypeOnDemand) { onDemandOfferings := lo.Filter(ofs, func(of cloudprovider.Offering, _ int) bool { - return of.CapacityType == v1beta1.CapacityTypeOnDemand && reqs.Get(v1.LabelTopologyZone).Has(of.Zone) + if of.Constraints[v1beta1.CapacityTypeLabelKey] == v1beta1.CapacityTypeOnDemand { + match := false + for label, v := range of.Constraints { + match = lo.Ternary(reqs.Get(label).Has(v), true, false) + } + return match + } + return false }) if len(onDemandOfferings) > 0 { return lo.MaxBy(onDemandOfferings, func(of1, of2 cloudprovider.Offering) bool { diff --git a/pkg/controllers/disruption/multinodeconsolidation.go b/pkg/controllers/disruption/multinodeconsolidation.go index 11fed44e79..56a2c759fd 100644 --- a/pkg/controllers/disruption/multinodeconsolidation.go +++ b/pkg/controllers/disruption/multinodeconsolidation.go @@ -176,7 +176,8 @@ func filterOutSameType(newNodeClaim *scheduling.NodeClaim, consolidate []*Candid // get the price of the cheapest node that we currently are considering deleting indexed by instance type for _, c := range consolidate { existingInstanceTypes.Insert(c.instanceType.Name) - of, ok := c.instanceType.Offerings.Get(c.capacityType, c.zone) + fmt.Println(c.Labels()) + of, ok := c.instanceType.Offerings.Get(c.Labels()) if !ok { continue } diff --git a/pkg/controllers/disruption/orchestration/suite_test.go b/pkg/controllers/disruption/orchestration/suite_test.go index d500bac90b..eee8442a18 100644 --- a/pkg/controllers/disruption/orchestration/suite_test.go +++ b/pkg/controllers/disruption/orchestration/suite_test.go @@ -112,8 +112,8 @@ var _ = Describe("Queue", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: cloudProvider.InstanceTypes[0].Name, - v1beta1.CapacityTypeLabelKey: cloudProvider.InstanceTypes[0].Offerings.Cheapest().CapacityType, - v1.LabelTopologyZone: cloudProvider.InstanceTypes[0].Offerings.Cheapest().Zone, + v1beta1.CapacityTypeLabelKey: cloudProvider.InstanceTypes[0].Offerings.Cheapest().Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: cloudProvider.InstanceTypes[0].Offerings.Cheapest().Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -128,8 +128,8 @@ var _ = Describe("Queue", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: cloudProvider.InstanceTypes[0].Name, - v1beta1.CapacityTypeLabelKey: cloudProvider.InstanceTypes[0].Offerings.Cheapest().CapacityType, - v1.LabelTopologyZone: cloudProvider.InstanceTypes[0].Offerings.Cheapest().Zone, + v1beta1.CapacityTypeLabelKey: cloudProvider.InstanceTypes[0].Offerings.Cheapest().Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: cloudProvider.InstanceTypes[0].Offerings.Cheapest().Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -150,8 +150,8 @@ var _ = Describe("Queue", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: cloudProvider.InstanceTypes[0].Name, - v1beta1.CapacityTypeLabelKey: cloudProvider.InstanceTypes[0].Offerings.Cheapest().CapacityType, - v1.LabelTopologyZone: cloudProvider.InstanceTypes[0].Offerings.Cheapest().Zone, + v1beta1.CapacityTypeLabelKey: cloudProvider.InstanceTypes[0].Offerings.Cheapest().Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: cloudProvider.InstanceTypes[0].Offerings.Cheapest().Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ diff --git a/pkg/controllers/disruption/suite_test.go b/pkg/controllers/disruption/suite_test.go index 80fa3a1a2c..3832ede34c 100644 --- a/pkg/controllers/disruption/suite_test.go +++ b/pkg/controllers/disruption/suite_test.go @@ -117,7 +117,7 @@ var _ = BeforeEach(func() { onDemandInstances = lo.Filter(cloudProvider.InstanceTypes, func(i *cloudprovider.InstanceType, _ int) bool { for _, o := range i.Offerings.Available() { - if o.CapacityType == v1beta1.CapacityTypeOnDemand { + if o.Constraints[v1beta1.CapacityTypeLabelKey] == v1beta1.CapacityTypeOnDemand { return true } } @@ -131,7 +131,7 @@ var _ = BeforeEach(func() { leastExpensiveOffering, mostExpensiveOffering = leastExpensiveInstance.Offerings[0], mostExpensiveInstance.Offerings[0] spotInstances = lo.Filter(cloudProvider.InstanceTypes, func(i *cloudprovider.InstanceType, _ int) bool { for _, o := range i.Offerings.Available() { - if o.CapacityType == v1beta1.CapacityTypeSpot { + if o.Constraints[v1beta1.CapacityTypeLabelKey] == v1beta1.CapacityTypeSpot { return true } } @@ -167,8 +167,8 @@ var _ = Describe("Simulate Scheduling", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -237,8 +237,8 @@ var _ = Describe("Simulate Scheduling", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -365,8 +365,8 @@ var _ = Describe("Simulate Scheduling", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -465,10 +465,9 @@ var _ = Describe("Disruption Taints", func() { Name: "current-on-demand", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 1.5, - Available: false, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 1.5, + Available: false, }, }, }) @@ -476,22 +475,19 @@ var _ = Describe("Disruption Taints", func() { Name: "spot-replacement", Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1a", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1a"), + Price: 1.0, + Available: true, }, { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1b", - Price: 0.2, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1b"), + Price: 0.2, + Available: true, }, { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1c", - Price: 0.4, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1c"), + Price: 0.4, + Available: true, }, }, }) @@ -500,8 +496,8 @@ var _ = Describe("Disruption Taints", func() { ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ v1.LabelInstanceTypeStable: currentInstance.Name, - v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].CapacityType, - v1.LabelTopologyZone: currentInstance.Offerings[0].Zone, + v1beta1.CapacityTypeLabelKey: currentInstance.Offerings[0].Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: currentInstance.Offerings[0].Constraints[v1.LabelTopologyZone], v1beta1.NodePoolLabelKey: nodePool.Name, }, }, @@ -615,8 +611,8 @@ var _ = Describe("BuildDisruptionBudgetMapping", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -655,8 +651,8 @@ var _ = Describe("BuildDisruptionBudgetMapping", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -817,8 +813,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -845,8 +841,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -884,8 +880,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -922,8 +918,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -952,8 +948,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -993,8 +989,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1013,8 +1009,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1050,8 +1046,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1096,8 +1092,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1142,8 +1138,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1186,8 +1182,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1224,8 +1220,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1243,8 +1239,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1262,8 +1258,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1283,8 +1279,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1305,8 +1301,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1326,8 +1322,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1345,8 +1341,8 @@ var _ = Describe("Candidate Filtering", func() { ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1364,8 +1360,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1389,7 +1385,7 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1408,7 +1404,7 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], }, }, }) @@ -1426,8 +1422,8 @@ var _ = Describe("Candidate Filtering", func() { ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1446,8 +1442,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1469,8 +1465,8 @@ var _ = Describe("Candidate Filtering", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, }) @@ -1510,8 +1506,8 @@ var _ = Describe("Metrics", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -1556,8 +1552,8 @@ var _ = Describe("Metrics", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -1610,8 +1606,8 @@ var _ = Describe("Metrics", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -1664,8 +1660,8 @@ var _ = Describe("Metrics", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -1711,8 +1707,8 @@ var _ = Describe("Metrics", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: leastExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.CapacityType, - v1.LabelTopologyZone: leastExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: leastExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: leastExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ @@ -1782,8 +1778,8 @@ var _ = Describe("Metrics", func() { Labels: map[string]string{ v1beta1.NodePoolLabelKey: nodePool.Name, v1.LabelInstanceTypeStable: mostExpensiveInstance.Name, - v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.CapacityType, - v1.LabelTopologyZone: mostExpensiveOffering.Zone, + v1beta1.CapacityTypeLabelKey: mostExpensiveOffering.Constraints[v1beta1.CapacityTypeLabelKey], + v1.LabelTopologyZone: mostExpensiveOffering.Constraints[v1.LabelTopologyZone], }, }, Status: v1beta1.NodeClaimStatus{ diff --git a/pkg/controllers/provisioning/scheduling/instance_selection_test.go b/pkg/controllers/provisioning/scheduling/instance_selection_test.go index d086d90aaf..7fedd94f83 100644 --- a/pkg/controllers/provisioning/scheduling/instance_selection_test.go +++ b/pkg/controllers/provisioning/scheduling/instance_selection_test.go @@ -43,7 +43,7 @@ var _ = Describe("Instance Type Selection", func() { var minPrice float64 var instanceTypeMap map[string]*cloudprovider.InstanceType nodePrice := func(n *v1.Node) float64 { - of, _ := instanceTypeMap[n.Labels[v1.LabelInstanceTypeStable]].Offerings.Get(n.Labels[v1beta1.CapacityTypeLabelKey], n.Labels[v1.LabelTopologyZone]) + of, _ := instanceTypeMap[n.Labels[v1.LabelInstanceTypeStable]].Offerings.Get(n.Labels) return of.Price } @@ -485,7 +485,7 @@ var _ = Describe("Instance Type Selection", func() { // remove all Arm instance types in zone-2 cloudProvider.InstanceTypes = filterInstanceTypes(cloudProvider.InstanceTypes, func(i *cloudprovider.InstanceType) bool { for _, off := range i.Offerings { - if off.Zone == "test-zone-2" { + if off.Constraints[v1.LabelTopologyZone] == "test-zone-2" { return i.Requirements.Get(v1.LabelArchStable).Has(v1beta1.ArchitectureAmd64) } } @@ -514,7 +514,7 @@ var _ = Describe("Instance Type Selection", func() { // remove all Arm instance types in zone-2 cloudProvider.InstanceTypes = filterInstanceTypes(cloudProvider.InstanceTypes, func(i *cloudprovider.InstanceType) bool { for _, off := range i.Offerings { - if off.Zone == "test-zone-2" { + if off.Constraints[v1.LabelTopologyZone] == "test-zone-2" { return i.Requirements.Get(v1.LabelArchStable).Has(v1beta1.ArchitectureAmd64) } } @@ -609,8 +609,8 @@ var _ = Describe("Instance Type Selection", func() { v1.ResourceMemory: resource.MustParse("1Gi"), }, Offerings: []cloudprovider.Offering{ - {CapacityType: v1beta1.CapacityTypeOnDemand, Zone: "test-zone-1a", Price: 1.0, Available: true}, - {CapacityType: v1beta1.CapacityTypeSpot, Zone: "test-zone-1a", Price: 0.2, Available: true}, + {Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), Price: 1.0, Available: true}, + {Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1a"), Price: 0.2, Available: true}, }, }), fake.NewInstanceType(fake.InstanceTypeOptions{ @@ -622,8 +622,8 @@ var _ = Describe("Instance Type Selection", func() { v1.ResourceMemory: resource.MustParse("1Gi"), }, Offerings: []cloudprovider.Offering{ - {CapacityType: v1beta1.CapacityTypeOnDemand, Zone: "test-zone-1a", Price: 1.3, Available: true}, - {CapacityType: v1beta1.CapacityTypeSpot, Zone: "test-zone-1a", Price: 0.1, Available: true}, + {Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), Price: 1.3, Available: true}, + {Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1a"), Price: 0.1, Available: true}, }, }), } @@ -658,10 +658,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -675,10 +674,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.0, + Available: true, }, } instanceTypes = append(instanceTypes, fake.NewInstanceType(opts1)) @@ -738,10 +736,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -755,10 +752,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.0, + Available: true, }, } opts3 := fake.InstanceTypeOptions{ @@ -772,10 +768,9 @@ var _ = Describe("Instance Type Selection", func() { } opts3.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.2, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.2, + Available: true, }, } @@ -837,10 +832,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -854,10 +848,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.0, + Available: true, }, } instanceTypes = append(instanceTypes, fake.NewInstanceTypeWithCustomRequirement(opts1, scheduler.NewRequirement(instanceGeneration, v1.NodeSelectorOpIn, "2"))) @@ -915,10 +908,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -932,10 +924,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.0, + Available: true, }, } opts3 := fake.InstanceTypeOptions{ @@ -949,10 +940,9 @@ var _ = Describe("Instance Type Selection", func() { } opts3.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.2, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.2, + Available: true, }, } instanceTypes = append(instanceTypes, fake.NewInstanceTypeWithCustomRequirement(opts1, scheduler.NewRequirement(instanceGeneration, v1.NodeSelectorOpIn, "2"))) @@ -1013,10 +1003,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -1030,10 +1019,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.2, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.2, + Available: true, }, } instanceTypes = append(instanceTypes, fake.NewInstanceTypeWithCustomRequirement(opts1, scheduler.NewRequirement(instanceGeneration, v1.NodeSelectorOpIn, "2"))) @@ -1084,10 +1072,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -1101,10 +1088,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.0, + Available: true, }, } opts3 := fake.InstanceTypeOptions{ @@ -1118,10 +1104,9 @@ var _ = Describe("Instance Type Selection", func() { } opts3.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.2, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.2, + Available: true, }, } instanceTypes = append(instanceTypes, fake.NewInstanceType(opts1)) @@ -1189,10 +1174,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -1206,10 +1190,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.0, + Available: true, }, } opts3 := fake.InstanceTypeOptions{ @@ -1223,10 +1206,9 @@ var _ = Describe("Instance Type Selection", func() { } opts3.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.2, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.2, + Available: true, }, } opts4 := fake.InstanceTypeOptions{ @@ -1240,10 +1222,9 @@ var _ = Describe("Instance Type Selection", func() { } opts4.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.2, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.2, + Available: true, }, } instanceTypes = append(instanceTypes, fake.NewInstanceTypeWithCustomRequirement(opts1, scheduler.NewRequirement(instanceGeneration, v1.NodeSelectorOpIn, "2"))) @@ -1339,10 +1320,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -1356,10 +1336,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.0, + Available: true, }, } instanceTypes = append(instanceTypes, fake.NewInstanceType(opts1)) @@ -1416,10 +1395,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -1433,10 +1411,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.0, + Available: true, }, } instanceTypes = append(instanceTypes, fake.NewInstanceType(opts1)) @@ -1503,10 +1480,9 @@ var _ = Describe("Instance Type Selection", func() { } opts1.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 0.52, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 0.52, + Available: true, }, } opts2 := fake.InstanceTypeOptions{ @@ -1520,10 +1496,9 @@ var _ = Describe("Instance Type Selection", func() { } opts2.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1-spot", - Price: 1.0, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeSpot, "test-zone-1-spot"), + Price: 1.0, + Available: true, }, } instanceTypes = append(instanceTypes, fake.NewInstanceType(opts1)) diff --git a/pkg/controllers/provisioning/scheduling/nodeclaim.go b/pkg/controllers/provisioning/scheduling/nodeclaim.go index f73351f998..4fa9557988 100644 --- a/pkg/controllers/provisioning/scheduling/nodeclaim.go +++ b/pkg/controllers/provisioning/scheduling/nodeclaim.go @@ -284,8 +284,8 @@ func fits(instanceType *cloudprovider.InstanceType, requests v1.ResourceList) bo func hasOffering(instanceType *cloudprovider.InstanceType, requirements scheduling.Requirements) bool { for _, offering := range instanceType.Offerings.Available() { - if (!requirements.Has(v1.LabelTopologyZone) || requirements.Get(v1.LabelTopologyZone).Has(offering.Zone)) && - (!requirements.Has(v1beta1.CapacityTypeLabelKey) || requirements.Get(v1beta1.CapacityTypeLabelKey).Has(offering.CapacityType)) { + if (!requirements.Has(v1.LabelTopologyZone) || requirements.Get(v1.LabelTopologyZone).Has(offering.Constraints[v1.LabelTopologyZone])) && + (!requirements.Has(v1beta1.CapacityTypeLabelKey) || requirements.Get(v1beta1.CapacityTypeLabelKey).Has(offering.Constraints[v1beta1.CapacityTypeLabelKey])) { return true } } diff --git a/pkg/controllers/provisioning/scheduling/suite_test.go b/pkg/controllers/provisioning/scheduling/suite_test.go index 2a5862e4a4..b1a60bdd7b 100644 --- a/pkg/controllers/provisioning/scheduling/suite_test.go +++ b/pkg/controllers/provisioning/scheduling/suite_test.go @@ -1745,10 +1745,9 @@ var _ = Context("Scheduling", func() { }, Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 3.00, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 3.00, + Available: true, }, }, }), @@ -1760,10 +1759,9 @@ var _ = Context("Scheduling", func() { }, Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 2.00, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 2.00, + Available: true, }, }, }), @@ -1775,10 +1773,9 @@ var _ = Context("Scheduling", func() { }, Offerings: []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeOnDemand, - Zone: "test-zone-1a", - Price: 1.00, - Available: true, + Constraints: test.Constraints(v1beta1.CapacityTypeOnDemand, "test-zone-1a"), + Price: 1.00, + Available: true, }, }, }), @@ -3795,7 +3792,7 @@ func ExpectInstancesWithOffering(instanceTypes []*cloudprovider.InstanceType, ca for _, it := range instanceTypes { matched := false for _, offering := range it.Offerings { - if offering.CapacityType == capacityType && offering.Zone == zone { + if offering.Constraints[v1beta1.CapacityTypeLabelKey] == capacityType && offering.Constraints[v1.LabelTopologyZone] == zone { matched = true } } @@ -3814,7 +3811,7 @@ func ExpectInstancesWithLabel(instanceTypes []*cloudprovider.InstanceType, label { matched := false for _, offering := range it.Offerings { - if offering.Zone == value { + if offering.Constraints[v1.LabelTopologyZone] == value { matched = true break } @@ -3825,7 +3822,7 @@ func ExpectInstancesWithLabel(instanceTypes []*cloudprovider.InstanceType, label { matched := false for _, offering := range it.Offerings { - if offering.CapacityType == value { + if offering.Constraints[v1beta1.CapacityTypeLabelKey] == value { matched = true break } diff --git a/pkg/controllers/provisioning/suite_test.go b/pkg/controllers/provisioning/suite_test.go index cf8494476c..ce09744aca 100644 --- a/pkg/controllers/provisioning/suite_test.go +++ b/pkg/controllers/provisioning/suite_test.go @@ -1959,10 +1959,12 @@ func AddInstanceResources(instanceTypes []*cloudprovider.InstanceType, resources price := fake.PriceFromResources(opts.Resources) opts.Offerings = []cloudprovider.Offering{ { - CapacityType: v1beta1.CapacityTypeSpot, - Zone: "test-zone-1", - Price: price, - Available: true, + Constraints: map[string]string{ + v1beta1.CapacityTypeLabelKey: v1beta1.CapacityTypeSpot, + v1.LabelTopologyZone: "test-zone-1", + }, + Price: price, + Available: true, }, } diff --git a/pkg/test/helpers.go b/pkg/test/helpers.go new file mode 100644 index 0000000000..da03a198ce --- /dev/null +++ b/pkg/test/helpers.go @@ -0,0 +1,35 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package test + +import ( + v1 "k8s.io/api/core/v1" + "sigs.k8s.io/karpenter/pkg/apis/v1beta1" +) + +func Constraints(capacityType, zone string) map[string]string { + return map[string]string{ + v1beta1.CapacityTypeLabelKey: capacityType, + v1.LabelTopologyZone: zone, + } +}