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 // 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 // running multi-node kubernetes using docker. In this case the user should set
// overrideIP = true in cloud config file. Default value is false. // overrideIP = true in cloud config file. Default value is false.
var overrideIP bool = false var overrideIP = false
var _ cloudprovider.Interface = (*PCCloud)(nil) var _ cloudprovider.Interface = (*PCCloud)(nil)
var _ cloudprovider.Instances = (*PCCloud)(nil) var _ cloudprovider.Instances = (*PCCloud)(nil)
var _ cloudprovider.Zones = (*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 { type PCCloud struct {
cfg *PCConfig cfg *PCConfig
// InstanceID of the server where this PCCloud object is instantiated. // 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) { func getPhotonClient(pc *PCCloud) (*photon.Client, error) {
var err error var err error
if len(pc.cfg.Global.CloudTarget) == 0 { 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{ options := &photon.ClientOptions{
@ -241,7 +241,7 @@ func getPhotonClient(pc *PCCloud) (*photon.Client, error) {
} }
password := scanner.Text() password := scanner.Text()
token_options, err := pc.photonClient.Auth.GetTokensByPassword(username, password) tokenOptions, err := pc.photonClient.Auth.GetTokensByPassword(username, password)
if err != nil { if err != nil {
klog.Error("Photon Cloud Provider: failed to get tokens by password") klog.Error("Photon Cloud Provider: failed to get tokens by password")
return nil, err return nil, err
@ -250,7 +250,7 @@ func getPhotonClient(pc *PCCloud) (*photon.Client, error) {
options = &photon.ClientOptions{ options = &photon.ClientOptions{
IgnoreCertificate: true, IgnoreCertificate: true,
TokenOptions: &photon.TokenOptions{ TokenOptions: &photon.TokenOptions{
AccessToken: token_options.AccessToken, AccessToken: tokenOptions.AccessToken,
}, },
} }
pc.photonClient = photon.NewClient(pc.cfg.Global.CloudTarget, options, pc.logger) 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) name := string(nodeName)
if name == pc.localK8sHostname { if name == pc.localK8sHostname {
return pc.localInstanceID, nil return pc.localInstanceID, nil
} else { }
// We assume only master need to get InstanceID of a node other than itself // We assume only master need to get InstanceID of a node other than itself
ID, err := getInstanceID(pc, name) id, err := getInstanceID(pc, name)
if err != nil { if err != nil {
klog.Errorf("Photon Cloud Provider: getInstanceID failed for InstanceID. Error[%v]", err) klog.Errorf("Photon Cloud Provider: getInstanceID failed for InstanceID. Error[%v]", err)
return ID, err
} else {
return ID, nil
}
} }
return id, err
} }
// InstanceTypeByProviderID returns the cloudprovider instance type of the node with the specified unique providerID // 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 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 { func (pc *PCCloud) AttachDisk(ctx context.Context, pdID string, nodeName k8stypes.NodeName) error {
photonClient, err := getPhotonClient(pc) photonClient, err := getPhotonClient(pc)
if err != nil { if err != nil {
@ -712,7 +710,7 @@ func (pc *PCCloud) CreateDisk(volumeOptions *VolumeOptions) (pdID string, err er
return waitTask.Entity.ID, nil 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 { func (pc *PCCloud) DeleteDisk(pdID string) error {
photonClient, err := getPhotonClient(pc) photonClient, err := getPhotonClient(pc)
if err != nil { if err != nil {