Skip to content

Commit

Permalink
Merge pull request #144 from mrbarge/backplane-session-manager
Browse files Browse the repository at this point in the history
Add service and manager flags to backplane session
  • Loading branch information
openshift-merge-robot authored Jul 10, 2023
2 parents 38d58b1 + e9c50a0 commit 897c064
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
16 changes: 16 additions & 0 deletions cmd/ocm-backplane/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ func NewCmdSession() *cobra.Command {
return validEnvs, cobra.ShellCompDirectiveNoFileComp
},
}

// Add login cmd specific flags
sessionCmd.Flags().BoolVar(
&options.Manager,
"manager",
false,
"Login to management cluster instead of the cluster itself.",
)

sessionCmd.Flags().BoolVar(
&options.Service,
"service",
false,
"Login to service cluster for the given hosted cluster or mgmt cluster.",
)

sessionCmd.Flags().BoolVarP(
&options.DeleteSession,
"delete",
Expand Down
29 changes: 26 additions & 3 deletions pkg/cli/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Options struct {

ClusterId string
ClusterName string

Manager bool
Service bool
}

var (
Expand Down Expand Up @@ -73,6 +76,26 @@ func (e *BackplaneSession) RunCommand(cmd *cobra.Command, args []string) error {
return fmt.Errorf("invalid cluster Id %s", clusterKey)
}

if e.Options.Manager {
clusterId, clusterName, err = utils.DefaultOCMInterface.GetManagingCluster(clusterId)
e.Options.Alias = clusterId
if err != nil {
return err
}

fmt.Printf("Switching to management cluster ID: %v, Name: %v\n", clusterId, clusterName)
}

if e.Options.Service {
clusterId, clusterName, err = utils.DefaultOCMInterface.GetServiceCluster(clusterId)
e.Options.Alias = clusterId
if err != nil {
return err
}

fmt.Printf("Switching to service cluster ID: %v, Name: %v\n", clusterId, clusterName)
}

// set cluster options
e.Options.ClusterName = clusterName
e.Options.ClusterId = clusterId
Expand Down Expand Up @@ -373,17 +396,17 @@ func (e *BackplaneSession) initClusterLogin(cmd *cobra.Command) error {
// Setting up the flags
err := login.LoginCmd.Flags().Set("multi", "true")
if err != nil {
return fmt.Errorf("error occered when setting multi flag %v", err)
return fmt.Errorf("error occurred when setting multi flag %v", err)
}
err = login.LoginCmd.Flags().Set("kube-path", e.Path)
if err != nil {
return fmt.Errorf("error occered when kube-path flag %v", err)
return fmt.Errorf("error occurred when kube-path flag %v", err)
}

// Execute login command
err = login.LoginCmd.RunE(cmd, []string{e.Options.ClusterId})
if err != nil {
return fmt.Errorf("error occered when login to the cluster %v", err)
return fmt.Errorf("error occurred when login to the cluster %v", err)
}
}

Expand Down

0 comments on commit 897c064

Please sign in to comment.