Skip to content

Commit

Permalink
Merge pull request #2138 from emailksravi/master
Browse files Browse the repository at this point in the history
Validation to verify if node.Spec.ProviderID is nil - for GCE
  • Loading branch information
k8s-ci-robot authored Jun 24, 2019
2 parents 385a2b5 + fa39775 commit a173ea1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cluster-autoscaler/cloudprovider/gce/gce_cloud_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -158,6 +159,10 @@ func (ref GceRef) ToProviderId() string {
// gce://<project-id>/<zone>/<name>
// 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://<project-id>/<zone>/<name>, got nil")
}

splitted := strings.Split(id[6:], "/")
if len(splitted) != 3 {
return GceRef{}, fmt.Errorf("wrong id: expected format gce://<project-id>/<zone>/<name>, got %v", id)
Expand Down

0 comments on commit a173ea1

Please sign in to comment.