Skip to content

Commit

Permalink
Only show joined msg when auto approval enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
skeeey committed Jun 25, 2024
1 parent 261c92a commit 5860a13
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/cmd/init/scenario/init/bootstrap_cluster_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ rules:
- "managedclustersets/join"
verbs:
- "create"

- apiGroups:
- operator.open-cluster-management.io
resources:
- clustermanagers
verbs:
- get
31 changes: 31 additions & 0 deletions pkg/cmd/join/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/join/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5860a13

Please sign in to comment.