mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Refactory a little bit.
This commit is contained in:
parent
4796120f70
commit
bdfd5045f3
@ -19,7 +19,7 @@
|
|||||||
set -o errexit
|
set -o errexit
|
||||||
set -o nounset
|
set -o nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
set -e
|
set -x
|
||||||
|
|
||||||
source "${KUBE_REPO_ROOT}/cluster/kube-env.sh"
|
source "${KUBE_REPO_ROOT}/cluster/kube-env.sh"
|
||||||
source "${KUBE_REPO_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
|
source "${KUBE_REPO_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
|
||||||
|
@ -106,10 +106,7 @@ func (gce *GCECloud) Zones() (cloudprovider.Zones, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func makeHostLink(projectID, zone, host string) string {
|
func makeHostLink(projectID, zone, host string) string {
|
||||||
ix := strings.Index(host, ".")
|
host = canonicalizeInstanceName(host)
|
||||||
if ix != -1 {
|
|
||||||
host = host[:ix]
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instances/%s",
|
return fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instances/%s",
|
||||||
projectID, zone, host)
|
projectID, zone, host)
|
||||||
}
|
}
|
||||||
@ -190,16 +187,21 @@ func (gce *GCECloud) DeleteTCPLoadBalancer(name, region string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Take a GCE instance 'hostname' and break it down to something that can be fed
|
||||||
|
// to the GCE API client library. Basically this means reducing 'kubernetes-
|
||||||
|
// minion-2.c.my-proj.internal' to 'kubernetes-minion-2' if necessary.
|
||||||
|
func canonicalizeInstanceName(name string) string {
|
||||||
|
ix := strings.Index(name, ".")
|
||||||
|
if ix != -1 {
|
||||||
|
name = name[:ix]
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
// IPAddress is an implementation of Instances.IPAddress.
|
// IPAddress is an implementation of Instances.IPAddress.
|
||||||
func (gce *GCECloud) IPAddress(instance string) (net.IP, error) {
|
func (gce *GCECloud) IPAddress(instance string) (net.IP, error) {
|
||||||
suffix, err := fqdnSuffix()
|
instance = canonicalizeInstanceName(instance)
|
||||||
if err != nil {
|
res, err := gce.service.Instances.Get(gce.projectID, gce.zone, instance).Do()
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(suffix) > 0 {
|
|
||||||
suffix = "." + suffix
|
|
||||||
}
|
|
||||||
res, err := gce.service.Instances.Get(gce.projectID, gce.zone, strings.Replace(instance, suffix, "", 1)).Do()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to retrieve TargetInstance resource for instance:%s", instance)
|
glog.Errorf("Failed to retrieve TargetInstance resource for instance:%s", instance)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user