From ceeff824862344be5394169fcc381c09380e1d42 Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Mon, 7 Aug 2023 08:45:01 +1000 Subject: [PATCH] Add command line argument for specifying workshop file path. --- .../pkg/cmd/cluster_workshop_delete_cmd.go | 10 ++++++- .../pkg/cmd/cluster_workshop_deploy_cmd.go | 10 ++++++- .../pkg/cmd/cluster_workshop_request_cmd.go | 10 ++++++- .../pkg/cmd/cluster_workshop_serve_cmd.go | 14 +++++++-- .../pkg/cmd/cluster_workshop_update_cmd.go | 30 +++++++++++++------ .../pkg/cmd/docker_workshop_delete_cmd.go | 10 ++++++- .../pkg/cmd/docker_workshop_deploy_cmd.go | 10 ++++++- .../pkg/cmd/docker_workshop_logs.go | 10 ++++++- .../pkg/cmd/docker_workshop_open_cmd.go | 10 ++++++- 9 files changed, 95 insertions(+), 19 deletions(-) diff --git a/client-programs/pkg/cmd/cluster_workshop_delete_cmd.go b/client-programs/pkg/cmd/cluster_workshop_delete_cmd.go index 7f8bf996..266fc386 100644 --- a/client-programs/pkg/cmd/cluster_workshop_delete_cmd.go +++ b/client-programs/pkg/cmd/cluster_workshop_delete_cmd.go @@ -20,6 +20,7 @@ type ClusterWorkshopDeleteOptions struct { Path string Kubeconfig string Portal string + WorkshopFile string DataValuesFlags yttcmd.DataValuesFlags } @@ -51,7 +52,7 @@ func (o *ClusterWorkshopDeleteOptions) Run() error { var workshop *unstructured.Unstructured - if workshop, err = loadWorkshopDefinition(o.Name, path, o.Portal, o.DataValuesFlags); err != nil { + if workshop, err = loadWorkshopDefinition(o.Name, path, o.Portal, o.WorkshopFile, o.DataValuesFlags); err != nil { return err } @@ -115,6 +116,13 @@ func (p *ProjectInfo) NewClusterWorkshopDeleteCmd() *cobra.Command { "name to be used for training portal and workshop name prefixes", ) + c.Flags().StringVar( + &o.WorkshopFile, + "workshop-file", + "resources/workshop.yaml", + "location of the workshop definition file", + ) + c.Flags().StringArrayVar( &o.DataValuesFlags.EnvFromStrings, "data-values-env", diff --git a/client-programs/pkg/cmd/cluster_workshop_deploy_cmd.go b/client-programs/pkg/cmd/cluster_workshop_deploy_cmd.go index c75d8d5f..cf71956f 100644 --- a/client-programs/pkg/cmd/cluster_workshop_deploy_cmd.go +++ b/client-programs/pkg/cmd/cluster_workshop_deploy_cmd.go @@ -35,6 +35,7 @@ type ClusterWorkshopDeployOptions struct { Overdue string Refresh string Environ []string + WorkshopFile string DataValuesFlags yttcmd.DataValuesFlags } @@ -63,7 +64,7 @@ func (o *ClusterWorkshopDeployOptions) Run() error { var workshop *unstructured.Unstructured - if workshop, err = loadWorkshopDefinition(o.Name, path, o.Portal, o.DataValuesFlags); err != nil { + if workshop, err = loadWorkshopDefinition(o.Name, path, o.Portal, o.WorkshopFile, o.DataValuesFlags); err != nil { return err } @@ -193,6 +194,13 @@ func (p *ProjectInfo) NewClusterWorkshopDeployCmd() *cobra.Command { "environment variable overrides for workshop", ) + c.Flags().StringVar( + &o.WorkshopFile, + "workshop-file", + "resources/workshop.yaml", + "location of the workshop definition file", + ) + c.Flags().StringArrayVar( &o.DataValuesFlags.EnvFromStrings, "data-values-env", diff --git a/client-programs/pkg/cmd/cluster_workshop_request_cmd.go b/client-programs/pkg/cmd/cluster_workshop_request_cmd.go index 3ca9f29a..308242b3 100644 --- a/client-programs/pkg/cmd/cluster_workshop_request_cmd.go +++ b/client-programs/pkg/cmd/cluster_workshop_request_cmd.go @@ -36,6 +36,7 @@ type ClusterWorkshopRequestOptions struct { ParamFiles []string ParamsFiles []string IndexUrl string + WorkshopFile string DataValuesFlags yttcmd.DataValuesFlags } @@ -111,7 +112,7 @@ func (o *ClusterWorkshopRequestOptions) Run() error { var workshop *unstructured.Unstructured - if workshop, err = loadWorkshopDefinition(o.Name, path, o.Portal, o.DataValuesFlags); err != nil { + if workshop, err = loadWorkshopDefinition(o.Name, path, o.Portal, o.WorkshopFile, o.DataValuesFlags); err != nil { return err } @@ -202,6 +203,13 @@ func (p *ProjectInfo) NewClusterWorkshopRequestCmd() *cobra.Command { "the URL to redirect to when workshop session is complete", ) + c.Flags().StringVar( + &o.WorkshopFile, + "workshop-file", + "resources/workshop.yaml", + "location of the workshop definition file", + ) + c.Flags().StringArrayVar( &o.DataValuesFlags.EnvFromStrings, "data-values-env", diff --git a/client-programs/pkg/cmd/cluster_workshop_serve_cmd.go b/client-programs/pkg/cmd/cluster_workshop_serve_cmd.go index def8b544..d1801916 100644 --- a/client-programs/pkg/cmd/cluster_workshop_serve_cmd.go +++ b/client-programs/pkg/cmd/cluster_workshop_serve_cmd.go @@ -38,7 +38,7 @@ func calculateWorkshopRoot(path string) (string, error) { return path, nil } -func calculateWorkshopName(name string, path string, portal string, dataValuesFlags yttcmd.DataValuesFlags) (string, error) { +func calculateWorkshopName(name string, path string, portal string, workshopFile string, dataValuesFlags yttcmd.DataValuesFlags) (string, error) { var err error if name == "" { @@ -47,7 +47,7 @@ func calculateWorkshopName(name string, path string, portal string, dataValuesFl var workshop *unstructured.Unstructured - if workshop, err = loadWorkshopDefinition(name, path, portal, dataValuesFlags); err != nil { + if workshop, err = loadWorkshopDefinition(name, path, portal, workshopFile, dataValuesFlags); err != nil { return "", err } @@ -256,6 +256,7 @@ type ClusterWorkshopServeOptions struct { HugoPort int Token string Files bool + WorkshopFile string DataValuesFlags yttcmd.DataValuesFlags } @@ -279,7 +280,7 @@ func (o *ClusterWorkshopServeOptions) Run() error { return err } - if name, err = calculateWorkshopName(name, path, portal, o.DataValuesFlags); err != nil { + if name, err = calculateWorkshopName(name, path, portal, o.WorkshopFile, o.DataValuesFlags); err != nil { return err } @@ -352,6 +353,13 @@ func (p *ProjectInfo) NewClusterWorkshopServeCmd() *cobra.Command { "enable download of workshop files as tarball", ) + c.Flags().StringVar( + &o.WorkshopFile, + "workshop-file", + "resources/workshop.yaml", + "location of the workshop definition file", + ) + c.Flags().StringArrayVar( &o.DataValuesFlags.EnvFromStrings, "data-values-env", diff --git a/client-programs/pkg/cmd/cluster_workshop_update_cmd.go b/client-programs/pkg/cmd/cluster_workshop_update_cmd.go index 5a382718..79162a99 100644 --- a/client-programs/pkg/cmd/cluster_workshop_update_cmd.go +++ b/client-programs/pkg/cmd/cluster_workshop_update_cmd.go @@ -31,6 +31,7 @@ type ClusterWorkshopUpdateOptions struct { Path string Kubeconfig string Portal string + WorkshopFile string DataValuesFlags yttcmd.DataValuesFlags } @@ -59,7 +60,7 @@ func (o *ClusterWorkshopUpdateOptions) Run() error { var workshop *unstructured.Unstructured - if workshop, err = loadWorkshopDefinition(o.Name, path, o.Portal, o.DataValuesFlags); err != nil { + if workshop, err = loadWorkshopDefinition(o.Name, path, o.Portal, o.WorkshopFile, o.DataValuesFlags); err != nil { return err } @@ -120,6 +121,13 @@ func (p *ProjectInfo) NewClusterWorkshopUpdateCmd() *cobra.Command { "name to be used for training portal and workshop name prefixes", ) + c.Flags().StringVar( + &o.WorkshopFile, + "workshop-file", + "resources/workshop.yaml", + "location of the workshop definition file", + ) + c.Flags().StringArrayVar( &o.DataValuesFlags.EnvFromStrings, "data-values-env", @@ -161,7 +169,7 @@ func (p *ProjectInfo) NewClusterWorkshopUpdateCmd() *cobra.Command { return c } -func loadWorkshopDefinition(name string, path string, portal string, dataValueFlags yttcmd.DataValuesFlags) (*unstructured.Unstructured, error) { +func loadWorkshopDefinition(name string, path string, portal string, workshopFile string, dataValueFlags yttcmd.DataValuesFlags) (*unstructured.Unstructured, error) { // Parse the workshop location so we can determine if it is a local file // or accessible using a HTTP/HTTPS URL. @@ -174,7 +182,7 @@ func loadWorkshopDefinition(name string, path string, portal string, dataValueFl // Check if file system path first (not HTTP/HTTPS) and if so normalize // the path. If it the path references a directory, then extend the path - // so we look for the resources/workshop.yaml file within that directory. + // so we look for the workshop file within that directory. if urlInfo.Scheme != "http" && urlInfo.Scheme != "https" { path = filepath.Clean(path) @@ -183,14 +191,18 @@ func loadWorkshopDefinition(name string, path string, portal string, dataValueFl return nil, errors.Wrap(err, "couldn't convert workshop location to absolute path") } - fileInfo, err := os.Stat(path) + if !filepath.IsAbs(workshopFile) { + fileInfo, err := os.Stat(path) - if err != nil { - return nil, errors.Wrap(err, "couldn't test if workshop location is a directory") - } + if err != nil { + return nil, errors.Wrap(err, "couldn't test if workshop location is a directory") + } - if fileInfo.IsDir() { - path = filepath.Join(path, "resources", "workshop.yaml") + if fileInfo.IsDir() { + path = filepath.Join(path, workshopFile) + } + } else { + path = workshopFile } } diff --git a/client-programs/pkg/cmd/docker_workshop_delete_cmd.go b/client-programs/pkg/cmd/docker_workshop_delete_cmd.go index 75d5cdd2..dff22f91 100644 --- a/client-programs/pkg/cmd/docker_workshop_delete_cmd.go +++ b/client-programs/pkg/cmd/docker_workshop_delete_cmd.go @@ -20,6 +20,7 @@ import ( type DockerWorkshopDeleteOptions struct { Name string Path string + WorkshopFile string DataValuesFlags yttcmd.DataValuesFlags } @@ -45,7 +46,7 @@ func (o *DockerWorkshopDeleteOptions) Run(cmd *cobra.Command) error { var workshop *unstructured.Unstructured - if workshop, err = loadWorkshopDefinition(o.Name, path, "educates-cli", o.DataValuesFlags); err != nil { + if workshop, err = loadWorkshopDefinition(o.Name, path, "educates-cli", o.WorkshopFile, o.DataValuesFlags); err != nil { return err } @@ -121,6 +122,13 @@ func (p *ProjectInfo) NewDockerWorkshopDeleteCmd() *cobra.Command { "path to local workshop directory, definition file, or URL for workshop definition file", ) + c.Flags().StringVar( + &o.WorkshopFile, + "workshop-file", + "resources/workshop.yaml", + "location of the workshop definition file", + ) + c.Flags().StringArrayVar( &o.DataValuesFlags.EnvFromStrings, "data-values-env", diff --git a/client-programs/pkg/cmd/docker_workshop_deploy_cmd.go b/client-programs/pkg/cmd/docker_workshop_deploy_cmd.go index 09737153..f9f69a7c 100644 --- a/client-programs/pkg/cmd/docker_workshop_deploy_cmd.go +++ b/client-programs/pkg/cmd/docker_workshop_deploy_cmd.go @@ -43,6 +43,7 @@ type DockerWorkshopDeployOptions struct { Cluster string KubeConfig string Assets string + WorkshopFile string DataValuesFlags yttcmd.DataValuesFlags } @@ -102,7 +103,7 @@ func (o *DockerWorkshopDeployOptions) Run(cmd *cobra.Command) error { var workshop *unstructured.Unstructured - if workshop, err = loadWorkshopDefinition("", o.Path, "educates-cli", o.DataValuesFlags); err != nil { + if workshop, err = loadWorkshopDefinition("", o.Path, "educates-cli", o.WorkshopFile, o.DataValuesFlags); err != nil { return err } @@ -497,6 +498,13 @@ func (p *ProjectInfo) NewDockerWorkshopDeployCmd() *cobra.Command { "local directory path to workshop assets", ) + c.Flags().StringVar( + &o.WorkshopFile, + "workshop-file", + "resources/workshop.yaml", + "location of the workshop definition file", + ) + c.Flags().StringArrayVar( &o.DataValuesFlags.EnvFromStrings, "data-values-env", diff --git a/client-programs/pkg/cmd/docker_workshop_logs.go b/client-programs/pkg/cmd/docker_workshop_logs.go index 7ffbb59f..6ec424e1 100644 --- a/client-programs/pkg/cmd/docker_workshop_logs.go +++ b/client-programs/pkg/cmd/docker_workshop_logs.go @@ -15,6 +15,7 @@ type DockerWorkshopLogsOptions struct { Name string Path string Follow bool + WorkshopFile string DataValuesFlags yttcmd.DataValuesFlags } @@ -40,7 +41,7 @@ func (o *DockerWorkshopLogsOptions) Run(cmd *cobra.Command) error { var workshop *unstructured.Unstructured - if workshop, err = loadWorkshopDefinition(o.Name, path, "educates-cli", o.DataValuesFlags); err != nil { + if workshop, err = loadWorkshopDefinition(o.Name, path, "educates-cli", o.WorkshopFile, o.DataValuesFlags); err != nil { return err } @@ -103,6 +104,13 @@ func (p *ProjectInfo) NewDockerWorkshopLogsCmd() *cobra.Command { "specify if the logs should be streamed", ) + c.Flags().StringVar( + &o.WorkshopFile, + "workshop-file", + "resources/workshop.yaml", + "location of the workshop definition file", + ) + c.Flags().StringArrayVar( &o.DataValuesFlags.EnvFromStrings, "data-values-env", diff --git a/client-programs/pkg/cmd/docker_workshop_open_cmd.go b/client-programs/pkg/cmd/docker_workshop_open_cmd.go index 8d1af713..5f0bbd80 100644 --- a/client-programs/pkg/cmd/docker_workshop_open_cmd.go +++ b/client-programs/pkg/cmd/docker_workshop_open_cmd.go @@ -21,6 +21,7 @@ import ( type DockerWorkshopOpenOptions struct { Name string Path string + WorkshopFile string DataValuesFlags yttcmd.DataValuesFlags } @@ -46,7 +47,7 @@ func (o *DockerWorkshopOpenOptions) Run() error { var workshop *unstructured.Unstructured - if workshop, err = loadWorkshopDefinition(o.Name, path, "educates-cli", o.DataValuesFlags); err != nil { + if workshop, err = loadWorkshopDefinition(o.Name, path, "educates-cli", o.WorkshopFile, o.DataValuesFlags); err != nil { return err } @@ -136,6 +137,13 @@ func (p *ProjectInfo) NewDockerWorkshopOpenCmd() *cobra.Command { "path to local workshop directory, definition file, or URL for workshop definition file", ) + c.Flags().StringVar( + &o.WorkshopFile, + "workshop-file", + "resources/workshop.yaml", + "location of the workshop definition file", + ) + c.Flags().StringArrayVar( &o.DataValuesFlags.EnvFromStrings, "data-values-env",