Skip to content

Commit 1726be9

Browse files
committed
Update flag to use pointers
1 parent 91fbd91 commit 1726be9

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ var (
7070
formatAndMountTimeout = flag.Duration("format-and-mount-timeout", 1*time.Minute, "The maximum duration of a format and mount operation before another such operation will be started. Used only if --serialize-format-and-mount")
7171
fallbackRequisiteZonesFlag = flag.String("fallback-requisite-zones", "", "Comma separated list of requisite zones that will be used if there are not sufficient zones present in requisite topologies when provisioning a disk")
7272

73-
computeEnvironment gce.Environment = "production"
74-
computeEndpoint url.URL
73+
computeEnvironment gce.Environment = gce.EnvironmentProduction
74+
computeEndpoint *url.URL
7575
version string
7676
allowedComputeEnvironment = []gce.Environment{gce.EnvironmentStaging, gce.EnvironmentProduction}
7777
)
@@ -87,7 +87,7 @@ func init() {
8787
// Use V(5) for GCE Cloud Provider Call informational logging
8888
// Use V(6) for extra repeated/polling information
8989
enumFlag(&computeEnvironment, "compute-environment", allowedComputeEnvironment, "Operating compute environment")
90-
urlFlag(&computeEndpoint, "compute-endpoint", "Compute endpoint")
90+
urlFlag(computeEndpoint, "compute-endpoint", "Compute endpoint")
9191
klog.InitFlags(flag.CommandLine)
9292
flag.Set("logtostderr", "true")
9393
}
@@ -211,7 +211,7 @@ func urlFlag(target *url.URL, name string, usage string) {
211211
flag.Func(name, usage, func(flagValue string) error {
212212
computeURL, err := url.ParseRequestURI(flagValue)
213213
if err == nil {
214-
*target = *computeURL
214+
target = computeURL
215215
return nil
216216
}
217217
return err

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

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

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

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

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

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

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

223-
if computeEndpoint.String() != "" {
223+
if computeEndpoint != nil {
224224
computeEnvironmentSuffix := constructComputeEndpointPath(computeEnvironment, computeVersion)
225225
computeEndpoint.Path = computeEnvironmentSuffix
226226
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)