mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
implement functionality to return all found instances
This commit is contained in:
parent
2b4efdea7d
commit
d44abb4ebe
@ -426,28 +426,19 @@ func (g *Cloud) AddAliasToInstance(nodeName types.NodeName, alias *net.IPNet) er
|
|||||||
// Gets the named instances, returning cloudprovider.InstanceNotFound if any
|
// Gets the named instances, returning cloudprovider.InstanceNotFound if any
|
||||||
// instance is not found
|
// instance is not found
|
||||||
func (g *Cloud) getInstancesByNames(names []string) ([]*gceInstance, error) {
|
func (g *Cloud) getInstancesByNames(names []string) ([]*gceInstance, error) {
|
||||||
instanceOrErrors, err := g.getInstanceOrErrorsByNames(names)
|
foundInstances, err := g.getFoundInstanceByNames(names)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var allInstances []*gceInstance
|
if len(foundInstances) != len(names) {
|
||||||
for _, entry := range instanceOrErrors {
|
return nil, cloudprovider.InstanceNotFound
|
||||||
if entry.err != nil {
|
|
||||||
return nil, entry.err
|
|
||||||
}
|
|
||||||
allInstances = append(allInstances, entry.instance)
|
|
||||||
}
|
}
|
||||||
return allInstances, nil
|
return foundInstances, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type instanceOrError struct {
|
// Gets the named instances, returning a list of gceInstances it was able to find from the provided
|
||||||
instance *gceInstance
|
// list of names.
|
||||||
err error
|
func (g *Cloud) getFoundInstanceByNames(names []string) ([]*gceInstance, error) {
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the named instances, returning a map of each name to either the found instances or
|
|
||||||
// cloudprovider.InstanceNotFound if the instance is not found
|
|
||||||
func (g *Cloud) getInstanceOrErrorsByNames(allNames []string) (map[string]*instanceOrError, error) {
|
|
||||||
ctx, cancel := cloud.ContextWithCallTimeout()
|
ctx, cancel := cloud.ContextWithCallTimeout()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
@ -494,20 +485,17 @@ func (g *Cloud) getInstanceOrErrorsByNames(allNames []string) (map[string]*insta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if remaining > 0 {
|
|
||||||
var failed []string
|
|
||||||
for k := range found {
|
|
||||||
if found[k] == nil {
|
|
||||||
failed = append(failed, k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
klog.Errorf("Failed to retrieve instances: %v", failed)
|
|
||||||
return nil, cloudprovider.InstanceNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
var ret []*gceInstance
|
var ret []*gceInstance
|
||||||
for _, instance := range found {
|
var failed []string
|
||||||
ret = append(ret, instance)
|
for name, instance := range found {
|
||||||
|
if instance != nil {
|
||||||
|
ret = append(ret, instance)
|
||||||
|
} else {
|
||||||
|
failed = append(failed, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(failed) > 0 {
|
||||||
|
klog.Errorf("Failed to retrieve instances: %v", failed)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user