-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add code for multiproject GCE Client creation #2725
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: panslava The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
0e8f463
to
3849802
Compare
3849802
to
49ef5d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @panslava! Great unit tests.
@@ -19,6 +19,22 @@ func (p *Project) ProjectName() string { | |||
return p.ObjectMeta.Labels[flags.F.MultiProjectCRDProjectNameLabel] | |||
} | |||
|
|||
func (p *Project) ProjectID() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need both ProjectName() and ProjectID()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this, not needed for now
pkg/multiproject/gce/gce.go
Outdated
} | ||
|
||
// convert file struct to bytes | ||
configBytes, err := json.Marshal(configFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that this roundrip of converting the config file back to a gce.conf may not work.
To elaborate, I think json.Marshal()
, when converting the structs to JSON would use the default camelCase names for the fields. So something like NetworkProjectID
ends up in JSON as networkProjectID
.
On the other hand, when gcfg code reads the json, it is likely using the gcfg
struct tags to interpret the field names. So it expects the JSON field name to be network-project-id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
I changed the code significantly. Now it treats the file as ini file, and, I also updated unit tests to double check it, looks correct
pkg/multiproject/gce/gce.go
Outdated
if flags.F.ConfigFilePath == "" { | ||
return nil | ||
} | ||
|
||
logger.Info("Reading config from the specified path", "path", flags.F.ConfigFilePath) | ||
config, err := os.Open(flags.F.ConfigFilePath) | ||
if err != nil { | ||
klog.Fatalf("%v", err) | ||
} | ||
defer config.Close() | ||
|
||
allConfig, err := io.ReadAll(config) | ||
if err != nil { | ||
klog.Fatalf("Error while reading config (%q): %v", flags.F.ConfigFilePath, err) | ||
} | ||
logger.V(4).Info("Cloudprovider config file", "config", string(allConfig)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm contemplating whether it's helpful to refactor some of the code here that's shared with the NewGCEClient
within glbc/app
package. On one hand I feel it's maybe not that complex that it needs de-duplication, but on the other hand it maybe feels more natural to just have it in one place (perhaps within the glbc/app
package?). Any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved a part of it into glbc/app, so we reuse some code, and it just makes it clearer :)
- Still uses default gce.conf to get most of the info - If project info not specified will use default config values, which corresponds to cluster-project - Overrides TokenURL and TokenBody and Network info if project is specified - Imports new package github.com/go-ini/ini to properly work with gce.conf which is in ini file format
49ef5d9
to
f36df0a
Compare
/assign @gauravkghildiyal