Skip to content
Open
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
11 changes: 8 additions & 3 deletions pkg/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ func generateKubeconfig(ctx context.Context, c client.Client, clusterName client
return nil, ErrCertNotInKubeconfig
}

cfg, err := New(clusterName.Name, endpoint, clientCACert, clientCAKey, serverCACert)
httpProxy, err := secret.GetFromNamespacedName(ctx, c, clusterName, secret.HTTPProxy)
if err != nil {
return nil, errors.Wrap(err, "failed to retrieve HTTPProxy secret")
}

cfg, err := New(clusterName.Name, endpoint, clientCACert, clientCAKey, serverCACert, httpProxy.Data[secret.HTTPProxyKey])
if err != nil {
return nil, errors.Wrap(err, "failed to generate a kubeconfig")
}
Expand All @@ -78,7 +83,7 @@ func generateKubeconfig(ctx context.Context, c client.Client, clusterName client
}

// New creates a new Kubeconfig using the cluster name and specified endpoint.
func New(clusterName, endpoint string, clientCACert *x509.Certificate, clientCAKey crypto.Signer, serverCACert *x509.Certificate) (*api.Config, error) {
func New(clusterName, endpoint string, clientCACert *x509.Certificate, clientCAKey crypto.Signer, serverCACert *x509.Certificate, proxyURL []byte) (*api.Config, error) {
cfg := &certs.Config{
CommonName: "kubernetes-admin",
Organization: []string{"system:masters"},
Expand All @@ -97,12 +102,12 @@ func New(clusterName, endpoint string, clientCACert *x509.Certificate, clientCAK

userName := fmt.Sprintf("%s-admin", clusterName)
contextName := fmt.Sprintf("%s@%s", userName, clusterName)

return &api.Config{
Clusters: map[string]*api.Cluster{
clusterName: {
Server: endpoint,
CertificateAuthorityData: certs.EncodeCertPEM(serverCACert),
ProxyURL: string(proxyURL),
},
},
Contexts: map[string]*api.Context{
Expand Down
6 changes: 6 additions & 0 deletions pkg/secret/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const (
// FrontProxyCA is the secret name suffix for Front Proxy CA.
FrontProxyCA Purpose = "proxy"

// HTTPProxy is the secret name suffix for http Proxy.
HTTPProxy = Purpose("http-proxy-config")

// HTTPProxyKey is the key storing http Proxy.
HTTPProxyKey = "http-proxy"

// APIServerEtcdClient is the secret name of user-supplied secret containing the apiserver-etcd-client key/cert.
APIServerEtcdClient Purpose = "apiserver-etcd-client"
)
Expand Down
4 changes: 4 additions & 0 deletions pkg/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func GetFromNamespacedName(ctx context.Context, c client.Reader, clusterName cli
Name: Name(clusterName.Name, purpose),
}

if purpose == HTTPProxy {
secretKey.Name = string(purpose)
}

if err := c.Get(ctx, secretKey, secret); err != nil {
return nil, err
}
Expand Down