Skip to content

Commit

Permalink
feat: Support PodRequests calculations for initContainers with restar… (
Browse files Browse the repository at this point in the history
#569)

Signed-off-by: sadath-12 <[email protected]>
Co-authored-by: Jonathan Innis <[email protected]>
  • Loading branch information
sadath-12 and jonathan-innis authored Feb 2, 2024
1 parent 49a70dc commit 0e77b78
Show file tree
Hide file tree
Showing 7 changed files with 930 additions and 63 deletions.
4 changes: 2 additions & 2 deletions kwok/cloudprovider/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func ConstructInstanceTypes() []*cloudprovider.InstanceType {
},
InstanceTypeLabels: labels,
}
price := priceFromResources(opts.Resources)
price := PriceFromResources(opts.Resources)

opts.Offerings = cloudprovider.Offerings{}
for _, zone := range KwokZones {
Expand Down Expand Up @@ -131,7 +131,7 @@ func newInstanceType(options InstanceTypeOptions) *cloudprovider.InstanceType {
}
}

func priceFromResources(resources v1.ResourceList) float64 {
func PriceFromResources(resources v1.ResourceList) float64 {
price := 0.0
for k, v := range resources {
switch k {
Expand Down
14 changes: 7 additions & 7 deletions pkg/cloudprovider/fake/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func NewInstanceType(options InstanceTypeOptions) *cloudprovider.InstanceType {
}
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},
{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},
}
}
if len(options.Architecture) == 0 {
Expand Down Expand Up @@ -125,7 +125,7 @@ func InstanceTypesAssorted() []*cloudprovider.InstanceType {
v1.ResourceMemory: resource.MustParse(fmt.Sprintf("%dGi", mem)),
},
}
price := priceFromResources(opts.Resources)
price := PriceFromResources(opts.Resources)
opts.Offerings = []cloudprovider.Offering{
{
CapacityType: ct,
Expand Down Expand Up @@ -173,7 +173,7 @@ type InstanceTypeOptions struct {
Resources v1.ResourceList
}

func priceFromResources(resources v1.ResourceList) float64 {
func PriceFromResources(resources v1.ResourceList) float64 {
price := 0.0
for k, v := range resources {
switch k {
Expand Down
28 changes: 17 additions & 11 deletions pkg/controllers/provisioning/scheduling/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,11 +1663,15 @@ var _ = Context("NodePool", func() {
v1.ResourceCPU: resource.MustParse("1"),
},
},
InitImage: "pause",
InitResourceRequirements: v1.ResourceRequirements{
Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceMemory: resource.MustParse("1Gi"),
v1.ResourceCPU: resource.MustParse("2"),
InitContainers: []v1.Container{
{
Resources: v1.ResourceRequirements{

Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceMemory: resource.MustParse("1Gi"),
v1.ResourceCPU: resource.MustParse("2"),
},
},
},
},
})
Expand All @@ -1684,13 +1688,15 @@ var _ = Context("NodePool", func() {
v1.ResourceCPU: resource.MustParse("1"),
},
},
InitImage: "pause",
InitResourceRequirements: v1.ResourceRequirements{
Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceMemory: resource.MustParse("1Ti"),
v1.ResourceCPU: resource.MustParse("2"),
InitContainers: []v1.Container{{
Resources: v1.ResourceRequirements{

Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceMemory: resource.MustParse("1Ti"),
v1.ResourceCPU: resource.MustParse("2"),
},
},
},
}},
})
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, prov, pod)
ExpectNotScheduled(ctx, env.Client, pod)
Expand Down
Loading

0 comments on commit 0e77b78

Please sign in to comment.