From 2686cc2dd22dea7268e76392d60c768f56c6079b Mon Sep 17 00:00:00 2001 From: tombokombo Date: Mon, 23 Jan 2023 22:06:11 +0100 Subject: [PATCH 1/2] extended test for resource extracting Signed-off-by: tombokombo --- cluster-autoscaler/cloudprovider/aws/aws_manager_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go b/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go index cd7689cb39f1..9fd62c6c0a46 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go @@ -123,6 +123,10 @@ func TestExtractAllocatableResourcesFromAsg(t *testing.T) { Key: aws.String("k8s.io/cluster-autoscaler/node-template/resources/ephemeral-storage"), Value: aws.String("20G"), }, + { + Key: aws.String("k8s.io/cluster-autoscaler/node-template/resources/custom-resource"), + Value: aws.String("5"), + }, } labels := extractAllocatableResourcesFromAsg(tags) @@ -132,6 +136,7 @@ func TestExtractAllocatableResourcesFromAsg(t *testing.T) { assert.Equal(t, (&expectedMemory).String(), labels["memory"].String()) expectedEphemeralStorage := resource.MustParse("20G") assert.Equal(t, (&expectedEphemeralStorage).String(), labels["ephemeral-storage"].String()) + assert.Equal(t, resource.NewQuantity(5, resource.DecimalSI).String(), labels["custom-resource"].String()) } func TestGetAsgOptions(t *testing.T) { From e813167326c2d044c40906273a204e876822a7e1 Mon Sep 17 00:00:00 2001 From: tombokombo Date: Mon, 23 Jan 2023 22:42:15 +0100 Subject: [PATCH 2/2] more tests Signed-off-by: tombokombo --- cluster-autoscaler/cloudprovider/aws/aws_manager_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go b/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go index 9fd62c6c0a46..9c8cff14eab6 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_manager_test.go @@ -405,6 +405,8 @@ func TestBuildNodeFromTemplate(t *testing.T) { // Node with custom resource ephemeralStorageKey := "ephemeral-storage" ephemeralStorageValue := int64(20) + customResourceKey := "custom-resource" + customResourceValue := int64(5) vpcIPKey := "vpc.amazonaws.com/PrivateIPv4Address" observedNode, observedErr := awsManager.buildNodeFromTemplate(asg, &asgTemplate{ InstanceType: c5Instance, @@ -413,12 +415,19 @@ func TestBuildNodeFromTemplate(t *testing.T) { Key: aws.String(fmt.Sprintf("k8s.io/cluster-autoscaler/node-template/resources/%s", ephemeralStorageKey)), Value: aws.String(strconv.FormatInt(ephemeralStorageValue, 10)), }, + { + Key: aws.String(fmt.Sprintf("k8s.io/cluster-autoscaler/node-template/resources/%s", customResourceKey)), + Value: aws.String(strconv.FormatInt(customResourceValue, 10)), + }, }, }) assert.NoError(t, observedErr) esValue, esExist := observedNode.Status.Capacity[apiv1.ResourceName(ephemeralStorageKey)] assert.True(t, esExist) assert.Equal(t, int64(20), esValue.Value()) + crValue, crExist := observedNode.Status.Capacity[apiv1.ResourceName(customResourceKey)] + assert.True(t, crExist) + assert.Equal(t, int64(5), crValue.Value()) _, ipExist := observedNode.Status.Capacity[apiv1.ResourceName(vpcIPKey)] assert.False(t, ipExist)