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 API to set active UCP resource for UCP context #106

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

prkalle
Copy link
Contributor

@prkalle prkalle commented Sep 29, 2023

What this PR does / why we need it

This PR adds the API to set UCP active resource for the given UCP context.

Changes summary:

  • Added API to set active UCP resource for given UCP context. API would call the CLI command to set the active UCP resource for the given UCP context

Which issue(s) this PR fixes

Fixes #

Describe testing done for PR

Unit tests are passed.
Also ran few tests using the below test stub (in ucp.test.go) with ucp context("myucp") already created in CLI.

func TestSetUCPContextActiveResourceSample(t *testing.T) {
        // Test updating the UCP context active resource to space
        os.Setenv("TANZU_BIN", "/Users/pkalle/projects/tanzu-cli/artifacts/darwin/amd64/cli/core/v1.1.0-dev/tanzu-cli-darwin_amd64")
        projectName := "projectA"
        spaceName:="spaceA"
        err := SetUCPContextActiveResource("myucp", projectName, spaceName)
        assert.NoError(t, err)
}

Tested setting the UCP active resource to projectA/SpaceA and validated the context in CLI config file is updated as well as the kubeconfig server URL as shown below

// kubeconfig snippet after update
apiVersion: v1
clusters:
- cluster:
    server: https://ucp-aria.stacks.bluesky.tmc-dev.cloud.vmware.com/org/ee04bfae-a665-4f20-a5b9-d8b043180252/project/projectA/space/spaceA
  name: tanzu-cli-myucp/current


// context snippet after update
      clusterOpts:
        endpoint: https://ucp-aria.stacks.bluesky.tmc-dev.cloud.vmware.com/org/ee04bfae-a665-4f20-a5b9-d8b043180252
        path: /Users/pkalle/.kube/config
        context: tanzu-cli-myucp
      discoverySources: []
      additionalMetadata:
        ucpOrgID: ee04bfae-a665-4f20-a5b9-d8b043180252
        ucpProjectName: projectA
        ucpSpaceName: spaceA

Tested setting the UCP active resource to projectA/spaceB and validated the context in CLI config file is updated as well as the kubeconfig server URL as shown below

// kubeconfig snippet after update
apiVersion: v1
clusters:
- cluster:
    server: https://ucp-aria.stacks.bluesky.tmc-dev.cloud.vmware.com/org/ee04bfae-a665-4f20-a5b9-d8b043180252/project/projectA/space/spaceB
  name: tanzu-cli-myucp/current


// context snippet after update
      clusterOpts:
        endpoint: https://ucp-aria.stacks.bluesky.tmc-dev.cloud.vmware.com/org/ee04bfae-a665-4f20-a5b9-d8b043180252
        path: /Users/pkalle/.kube/config
        context: tanzu-cli-myucp
      discoverySources: []
      additionalMetadata:
        ucpOrgID: ee04bfae-a665-4f20-a5b9-d8b043180252
        ucpProjectName: projectA
        ucpSpaceName: spaceB

Tested setting the UCP active resource to projectA and validated the context in CLI config file is updated as well as the kubeconfig server URL as shown below

// kubeconfig snippet after update
apiVersion: v1
clusters:
- cluster:
    server: https://ucp-aria.stacks.bluesky.tmc-dev.cloud.vmware.com/org/ee04bfae-a665-4f20-a5b9-d8b043180252/project/projectA
  name: tanzu-cli-myucp/current


// context snippet after update
      clusterOpts:
        endpoint: https://ucp-aria.stacks.bluesky.tmc-dev.cloud.vmware.com/org/ee04bfae-a665-4f20-a5b9-d8b043180252
        path: /Users/pkalle/.kube/config
        context: tanzu-cli-myucp
      discoverySources: []
      additionalMetadata:
        ucpOrgID: ee04bfae-a665-4f20-a5b9-d8b043180252
        ucpProjectName: projectA
        ucpSpaceName: ""

Tested setting the UCP active resource to back to Org level and validated the context in CLI config file is updated as well as the kubeconfig server URL as shown below

// kubeconfig snippet after update
apiVersion: v1
clusters:
- cluster:
    server: https://ucp-aria.stacks.bluesky.tmc-dev.cloud.vmware.com/org/ee04bfae-a665-4f20-a5b9-d8b043180252
  name: tanzu-cli-myucp/current


// context snippet after update
     clusterOpts:
        endpoint: https://ucp-aria.stacks.bluesky.tmc-dev.cloud.vmware.com/org/ee04bfae-a665-4f20-a5b9-d8b043180252
        path: /Users/pkalle/.kube/config
        context: tanzu-cli-myucp
      discoverySources: []
      additionalMetadata:
        ucpOrgID: ee04bfae-a665-4f20-a5b9-d8b043180252
        ucpProjectName: ""
        ucpSpaceName: ""

Release note

Add API to set active UCP resource for UCP context

Additional information

Special notes for your reviewer

@prkalle prkalle requested a review from a team as a code owner September 29, 2023 20:08
ucp/ucp.go Outdated Show resolved Hide resolved
ucp/ucp.go Outdated Show resolved Hide resolved
ucp/ucp.go Show resolved Hide resolved
ucp/ucp.go Show resolved Hide resolved
ucp/ucp_test.go Show resolved Hide resolved
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.

we should explore possibility of deduping in a followup, but rest of changes lgtm.

- Add API to set active UCP resource for given UCP context. It would call the CLI command to set the active UCP resource for the given UCP context

Signed-off-by: Prem Kumar Kalle <[email protected]>
@prkalle prkalle merged commit fe52a9b into vmware-tanzu:main Sep 29, 2023
4 checks passed
@marckhouzam marckhouzam added this to the v1.1.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.

4 participants