Skip to content

Commit

Permalink
Merge pull request #133 from GrahamDumpleton/override-environment-name
Browse files Browse the repository at this point in the history
Add way to override environment name when requesting workshop session using CLI.
  • Loading branch information
GrahamDumpleton authored Sep 21, 2023
2 parents 65ebb38 + 71b01f4 commit 372d48c
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions client-programs/pkg/cmd/cluster_workshop_request_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ClusterWorkshopRequestOptions struct {
ParamsFiles []string
IndexUrl string
UserIdentity string
EnvironmentName string
ActivationTimeout int
NoBrowser bool
WorkshopFile string
Expand Down Expand Up @@ -131,7 +132,7 @@ func (o *ClusterWorkshopRequestOptions) Run() error {

// Request the workshop from the training portal.

err = requestWorkshop(dynamicClient, name, o.Portal, params, o.IndexUrl, o.UserIdentity, o.ActivationTimeout, o.NoBrowser)
err = requestWorkshop(dynamicClient, name, o.EnvironmentName, o.Portal, params, o.IndexUrl, o.UserIdentity, o.ActivationTimeout, o.NoBrowser)

if err != nil {
return err
Expand Down Expand Up @@ -219,6 +220,13 @@ func (p *ProjectInfo) NewClusterWorkshopRequestCmd() *cobra.Command {
"maximum time in seconds to activate the workshop",
)

c.Flags().StringVar(
&o.EnvironmentName,
"environment-name",
"",
"workshop environment name, overrides derived environment name",
)

c.Flags().BoolVar(
&o.NoBrowser,
"no-browser",
Expand Down Expand Up @@ -281,7 +289,7 @@ func (p *ProjectInfo) NewClusterWorkshopRequestCmd() *cobra.Command {
return c
}

func requestWorkshop(client dynamic.Interface, name string, portal string, params map[string]string, indexUrl string, user string, timeout int, noBrowser bool) error {
func requestWorkshop(client dynamic.Interface, name string, environmentName string, portal string, params map[string]string, indexUrl string, user string, timeout int, noBrowser bool) error {
trainingPortalClient := client.Resource(trainingPortalResource)

trainingPortal, err := trainingPortalClient.Get(context.TODO(), portal, metav1.GetOptions{})
Expand Down Expand Up @@ -455,11 +463,11 @@ func requestWorkshop(client dynamic.Interface, name string, portal string, param

// Work out the name of the workshop environment.

environmentName := ""

for _, item := range listEnvironmentsResult.Environments {
if item.Workshop.Name == name && item.State == "RUNNING" {
environmentName = item.Name
if environmentName == "" {
for _, item := range listEnvironmentsResult.Environments {
if item.Workshop.Name == name && item.State == "RUNNING" {
environmentName = item.Name
}
}
}

Expand Down

0 comments on commit 372d48c

Please sign in to comment.