Kuberenets 1.11 has deprecated ExternalID this replaces it with ProviderID

Per https://github.com/kubernetes/kubernetes/pull/61877 ExternalID
is now removed from k8s.
This commit is contained in:
Zach Aller 2018-05-16 13:31:04 -05:00
parent be15242551
commit 4cb92b7c1e
3 changed files with 18 additions and 5 deletions

View File

@ -18,9 +18,12 @@ package cloudinstances
import (
"fmt"
"strings"
"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/pkg/apis/kops/util"
api "k8s.io/kops/pkg/apis/kops"
)
@ -83,11 +86,21 @@ func (c *CloudInstanceGroup) Status() string {
}
// GetNodeMap returns a list of nodes keyed by their external id
func GetNodeMap(nodes []v1.Node) map[string]*v1.Node {
func GetNodeMap(nodes []v1.Node, cluster *kops.Cluster) map[string]*v1.Node {
sv, _ := util.ParseKubernetesVersion(cluster.Spec.KubernetesVersion)
nodeMap := make(map[string]*v1.Node)
for i := range nodes {
node := &nodes[i]
nodeMap[node.Spec.ExternalID] = node
//ExternalID is deprecated in kubernetes 1.11 https://github.com/kubernetes/kubernetes/pull/61877
//Mappings from ExternalID https://github.com/kubernetes/kubernetes/issues/61966#issuecomment-377659476
if sv.Major == 1 && sv.Minor < 10 {
nodeMap[node.Spec.ExternalID] = node
} else {
providerIDs := strings.Split(node.Spec.ProviderID,"/")
instanceID := providerIDs[len(providerIDs)-1]
nodeMap[instanceID] = node
}
}
return nodeMap

View File

@ -383,7 +383,7 @@ func (c *awsCloudImplementation) GetCloudGroups(cluster *kops.Cluster, instanceg
}
func getCloudGroups(c AWSCloud, cluster *kops.Cluster, instancegroups []*kops.InstanceGroup, warnUnmatched bool, nodes []v1.Node) (map[string]*cloudinstances.CloudInstanceGroup, error) {
nodeMap := cloudinstances.GetNodeMap(nodes)
nodeMap := cloudinstances.GetNodeMap(nodes, cluster)
groups := make(map[string]*cloudinstances.CloudInstanceGroup)
asgs, err := FindAutoscalingGroups(c, c.Tags())

View File

@ -100,7 +100,7 @@ func getCloudGroups(c GCECloud, cluster *kops.Cluster, instancegroups []*kops.In
project := c.Project()
ctx := context.Background()
nodesByExternalID := cloudinstances.GetNodeMap(nodes)
nodesByProviderID := cloudinstances.GetNodeMap(nodes, cluster)
// There is some code duplication with resources/gce.go here, but more in the structure than a straight copy-paste
@ -171,7 +171,7 @@ func getCloudGroups(c GCECloud, cluster *kops.Cluster, instancegroups []*kops.In
CloudInstanceGroup: g,
}
node := nodesByExternalID[strconv.FormatUint(i.Id, 10)]
node := nodesByProviderID[strconv.FormatUint(i.Id, 10)]
if node != nil {
cm.Node = node
} else {