diff --git a/pkg/cmd/init/scenario/init/bootstrap_cluster_role.yaml b/pkg/cmd/init/scenario/init/bootstrap_cluster_role.yaml index 9fc60076e..daa1741bc 100644 --- a/pkg/cmd/init/scenario/init/bootstrap_cluster_role.yaml +++ b/pkg/cmd/init/scenario/init/bootstrap_cluster_role.yaml @@ -34,4 +34,9 @@ rules: - "managedclustersets/join" verbs: - "create" - \ No newline at end of file +- apiGroups: + - operator.open-cluster-management.io + resources: + - clustermanagers + verbs: + - get diff --git a/pkg/cmd/join/exec.go b/pkg/cmd/join/exec.go index ceedbf679..3a4dc239d 100644 --- a/pkg/cmd/join/exec.go +++ b/pkg/cmd/join/exec.go @@ -202,6 +202,32 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) { return err } + // check if the ManagedClusterAutoApproval is enabled + restHubConfig, err := helpers.CreateRESTConfigFromClientcmdapiv1Config(*o.HubConfig) + if err != nil { + return err + } + + operatorClient, err := operatorclient.NewForConfig(restHubConfig) + if err != nil { + return err + } + + clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Get(context.Background(), "cluster-manager", metav1.GetOptions{}) + if err != nil { + return err + } + + registrationConfiguration := clusterManager.Spec.RegistrationConfiguration + if registrationConfiguration != nil { + for _, feature := range registrationConfiguration.FeatureGates { + if feature.Feature == string(ocmfeature.ManagedClusterAutoApproval) { + o.autoApprovalEnabled = true + break + } + } + } + // get managed cluster externalServerURL var kubeClient *kubernetes.Clientset switch o.mode { @@ -355,6 +381,11 @@ func (o *Options) run() error { } } + if o.autoApprovalEnabled { + fmt.Fprintf(o.Streams.Out, "\n Your managed cluster %s has joined the Hub. Visit https://open-cluster-management.io/scenarios or https://github.com/open-cluster-management-io/OCM/tree/main/solutions for next steps.\n", o.values.ClusterName) + return nil + } + fmt.Fprintf(o.Streams.Out, "Please log onto the hub cluster and run the following command:\n\n"+ " %s accept --clusters %s\n\n", helpers.GetExampleHeader(), o.values.ClusterName) return nil diff --git a/pkg/cmd/join/options.go b/pkg/cmd/join/options.go index 2aed19436..29d819ecf 100644 --- a/pkg/cmd/join/options.go +++ b/pkg/cmd/join/options.go @@ -85,6 +85,8 @@ type Options struct { // enableSyncLabels is to enable the feature which can sync the labels from klusterlet to all agent resources. enableSyncLabels bool + + autoApprovalEnabled bool } func newOptions(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, streams genericclioptions.IOStreams) *Options {