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

Move the DiscoverySources config section #58

Merged
merged 2 commits into from
Apr 25, 2023

Conversation

marckhouzam
Copy link
Contributor

@marckhouzam marckhouzam commented Apr 24, 2023

What this PR does / why we need it

This PR moves the DiscoverySources configuration section from "clientOptions.cli.discoverySources" to "cli.discoverySources". The actual handling of discovery sources is kept the same; it is just the section of the configuration file in which they are stored that is moved.

This change is necessary as plugins built with the previous version of the runtime library would set a "default" discovery source which the new independent CLI should not use; by moving the discovery sources section in the config file, the new CLI can ignore the old section and trust that the new section only contains valid sources, even when older plugins are used.

Note that we don't yet modify the CLI to make use of this change but simply start by making sure the tz plugin source commands properly work with the new section of discoverySources of the config file. For this to work though PR vmware-tanzu/tanzu-cli#225 must be used for the CLI.

Which issue(s) this PR fixes

Fixes #54

Describe testing done for PR

Using PR vmware-tanzu/tanzu-cli#225, I built the CLI and then verified that the tanzu plugin source commands work with the new discoverySources section.

# Initialize the config file
$ rm ~/.config/tanzu/config*
$ tz ceip-participation set true
$ tz config get
clientOptions:
    cli:
        edition: tkg
        bomRepo: projects.registry.vmware.com/tkg
        compatibilityFilePath: tkg-compatibility
    features:
        global:
            context-target-v2: "true"
cli:
    ceipOptIn: "true"

# Add a plugin source in the new section and verify the config
$ tz plugin source add --name central --type local --uri /Users/kmarc/tanzu/plugins/central:large
[ok] successfully added discovery source central
$ tz config get
clientOptions:
    cli:
        edition: tkg
        bomRepo: projects.registry.vmware.com/tkg
        compatibilityFilePath: tkg-compatibility
    features:
        global:
            context-target-v2: "true"
cli:
    ceipOptIn: "true"
    discoverySources:
        - local:
            name: central
            path: /Users/kmarc/tanzu/plugins/central:large

$ tz plugin source list
  NAME     TYPE   SCOPE
  central  local  Standalone

# Add a second source and verify the config
$ tz plugin source add --name default -u projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest -t oci
[ok] successfully added discovery source default
$ tz config get
clientOptions:
    cli:
        edition: tkg
        bomRepo: projects.registry.vmware.com/tkg
        compatibilityFilePath: tkg-compatibility
    features:
        global:
            context-target-v2: "true"
cli:
    ceipOptIn: "true"
    discoverySources:
        - local:
            name: central
            path: /Users/kmarc/tanzu/plugins/central:large
        - oci:
            name: default
            image: projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest

$ tz plugin source list
  NAME     TYPE   SCOPE
  central  local  Standalone
  default  oci    Standalone

# Delete a plugin source
$ tz plugin source delete central
[ok] deleted discovery source central
$ tz config get
clientOptions:
    cli:
        edition: tkg
        bomRepo: projects.registry.vmware.com/tkg
        compatibilityFilePath: tkg-compatibility
    features:
        global:
            context-target-v2: "true"
cli:
    ceipOptIn: "true"
    discoverySources:
        - oci:
            name: default
            image: projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest

# Update a plugin source
$ tz plugin source update default -u localhost:9876/bad -t oci
[ok] updated discovery source default
$ tz config get
clientOptions:
    cli:
        edition: tkg
        bomRepo: projects.registry.vmware.com/tkg
        compatibilityFilePath: tkg-compatibility
    features:
        global:
            context-target-v2: "true"
cli:
    ceipOptIn: "true"
    discoverySources:
        - oci:
            name: default
            image: localhost:9876/bad

# Execute an old plugin to populate the old discoverySources section and check the config
$ tz cluster
Kubernetes cluster operations
[...]

# Notice the old and new discoverySources sections not conflicting with each other
$ tz config get
clientOptions:
    cli:
        discoverySources:
            - local:
                name: default
                path: standalone
        edition: tkg
        bomRepo: projects.registry.vmware.com/tkg
        compatibilityFilePath: tkg-compatibility
    features:
        cluster:
            allow-legacy-cluster: "false"
        global:
            context-aware-cli-for-plugins: "true"
            context-target-v2: "true"
        management-cluster:
            package-based-cc: "true"
cli:
    ceipOptIn: "true"
    discoverySources:
        - oci:
            name: default
            image: localhost:9876/bad

# One plugin source is considered.  It is the new one, but since I named them the same, let check further below...
$ tz plugin source list
  NAME     TYPE  SCOPE
  default  oci   Standalone

# Add a different named source
$ tz plugin source add --name default2 -u projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest -t oci
[ok] successfully added discovery source default2

# Delete the new one named "default"
$ tz plugin source delete default
[ok] deleted discovery source default

# Notice a plugin source named "default" in the old section (which will be ignored)
# and one named "default2" in the new section
$ tz config get
clientOptions:
    cli:
        discoverySources:
            - local:
                name: default
                path: standalone
        edition: tkg
        bomRepo: projects.registry.vmware.com/tkg
        compatibilityFilePath: tkg-compatibility
    features:
        cluster:
            allow-legacy-cluster: "false"
        global:
            context-aware-cli-for-plugins: "true"
            context-target-v2: "true"
        management-cluster:
            package-based-cc: "true"
cli:
    ceipOptIn: "true"
    discoverySources:
        - oci:
            name: default2
            image: projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest

# Notice that only the new section is considered
$ tz plugin source list
  NAME      TYPE  SCOPE
  default2  oci   Standalone

# Verify config init
$ tz config init
[ok] successfully initialized the config
$ tz config get
clientOptions:
    cli:
        discoverySources:
            - local:
                name: default
                path: standalone
        edition: tkg
        bomRepo: projects.registry.vmware.com/tkg
        compatibilityFilePath: tkg-compatibility
    features:
        cluster:
            allow-legacy-cluster: "false"
            custom-nameservers: "false"
            dual-stack-ipv4-primary: "false"
            dual-stack-ipv6-primary: "false"
        global:
            context-aware-cli-for-plugins: "true"
            context-target-v2: "true"
            tkr-version-v1alpha3-beta: "false"
        management-cluster:
            aws-instance-types-exclude-arm: "true"
            custom-nameservers: "false"
            deploy-in-cluster-ipam-provider: "true"
            dual-stack-ipv4-primary: "false"
            dual-stack-ipv6-primary: "false"
            export-from-confirm: "true"
            import: "false"
            package-based-cc: "true"
            standalone-cluster-mode: "false"
        package:
            kctrl-command-tree: "true"
cli:
    ceipOptIn: "true"
    discoverySources:
        - oci:
            name: default2
            image: projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest

Release note

The configuration entries for Discovery Sources have been moved to a new section under the top-level "cli" tag.  The old "clientOptions.cli.discoverySources" section is no longer used and any content will be ignored. 

Additional information

Special notes for your reviewer

@anujc25
Copy link
Contributor

anujc25 commented Apr 25, 2023

CI for Cross-version API Compatibility Tests is not running as part of this PR.
Can you update compatibility_tests.yaml#L7 with ** or completely remove paths section so that those tests run for this PR?

Copy link
Contributor

@anujc25 anujc25 left a comment

Choose a reason for hiding this comment

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

Overall looks good.
Please add the release note in the PR description. Also, we should verify the change with Cross-version API Compatibility Tests as mentioned in the previous comment.

Copy link
Contributor

@anujc25 anujc25 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!

The handling of discovery sources is kept the same but the section of
the configuration file in which they are stored is moved.

The old section was under "clientOptions.cli.discoverySources" while
the new section is now under "cli.discoverySources".

This change is necessary as plugins built with the previous version
of the runtime library would set a "default" discovery source which the
new independent CLI should not use; by moving the discovery sources
section in the config file, the new CLI can ignore the old section
and trust that the new section only contains valid sources, even when
older plugins are used.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
Signed-off-by: Marc Khouzam <kmarc@vmware.com>
Copy link
Contributor

@mpanchajanya mpanchajanya 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 for the changes

@marckhouzam marckhouzam merged commit 014e58e into vmware-tanzu:main Apr 25, 2023
@marckhouzam marckhouzam deleted the feat/newDiscoveryConfig branch April 25, 2023 19:15
vuil pushed a commit that referenced this pull request May 2, 2023
The handling of discovery sources is kept the same but the section of
the configuration file in which they are stored is moved.

The old section was under "clientOptions.cli.discoverySources" while
the new section is now under "cli.discoverySources".

This change is necessary as plugins built with the previous version
of the runtime library would set a "default" discovery source which the
new independent CLI should not use; by moving the discovery sources
section in the config file, the new CLI can ignore the old section
and trust that the new section only contains valid sources, even when
older plugins are used.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
@marckhouzam marckhouzam added this to the v0.90.0 milestone Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a new plugin source discovery section
4 participants