mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Update Instances to use generated code
Update LoadBalancer to use generated code
This commit is contained in:
parent
ddea2dd56f
commit
02e52da702
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package gce
|
package gce
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -35,6 +36,8 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||||
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/filter"
|
||||||
|
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce/cloud/meta"
|
||||||
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
|
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,15 +93,15 @@ func (gce *GCECloud) NodeAddresses(_ types.NodeName) ([]v1.NodeAddress, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method will not be called from the node that is requesting this ID.
|
// NodeAddressesByProviderID will not be called from the node that is requesting this ID.
|
||||||
// i.e. metadata service and other local methods cannot be used here
|
// i.e. metadata service and other local methods cannot be used here
|
||||||
func (gce *GCECloud) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddress, error) {
|
func (gce *GCECloud) NodeAddressesByProviderID(providerID string) ([]v1.NodeAddress, error) {
|
||||||
project, zone, name, err := splitProviderID(providerID)
|
_, zone, name, err := splitProviderID(providerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []v1.NodeAddress{}, err
|
return []v1.NodeAddress{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
instance, err := gce.service.Instances.Get(project, zone, canonicalizeInstanceName(name)).Do()
|
instance, err := gce.c.Instances().Get(context.Background(), meta.ZonalKey(canonicalizeInstanceName(name), zone))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []v1.NodeAddress{}, fmt.Errorf("error while querying for providerID %q: %v", providerID, err)
|
return []v1.NodeAddress{}, fmt.Errorf("error while querying for providerID %q: %v", providerID, err)
|
||||||
}
|
}
|
||||||
@ -223,7 +226,7 @@ func (gce *GCECloud) InstanceType(nodeName types.NodeName) (string, error) {
|
|||||||
|
|
||||||
func (gce *GCECloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
func (gce *GCECloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
||||||
return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
|
return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
|
||||||
project, err := gce.service.Projects.Get(gce.projectID).Do()
|
project, err := gce.c.Projects().Get(context.Background(), gce.projectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Could not get project: %v", err)
|
glog.Errorf("Could not get project: %v", err)
|
||||||
return false, nil
|
return false, nil
|
||||||
@ -254,20 +257,13 @@ func (gce *GCECloud) AddSSHKeyToAllInstances(user string, keyData []byte) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
mc := newInstancesMetricContext("add_ssh_key", "")
|
mc := newInstancesMetricContext("add_ssh_key", "")
|
||||||
op, err := gce.service.Projects.SetCommonInstanceMetadata(
|
err = gce.c.Projects().SetCommonInstanceMetadata(context.Background(), gce.projectID, project.CommonInstanceMetadata)
|
||||||
gce.projectID, project.CommonInstanceMetadata).Do()
|
mc.Observe(err)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Could not Set Metadata: %v", err)
|
glog.Errorf("Could not Set Metadata: %v", err)
|
||||||
mc.Observe(err)
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gce.waitForGlobalOp(op, mc); err != nil {
|
|
||||||
glog.Errorf("Could not Set Metadata: %v", err)
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
glog.Infof("Successfully added sshKey to project metadata")
|
glog.Infof("Successfully added sshKey to project metadata")
|
||||||
return true, nil
|
return true, nil
|
||||||
})
|
})
|
||||||
@ -282,7 +278,7 @@ func (gce *GCECloud) GetAllCurrentZones() (sets.String, error) {
|
|||||||
gce.nodeZonesLock.Lock()
|
gce.nodeZonesLock.Lock()
|
||||||
defer gce.nodeZonesLock.Unlock()
|
defer gce.nodeZonesLock.Unlock()
|
||||||
if !gce.nodeInformerSynced() {
|
if !gce.nodeInformerSynced() {
|
||||||
return nil, fmt.Errorf("Node informer is not synced when trying to GetAllCurrentZones")
|
return nil, fmt.Errorf("node informer is not synced when trying to GetAllCurrentZones")
|
||||||
}
|
}
|
||||||
zones := sets.NewString()
|
zones := sets.NewString()
|
||||||
for zone, nodes := range gce.nodeZones {
|
for zone, nodes := range gce.nodeZones {
|
||||||
@ -298,55 +294,46 @@ func (gce *GCECloud) GetAllCurrentZones() (sets.String, error) {
|
|||||||
// get all zones with compute instances in them even if not k8s instances!!!
|
// get all zones with compute instances in them even if not k8s instances!!!
|
||||||
// ex. I have k8s nodes in us-central1-c and us-central1-b. I also have
|
// ex. I have k8s nodes in us-central1-c and us-central1-b. I also have
|
||||||
// a non-k8s compute in us-central1-a. This func will return a,b, and c.
|
// a non-k8s compute in us-central1-a. This func will return a,b, and c.
|
||||||
|
//
|
||||||
|
// TODO: this should be removed from the cloud provider.
|
||||||
func (gce *GCECloud) GetAllZonesFromCloudProvider() (sets.String, error) {
|
func (gce *GCECloud) GetAllZonesFromCloudProvider() (sets.String, error) {
|
||||||
zones := sets.NewString()
|
zones := sets.NewString()
|
||||||
|
|
||||||
for _, zone := range gce.managedZones {
|
for _, zone := range gce.managedZones {
|
||||||
mc := newInstancesMetricContext("list", zone)
|
instances, err := gce.c.Instances().List(context.Background(), zone, filter.None)
|
||||||
// We only retrieve one page in each zone - we only care about existence
|
|
||||||
listCall := gce.service.Instances.List(gce.projectID, zone)
|
|
||||||
|
|
||||||
listCall = listCall.Fields("items(name)")
|
|
||||||
res, err := listCall.Do()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, mc.Observe(err)
|
return sets.NewString(), err
|
||||||
}
|
}
|
||||||
mc.Observe(nil)
|
if len(instances) > 0 {
|
||||||
|
|
||||||
if len(res.Items) != 0 {
|
|
||||||
zones.Insert(zone)
|
zones.Insert(zone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return zones, nil
|
return zones, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertInstance creates a new instance on GCP
|
// InsertInstance creates a new instance on GCP
|
||||||
func (gce *GCECloud) InsertInstance(project string, zone string, rb *compute.Instance) error {
|
func (gce *GCECloud) InsertInstance(project string, zone string, i *compute.Instance) error {
|
||||||
mc := newInstancesMetricContext("create", zone)
|
mc := newInstancesMetricContext("create", zone)
|
||||||
op, err := gce.service.Instances.Insert(project, zone, rb).Do()
|
return mc.Observe(gce.c.Instances().Insert(context.Background(), meta.ZonalKey(i.Name, zone), i))
|
||||||
if err != nil {
|
|
||||||
return mc.Observe(err)
|
|
||||||
}
|
|
||||||
return gce.waitForZoneOp(op, zone, mc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListInstanceNames returns a string of instance names seperated by spaces.
|
// ListInstanceNames returns a string of instance names separated by spaces.
|
||||||
|
// This method should only be used for e2e testing.
|
||||||
|
// TODO: remove this method.
|
||||||
func (gce *GCECloud) ListInstanceNames(project, zone string) (string, error) {
|
func (gce *GCECloud) ListInstanceNames(project, zone string) (string, error) {
|
||||||
res, err := gce.service.Instances.List(project, zone).Fields("items(name)").Do()
|
l, err := gce.c.Instances().List(context.Background(), zone, filter.None)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
var output string
|
var names []string
|
||||||
for _, item := range res.Items {
|
for _, i := range l {
|
||||||
output += item.Name + " "
|
names = append(names, i.Name)
|
||||||
}
|
}
|
||||||
return output, nil
|
return strings.Join(names, " "), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteInstance deletes an instance specified by project, zone, and name
|
// DeleteInstance deletes an instance specified by project, zone, and name
|
||||||
func (gce *GCECloud) DeleteInstance(project, zone, name string) (*compute.Operation, error) {
|
func (gce *GCECloud) DeleteInstance(project, zone, name string) error {
|
||||||
return gce.service.Instances.Delete(project, zone, name).Do()
|
return gce.c.Instances().Delete(context.Background(), meta.ZonalKey(name, zone))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of Instances.CurrentNodeName
|
// Implementation of Instances.CurrentNodeName
|
||||||
@ -365,15 +352,14 @@ func (gce *GCECloud) AliasRanges(nodeName types.NodeName) (cidrs []string, err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
var res *computebeta.Instance
|
var res *computebeta.Instance
|
||||||
res, err = gce.serviceBeta.Instances.Get(
|
res, err = gce.c.BetaInstances().Get(context.Background(), meta.ZonalKey(instance.Name, lastComponent(instance.Zone)))
|
||||||
gce.projectID, instance.Zone, instance.Name).Do()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, networkInterface := range res.NetworkInterfaces {
|
for _, networkInterface := range res.NetworkInterfaces {
|
||||||
for _, aliasIpRange := range networkInterface.AliasIpRanges {
|
for _, r := range networkInterface.AliasIpRanges {
|
||||||
cidrs = append(cidrs, aliasIpRange.IpCidrRange)
|
cidrs = append(cidrs, r.IpCidrRange)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -387,14 +373,14 @@ func (gce *GCECloud) AddAliasToInstance(nodeName types.NodeName, alias *net.IPNe
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
instance, err := gce.serviceAlpha.Instances.Get(gce.projectID, v1instance.Zone, v1instance.Name).Do()
|
instance, err := gce.c.AlphaInstances().Get(context.Background(), meta.ZonalKey(v1instance.Name, lastComponent(v1instance.Zone)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch len(instance.NetworkInterfaces) {
|
switch len(instance.NetworkInterfaces) {
|
||||||
case 0:
|
case 0:
|
||||||
return fmt.Errorf("Instance %q has no network interfaces", nodeName)
|
return fmt.Errorf("instance %q has no network interfaces", nodeName)
|
||||||
case 1:
|
case 1:
|
||||||
default:
|
default:
|
||||||
glog.Warningf("Instance %q has more than one network interface, using only the first (%v)",
|
glog.Warningf("Instance %q has more than one network interface, using only the first (%v)",
|
||||||
@ -407,90 +393,74 @@ func (gce *GCECloud) AddAliasToInstance(nodeName types.NodeName, alias *net.IPNe
|
|||||||
SubnetworkRangeName: gce.secondaryRangeName,
|
SubnetworkRangeName: gce.secondaryRangeName,
|
||||||
})
|
})
|
||||||
|
|
||||||
mc := newInstancesMetricContext("addalias", v1instance.Zone)
|
mc := newInstancesMetricContext("add_alias", v1instance.Zone)
|
||||||
op, err := gce.serviceAlpha.Instances.UpdateNetworkInterface(
|
err = gce.c.AlphaInstances().UpdateNetworkInterface(context.Background(), meta.ZonalKey(instance.Name, lastComponent(instance.Zone)), iface.Name, iface)
|
||||||
gce.projectID, lastComponent(instance.Zone), instance.Name, iface.Name, iface).Do()
|
|
||||||
if err != nil {
|
|
||||||
return mc.Observe(err)
|
return mc.Observe(err)
|
||||||
}
|
}
|
||||||
return gce.waitForZoneOp(op, v1instance.Zone, mc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the named instances, returning cloudprovider.InstanceNotFound if any instance is not found
|
// Gets the named instances, returning cloudprovider.InstanceNotFound if any
|
||||||
|
// instance is not found
|
||||||
func (gce *GCECloud) getInstancesByNames(names []string) ([]*gceInstance, error) {
|
func (gce *GCECloud) getInstancesByNames(names []string) ([]*gceInstance, error) {
|
||||||
instances := make(map[string]*gceInstance)
|
found := map[string]*gceInstance{}
|
||||||
remaining := len(names)
|
remaining := len(names)
|
||||||
|
|
||||||
nodeInstancePrefix := gce.nodeInstancePrefix
|
nodeInstancePrefix := gce.nodeInstancePrefix
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
name = canonicalizeInstanceName(name)
|
name = canonicalizeInstanceName(name)
|
||||||
if !strings.HasPrefix(name, gce.nodeInstancePrefix) {
|
if !strings.HasPrefix(name, gce.nodeInstancePrefix) {
|
||||||
glog.Warningf("instance '%s' does not conform to prefix '%s', removing filter", name, gce.nodeInstancePrefix)
|
glog.Warningf("Instance %q does not conform to prefix %q, removing filter", name, gce.nodeInstancePrefix)
|
||||||
nodeInstancePrefix = ""
|
nodeInstancePrefix = ""
|
||||||
}
|
}
|
||||||
instances[name] = nil
|
found[name] = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, zone := range gce.managedZones {
|
for _, zone := range gce.managedZones {
|
||||||
if remaining == 0 {
|
if remaining == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
instances, err := gce.c.Instances().List(context.Background(), zone, filter.Regexp("name", nodeInstancePrefix+".*"))
|
||||||
pageToken := ""
|
|
||||||
page := 0
|
|
||||||
for ; page == 0 || (pageToken != "" && page < maxPages); page++ {
|
|
||||||
listCall := gce.service.Instances.List(gce.projectID, zone)
|
|
||||||
|
|
||||||
if nodeInstancePrefix != "" {
|
|
||||||
// Add the filter for hosts
|
|
||||||
listCall = listCall.Filter("name eq " + nodeInstancePrefix + ".*")
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(zmerlynn): Internal bug 29524655
|
|
||||||
// listCall = listCall.Fields("items(name,id,disks,machineType)")
|
|
||||||
if pageToken != "" {
|
|
||||||
listCall.PageToken(pageToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := listCall.Do()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pageToken = res.NextPageToken
|
for _, inst := range instances {
|
||||||
for _, i := range res.Items {
|
if remaining == 0 {
|
||||||
name := i.Name
|
break
|
||||||
if _, ok := instances[name]; !ok {
|
}
|
||||||
|
if _, ok := found[inst.Name]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if found[inst.Name] != nil {
|
||||||
instance := &gceInstance{
|
glog.Errorf("Instance name %q was duplicated (in zone %q and %q)", inst.Name, zone, found[inst.Name].Zone)
|
||||||
Zone: zone,
|
continue
|
||||||
Name: name,
|
}
|
||||||
ID: i.Id,
|
found[inst.Name] = &gceInstance{
|
||||||
Disks: i.Disks,
|
Zone: zone,
|
||||||
Type: lastComponent(i.MachineType),
|
Name: inst.Name,
|
||||||
|
ID: inst.Id,
|
||||||
|
Disks: inst.Disks,
|
||||||
|
Type: lastComponent(inst.MachineType),
|
||||||
}
|
}
|
||||||
instances[name] = instance
|
|
||||||
remaining--
|
remaining--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if page >= maxPages {
|
|
||||||
glog.Errorf("getInstancesByNames exceeded maxPages=%d for Instances.List: truncating.", maxPages)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceArray := make([]*gceInstance, len(names))
|
if remaining > 0 {
|
||||||
for i, name := range names {
|
var failed []string
|
||||||
name = canonicalizeInstanceName(name)
|
for k := range found {
|
||||||
instance := instances[name]
|
if found[k] == nil {
|
||||||
if instance == nil {
|
failed = append(failed, k)
|
||||||
glog.Errorf("Failed to retrieve instance: %q", name)
|
}
|
||||||
|
}
|
||||||
|
glog.Errorf("Failed to retrieve instances: %v", failed)
|
||||||
return nil, cloudprovider.InstanceNotFound
|
return nil, cloudprovider.InstanceNotFound
|
||||||
}
|
}
|
||||||
instanceArray[i] = instances[name]
|
|
||||||
|
var ret []*gceInstance
|
||||||
|
for _, instance := range found {
|
||||||
|
ret = append(ret, instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
return instanceArray, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the named instance, returning cloudprovider.InstanceNotFound if the instance is not found
|
// Gets the named instance, returning cloudprovider.InstanceNotFound if the instance is not found
|
||||||
@ -514,12 +484,11 @@ func (gce *GCECloud) getInstanceByName(name string) (*gceInstance, error) {
|
|||||||
func (gce *GCECloud) getInstanceFromProjectInZoneByName(project, zone, name string) (*gceInstance, error) {
|
func (gce *GCECloud) getInstanceFromProjectInZoneByName(project, zone, name string) (*gceInstance, error) {
|
||||||
name = canonicalizeInstanceName(name)
|
name = canonicalizeInstanceName(name)
|
||||||
mc := newInstancesMetricContext("get", zone)
|
mc := newInstancesMetricContext("get", zone)
|
||||||
res, err := gce.service.Instances.Get(project, zone, name).Do()
|
res, err := gce.c.Instances().Get(context.Background(), meta.ZonalKey(name, zone))
|
||||||
mc.Observe(err)
|
mc.Observe(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &gceInstance{
|
return &gceInstance{
|
||||||
Zone: lastComponent(res.Zone),
|
Zone: lastComponent(res.Zone),
|
||||||
Name: res.Name,
|
Name: res.Name,
|
||||||
@ -578,9 +547,9 @@ func (gce *GCECloud) isCurrentInstance(instanceID string) bool {
|
|||||||
// ComputeHostTags grabs all tags from all instances being added to the pool.
|
// ComputeHostTags grabs all tags from all instances being added to the pool.
|
||||||
// * The longest tag that is a prefix of the instance name is used
|
// * The longest tag that is a prefix of the instance name is used
|
||||||
// * If any instance has no matching prefix tag, return error
|
// * If any instance has no matching prefix tag, return error
|
||||||
// Invoking this method to get host tags is risky since it depends on the format
|
// Invoking this method to get host tags is risky since it depends on the
|
||||||
// of the host names in the cluster. Only use it as a fallback if gce.nodeTags
|
// format of the host names in the cluster. Only use it as a fallback if
|
||||||
// is unspecified
|
// gce.nodeTags is unspecified
|
||||||
func (gce *GCECloud) computeHostTags(hosts []*gceInstance) ([]string, error) {
|
func (gce *GCECloud) computeHostTags(hosts []*gceInstance) ([]string, error) {
|
||||||
// TODO: We could store the tags in gceInstance, so we could have already fetched it
|
// TODO: We could store the tags in gceInstance, so we could have already fetched it
|
||||||
hostNamesByZone := make(map[string]map[string]bool) // map of zones -> map of names -> bool (for easy lookup)
|
hostNamesByZone := make(map[string]map[string]bool) // map of zones -> map of names -> bool (for easy lookup)
|
||||||
@ -601,35 +570,19 @@ func (gce *GCECloud) computeHostTags(hosts []*gceInstance) ([]string, error) {
|
|||||||
|
|
||||||
tags := sets.NewString()
|
tags := sets.NewString()
|
||||||
|
|
||||||
for zone, hostNames := range hostNamesByZone {
|
filt := filter.None
|
||||||
pageToken := ""
|
|
||||||
page := 0
|
|
||||||
for ; page == 0 || (pageToken != "" && page < maxPages); page++ {
|
|
||||||
listCall := gce.service.Instances.List(gce.projectID, zone)
|
|
||||||
|
|
||||||
if nodeInstancePrefix != "" {
|
if nodeInstancePrefix != "" {
|
||||||
// Add the filter for hosts
|
filt = filter.Regexp("name", nodeInstancePrefix+".*")
|
||||||
listCall = listCall.Filter("name eq " + nodeInstancePrefix + ".*")
|
|
||||||
}
|
}
|
||||||
|
for zone, hostNames := range hostNamesByZone {
|
||||||
// Add the fields we want
|
instances, err := gce.c.Instances().List(context.Background(), zone, filt)
|
||||||
// TODO(zmerlynn): Internal bug 29524655
|
|
||||||
// listCall = listCall.Fields("items(name,tags)")
|
|
||||||
|
|
||||||
if pageToken != "" {
|
|
||||||
listCall = listCall.PageToken(pageToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := listCall.Do()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pageToken = res.NextPageToken
|
for _, instance := range instances {
|
||||||
for _, instance := range res.Items {
|
|
||||||
if !hostNames[instance.Name] {
|
if !hostNames[instance.Name] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
longest_tag := ""
|
longest_tag := ""
|
||||||
for _, tag := range instance.Tags.Items {
|
for _, tag := range instance.Tags.Items {
|
||||||
if strings.HasPrefix(instance.Name, tag) && len(tag) > len(longest_tag) {
|
if strings.HasPrefix(instance.Name, tag) && len(tag) > len(longest_tag) {
|
||||||
@ -639,16 +592,12 @@ func (gce *GCECloud) computeHostTags(hosts []*gceInstance) ([]string, error) {
|
|||||||
if len(longest_tag) > 0 {
|
if len(longest_tag) > 0 {
|
||||||
tags.Insert(longest_tag)
|
tags.Insert(longest_tag)
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("Could not find any tag that is a prefix of instance name for instance %s", instance.Name)
|
return nil, fmt.Errorf("could not find any tag that is a prefix of instance name for instance %s", instance.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if page >= maxPages {
|
|
||||||
glog.Errorf("computeHostTags exceeded maxPages=%d for Instances.List: truncating.", maxPages)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(tags) == 0 {
|
if len(tags) == 0 {
|
||||||
return nil, fmt.Errorf("No instances found")
|
return nil, fmt.Errorf("no instances found")
|
||||||
}
|
}
|
||||||
return tags.List(), nil
|
return tags.List(), nil
|
||||||
}
|
}
|
||||||
|
@ -121,9 +121,8 @@ func OnlyAllowNodeZones(f *framework.Framework, zoneCount int, image string) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
// Teardown of the compute instance
|
// Teardown of the compute instance
|
||||||
framework.Logf("Deleting compute resource: %v", name)
|
framework.Logf("Deleting compute resource: %v", name)
|
||||||
resp, err := gceCloud.DeleteInstance(project, zone, name)
|
err := gceCloud.DeleteInstance(project, zone, name)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
framework.Logf("Compute deletion response: %v\n", resp)
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
By("Creating zoneCount+1 PVCs and making sure PDs are only provisioned in zones with nodes")
|
By("Creating zoneCount+1 PVCs and making sure PDs are only provisioned in zones with nodes")
|
||||||
|
@ -390,8 +390,8 @@ var _ = utils.SIGDescribe("Pod Disks", func() {
|
|||||||
Expect(true, strings.Contains(string(output), string(host0Name)))
|
Expect(true, strings.Contains(string(output), string(host0Name)))
|
||||||
|
|
||||||
By("deleting host0")
|
By("deleting host0")
|
||||||
resp, err := gceCloud.DeleteInstance(framework.TestContext.CloudConfig.ProjectID, framework.TestContext.CloudConfig.Zone, string(host0Name))
|
err = gceCloud.DeleteInstance(framework.TestContext.CloudConfig.ProjectID, framework.TestContext.CloudConfig.Zone, string(host0Name))
|
||||||
framework.ExpectNoError(err, fmt.Sprintf("Failed to delete host0Pod: err=%v response=%#v", err, resp))
|
framework.ExpectNoError(err, fmt.Sprintf("Failed to delete host0Pod: err=%v", err))
|
||||||
By("expecting host0 node to be re-created")
|
By("expecting host0 node to be re-created")
|
||||||
numNodes := countReadyNodes(cs, host0Name)
|
numNodes := countReadyNodes(cs, host0Name)
|
||||||
Expect(numNodes).To(Equal(origNodeCnt), fmt.Sprintf("Requires current node count (%d) to return to original node count (%d)", numNodes, origNodeCnt))
|
Expect(numNodes).To(Equal(origNodeCnt), fmt.Sprintf("Requires current node count (%d) to return to original node count (%d)", numNodes, origNodeCnt))
|
||||||
|
Loading…
Reference in New Issue
Block a user