Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add option for passing extended resources in node labels in GKE #7604

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions cluster-autoscaler/cloudprovider/gce/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,22 +438,44 @@ func extractExtendedResourcesFromKubeEnv(kubeEnv KubeEnv) (apiv1.ResourceList, e
klog.Warningf("error while obtaining extended_resources from AUTOSCALER_ENV_VARS; %v", err)
return nil, err
}

if !found {
return apiv1.ResourceList{}, nil
var extendedResourcesMap map[string]string
if found {
extendedResourcesMap, err = parseKeyValueListToMap(extendedResourcesAsString)
if err != nil {
return apiv1.ResourceList{}, err
}
} else {
extendedResourcesMap = make(map[string]string)
}

extendedResourcesMap, err := parseKeyValueListToMap(extendedResourcesAsString)
nodeLabelsAsString, found, err := extractAutoscalerVarFromKubeEnv(kubeEnv, "node_labels")
if err != nil {
return apiv1.ResourceList{}, err
klog.Warningf("error while obtaining node_labels from AUTOSCALER_ENV_VARS; %v", err)
return nil, err
}
if found {
nodeLabelsMap, err := parseKeyValueListToMap(nodeLabelsAsString)
if err != nil {
return apiv1.ResourceList{}, err
}
const extendedResourcesKeyPrefix = "clusterautoscaler-nodetemplate-resources-"
mu-soliman marked this conversation as resolved.
Show resolved Hide resolved
for key, value := range nodeLabelsMap {
if strings.HasPrefix(key, extendedResourcesKeyPrefix) {
key = strings.TrimPrefix(key, extendedResourcesKeyPrefix)
extendedResourcesMap[key] = value
}
}
}

if len(extendedResourcesMap) == 0 {
return apiv1.ResourceList{}, nil
}

extendedResources := apiv1.ResourceList{}
for name, quantity := range extendedResourcesMap {
if q, err := resource.ParseQuantity(quantity); err == nil && q.Sign() >= 0 {
extendedResources[apiv1.ResourceName(name)] = q
} else if err != nil {
klog.Warningf("ignoring invalid value in extended_resources defined in AUTOSCALER_ENV_VARS; %v", err)
klog.Warningf("ignoring invalid value in extended_resources or node_labels defined in AUTOSCALER_ENV_VARS; %v", err)
}
}
return extendedResources, nil
Expand Down
12 changes: 12 additions & 0 deletions cluster-autoscaler/cloudprovider/gce/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,18 @@ func TestExtractExtendedResourcesFromKubeEnv(t *testing.T) {
expectedExtendedResources: apiv1.ResourceList{},
expectedErr: true,
},
{
name: "two valid values one of them defined in node labels",
kubeEnvValue: "AUTOSCALER_ENV_VARS: node_labels=a=b,c=d,clusterautoscaler-nodetemplate-resources-test.co/test-resource=3,cloud.google.com/gke-nodepool=pool-3,cloud.google.com/gke-preemptible=true;" +
"node_taints='dedicated=ml:NoSchedule,test=dev:PreferNoSchedule,a=b:c';" +
"kube_reserved=cpu=1000m,memory=300000Mi;" +
"extended_resources=foo=bar,baz=10G",
expectedExtendedResources: apiv1.ResourceList{
apiv1.ResourceName("baz"): *resource.NewQuantity(10*units.GB, resource.DecimalSI),
apiv1.ResourceName("test.co/test-resource"): *resource.NewQuantity(3, resource.DecimalSI),
},
expectedErr: false,
},
}

for _, tc := range testCases {
Expand Down
Loading