Skip to content

Commit

Permalink
apis: add cluster name to the kubernetes status api (#5644)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks authored Mar 31, 2022
1 parent b10384e commit dc45b0e
Show file tree
Hide file tree
Showing 10 changed files with 655 additions and 578 deletions.
40 changes: 25 additions & 15 deletions internal/cli/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal/controllers/core/cluster/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func KubernetesClientFromEnv(ctx context.Context, contextOverride k8s.KubeContex
return nil, err
}
minikubeClient := k8s.ProvideMinikubeClient(kubeContext)
client := k8s.ProvideK8sClient(ctx, env, restConfigOrError, clientsetOrError, portForwardClient, kubeContext, namespace, minikubeClient, clientConfig)
clusterName := k8s.ProvideClusterName(apiConfig)
client := k8s.ProvideK8sClient(ctx, env, restConfigOrError, clientsetOrError, portForwardClient, kubeContext, clusterName, namespace, minikubeClient, clientConfig)
_, err = client.CheckConnected(ctx)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions internal/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ type K8sClient struct {
restConfig *rest.Config
portForwardClient PortForwardClient
configContext KubeContext
configCluster ClusterName
configNamespace Namespace
clientset kubernetes.Interface
discovery discovery.CachedDiscoveryInterface
Expand All @@ -176,6 +177,7 @@ func ProvideK8sClient(
maybeClientset ClientsetOrError,
pfClient PortForwardClient,
configContext KubeContext,
configCluster ClusterName,
configNamespace Namespace,
mkClient MinikubeClient,
clientLoader clientcmd.ClientConfig) Client {
Expand Down Expand Up @@ -227,6 +229,7 @@ func ProvideK8sClient(
portForwardClient: pfClient,
discovery: discovery,
configContext: configContext,
configCluster: configCluster,
configNamespace: configNamespace,
clientset: clientset,
runtimeAsync: runtimeAsync,
Expand Down Expand Up @@ -366,6 +369,7 @@ func (k *K8sClient) ConnectionConfig() *v1alpha1.KubernetesClusterConnectionStat
Context: string(k.configContext),
Namespace: k.configNamespace.String(),
Product: string(k.product),
Cluster: string(k.configCluster),
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/k8s/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func ProvideKubeConfig(clientLoader clientcmd.ClientConfig, contextOverride Kube
return &config, nil
}

func ProvideClusterName(ctx context.Context, config *api.Config) ClusterName {
func ProvideClusterName(config *api.Config) ClusterName {
n := config.CurrentContext
c, ok := config.Contexts[n]
if !ok {
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/core/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ type KubernetesClusterConnectionStatus struct {
// The resolved default namespace.
Namespace string `json:"namespace" protobuf:"bytes,3,opt,name=namespace"`

// The resolved cluster name (as determined by the kubeconfig context).
Cluster string `json:"cluster" protobuf:"bytes,4,opt,name=cluster"`

// The product name for this cluster.
//
// For a complete list of possible product names, see:
Expand Down
Loading

0 comments on commit dc45b0e

Please sign in to comment.