Use better variable names and remove unwanted code blocks. (#72847)

* Use better variable names and remove unwanted code blocks.

Signed-off-by: hchiramm <hchiramm@redhat.com>

* Simplify return from InstanceID func()

Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
Humble Devassy Chirammal 2019-01-15 02:35:03 +05:30 committed by Kubernetes Prow Robot
parent 4eddb777ed
commit 6b8c2e07fa

View File

@ -53,13 +53,13 @@ const (
// overrideIP indicates if the hostname is overridden by IP address, such as when
// running multi-node kubernetes using docker. In this case the user should set
// overrideIP = true in cloud config file. Default value is false.
var overrideIP bool = false
var overrideIP = false
var _ cloudprovider.Interface = (*PCCloud)(nil)
var _ cloudprovider.Instances = (*PCCloud)(nil)
var _ cloudprovider.Zones = (*PCCloud)(nil)
// Photon is an implementation of the cloud provider interface for Photon Controller.
// PCCloud is an implementation of the cloud provider interface for Photon Controller.
type PCCloud struct {
cfg *PCConfig
// InstanceID of the server where this PCCloud object is instantiated.
@ -213,7 +213,7 @@ func getVMIDbyIP(pc *PCCloud, IPAddress string) (string, error) {
func getPhotonClient(pc *PCCloud) (*photon.Client, error) {
var err error
if len(pc.cfg.Global.CloudTarget) == 0 {
return nil, fmt.Errorf("Photon Controller endpoint was not specified.")
return nil, fmt.Errorf("Photon Controller endpoint was not specified")
}
options := &photon.ClientOptions{
@ -241,7 +241,7 @@ func getPhotonClient(pc *PCCloud) (*photon.Client, error) {
}
password := scanner.Text()
token_options, err := pc.photonClient.Auth.GetTokensByPassword(username, password)
tokenOptions, err := pc.photonClient.Auth.GetTokensByPassword(username, password)
if err != nil {
klog.Error("Photon Cloud Provider: failed to get tokens by password")
return nil, err
@ -250,7 +250,7 @@ func getPhotonClient(pc *PCCloud) (*photon.Client, error) {
options = &photon.ClientOptions{
IgnoreCertificate: true,
TokenOptions: &photon.TokenOptions{
AccessToken: token_options.AccessToken,
AccessToken: tokenOptions.AccessToken,
},
}
pc.photonClient = photon.NewClient(pc.cfg.Global.CloudTarget, options, pc.logger)
@ -474,16 +474,14 @@ func (pc *PCCloud) InstanceID(ctx context.Context, nodeName k8stypes.NodeName) (
name := string(nodeName)
if name == pc.localK8sHostname {
return pc.localInstanceID, nil
} else {
// We assume only master need to get InstanceID of a node other than itself
ID, err := getInstanceID(pc, name)
if err != nil {
klog.Errorf("Photon Cloud Provider: getInstanceID failed for InstanceID. Error[%v]", err)
return ID, err
} else {
return ID, nil
}
}
// We assume only master need to get InstanceID of a node other than itself
id, err := getInstanceID(pc, name)
if err != nil {
klog.Errorf("Photon Cloud Provider: getInstanceID failed for InstanceID. Error[%v]", err)
}
return id, err
}
// InstanceTypeByProviderID returns the cloudprovider instance type of the node with the specified unique providerID
@ -544,7 +542,7 @@ func (pc *PCCloud) HasClusterID() bool {
return true
}
// Attaches given virtual disk volume to the compute running kubelet.
// AttachDisk attaches given virtual disk volume to the compute running kubelet.
func (pc *PCCloud) AttachDisk(ctx context.Context, pdID string, nodeName k8stypes.NodeName) error {
photonClient, err := getPhotonClient(pc)
if err != nil {
@ -712,7 +710,7 @@ func (pc *PCCloud) CreateDisk(volumeOptions *VolumeOptions) (pdID string, err er
return waitTask.Entity.ID, nil
}
// Deletes a volume given volume name.
// DeleteDisk deletes a volume given volume name.
func (pc *PCCloud) DeleteDisk(pdID string) error {
photonClient, err := getPhotonClient(pc)
if err != nil {