@@ -25,11 +25,10 @@ import (
2525)
2626
2727type Client struct {
28- DefaultClient client.Client
29- ClusterClient cluster.Client
30- RuntimeClient ctrlclient.Client
31- K8sConfigClient * api.Config
32- CurrentNamespace string
28+ ClusterctlClient client.Client // The clusterctl client needed to run clusterctl operations like `c.DescribeCluster()`
29+ ControllerRuntimeClient ctrlclient.Client // The Kubernetes controller-runtime client needed to run `external.Get()` to fetch any CRD as a JSON object
30+ K8sConfigClient * api.Config // This is the Kubernetes config client needed to access information from the kubeconfig like the namespace and context
31+ CurrentNamespace string
3332}
3433
3534var c * Client
@@ -46,8 +45,7 @@ func newClient() (*Client, *internal.HTTPError) {
4645
4746 clusterKubeconfig := cluster.Kubeconfig {Path : kubeconfigPath , Context : kubeContext }
4847
49- c .DefaultClient , err = client .New (clusterctlConfigPath )
50- c .DefaultClient .Init (client.InitOptions {Kubeconfig : client .Kubeconfig (clusterKubeconfig )})
48+ c .ClusterctlClient , err = client .New (clusterctlConfigPath )
5149 if err != nil {
5250 log .Error (err , "failed to create client" )
5351 return nil , internal .NewInternalError (err )
@@ -59,28 +57,28 @@ func newClient() (*Client, *internal.HTTPError) {
5957 return nil , internal .NewInternalError (err )
6058 }
6159
62- c . ClusterClient = cluster .New (clusterKubeconfig , configClient )
60+ clusterClient : = cluster .New (clusterKubeconfig , configClient )
6361
64- err = c . ClusterClient .Proxy ().CheckClusterAvailable ()
62+ err = clusterClient .Proxy ().CheckClusterAvailable ()
6563 if err != nil {
6664 log .Error (err , "failed to check cluster availability for cluster client" )
6765 return nil , & internal.HTTPError {Status : http .StatusNotFound , Message : err .Error ()}
6866 }
6967
70- c .RuntimeClient , err = c . ClusterClient .Proxy ().NewClient ()
68+ c .ControllerRuntimeClient , err = clusterClient .Proxy ().NewClient ()
7169 if err != nil {
7270 log .Error (err , "failed to create client" )
7371 return nil , internal .NewInternalError (err )
7472 }
7573
76- c .CurrentNamespace , err = c . ClusterClient .Proxy ().CurrentNamespace ()
74+ c .CurrentNamespace , err = clusterClient .Proxy ().CurrentNamespace ()
7775 if err != nil {
7876 log .Error (err , "failed to create client" )
7977 return nil , internal .NewInternalError (err )
8078 }
8179
8280 rules := clientcmd .NewDefaultClientConfigLoadingRules ()
83- rules .ExplicitPath = c . ClusterClient .Kubeconfig ().Path
81+ rules .ExplicitPath = clusterClient .Kubeconfig ().Path
8482 c .K8sConfigClient , err = rules .Load ()
8583 if err != nil {
8684 log .Error (err , "failed to create client" )
@@ -246,7 +244,7 @@ func handleManagementClusterTree(w http.ResponseWriter, r *http.Request) {
246244 return
247245 }
248246
249- tree , httpErr := internal .ConstructMultiClusterTree (c .RuntimeClient , c .K8sConfigClient )
247+ tree , httpErr := internal .ConstructMultiClusterTree (c .ControllerRuntimeClient , c .K8sConfigClient )
250248 if httpErr != nil {
251249 log .Error (httpErr , "failed to construct management cluster tree view" )
252250 http .Error (w , httpErr .Error (), httpErr .Status )
@@ -286,7 +284,7 @@ func handleDescribeClusterTree(w http.ResponseWriter, r *http.Request) {
286284 ShowTemplates : true ,
287285 }
288286
289- tree , httpErr := internal .ConstructClusterResourceTree (c .DefaultClient , dcOptions )
287+ tree , httpErr := internal .ConstructClusterResourceTree (c .ClusterctlClient , dcOptions )
290288 if httpErr != nil {
291289 log .Error (httpErr , "failed to construct resource tree for target cluster" , "clusterName" , name )
292290 http .Error (w , httpErr .Error (), httpErr .Status )
@@ -317,7 +315,7 @@ func handleCustomResourceDefinitionTree(w http.ResponseWriter, r *http.Request)
317315 namespace := r .URL .Query ().Get ("namespace" )
318316
319317 // TODO: should the runtimeClient be regenerated here?
320- object , httpErr := internal .GetCustomResource (c .RuntimeClient , kind , apiVersion , namespace , name )
318+ object , httpErr := internal .GetCustomResource (c .ControllerRuntimeClient , kind , apiVersion , namespace , name )
321319 if httpErr != nil {
322320 log .Error (httpErr , "failed to construct tree for custom resource" , "kind" , kind , "name" , name )
323321 http .Error (w , httpErr .Error (), httpErr .Status )
0 commit comments