From fa397758e28485bb446da211be4feec1ede3fc0e Mon Sep 17 00:00:00 2001 From: Ravishankar Suribabu Date: Tue, 25 Jun 2019 00:29:41 +0530 Subject: [PATCH] Validation to verify if node.Spec.ProviderID is nil - for GCE --- cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go b/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go index 35c60d5e672c..b4c314804f62 100644 --- a/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go +++ b/cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go @@ -96,6 +96,7 @@ func (gce *GceCloudProvider) NodeGroups() []cloudprovider.NodeGroup { func (gce *GceCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.NodeGroup, error) { ref, err := GceRefFromProviderId(node.Spec.ProviderID) if err != nil { + klog.Errorf("Error extracting node.Spec.ProviderID for node %v: %v", node.Name, err) return nil, err } mig, err := gce.gceManager.GetMigForInstance(ref) @@ -158,6 +159,10 @@ func (ref GceRef) ToProviderId() string { // gce://// // TODO(piosz): add better check whether the id is correct func GceRefFromProviderId(id string) (GceRef, error) { + if len(id) == 0 { + return GceRef{}, fmt.Errorf("wrong id: expected format gce:////, got nil") + } + splitted := strings.Split(id[6:], "/") if len(splitted) != 3 { return GceRef{}, fmt.Errorf("wrong id: expected format gce:////, got %v", id)