Skip to content

Commit

Permalink
Use better variable names and remove unwanted code blocks. (kubernete…
Browse files Browse the repository at this point in the history
…s#72847)

* Use better variable names and remove unwanted code blocks.

Signed-off-by: hchiramm <[email protected]>

* Simplify return from InstanceID func()

Signed-off-by: Humble Chirammal <[email protected]>
  • Loading branch information
humblec authored and k8s-ci-robot committed Jan 14, 2019
1 parent 4eddb77 commit 6b8c2e0
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions pkg/cloudprovider/providers/photon/photon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6b8c2e0

Please sign in to comment.