@@ -21,6 +21,7 @@ import (
2121
2222 appsv1 "k8s.io/api/apps/v1"
2323 corev1 "k8s.io/api/core/v1"
24+ "sigs.k8s.io/controller-runtime/pkg/client"
2425
2526 liqov1beta1 "github.com/liqotech/liqo/apis/core/v1beta1"
2627 "github.com/liqotech/liqo/pkg/liqoctl/info"
@@ -63,21 +64,23 @@ func (l *InstallationChecker) Collect(ctx context.Context, options info.Options)
6364 if err != nil {
6465 l .AddCollectionError (fmt .Errorf ("unable to get Liqo version and cluster labels: %w" , err ))
6566 } else {
66- if err := l .collectLiqoVersion (ctrlDeployment ); err != nil {
67- l .AddCollectionError (fmt .Errorf ("unable to get Liqo version: %w" , err ))
67+ ctrlContainer , err := l .getCtrlManagerContainer (ctrlDeployment )
68+ if err != nil {
69+ l .AddCollectionError (fmt .Errorf ("unable to get Liqo instance info: %w" , err ))
70+ } else {
71+ if err := l .collectLiqoVersion (ctrlDeployment ); err != nil {
72+ l .AddCollectionError (fmt .Errorf ("unable to get Liqo version: %w" , err ))
73+ }
74+
75+ if err := l .collectClusterLabels (ctrlContainer ); err != nil {
76+ l .AddCollectionError (fmt .Errorf ("unable to get cluster labels: %w" , err ))
77+ }
78+
79+ if err := l .collectLiqoAPIServerAddr (ctx , options .CRClient , ctrlContainer ); err != nil {
80+ l .AddCollectionError (fmt .Errorf ("unable to get K8s API server: %w" , err ))
81+ }
6882 }
69-
70- if err := l .collectClusterLabels (ctrlDeployment ); err != nil {
71- l .AddCollectionError (fmt .Errorf ("unable to get cluster labels: %w" , err ))
72- }
73- }
74-
75- // Get the URL of the K8s API
76- apiAddr , err := apiserver .GetURL (ctx , options .CRClient , "" )
77- if err != nil {
78- l .AddCollectionError (fmt .Errorf ("unable to get K8s API server: %w" , err ))
7983 }
80- l .data .APIServerAddr = apiAddr
8184}
8285
8386// Format returns the collected data using a user friendly output.
@@ -86,10 +89,13 @@ func (l *InstallationChecker) Format(options info.Options) string {
8689 main .AddEntry ("Cluster ID" , string (l .data .ClusterID ))
8790 main .AddEntry ("Version" , l .data .Version )
8891 main .AddEntry ("K8s API server" , l .data .APIServerAddr )
89- labelsSection := main .AddSection ("Cluster labels" )
90- for key , val := range l .data .Labels {
91- labelsSection .AddEntry (key , val )
92+ if len (l .data .Labels ) > 0 {
93+ labelsSection := main .AddSection ("Cluster labels" )
94+ for key , val := range l .data .Labels {
95+ labelsSection .AddEntry (key , val )
96+ }
9297 }
98+
9399 return main .SprintForBox (options .Printer )
94100}
95101
@@ -108,20 +114,23 @@ func (l *InstallationChecker) GetTitle() string {
108114 return "Local installation info"
109115}
110116
111- func (l * InstallationChecker ) collectClusterLabels (ctrlDeployment * appsv1.Deployment ) error {
112- var ctrlContainer corev1.Container
113-
114- // Get the container of the controller manager
115- containers := ctrlDeployment .Spec .Template .Spec .Containers
116- for i := range containers {
117- if containers [i ].Name == ctrlManagerContainerName {
118- ctrlContainer = containers [i ]
119- }
117+ func (l * InstallationChecker ) collectLiqoAPIServerAddr (ctx context.Context , c client.Client , ctrlContainer * corev1.Container ) error {
118+ // Get the URL of the K8s API
119+ apiServerAddressOverride , _ := liqoctlutils .ExtractValuesFromArgumentList ("--api-server-address-override" , ctrlContainer .Args )
120+ apiAddr , err := apiserver .GetURL (ctx , c , apiServerAddressOverride )
121+ if err != nil {
122+ return err
120123 }
121124
125+ l .data .APIServerAddr = apiAddr
126+ return nil
127+ }
128+
129+ func (l * InstallationChecker ) collectClusterLabels (ctrlContainer * corev1.Container ) error {
122130 clusterLabelsArg , err := liqoctlutils .ExtractValuesFromArgumentList ("--cluster-labels" , ctrlContainer .Args )
123131 if err != nil {
124- return err
132+ // If the `--cluster-labels` is not found, do not return any error and keep the field empty
133+ return nil
125134 }
126135
127136 clusterLabels , err := liqoctlutils .ParseArgsMultipleValues (clusterLabelsArg , "," )
@@ -141,3 +150,15 @@ func (l *InstallationChecker) collectLiqoVersion(ctrlDeployment *appsv1.Deployme
141150 l .data .Version = version
142151 return nil
143152}
153+
154+ func (l * InstallationChecker ) getCtrlManagerContainer (ctrlDeployment * appsv1.Deployment ) (* corev1.Container , error ) {
155+ // Get the container of the controller manager
156+ containers := ctrlDeployment .Spec .Template .Spec .Containers
157+ for i := range containers {
158+ if containers [i ].Name == ctrlManagerContainerName {
159+ return & containers [i ], nil
160+ }
161+ }
162+
163+ return nil , fmt .Errorf ("invalid controller manager deployment: no container with name %q found" , ctrlManagerContainerName )
164+ }
0 commit comments