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

Update the tanzu login command to log in to TAP SaaS #715

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

prkalle
Copy link
Contributor

@prkalle prkalle commented Mar 26, 2024

What this PR does / why we need it

This PR update the tanzu login command to log in to TAP SaaS platform

Changes Summary:

  • Refactor/update the existing deprecated tanzu login command to login to TAP SaaS
  • login command would create a context and user has to use tanzu context command to manage(delete/use) the context.
  • user can perform re-login and the context would be updated with the new tokens and kubeconfig would be re-generated( this would help users if they manully edit and mess-up the kube context associated with the context)

Which issue(s) this PR fixes

Fixes #

Login to production using tanzu login and was able to create a context. Also the tanzu project list and tanzu project use and tanzu space list working as expected.

❯ tanzu context list
  NAME                ISACTIVE  TYPE             PROJECT      SPACE
  mytmc-ctx           true      mission-control  n/a          n/a
  prem-ucp-prod-test  false     tanzu            sre-project  test
  tkg-mgmt-vc         false     kubernetes       n/a          n/a
  tt-test-selfmg      false     mission-control  n/a          n/a

[i] Use '--wide' flag to view additional columns.
❯ ./bin/tanzu login
[i] Opening the browser window to complete the login
Log in by visiting this link:

    https://console.cloud.vmware.com/csp/gateway/discovery?client_id=tanzu-cli-client-id&code_challenge=EyFVCaDWz30XjyY2U-sam-KmccLSykyTBvF8kYjAgwg&code_challenge_method=S256&redirect_uri=http%3A%2F%2F127.0.0.1%3A50840%2Fcallback&response_type=code&state=a26639750fd0ced0be1d056f5033509b

    Optionally, paste your authorization code: [...]


[ok] Successfully logged into 'TAP SAAS PRD' organization and created a tanzu context
[i] Checking for required plugins for context 'TAP_SAAS_PRD'...
[i] All required plugins are already installed and up-to-date
❯ ./bin/tanzu context list
  NAME                ISACTIVE  TYPE             PROJECT      SPACE
  TAP_SAAS_PRD        true      tanzu
  mytmc-ctx           true      mission-control  n/a          n/a
  prem-ucp-prod-test  false     tanzu            sre-project  test
  tkg-mgmt-vc         false     kubernetes       n/a          n/a
  tt-test-selfmg      false     mission-control  n/a          n/a

[i] Use '--wide' flag to view additional columns.
❯ ./bin/tanzu project list
Listing projects from bc6f01a5-8618-4fed-a457-161d3a138052 org
NAME                                   ACTIVE   AGE
default                                false    11d
sre-project                            false    11d
e2e                                    false    10d
beta2-prod-validation                  false    9d
project-tap-saas-tap-ci-prod-gql-103   false    7d6h
e2e-sre                                false    7d10h
wjimenez                               false    5d19h
e2e-project                            false    5d11h
vpaul                                  false    5d5h
mfine                                  false    5d3h
scorsonea                              false    4d3h
beta2-fix-validation                   false    3d4h
pedersenju-project                     false    27h
ramanav-e2-validation                  false    27h
dwyer                                  false    26h
pete-project                           false    23h
nebhale                                false    20h
project-tap-saas-prod-gql-153          false    15h
ksedky-project-3                       false    13h
project-tap-saas-prod-gql-1            false    12h
project-tap-saas-prod-gql-4            false    9h
project-tap-saas-prod-gql-5            false    9h
project-tap-saas-prod-gql-6            false    9h
project-tap-saas-prod-gql-7            false    8h
fabio-b2-prod2                         false    6h18m
project-tap-saas-prod-gql-8            false    6h10m
project-tap-saas-prod-gql-9            false    152m

🔎 To set your active project use 'tanzu project use NAME'
❯ ./bin/tanzu project use sre-project
✓ Successfully set project to sre-project
❯ ./bin/tanzu space list
Listing spaces from bc6f01a5-8618-4fed-a457-161d3a138052 org, current context is sre-project project
NAME   READY   PROFILES RESOLVED   REPLICAS   AGE    ACTIVE
test   True    0/0                 0/0        4d4h   false

🔎 For more details use 'tanzu space get NAME'

With the current active resource of tanzu context set to project, did a re-login to verify the users current context is handled gracefully. The login was successful and the kubeconfig(pointing to the project resource) and context active resources are set in tact.

❯ #relogin with current tanzu context set to project resource
❯ ./bin/tanzu login
[i] Opening the browser window to complete the login
Log in by visiting this link:

    https://console.cloud.vmware.com/csp/gateway/discovery?client_id=tanzu-cli-client-id&code_challenge=YHR64ndYI0s_p21zIY9eB3p2pAKHwBenpRyxdCYcmt8&code_challenge_method=S256&redirect_uri=http%3A%2F%2F127.0.0.1%3A50892%2Fcallback&response_type=code&state=6a81cf3e14fd5f56b3f1db954bcf2a8c

    Optionally, paste your authorization code: [...]


[ok] Successfully logged into 'TAP SAAS PRD' organization and created a tanzu context
[i] Checking for required plugins for context 'TAP_SAAS_PRD'...
[i] All required plugins are already installed and up-to-date
❯ ./bin/tanzu context list
  NAME                ISACTIVE  TYPE             PROJECT      SPACE
  TAP_SAAS_PRD        true      tanzu            sre-project
  mytmc-ctx           true      mission-control  n/a          n/a
  prem-ucp-prod-test  false     tanzu            sre-project  test
  tkg-mgmt-vc         false     kubernetes       n/a          n/a
  tt-test-selfmg      false     mission-control  n/a          n/a

[i] Use '--wide' flag to view additional columns.
❯ ./bin/tanzu space list
Listing spaces from bc6f01a5-8618-4fed-a457-161d3a138052 org, current context is sre-project project
NAME   READY   PROFILES RESOLVED   REPLICAS   AGE    ACTIVE
test   True    0/0                 0/0        4d4h   false

🔎 For more details use 'tanzu space get NAME'

Removed the kube context related to the tanzu context from the kubeconfig file and did re-login. The login was success and kubeconfig is generated again.

❯ #remove the kube context related to tanzu context from the kubeconfig file and relogin. It should regenerate the kubeconfig again
❯ kubectl config get-contexts
CURRENT   NAME                                                          CLUSTER                                                       AUTHINFO                                                      NAMESPACE
          gke_developer-framework-team_us-central1-c_downstream-adhol   gke_developer-framework-team_us-central1-c_downstream-adhol   gke_developer-framework-team_us-central1-c_downstream-adhol
          gke_kshaheer-playground_us-east4_tap-sc                       gke_kshaheer-playground_us-east4_tap-sc                       gke_kshaheer-playground_us-east4_tap-sc
          kind-ucp                                                      kind-ucp                                                      kind-ucp
*         tanzu-cli-TAP_SAAS_PRD                                        tanzu-cli-TAP_SAAS_PRD/current                                tanzu-cli-TAP_SAAS_PRD-user
          tanzu-cli-prem-ucp-prod-test                                  tanzu-cli-prem-ucp-prod-test/current                          tanzu-cli-prem-ucp-prod-test-user
❯ kubectl config delete-context tanzu-cli-TAP_SAAS_PRD
warning: this removed your active context, use "kubectl config use-context" to select a different one
deleted context tanzu-cli-TAP_SAAS_PRD from /Users/pkalle/.kube/config
❯ ./bin/tanzu login
[i] Opening the browser window to complete the login
Log in by visiting this link:

    https://console.cloud.vmware.com/csp/gateway/discovery?client_id=tanzu-cli-client-id&code_challenge=stDi8o_EzoU133jSb-z19U_JIpmDe4XJ_i1TpSNt8_M&code_challenge_method=S256&redirect_uri=http%3A%2F%2F127.0.0.1%3A50923%2Fcallback&response_type=code&state=da5f4c6291979ae1a11b0383daf92aa9

    Optionally, paste your authorization code: [...]


[ok] Successfully logged into 'TAP SAAS PRD' organization and created a tanzu context
[i] Checking for required plugins for context 'TAP_SAAS_PRD'...
[i] All required plugins are already installed and up-to-date
❯ kubectl config get-contexts
CURRENT   NAME                                                          CLUSTER                                                       AUTHINFO                                                      NAMESPACE
          gke_developer-framework-team_us-central1-c_downstream-adhol   gke_developer-framework-team_us-central1-c_downstream-adhol   gke_developer-framework-team_us-central1-c_downstream-adhol
          gke_kshaheer-playground_us-east4_tap-sc                       gke_kshaheer-playground_us-east4_tap-sc                       gke_kshaheer-playground_us-east4_tap-sc
          kind-ucp                                                      kind-ucp                                                      kind-ucp
*         tanzu-cli-TAP_SAAS_PRD                                        tanzu-cli-TAP_SAAS_PRD/current                                tanzu-cli-TAP_SAAS_PRD-user
          tanzu-cli-prem-ucp-prod-test                                  tanzu-cli-prem-ucp-prod-test/current                          tanzu-cli-prem-ucp-prod-test-user
❯ ./bin/tanzu space list
Listing spaces from bc6f01a5-8618-4fed-a457-161d3a138052 org, current context is sre-project project
NAME   READY   PROFILES RESOLVED   REPLICAS   AGE    ACTIVE
test   True    0/0                 0/0        4d5h   false

🔎 For more details use 'tanzu space get NAME'

tanzu context was set to space and did re-login. The login was successful and the context active resource was kept in tact( honoured the users existing context setting).

❯ ./bin/tanzu space use test
✓ Successfully set space to test
❯ ./bin/tanzu context list
  NAME                ISACTIVE  TYPE             PROJECT      SPACE
  TAP_SAAS_PRD        true      tanzu            sre-project  test
  mytmc-ctx           true      mission-control  n/a          n/a
  prem-ucp-prod-test  false     tanzu            sre-project  test
  tkg-mgmt-vc         false     kubernetes       n/a          n/a
  tt-test-selfmg      false     mission-control  n/a          n/a

[i] Use '--wide' flag to view additional columns.
❯ ./bin/tanzu space profile list
No Profiles found.
❯ ./bin/tanzu login
[i] Opening the browser window to complete the login
Log in by visiting this link:

    https://console.cloud.vmware.com/csp/gateway/discovery?client_id=tanzu-cli-client-id&code_challenge=OU2ns4qrpg0epDlGrlcVXDIY2OW4TjtZeFFp_iNaEnY&code_challenge_method=S256&redirect_uri=http%3A%2F%2F127.0.0.1%3A51021%2Fcallback&response_type=code&state=9bf887893e67036ec145fa4994271384

    Optionally, paste your authorization code: [...]


[ok] Successfully logged into 'TAP SAAS PRD' organization and created a tanzu context
[i] Checking for required plugins for context 'TAP_SAAS_PRD'...
[i] All required plugins are already installed and up-to-date
❯ ./bin/tanzu space profile list
No Profiles found.

Logged in to staging env. It was successful and the context name was appended with -staging and hash string of the endpoint.

❯ ./bin/tanzu login --endpoint https://test-project-syncer.stacks.bluesky.tmc-dev.cloud.vmware.com --staging
[i] Opening the browser window to complete the login
Log in by visiting this link:

    https://console-stg.cloud.vmware.com/csp/gateway/discovery?client_id=tanzu-cli-client-id&code_challenge=jPOXWt55goqrlP0nP7lhD1JrJ-YjxRc-82FqEvY6X4c&code_challenge_method=S256&redirect_uri=http%3A%2F%2F127.0.0.1%3A51259%2Fcallback&response_type=code&state=3eb6596263a5ce56ba5f6dd231a0ab2e

    Optionally, paste your authorization code: [...]


[ok] Successfully logged into 'TestProjectSyncer' organization and created a tanzu context
[i] Checking for required plugins for context 'TestProjectSyncer-staging-3d4f75b3'...
[i] All required plugins are already installed and up-to-date


❯ ./bin/tanzu context list
  NAME                                ISACTIVE  TYPE             PROJECT      SPACE
  TAP_SAAS_PRD                        false     tanzu            sre-project  test
  TestProjectSyncer-staging-3d4f75b3  true      tanzu
  mytmc-ctx                           true      mission-control  n/a          n/a
  prem-ucp-prod-test                  false     tanzu            sre-project  test
  tkg-mgmt-vc                         false     kubernetes       n/a          n/a
  tt-test-selfmg                      false     mission-control  n/a          n/a

[i] Use '--wide' flag to view additional columns.


❯ ./bin/tanzu project list
Listing projects from dcd7e146-57e6-4a1b-905c-0d4079dc9f38 org
NAME                                   ACTIVE   AGE
9ba6ba75-9782-48a2-ae3b-eaa11c6e5316   false    35h
3351bd40-5150-46f7-96c5-d368b5f99932   false    29h
fd72b29b-bd90-40a6-a684-3e78de397028   false    29h
default                                false    13h

🔎 To set your active project use 'tanzu project use NAME'

Describe testing done for PR

Release note

Repurpose the deprecated tanzu login command to log in to TAP SaaS

Additional information

Special notes for your reviewer

@prkalle prkalle requested a review from a team as a code owner March 26, 2024 17:06
@prkalle prkalle force-pushed the feature/tazu_login_update branch 2 times, most recently from bb85746 to 2bc4c29 Compare March 27, 2024 02:10
@vuil vuil self-requested a review March 27, 2024 16:50
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.

This is great @prkalle ! I'm going to start using tanzu login instead of tanzu context create now 😄
Could you add some release notes in the PR description?
All my comments are nits.

pkg/command/login.go Show resolved Hide resolved
pkg/command/login.go Outdated Show resolved Hide resolved
pkg/command/login.go Show resolved Hide resolved
pkg/command/login.go Show resolved Hide resolved
pkg/command/login.go Outdated Show resolved Hide resolved
pkg/command/context.go Outdated Show resolved Hide resolved
pkg/command/context.go Outdated Show resolved Hide resolved
@marckhouzam
Copy link
Contributor

I didn't approve simply because the PR needs to use projectID now that #711 has been merged.

@prkalle prkalle force-pushed the feature/tazu_login_update branch 4 times, most recently from ed8d4c7 to fa7880b Compare April 5, 2024 17:59
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.

Nice! LGTM
Could you just remove the TODO section from the PR description?

@marckhouzam marckhouzam added this to the v1.3.0 milestone Apr 8, 2024
@prkalle prkalle added the docs-impact issues with documentation impact label Apr 8, 2024
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

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.

Thanks for the changes and updates!
lgtm, just a nit on the markdown.

docs/quickstart/quickstart.md Outdated Show resolved Hide resolved
- Refactor/update the existing deprecated tanzu login command to login to TAP SaaS

Signed-off-by: Prem Kumar Kalle <prem.kalle@broadcom.com>

Update the docs for tanzu login command

Signed-off-by: Prem Kumar Kalle <prem.kalle@broadcom.com>
@prkalle prkalle merged commit 7bbadfd into vmware-tanzu:main Apr 10, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-not-required docs-impact issues with documentation impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants