Skip to content

Commit

Permalink
Add command line argument for specifying workshop file path.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Aug 6, 2023
1 parent 92ef95e commit ceeff82
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 19 deletions.
10 changes: 9 additions & 1 deletion client-programs/pkg/cmd/cluster_workshop_delete_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ClusterWorkshopDeleteOptions struct {
Path string
Kubeconfig string
Portal string
WorkshopFile string
DataValuesFlags yttcmd.DataValuesFlags
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion client-programs/pkg/cmd/cluster_workshop_deploy_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ClusterWorkshopDeployOptions struct {
Overdue string
Refresh string
Environ []string
WorkshopFile string
DataValuesFlags yttcmd.DataValuesFlags
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion client-programs/pkg/cmd/cluster_workshop_request_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ClusterWorkshopRequestOptions struct {
ParamFiles []string
ParamsFiles []string
IndexUrl string
WorkshopFile string
DataValuesFlags yttcmd.DataValuesFlags
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
14 changes: 11 additions & 3 deletions client-programs/pkg/cmd/cluster_workshop_serve_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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
}

Expand Down Expand Up @@ -256,6 +256,7 @@ type ClusterWorkshopServeOptions struct {
HugoPort int
Token string
Files bool
WorkshopFile string
DataValuesFlags yttcmd.DataValuesFlags
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
30 changes: 21 additions & 9 deletions client-programs/pkg/cmd/cluster_workshop_update_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ClusterWorkshopUpdateOptions struct {
Path string
Kubeconfig string
Portal string
WorkshopFile string
DataValuesFlags yttcmd.DataValuesFlags
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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.

Expand All @@ -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)
Expand All @@ -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
}
}

Expand Down
10 changes: 9 additions & 1 deletion client-programs/pkg/cmd/docker_workshop_delete_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
type DockerWorkshopDeleteOptions struct {
Name string
Path string
WorkshopFile string
DataValuesFlags yttcmd.DataValuesFlags
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion client-programs/pkg/cmd/docker_workshop_deploy_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type DockerWorkshopDeployOptions struct {
Cluster string
KubeConfig string
Assets string
WorkshopFile string
DataValuesFlags yttcmd.DataValuesFlags
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion client-programs/pkg/cmd/docker_workshop_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type DockerWorkshopLogsOptions struct {
Name string
Path string
Follow bool
WorkshopFile string
DataValuesFlags yttcmd.DataValuesFlags
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion client-programs/pkg/cmd/docker_workshop_open_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
type DockerWorkshopOpenOptions struct {
Name string
Path string
WorkshopFile string
DataValuesFlags yttcmd.DataValuesFlags
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit ceeff82

Please sign in to comment.