Skip to content

Commit

Permalink
Ensure that clusters' apiServiceURL is honored for kubeapps cluster.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Nelson <minelson@vmware.com>
  • Loading branch information
absoludity committed Feb 22, 2023
1 parent 291d4d1 commit 6bf5238
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/kube/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ func NewClusterConfig(inClusterConfig *rest.Config, userToken string, cluster st
return config, nil
}

if cluster == clustersConfig.KubeappsClusterName {
// We cannot assume that if the cluster is the kubeapps cluster that we simply return
// the incluster config, because some users set proxies in front of their clusters in
// which case the incluster kubernetes.default will skip the proxy.
if cluster == clustersConfig.KubeappsClusterName && clusterConfig.APIServiceURL == "" {
return config, nil
}

Expand Down
33 changes: 33 additions & 0 deletions pkg/kube/cluster_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,39 @@ func TestNewClusterConfig(t *testing.T) {
BearerTokenFile: "",
},
},
{
name: "returns a cluster config with explicit apiServiceURL and cert even for the kubeapps default cluster, when specified",
userToken: "token-1",
cluster: "default",
clustersConfig: ClustersConfig{
KubeappsClusterName: "default",
Clusters: map[string]ClusterConfig{
"default": {
APIServiceURL: "https://proxy.example.com:7890",
CertificateAuthorityData: "Y2EtZmlsZS1kYXRhCg==",
CertificateAuthorityDataDecoded: "ca-file-data",
CAFile: "/tmp/ca-file-data",
},
},
},
inClusterConfig: &rest.Config{
Host: "https://something-else.example.com:6443",
BearerToken: "something-else",
BearerTokenFile: "/foo/bar",
TLSClientConfig: rest.TLSClientConfig{
CAFile: "/var/run/whatever/ca.crt",
},
},
expectedConfig: &rest.Config{
Host: "https://proxy.example.com:7890",
BearerToken: "token-1",
BearerTokenFile: "",
TLSClientConfig: rest.TLSClientConfig{
CAData: []byte("ca-file-data"),
CAFile: "/tmp/ca-file-data",
},
},
},
{
name: "returns an in-cluster config when the global packaging cluster token is specified",
userToken: "token-1",
Expand Down

0 comments on commit 6bf5238

Please sign in to comment.