Skip to content

Commit

Permalink
Support requesting CustomPath endpoint for kubeconfig with GetKubecon…
Browse files Browse the repository at this point in the history
…figForContext API
  • Loading branch information
anujc25 committed Jan 18, 2024
1 parent 8b70591 commit 4c442e9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions config/tanzu_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package config

import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -110,6 +111,8 @@ type resourceOptions struct {
spaceName string
// clusterGroupName name of the ClusterGroup
clusterGroupName string
// customPath use specified path when constructing kubeconfig
customPath string
}

type ResourceOptions func(o *resourceOptions)
Expand All @@ -129,6 +132,11 @@ func ForClusterGroup(clusterGroupName string) ResourceOptions {
o.clusterGroupName = strings.TrimSpace(clusterGroupName)
}
}
func ForCustomPath(customPath string) ResourceOptions {
return func(o *resourceOptions) {
o.customPath = customPath
}
}

// GetKubeconfigForContext returns the kubeconfig for any arbitrary Tanzu resource in the Tanzu object hierarchy
// referred by the Tanzu context
Expand Down Expand Up @@ -199,6 +207,12 @@ func GetKubeconfigForContext(contextName string, opts ...ResourceOptions) ([]byt

func prepareClusterServerURL(context *configtypes.Context, rOptions *resourceOptions) string {
serverURL := context.ClusterOpts.Endpoint

// If customPath is set, append customPath after endpoint to form endpoint URL
if rOptions.customPath != "" {
return fmt.Sprintf("%s/%s", strings.TrimRight(context.GlobalOpts.Endpoint, "/"), strings.TrimLeft(rOptions.customPath, "/"))
}

if rOptions.projectName == "" {
return serverURL
}
Expand Down

0 comments on commit 4c442e9

Please sign in to comment.