Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

panslava
Copy link
Contributor

@panslava panslava commented Nov 4, 2024

  • 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

/assign @gauravkghildiyal

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 4, 2024
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 4, 2024
@panslava panslava force-pushed the multi-project-gce branch 4 times, most recently from 0e8f463 to 3849802 Compare November 5, 2024 22:08
Copy link
Member

@gauravkghildiyal gauravkghildiyal left a 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 {
Copy link
Member

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()?

Copy link
Contributor Author

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

}

// convert file struct to bytes
configBytes, err := json.Marshal(configFile)
Copy link
Member

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.

Copy link
Contributor Author

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

Comment on lines 111 to 126
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))
Copy link
Member

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?

Copy link
Contributor Author

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
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants