Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit d219c48

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #59315 from dims/fix-golint-issues-in-openstack-cinder-packages
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix golint for openstack and cinder packages **What this PR does / why we need it**: Fix golint for openstack and cinder packages **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
2 parents 15a2dac + a7ad388 commit d219c48

15 files changed

Lines changed: 360 additions & 329 deletions

pkg/cloudprovider/providers/openstack/metadata.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ import (
3333
)
3434

3535
const (
36-
// metadataUrlTemplate allows building an OpenStack Metadata service URL.
36+
// metadataURLTemplate allows building an OpenStack Metadata service URL.
3737
// It's a hardcoded IPv4 link-local address as documented in "OpenStack Cloud
3838
// Administrator Guide", chapter Compute - Networking with nova-network.
3939
//https://docs.openstack.org/nova/latest/admin/networking-nova.html#metadata-service
4040
defaultMetadataVersion = "2012-08-10"
41-
metadataUrlTemplate = "http://169.254.169.254/openstack/%s/meta_data.json"
41+
metadataURLTemplate = "http://169.254.169.254/openstack/%s/meta_data.json"
4242

4343
// metadataID is used as an identifier on the metadata search order configuration.
4444
metadataID = "metadataService"
@@ -53,10 +53,10 @@ const (
5353
configDriveID = "configDrive"
5454
)
5555

56+
// ErrBadMetadata is used to indicate a problem parsing data from metadata server
5657
var ErrBadMetadata = errors.New("invalid OpenStack metadata, got empty uuid")
5758

58-
// There are multiple device types. To keep it simple, we're using a single structure
59-
// for all device metadata types.
59+
// DeviceMetadata is a single/simplified data structure for all kinds of device metadata types.
6060
type DeviceMetadata struct {
6161
Type string `json:"type"`
6262
Bus string `json:"bus,omitempty"`
@@ -65,10 +65,11 @@ type DeviceMetadata struct {
6565
// .. and other fields.
6666
}
6767

68-
// Assumes the "2012-08-10" meta_data.json format.
69-
//https://docs.openstack.org/nova/latest/user/config-drive.html
68+
// Metadata has the information fetched from OpenStack metadata service or
69+
// config drives. Assumes the "2012-08-10" meta_data.json format.
70+
// See http://docs.openstack.org/user-guide/cli_config_drive.html
7071
type Metadata struct {
71-
Uuid string `json:"uuid"`
72+
UUID string `json:"uuid"`
7273
Hostname string `json:"hostname"`
7374
AvailabilityZone string `json:"availability_zone"`
7475
Devices []DeviceMetadata `json:"devices,omitempty"`
@@ -84,15 +85,15 @@ func parseMetadata(r io.Reader) (*Metadata, error) {
8485
return nil, err
8586
}
8687

87-
if metadata.Uuid == "" {
88+
if metadata.UUID == "" {
8889
return nil, ErrBadMetadata
8990
}
9091

9192
return &metadata, nil
9293
}
9394

94-
func getMetadataUrl(metadataVersion string) string {
95-
return fmt.Sprintf(metadataUrlTemplate, metadataVersion)
95+
func getMetadataURL(metadataVersion string) string {
96+
return fmt.Sprintf(metadataURLTemplate, metadataVersion)
9697
}
9798

9899
func getConfigDrivePath(metadataVersion string) string {
@@ -147,16 +148,16 @@ func getMetadataFromConfigDrive(metadataVersion string) (*Metadata, error) {
147148

148149
func getMetadataFromMetadataService(metadataVersion string) (*Metadata, error) {
149150
// Try to get JSON from metadata server.
150-
metadataUrl := getMetadataUrl(metadataVersion)
151-
glog.V(4).Infof("Attempting to fetch metadata from %s", metadataUrl)
152-
resp, err := http.Get(metadataUrl)
151+
metadataURL := getMetadataURL(metadataVersion)
152+
glog.V(4).Infof("Attempting to fetch metadata from %s", metadataURL)
153+
resp, err := http.Get(metadataURL)
153154
if err != nil {
154-
return nil, fmt.Errorf("error fetching %s: %v", metadataUrl, err)
155+
return nil, fmt.Errorf("error fetching %s: %v", metadataURL, err)
155156
}
156157
defer resp.Body.Close()
157158

158159
if resp.StatusCode != http.StatusOK {
159-
err = fmt.Errorf("unexpected status code when reading metadata from %s: %s", metadataUrl, resp.Status)
160+
err = fmt.Errorf("unexpected status code when reading metadata from %s: %s", metadataURL, resp.Status)
160161
return nil, err
161162
}
162163

pkg/cloudprovider/providers/openstack/metadata_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
var FakeMetadata = Metadata{
25-
Uuid: "83679162-1378-4288-a2d4-70e13ec132aa",
25+
UUID: "83679162-1378-4288-a2d4-70e13ec132aa",
2626
Hostname: "test",
2727
AvailabilityZone: "nova",
2828
}
@@ -85,8 +85,8 @@ func TestParseMetadata(t *testing.T) {
8585
t.Errorf("incorrect hostname: %s", md.Hostname)
8686
}
8787

88-
if md.Uuid != "83679162-1378-4288-a2d4-70e13ec132aa" {
89-
t.Errorf("incorrect uuid: %s", md.Uuid)
88+
if md.UUID != "83679162-1378-4288-a2d4-70e13ec132aa" {
89+
t.Errorf("incorrect uuid: %s", md.UUID)
9090
}
9191

9292
if md.AvailabilityZone != "nova" {

0 commit comments

Comments
 (0)