Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Create separate go modules for apis/cli and apis/config #3141

Merged
merged 4 commits into from
Aug 18, 2022

Conversation

anujc25
Copy link
Contributor

@anujc25 anujc25 commented Aug 16, 2022

What this PR does / why we need it

  • Create separate go modules for apis/cli
  • Create separate go modules for apis/config

Which issue(s) this PR fixes

Fixes #3139 and #3140

Describe testing done for PR

Release note

Create separate go modules for `apis/cli` and `apis/config`

Additional information

Special notes for your reviewer

@anujc25 anujc25 requested review from a team as code owners August 16, 2022 05:23
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220816053039/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@marckhouzam
Copy link
Contributor

This looks great @anujc25.

Comparing the apis/cli and apis/config with the existing apis/cni and apis/cpi, I notice that the latter both have a Makefile and are part of the main Makefile manifests target. These Makefiles were added to fix #2398. I don't understand the controller-gen concept at the moment, but I thought I'd mention it, in case we need the same thing for the new go modules.

@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from be97f28 to dd97d76 Compare August 16, 2022 17:28
@anujc25
Copy link
Contributor Author

anujc25 commented Aug 16, 2022

Comparing the apis/cli and apis/config with the existing apis/cni and apis/cpi, I notice that the latter both have a Makefile and are part of the main Makefile manifests target. These Makefiles were added to fix #2398. I don't understand the controller-gen concept at the moment, but I thought I'd mention it, in case we need the same thing for the new go modules.

Thanks. Great catch. Updated the PR to update Makefiles.

@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220816174156/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@codecov
Copy link

codecov bot commented Aug 16, 2022

Codecov Report

Merging #3141 (ba90d37) into main (0086f33) will increase coverage by 0.46%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##             main    #3141      +/-   ##
==========================================
+ Coverage   44.46%   44.93%   +0.46%     
==========================================
  Files         417      412       -5     
  Lines       42399    41722     -677     
==========================================
- Hits        18851    18746     -105     
+ Misses      21818    21252     -566     
+ Partials     1730     1724       -6     
Impacted Files Coverage Δ
cmd/cli/plugin/cluster/create.go 41.30% <0.00%> (-0.92%) ⬇️
cmd/cli/plugin/cluster/upgrade.go 57.55% <0.00%> (-0.96%) ⬇️
pkg/v1/cli/command/core/config.go 36.15% <ø> (-0.32%) ⬇️
pkg/v1/tkg/tkgctl/compatibility.go 70.00% <70.00%> (ø)
addons/controllers/clusterbootstrap_controller.go 63.28% <0.00%> (-2.30%) ⬇️
apis/config/v1alpha1/clientconfig.go
apis/config/v1alpha1/featuregate_webhook.go
apis/config/v1alpha1/clientconfig_types.go
apis/config/v1alpha1/zz_generated.deepcopy.go
apis/config/v1alpha1/feature_types.go
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from dd97d76 to 08738f8 Compare August 16, 2022 19:30
@anujc25 anujc25 requested a review from prkalle as a code owner August 16, 2022 19:30
@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from 08738f8 to 851c4a1 Compare August 16, 2022 19:35
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220816194214/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220816194705/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from 851c4a1 to 5dcec40 Compare August 16, 2022 20:06
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220816201713/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@@ -190,12 +190,6 @@ func setEdition(cfg *configv1alpha1.ClientConfig, edition string) error {
switch editionOption {
case configv1alpha1.EditionCommunity, configv1alpha1.EditionStandard:
cfg.SetEditionSelector(editionOption)
// when community edition is set, configure the compatibility file to use
// community edition's.
err := cfg.SetCompatibilityFile(editionOption)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed from core-cli code and moved to individual plugin command invocations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, now I'm completely out of my element, but please be patient with me.

I was curious about the change in logic about SetCompatibilityFile. Looking at the change, I'm guessing that this compatibility file is only used when creating a cluster? That is why you only need to trigger it for the managed-cluster and cluster plugins?

But somehow (probably me doing something wrong), the main configuration file does not get updated properly anymore. This is a simplification of what I did:

# Check that the main config file is set to tkg (BOM and edition)
$ egrep 'bom|edition' ~/.config/tanzu/config.yaml
    bomRepo: projects-stg.registry.vmware.com/tkg
    edition: tkg

# Set the edition to TCE
$ tanzu config set cli.edition tce
# =====> Notice the BOM is no longer set properly
$ egrep 'bom|edition' ~/.config/tanzu/config.yaml
    bomRepo: projects-stg.registry.vmware.com/tkg
    edition: tce

# Remove the BOM line completely
$ grep -v bom ~/.config/tanzu/config.yaml > tt && \mv tt ~/.config/tanzu/config.yaml && grep bom ~/.config/tanzu/config.yaml

# Regenerate the config file by running any command
$ tanzu
Tanzu CLI
Usage:
  tanzu [command]
[...]
# =====> Notice the BOM is added but does not match the edition
$ egrep 'bom|edition' ~/.config/tanzu/config.yaml
    bomRepo: projects-stg.registry.vmware.com/tkg
    edition: tce

I don't know if this is actually a problem but it does not happen on the main branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that. I have fixed the problem and added unit test around SetCompatibilityFileBasedOnEdition function as well.

Please note that tanzu config set cli.edition tce command will now just update the edition field in config and BomRepo and Compatibility information is updated when user runs cluster or management-cluster plugin command. Ideally, BomRepo and Compatibility information should not be part of ClientConfig at the first place and I have filled #3149 for that.

@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from 5dcec40 to 224687b Compare August 16, 2022 20:32
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220816204219/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I'm all over the place, this is still pretty new to me...

apis/config/v1alpha1/featuregate_webhook.go Outdated Show resolved Hide resolved
apis/config/v1alpha1/featuregate_webhook_test.go Outdated Show resolved Hide resolved
pkg/v1/sdk/capabilities/Dockerfile Show resolved Hide resolved
@@ -190,12 +190,6 @@ func setEdition(cfg *configv1alpha1.ClientConfig, edition string) error {
switch editionOption {
case configv1alpha1.EditionCommunity, configv1alpha1.EditionStandard:
cfg.SetEditionSelector(editionOption)
// when community edition is set, configure the compatibility file to use
// community edition's.
err := cfg.SetCompatibilityFile(editionOption)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, now I'm completely out of my element, but please be patient with me.

I was curious about the change in logic about SetCompatibilityFile. Looking at the change, I'm guessing that this compatibility file is only used when creating a cluster? That is why you only need to trigger it for the managed-cluster and cluster plugins?

But somehow (probably me doing something wrong), the main configuration file does not get updated properly anymore. This is a simplification of what I did:

# Check that the main config file is set to tkg (BOM and edition)
$ egrep 'bom|edition' ~/.config/tanzu/config.yaml
    bomRepo: projects-stg.registry.vmware.com/tkg
    edition: tkg

# Set the edition to TCE
$ tanzu config set cli.edition tce
# =====> Notice the BOM is no longer set properly
$ egrep 'bom|edition' ~/.config/tanzu/config.yaml
    bomRepo: projects-stg.registry.vmware.com/tkg
    edition: tce

# Remove the BOM line completely
$ grep -v bom ~/.config/tanzu/config.yaml > tt && \mv tt ~/.config/tanzu/config.yaml && grep bom ~/.config/tanzu/config.yaml

# Regenerate the config file by running any command
$ tanzu
Tanzu CLI
Usage:
  tanzu [command]
[...]
# =====> Notice the BOM is added but does not match the edition
$ egrep 'bom|edition' ~/.config/tanzu/config.yaml
    bomRepo: projects-stg.registry.vmware.com/tkg
    edition: tce

I don't know if this is actually a problem but it does not happen on the main branch.

Copy link
Contributor

@prkalle prkalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes looks good

@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from 224687b to bcead3e Compare August 17, 2022 01:44
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220817015458/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from bcead3e to a1ac38c Compare August 17, 2022 03:37
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220817035002/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from a1ac38c to 9299bd2 Compare August 17, 2022 04:27
@anujc25 anujc25 assigned vuil and anujc25 and unassigned anujc25 Aug 17, 2022
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220817043732/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

Copy link
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience and efforts @anujc25. I think this will pave the way to easier future refactorings for everyone else.

The new tests have to be fixed (they don't compile), but the rest looks great 👍

pkg/v1/sdk/capabilities/Dockerfile Show resolved Hide resolved
cmd/cli/plugin/managementcluster/delete.go Show resolved Hide resolved
@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from 9299bd2 to 3767818 Compare August 17, 2022 15:33
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220817154345/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

@anujc25 anujc25 force-pushed the separate-go-mod-apis-cli-config branch from 3767818 to ba90d37 Compare August 17, 2022 16:21
@github-actions
Copy link

Cluster Generation A/B Results:
https://storage.googleapis.com/tkg-clustergen/3141/20220817163120/clustergen.diff.txt
Author/reviewers:
Please review to verify that the effects on the generated cluster configurations are exactly what the PR intended, and give a thumbs-up if so.

Copy link
Contributor

@vuil vuil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@anujc25 anujc25 added ok-to-merge PRs should be labelled with this before merging kind/refactor area/core-cli labels Aug 18, 2022
@anujc25 anujc25 merged commit 482ee91 into vmware-tanzu:main Aug 18, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
area/core-cli cla-not-required kind/refactor ok-to-merge PRs should be labelled with this before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create separate go modules for apis/cli
6 participants