Skip to content

Commit 20c0d00

Browse files
committed
OCPBUGS-28590: gcp: better error msg when service accnt missing
The JSON object is not set when the credentials are loaded from the cli, resulting in an unhelpful message about "unexpected end of JSON input". Let's provide a better error message in that case.
1 parent ff2a09f commit 20c0d00

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/asset/machines/gcp/machines.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ func provider(clusterID string, platform *gcp.Platform, mpool *gcp.MachinePool,
168168
return nil, err
169169
}
170170

171+
// The JSON can be `nil` if auth is provided from env
172+
// https://pkg.go.dev/golang.org/x/[email protected]/google#Credentials
173+
if len(sess.Credentials.JSON) == 0 {
174+
return nil, fmt.Errorf("could not extract service account from loaded credentials. Please specify a service account to be used for shared vpc installations in the install-config.yaml")
175+
}
176+
171177
var found bool
172178
serviceAccount := make(map[string]interface{})
173179
err = json.Unmarshal(sess.Credentials.JSON, &serviceAccount)

0 commit comments

Comments
 (0)