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

Rename UCP names and Context Type with TAE(Tanzu Application Engine) #108

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func EndpointFromContext(s *configtypes.Context) (endpoint string, err error) {
return s.ClusterOpts.Endpoint, nil
case configtypes.TargetTMC:
return s.GlobalOpts.Endpoint, nil
case configtypes.TargetUCP:
case configtypes.TargetTAE:
return s.ClusterOpts.Endpoint, nil
default:
return endpoint, fmt.Errorf("unknown server type %q", s.Target)
Expand Down
42 changes: 21 additions & 21 deletions config/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ func setupForGetContext(t *testing.T) {
},
},
{
Name: "test-ucp",
Target: configtypes.TargetUCP,
Name: "test-tae",
Target: configtypes.TargetTAE,
GlobalOpts: &configtypes.GlobalServer{
Endpoint: "test-endpoint",
},
Expand All @@ -477,7 +477,7 @@ func setupForGetContext(t *testing.T) {
CurrentContext: map[configtypes.Target]string{
configtypes.TargetK8s: "test-mc-2",
configtypes.TargetTMC: "test-tmc",
configtypes.TargetUCP: "test-ucp",
configtypes.TargetTAE: "test-tae",
},
}
func() {
Expand Down Expand Up @@ -508,8 +508,8 @@ func TestGetContext(t *testing.T) {
ctxName: "test-tmc",
},
{
name: "success ucp",
ctxName: "test-ucp",
name: "success tae",
ctxName: "test-tae",
},
{
name: "failure",
Expand Down Expand Up @@ -554,8 +554,8 @@ func TestContextExists(t *testing.T) {
ok: true,
},
{
name: "success ucp",
ctxName: "test-ucp",
name: "success tae",
ctxName: "test-tae",
ok: true,
},
{
Expand Down Expand Up @@ -681,10 +681,10 @@ func TestSetContext(t *testing.T) {
},
},
{
name: "success ucp current",
name: "success tae current",
ctx: &configtypes.Context{
Name: "test-ucp1",
Target: configtypes.TargetUCP,
Name: "test-tae1",
Target: configtypes.TargetTAE,
GlobalOpts: &configtypes.GlobalServer{
Endpoint: "test-endpoint",
},
Expand All @@ -700,10 +700,10 @@ func TestSetContext(t *testing.T) {
current: true,
},
{
name: "success ucp not_current",
name: "success tae not_current",
ctx: &configtypes.Context{
Name: "test-ucp2",
Target: configtypes.TargetUCP,
Name: "test-tae2",
Target: configtypes.TargetTAE,
GlobalOpts: &configtypes.GlobalServer{
Endpoint: "test-endpoint",
},
Expand Down Expand Up @@ -761,9 +761,9 @@ func TestRemoveContext(t *testing.T) {
target: configtypes.TargetTMC,
},
{
name: "success ucp",
ctxName: "test-ucp",
target: configtypes.TargetUCP,
name: "success tae",
ctxName: "test-tae",
target: configtypes.TargetTAE,
},
{
name: "failure",
Expand Down Expand Up @@ -820,9 +820,9 @@ func TestSetCurrentContext(t *testing.T) {
currServer: "test-mc",
},
{
name: "success ucp",
ctxName: "test-ucp",
target: configtypes.TargetUCP,
name: "success tae",
ctxName: "test-tae",
target: configtypes.TargetTAE,
},
{
name: "success tmc after setting k8s",
Expand Down Expand Up @@ -869,13 +869,13 @@ func TestSetCurrentContext(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "test-mc", currentContextMap[configtypes.TargetK8s].Name)
assert.Equal(t, "test-tmc", currentContextMap[configtypes.TargetTMC].Name)
assert.Equal(t, "test-ucp", currentContextMap[configtypes.TargetUCP].Name)
assert.Equal(t, "test-tae", currentContextMap[configtypes.TargetTAE].Name)

currentContextsList, err := GetAllCurrentContextsList()
assert.NoError(t, err)
assert.Contains(t, currentContextsList, "test-mc")
assert.Contains(t, currentContextsList, "test-tmc")
assert.Contains(t, currentContextsList, "test-ucp")
assert.Contains(t, currentContextsList, "test-tae")
}

func TestRemoveCurrentContext(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions config/types/clientconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ const (
// TargetUnknown specifies that the target is not currently known
TargetUnknown Target = ""

// TargetUCP is a used to indicate the type of Context used to interact with a
// Unified Control Plane endpoint
// TargetTAE is a used to indicate the type of Context used to interact with a
// Tanzu Application Engine endpoint
// Note!! Experimental, please expect changes
TargetUCP Target = "ucp"
TargetTAE Target = "application-engine"
targetTAE Target = "tae"
)

var (
// SupportedTargets is a list of all supported Target
SupportedTargets = []Target{TargetK8s, TargetTMC, TargetUCP}
SupportedTargets = []Target{TargetK8s, TargetTMC, TargetTAE}
)

const (
Expand Down
7 changes: 4 additions & 3 deletions config/types/clientconfig_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ func StringToTarget(target string) Target {
return TargetK8s
} else if target == string(targetTMC) || target == string(TargetTMC) {
return TargetTMC
} else if target == string(targetTAE) || target == string(TargetTAE) {
return TargetTAE
} else if target == string(TargetGlobal) {
return TargetGlobal
} else if target == string(TargetUCP) {
return TargetUCP
} else if target == string(TargetUnknown) {
return TargetUnknown
}
Expand All @@ -27,7 +27,8 @@ func IsValidTarget(target string, allowGlobal, allowUnknown bool) bool {
target == string(TargetK8s) ||
target == string(targetTMC) ||
target == string(TargetTMC) ||
target == string(TargetUCP) ||
target == string(targetTAE) ||
target == string(TargetTAE) ||
(allowGlobal && target == string(TargetGlobal)) ||
(allowUnknown && target == string(TargetUnknown))
}
12 changes: 6 additions & 6 deletions fakes/config/kubeconfig-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ clusters:
- cluster:
insecure-skip-tls-verify: true
server: https://api.tanzu.cloud.vmware.com:443/org/fake-org-id
name: tanzu-cli-myucp/current
name: tanzu-cli-mytae/current
contexts:
- context:
cluster: bar-cluster
Expand All @@ -28,9 +28,9 @@ contexts:
user: blue-user
name: foo-context
- context:
cluster: tanzu-cli-myucp/current
user: tanzu-cli-myucp-user
name: tanzu-cli-myucp
cluster: tanzu-cli-mytae/current
user: tanzu-cli-mytae-user
name: tanzu-cli-mytae
users:
- name: blue-user
user:
Expand All @@ -39,13 +39,13 @@ users:
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJQ24vUDZ1S1pWWTR3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TURBeE1qVXdPRFV4TVRCYUZ3MHlNVEF4TWpRd09EVXhNVEphTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXJuUmc4dklXQlBWQUJWTFUKNGNFckd4bE5XZVJHR2x0OW0wVElsUStNUytSZU9GNUhROW5pQlRSQWMwVWpsUk1EdzR3aEREVXV3Y2NsazFCNApoa3l2YUx5elZyeW9jOWV5NHU0SVZ0MFR4ZU85VUI5bXZHMkF6TlVnY0FkRkp4cWdKbSt2OXo0RzMyU0EwUEc1CjhxZWtBRzVLYU1RQlJEVm5pNXZBajJ5c0hpdHhkbGdJdEZkc1dzNUgwM3FIUjVNQU5jT01nYlZLSnRtbE9MUngKYWFmRHhxSWRaS0pERENxeDFoaWFlMk5WdWp1TzI3OE9DV3NaN3FUWVR4UzNpVVJBUXNpYWk5Y2Q5T2FITnJSTAozWWtUdTl0b1c5RTNFdVB0b0h3S2N6RlZsNk01dWtaWW5wZDEwL213Y2wzUzA1ZFd2SExhNGVMakZ3Z2RQc05XCkZ4NThTd0lEQVFBQm95Y3dKVEFPQmdOVkhROEJBZjhFQkFNQ0JhQXdFd1lEVlIwbEJBd3dDZ1lJS3dZQkJRVUgKQXdJd0RRWUp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G5KWk81TDNqZTdMSHhlMU9YNERQdgozWU9PZGtycStZOG1JSHk0am52VExRditCOG40L1h6V21GeDNkcjRVY0FiS2g3Nm5PZXlydFg3NXBtSmtXV1FkCmhZMk90dWREYWR5NWFPbU9qQTJEN3dLQmdGQ1UwN3RwTU1GUTIvei9kN3NWZHdpZDFSeFdveUxZUXhVQ2dsZVkKajJJdFI1S3Z3aEZib040azF1QlVKeTRLdlZwL2Z4QjRjNW9hTDZCeS9PQUM2ekgxZkd1WUNmTFRtVWhTRmI0aApFUC9WQjVEWENKbjB2N1poMEwvNjE1UVJXTjU5d3BJQ0Q0OHpKTm91QTNzWmU1YVJFSVNVNDRDbE0rVituNjluCmZERlJBb0dBUDZ1NGxrSjg0amRjTVROVTdYeW16ZkMwSkd5aFRNcWQ2YnV4NG9FQlViSFhoOW1DaVRMSmFaV1YKN0F5NkxTV21lRGIrWEFrS0tQL2UwQVMrWElKV2p6MDI5SFdDaXM0T3NZV3VqeksrVjVaVUVkQlJNUEN0QUo4ZApCaDBvRTliSUdIOVB0RTFIdTh6NGpGaG5WUmVqdmdhMzRQdG9QV3JNL01sZnQzLy9Lazg9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
- name: tanzu-cli-myucp-user
- name: tanzu-cli-mytae-user
user:
exec:
apiVersion: client.authentication.k8s.io/v1beta1
args:
- context
- get-token
- myucp
- mytae
command: tanzu
env: []
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ func copyFile(t *testing.T, sourceFile, destFile string) {
}

func TestReadAndMinifyKubeConfig(t *testing.T) {
expectedMyucpKubeconfig := `
expectedMytaeKubeconfig := `
kind: Config
apiVersion: v1
preferences: {}
clusters:
- name: tanzu-cli-myucp/current
- name: tanzu-cli-mytae/current
cluster:
server: https://api.tanzu.cloud.vmware.com:443/org/fake-org-id
insecure-skip-tls-verify: true
users:
- name: tanzu-cli-myucp-user
- name: tanzu-cli-mytae-user
user:
exec:
command: tanzu
args:
- context
- get-token
- myucp
- mytae
env: []
apiVersion: client.authentication.k8s.io/v1beta1
provideClusterInfo: false
contexts:
- name: tanzu-cli-myucp
- name: tanzu-cli-mytae
context:
cluster: tanzu-cli-myucp/current
user: tanzu-cli-myucp-user
current-context: tanzu-cli-myucp
cluster: tanzu-cli-mytae/current
user: tanzu-cli-mytae-user
current-context: tanzu-cli-mytae
`

expectedFooContextKubeconfig := `
Expand Down Expand Up @@ -97,10 +97,10 @@ current-context: foo-context
assert.Equal(t, minifiedKubeconfig, wantKubeConfig)

// Test reading and minifying the kubeconfig having ExecConfig as user(AuthInfo)
minifiedKubeconfig, err = MinifyKubeConfig(config, "tanzu-cli-myucp")
minifiedKubeconfig, err = MinifyKubeConfig(config, "tanzu-cli-mytae")
assert.NoError(t, err)
wantKubeConfig = &Config{}
err = yaml.Unmarshal([]byte(expectedMyucpKubeconfig), wantKubeConfig)
err = yaml.Unmarshal([]byte(expectedMytaeKubeconfig), wantKubeConfig)
assert.NoError(t, err)
assert.Equal(t, minifiedKubeconfig, wantKubeConfig)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package kubeconfig

// Note-IMPORTANT!! The below types are copied from the client-go library and modified a bit(removed fields like extensions not necessary for UCP kubeconfig)
// Note-IMPORTANT!! The below types are copied from the client-go library and modified a bit(removed fields like extensions not necessary for TAE kubeconfig)
// to provide kubeconfig access functionality without copying the k8s.io/client-go library which would bring in the other kubernetes dependencies
// and would impose dependency constraints on the plugin developers using the tanzu-plugin-runtime library

Expand Down
42 changes: 21 additions & 21 deletions ucp/ucp.go → tae/tae.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2023 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Package ucp provides APIs specific to ucp
package ucp
// Package tae provides APIs specific to Tanzu Application Engine(TAE)
package tae

import (
"bytes"
Expand All @@ -16,14 +16,14 @@ import (

"github.com/vmware-tanzu/tanzu-plugin-runtime/config"
configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types"
"github.com/vmware-tanzu/tanzu-plugin-runtime/ucp/internal/kubeconfig"
"github.com/vmware-tanzu/tanzu-plugin-runtime/tae/internal/kubeconfig"
)

// keys to Context's AdditionalMetadata map
const (
OrgIDKey = "ucpOrgID"
ProjectNameKey = "ucpProjectName"
SpaceNameKey = "ucpSpaceName"
OrgIDKey = "taeOrgID"
vuil marked this conversation as resolved.
Show resolved Hide resolved
ProjectNameKey = "taeProjectName"
SpaceNameKey = "taeSpaceName"
)

const (
Expand Down Expand Up @@ -91,34 +91,34 @@ func runCommand(commandPath string, args []string, opts *cmdOptions) (bytes.Buff
return stdout, stderr, command.Run()
}

// GetKubeconfigForContext returns the kubeconfig for any arbitrary UCP resource in the UCP object hierarchy
// referred by the UCP context
// GetKubeconfigForContext returns the kubeconfig for any arbitrary TAE resource in the TAE object hierarchy
// referred by the TAE context
// Pre-reqs: project and space names should be valid
//
// Notes:
// If projectName and spaceName is empty string the kubeconfig generated would be pointing to UCP org
// If projectName and spaceName is empty string the kubeconfig generated would be pointing to TAE org
//
// ex: kubeconfig's cluster.server URL : https://endpoint/org/orgid
//
// If projectName is valid projectName and spaceName is empty string the kubeconfig generated would be pointing to UCP project
// If projectName is valid projectName and spaceName is empty string the kubeconfig generated would be pointing to TAE project
//
// ex: kubeconfig's cluster.server URL : https://endpoint/org/orgid/project/<projectName>
//
// similarly if both project and space names are valid names the kubeconfig generated would be pointing to UCP space
// similarly if both project and space names are valid names the kubeconfig generated would be pointing to TAE space
//
// ex: kubeconfig's cluster.server URL: https://endpoint/org/orgid/project/<projectName>/space/<spaceName>
func GetKubeconfigForContext(contextName, projectName, spaceName string) ([]byte, error) {
ctx, err := config.GetContext(contextName)
if err != nil {
return nil, err
}
if ctx.Target != configtypes.TargetUCP {
return nil, errors.Errorf("context must be of type: %s", configtypes.TargetUCP)
if ctx.Target != configtypes.TargetTAE {
return nil, errors.Errorf("context must be of type: %s", configtypes.TargetTAE)
}

kc, err := kubeconfig.ReadKubeConfig(ctx.ClusterOpts.Path)
if err != nil {
return nil, errors.Wrap(err, "failed to read the UCP context kubeconfig")
return nil, errors.Wrap(err, "failed to read the TAE context kubeconfig")
}

kc, err = kubeconfig.MinifyKubeConfig(kc, ctx.ClusterOpts.Context)
Expand Down Expand Up @@ -154,18 +154,18 @@ func updateKubeconfigServerURL(kc *kubeconfig.Config, cliContext *configtypes.Co
cluster.Cluster.Server = prepareClusterServerURL(cliContext, projectName, spaceName)
}

// SetUCPContextActiveResource sets the active UCP resource for the given context and also updates
// the kubeconfig referrenced by the UCP context
// SetTAEContextActiveResource sets the active TAE resource for the given context and also updates
// the kubeconfig referrenced by the TAE context
//
// Pre-reqs: project and space names should be valid
//
// Note: To set
// - a space as active resource, both project and space names are required
// - a project as active resource, only project name is required (space should be empty string)
// - org as active resource, both project and space names should be empty strings
func SetUCPContextActiveResource(contextName, projectName, spaceName string, opts ...CommandOptions) error {
func SetTAEContextActiveResource(contextName, projectName, spaceName string, opts ...CommandOptions) error {
// For now, the implementation expects env var TANZU_BIN to be set and
// pointing to the core CLI binary used to invoke setting the active UCP resource.
// pointing to the core CLI binary used to invoke setting the active TAE resource.

options := &cmdOptions{}
for _, opt := range opts {
Expand All @@ -178,12 +178,12 @@ func SetUCPContextActiveResource(contextName, projectName, spaceName string, opt
}

altCommandArgs := []string{customCommandName}
args := []string{"context", "update", "ucp-active-resource", contextName, "--project", projectName, "--space", spaceName}
args := []string{"context", "update", "tae-active-resource", contextName, "--project", projectName, "--space", spaceName}

altCommandArgs = append(altCommandArgs, args...)

// Check if there is an alternate means to set the active UCP context active resource
// operation, if not fall back to `context update ucp-active-resource`
// Check if there is an alternate means to set the active TAE context active resource
// operation, if not fall back to `context update tae-active-resource`
stdoutOutput, _, err := runCommand(cliPath, altCommandArgs, &cmdOptions{outWriter: io.Discard, errWriter: io.Discard})
if err == nil {
args = strings.Fields(stdoutOutput.String())
Expand Down
Loading