Skip to content

Commit

Permalink
✨ Fix klusterlet-info command and update hub-info output. (#453)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
RokibulHasan7 authored Oct 29, 2024
1 parent c9917bb commit e5a4b77
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
22 changes: 22 additions & 0 deletions pkg/cmd/get/hubinfo/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package hubinfo
import (
"context"
"fmt"
"open-cluster-management.io/api/feature"
"open-cluster-management.io/clusteradm/pkg/helpers/check"

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

componentNameRegistrationController = "cluster-manager-registration-controller"
componentNameRegistrationWebhook = "cluster-manager-registration-webhook"
componentNameWorkController = "cluster-manager-work-controller"
componentNameWorkWebhook = "cluster-manager-work-webhook"
componentNamePlacementController = "cluster-manager-placement-controller"
componentNameAddOnManagerController = "cluster-manager-addon-manager-controller"
)

func (o *Options) run() error {
Expand Down Expand Up @@ -114,6 +118,10 @@ func (o *Options) printComponents() error {
}

o.printer.Write(printer.LEVEL_0, "Components:\n")

if err := o.printAddOnManager(cmgr); err != nil {
return err
}
if err := o.printRegistration(cmgr); err != nil {
return err
}
Expand Down Expand Up @@ -141,6 +149,12 @@ func (o *Options) printRegistration(cmgr *v1.ClusterManager) error {

func (o *Options) printWork(cmgr *v1.ClusterManager) error {
o.printer.Write(printer.LEVEL_1, "Work:\n")
if cmgr.Spec.WorkConfiguration != nil && check.IsFeatureEnabled(cmgr.Spec.WorkConfiguration.FeatureGates, string(feature.ManifestWorkReplicaSet)) {
err := printer.PrintComponentsDeploy(o.printer, o.kubeClient, cmgr.Status.RelatedResources, componentNameWorkController)
if err != nil {
return err
}
}
return printer.PrintComponentsDeploy(o.printer, o.kubeClient, cmgr.Status.RelatedResources, componentNameWorkWebhook)
}

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

func (o *Options) printAddOnManager(cmgr *v1.ClusterManager) error {
if cmgr.Spec.AddOnManagerConfiguration != nil && !check.IsFeatureEnabled(cmgr.Spec.AddOnManagerConfiguration.FeatureGates, string(feature.AddonManagement)) {
return nil
}
o.printer.Write(printer.LEVEL_1, "AddOn Manager:\n")
return printer.PrintComponentsDeploy(o.printer, o.kubeClient, cmgr.Status.RelatedResources, componentNameAddOnManagerController)
}

func (o *Options) printComponentsCRD(cmgr *v1.ClusterManager) error {
o.printer.Write(printer.LEVEL_1, "CustomResourceDefinition:\n")
return printer.PrintComponentsCRD(o.printer, o.crdClient, cmgr.Status.RelatedResources)
Expand Down
24 changes: 18 additions & 6 deletions pkg/cmd/get/klusterletinfo/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (

componentNameRegistrationAgent = "klusterlet-registration-agent"
componentNameWorkAgent = "klusterlet-work-agent"
componentNameKlusterletAgent = "klusterlet-agent"
)

func (o *Options) run() error {
Expand Down Expand Up @@ -136,14 +137,20 @@ func (o *Options) printRegistrationOperator() error {
}

func (o *Options) printComponents(klet *v1.Klusterlet) error {

o.printer.Write(printer.LEVEL_0, "Components:\n")

if err := o.printRegistration(klet); err != nil {
return err
}
if err := o.printWork(klet); err != nil {
return err
mode := klet.Spec.DeployOption.Mode
if mode == v1.InstallModeSingleton || mode == v1.InstallModeSingletonHosted {
if err := o.printAgent(klet); err != nil {
return err
}
} else {
if err := o.printRegistration(klet); err != nil {
return err
}
if err := o.printWork(klet); err != nil {
return err
}
}
if err := o.printComponentsCRD(klet); err != nil {
return err
Expand All @@ -161,6 +168,11 @@ func (o *Options) printWork(klet *v1.Klusterlet) error {
return printer.PrintComponentsDeploy(o.printer, o.kubeClient, klet.Status.RelatedResources, componentNameWorkAgent)
}

func (o *Options) printAgent(klet *v1.Klusterlet) error {
o.printer.Write(printer.LEVEL_1, "Controller:\n")
return printer.PrintComponentsDeploy(o.printer, o.kubeClient, klet.Status.RelatedResources, componentNameKlusterletAgent)
}

func (o *Options) printComponentsCRD(klet *v1.Klusterlet) error {
o.printer.Write(printer.LEVEL_1, "CustomResourceDefinition:\n")
return printer.PrintComponentsCRD(o.printer, o.crdClient, klet.Status.RelatedResources)
Expand Down
10 changes: 9 additions & 1 deletion pkg/helpers/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package check

import (
"fmt"

"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterclient "open-cluster-management.io/api/client/cluster/clientset/versioned"
Expand Down Expand Up @@ -79,3 +78,12 @@ func findResource(list *metav1.APIResourceList, resourceName string) bool {
}
return false
}

func IsFeatureEnabled(featureGates []operatorv1.FeatureGate, feature string) bool {
for _, fg := range featureGates {
if fg.Feature == feature && fg.Mode == operatorv1.FeatureGateModeTypeEnable {
return true
}
}
return false
}

0 comments on commit e5a4b77

Please sign in to comment.