Skip to content

Commit e5a4b77

Browse files
✨ Fix klusterlet-info command and update hub-info output. (#453)
* Fix `klusterlet-info` command and update `hub-info` output. Signed-off-by: Rokibul Hasan <[email protected]> * Handle Default mode of klusterlet Signed-off-by: Rokibul Hasan <[email protected]> * Print addon-manager info Signed-off-by: Rokibul Hasan <[email protected]> * Fix panic issue Signed-off-by: Rokibul Hasan <[email protected]> * Handle addon-manager case Signed-off-by: Rokibul Hasan <[email protected]> --------- Signed-off-by: Rokibul Hasan <[email protected]>
1 parent c9917bb commit e5a4b77

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

pkg/cmd/get/hubinfo/exec.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package hubinfo
44
import (
55
"context"
66
"fmt"
7+
"open-cluster-management.io/api/feature"
8+
"open-cluster-management.io/clusteradm/pkg/helpers/check"
79

810
"github.com/spf13/cobra"
911
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
@@ -59,8 +61,10 @@ const (
5961

6062
componentNameRegistrationController = "cluster-manager-registration-controller"
6163
componentNameRegistrationWebhook = "cluster-manager-registration-webhook"
64+
componentNameWorkController = "cluster-manager-work-controller"
6265
componentNameWorkWebhook = "cluster-manager-work-webhook"
6366
componentNamePlacementController = "cluster-manager-placement-controller"
67+
componentNameAddOnManagerController = "cluster-manager-addon-manager-controller"
6468
)
6569

6670
func (o *Options) run() error {
@@ -114,6 +118,10 @@ func (o *Options) printComponents() error {
114118
}
115119

116120
o.printer.Write(printer.LEVEL_0, "Components:\n")
121+
122+
if err := o.printAddOnManager(cmgr); err != nil {
123+
return err
124+
}
117125
if err := o.printRegistration(cmgr); err != nil {
118126
return err
119127
}
@@ -141,6 +149,12 @@ func (o *Options) printRegistration(cmgr *v1.ClusterManager) error {
141149

142150
func (o *Options) printWork(cmgr *v1.ClusterManager) error {
143151
o.printer.Write(printer.LEVEL_1, "Work:\n")
152+
if cmgr.Spec.WorkConfiguration != nil && check.IsFeatureEnabled(cmgr.Spec.WorkConfiguration.FeatureGates, string(feature.ManifestWorkReplicaSet)) {
153+
err := printer.PrintComponentsDeploy(o.printer, o.kubeClient, cmgr.Status.RelatedResources, componentNameWorkController)
154+
if err != nil {
155+
return err
156+
}
157+
}
144158
return printer.PrintComponentsDeploy(o.printer, o.kubeClient, cmgr.Status.RelatedResources, componentNameWorkWebhook)
145159
}
146160

@@ -149,6 +163,14 @@ func (o *Options) printPlacement(cmgr *v1.ClusterManager) error {
149163
return printer.PrintComponentsDeploy(o.printer, o.kubeClient, cmgr.Status.RelatedResources, componentNamePlacementController)
150164
}
151165

166+
func (o *Options) printAddOnManager(cmgr *v1.ClusterManager) error {
167+
if cmgr.Spec.AddOnManagerConfiguration != nil && !check.IsFeatureEnabled(cmgr.Spec.AddOnManagerConfiguration.FeatureGates, string(feature.AddonManagement)) {
168+
return nil
169+
}
170+
o.printer.Write(printer.LEVEL_1, "AddOn Manager:\n")
171+
return printer.PrintComponentsDeploy(o.printer, o.kubeClient, cmgr.Status.RelatedResources, componentNameAddOnManagerController)
172+
}
173+
152174
func (o *Options) printComponentsCRD(cmgr *v1.ClusterManager) error {
153175
o.printer.Write(printer.LEVEL_1, "CustomResourceDefinition:\n")
154176
return printer.PrintComponentsCRD(o.printer, o.crdClient, cmgr.Status.RelatedResources)

pkg/cmd/get/klusterletinfo/exec.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const (
5959

6060
componentNameRegistrationAgent = "klusterlet-registration-agent"
6161
componentNameWorkAgent = "klusterlet-work-agent"
62+
componentNameKlusterletAgent = "klusterlet-agent"
6263
)
6364

6465
func (o *Options) run() error {
@@ -136,14 +137,20 @@ func (o *Options) printRegistrationOperator() error {
136137
}
137138

138139
func (o *Options) printComponents(klet *v1.Klusterlet) error {
139-
140140
o.printer.Write(printer.LEVEL_0, "Components:\n")
141141

142-
if err := o.printRegistration(klet); err != nil {
143-
return err
144-
}
145-
if err := o.printWork(klet); err != nil {
146-
return err
142+
mode := klet.Spec.DeployOption.Mode
143+
if mode == v1.InstallModeSingleton || mode == v1.InstallModeSingletonHosted {
144+
if err := o.printAgent(klet); err != nil {
145+
return err
146+
}
147+
} else {
148+
if err := o.printRegistration(klet); err != nil {
149+
return err
150+
}
151+
if err := o.printWork(klet); err != nil {
152+
return err
153+
}
147154
}
148155
if err := o.printComponentsCRD(klet); err != nil {
149156
return err
@@ -161,6 +168,11 @@ func (o *Options) printWork(klet *v1.Klusterlet) error {
161168
return printer.PrintComponentsDeploy(o.printer, o.kubeClient, klet.Status.RelatedResources, componentNameWorkAgent)
162169
}
163170

171+
func (o *Options) printAgent(klet *v1.Klusterlet) error {
172+
o.printer.Write(printer.LEVEL_1, "Controller:\n")
173+
return printer.PrintComponentsDeploy(o.printer, o.kubeClient, klet.Status.RelatedResources, componentNameKlusterletAgent)
174+
}
175+
164176
func (o *Options) printComponentsCRD(klet *v1.Klusterlet) error {
165177
o.printer.Write(printer.LEVEL_1, "CustomResourceDefinition:\n")
166178
return printer.PrintComponentsCRD(o.printer, o.crdClient, klet.Status.RelatedResources)

pkg/helpers/check/check.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package check
33

44
import (
55
"fmt"
6-
76
"k8s.io/apimachinery/pkg/api/errors"
87
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
98
clusterclient "open-cluster-management.io/api/client/cluster/clientset/versioned"
@@ -79,3 +78,12 @@ func findResource(list *metav1.APIResourceList, resourceName string) bool {
7978
}
8079
return false
8180
}
81+
82+
func IsFeatureEnabled(featureGates []operatorv1.FeatureGate, feature string) bool {
83+
for _, fg := range featureGates {
84+
if fg.Feature == feature && fg.Mode == operatorv1.FeatureGateModeTypeEnable {
85+
return true
86+
}
87+
}
88+
return false
89+
}

0 commit comments

Comments
 (0)