Skip to content

Commit 840a2db

Browse files
committed
Update flag to use pointers
1 parent 4eab6b6 commit 840a2db

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

cmd/gce-pd-csi-driver/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var (
7373

7474
enableStoragePoolsFlag = flag.Bool("enable-storage-pools", false, "If set to true, the CSI Driver will allow volumes to be provisioned in Storage Pools")
7575
computeEnvironment gce.Environment = gce.EnvironmentProduction
76-
computeEndpoint url.URL
76+
computeEndpoint *url.URL
7777
version string
7878
allowedComputeEnvironment = []gce.Environment{gce.EnvironmentStaging, gce.EnvironmentProduction}
7979
)
@@ -89,7 +89,7 @@ func init() {
8989
// Use V(5) for GCE Cloud Provider Call informational logging
9090
// Use V(6) for extra repeated/polling information
9191
enumFlag(&computeEnvironment, "compute-environment", allowedComputeEnvironment, "Operating compute environment")
92-
urlFlag(&computeEndpoint, "compute-endpoint", "Compute endpoint")
92+
urlFlag(computeEndpoint, "compute-endpoint", "Compute endpoint")
9393
klog.InitFlags(flag.CommandLine)
9494
flag.Set("logtostderr", "true")
9595
}
@@ -229,7 +229,7 @@ func urlFlag(target *url.URL, name string, usage string) {
229229
flag.Func(name, usage, func(flagValue string) error {
230230
computeURL, err := url.ParseRequestURI(flagValue)
231231
if err == nil {
232-
*target = *computeURL
232+
target = computeURL
233233
return nil
234234
}
235235
return err

pkg/gce-cloud-provider/compute/gce.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ type ConfigGlobal struct {
8181
Zone string `gcfg:"zone"`
8282
}
8383

84-
func CreateCloudProvider(ctx context.Context, vendorVersion string, configPath string, computeEndpoint url.URL, computeEnvironment Environment) (*CloudProvider, error) {
84+
func CreateCloudProvider(ctx context.Context, vendorVersion string, configPath string, computeEndpoint *url.URL, computeEnvironment Environment) (*CloudProvider, error) {
8585
configFile, err := readConfig(configPath)
8686
if err != nil {
8787
return nil, err
@@ -176,7 +176,7 @@ func readConfig(configPath string) (*ConfigFile, error) {
176176
return cfg, nil
177177
}
178178

179-
func createAlphaCloudService(ctx context.Context, vendorVersion string, tokenSource oauth2.TokenSource, computeEndpoint url.URL, computeEnvironment Environment) (*computealpha.Service, error) {
179+
func createAlphaCloudService(ctx context.Context, vendorVersion string, tokenSource oauth2.TokenSource, computeEndpoint *url.URL, computeEnvironment Environment) (*computealpha.Service, error) {
180180
computeOpts, err := getComputeVersion(ctx, tokenSource, computeEndpoint, computeEnvironment, versionAlpha)
181181
if err != nil {
182182
klog.Errorf("Failed to get compute endpoint: %s", err)
@@ -189,7 +189,7 @@ func createAlphaCloudService(ctx context.Context, vendorVersion string, tokenSou
189189
return service, nil
190190
}
191191

192-
func createBetaCloudService(ctx context.Context, vendorVersion string, tokenSource oauth2.TokenSource, computeEndpoint url.URL, computeEnvironment Environment) (*computebeta.Service, error) {
192+
func createBetaCloudService(ctx context.Context, vendorVersion string, tokenSource oauth2.TokenSource, computeEndpoint *url.URL, computeEnvironment Environment) (*computebeta.Service, error) {
193193
computeOpts, err := getComputeVersion(ctx, tokenSource, computeEndpoint, computeEnvironment, versionBeta)
194194
if err != nil {
195195
klog.Errorf("Failed to get compute endpoint: %s", err)
@@ -202,7 +202,7 @@ func createBetaCloudService(ctx context.Context, vendorVersion string, tokenSour
202202
return service, nil
203203
}
204204

205-
func createCloudService(ctx context.Context, vendorVersion string, tokenSource oauth2.TokenSource, computeEndpoint url.URL, computeEnvironment Environment) (*compute.Service, error) {
205+
func createCloudService(ctx context.Context, vendorVersion string, tokenSource oauth2.TokenSource, computeEndpoint *url.URL, computeEnvironment Environment) (*compute.Service, error) {
206206
computeOpts, err := getComputeVersion(ctx, tokenSource, computeEndpoint, computeEnvironment, versionV1)
207207
if err != nil {
208208
klog.Errorf("Failed to get compute endpoint: %s", err)
@@ -215,14 +215,14 @@ func createCloudService(ctx context.Context, vendorVersion string, tokenSource o
215215
return service, nil
216216
}
217217

218-
func getComputeVersion(ctx context.Context, tokenSource oauth2.TokenSource, computeEndpoint url.URL, computeEnvironment Environment, computeVersion Version) ([]option.ClientOption, error) {
218+
func getComputeVersion(ctx context.Context, tokenSource oauth2.TokenSource, computeEndpoint *url.URL, computeEnvironment Environment, computeVersion Version) ([]option.ClientOption, error) {
219219
client, err := newOauthClient(ctx, tokenSource)
220220
if err != nil {
221221
return nil, err
222222
}
223223
computeOpts := []option.ClientOption{option.WithHTTPClient(client)}
224224

225-
if computeEndpoint.String() != "" {
225+
if computeEndpoint != nil {
226226
computeEnvironmentSuffix := constructComputeEndpointPath(computeEnvironment, computeVersion)
227227
computeEndpoint.Path = computeEnvironmentSuffix
228228
endpoint := computeEndpoint.String()

pkg/gce-cloud-provider/compute/gce_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestIsGCEError(t *testing.T) {
104104
func TestGetComputeVersion(t *testing.T) {
105105
testCases := []struct {
106106
name string
107-
computeEndpoint url.URL
107+
computeEndpoint *url.URL
108108
computeEnvironment Environment
109109
computeVersion Version
110110
expectedEndpoint string
@@ -129,7 +129,7 @@ func TestGetComputeVersion(t *testing.T) {
129129
},
130130
{
131131
name: "check for random string as endpoint",
132-
computeEndpoint: url.URL{},
132+
computeEndpoint: convertStringToURL(""),
133133
computeEnvironment: "prod",
134134
computeVersion: "v1",
135135
expectedEndpoint: "compute/v1/",
@@ -151,10 +151,10 @@ func TestGetComputeVersion(t *testing.T) {
151151

152152
}
153153

154-
func convertStringToURL(urlString string) url.URL {
154+
func convertStringToURL(urlString string) *url.URL {
155155
parsedURL, err := url.ParseRequestURI(urlString)
156156
if err != nil {
157-
return url.URL{}
157+
return nil
158158
}
159-
return *parsedURL
159+
return parsedURL
160160
}

0 commit comments

Comments
 (0)