Skip to content

Commit

Permalink
Add temporary block on publishing workshop if set as manually managed.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamDumpleton committed Aug 8, 2023
1 parent 378cae5 commit c3ff20d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ spec:
- helmChart
- required:
- directory
- required:
- manual
properties:
path:
type: string
Expand Down Expand Up @@ -116,6 +118,8 @@ spec:
directory:
type: object
x-kubernetes-preserve-unknown-fields: true
manual:
type: object
includePaths:
type: array
items:
Expand Down
6 changes: 6 additions & 0 deletions client-programs/pkg/cmd/cluster_workshop_update_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ func loadWorkshopDefinition(name string, path string, portal string, workshopFil
unstructured.SetNestedField(workshop.Object, workshopVersion, "spec", "version")
}

// Remove the publish section as will not be accurate after publising.

unstructured.RemoveNestedField(workshop.Object, "spec", "publish", "files")

unstructured.SetNestedField(workshop.Object, []interface{}{map[string]interface{}{"manual": map[string]interface{}{}}}, "spec", "publish", "files")

return workshop, nil
}

Expand Down
6 changes: 6 additions & 0 deletions client-programs/pkg/cmd/workshop_export_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func (o *FilesExportOptions) Export(directory string) error {
unstructured.SetNestedField(workshop.Object, o.WorkshopVersion, "spec", "version")
}

// Remove the publish section as will not be accurate after publising.

unstructured.RemoveNestedField(workshop.Object, "spec", "publish", "files")

unstructured.SetNestedField(workshop.Object, []interface{}{map[string]interface{}{"manual": map[string]interface{}{}}}, "spec", "publish", "files")

// Export modified workshop definition file.

workshopFileData, err = yaml.Marshal(&workshop.Object)
Expand Down
12 changes: 12 additions & 0 deletions client-programs/pkg/cmd/workshop_publish_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ func (o *FilesPublishOptions) Publish(directory string) error {
defer confUI.Flush()

if fileArtifacts, found, _ := unstructured.NestedSlice(workshop.Object, "spec", "publish", "files"); found && len(fileArtifacts) != 0 {
if len(fileArtifacts) == 1 {
if _, found, _ := unstructured.NestedStringMap(fileArtifacts[0].(map[string]interface{}), "manual"); found {
return errors.New("workshop cannot be published")
}
}

tempDir, err := os.MkdirTemp("", "educates-imgpkg")

if err != nil {
Expand Down Expand Up @@ -305,6 +311,12 @@ func (o *FilesPublishOptions) Publish(directory string) error {
unstructured.SetNestedField(workshop.Object, o.WorkshopVersion, "spec", "version")
}

// Remove the publish section as will not be accurate after publising.

unstructured.RemoveNestedField(workshop.Object, "spec", "publish", "files")

unstructured.SetNestedField(workshop.Object, []interface{}{map[string]interface{}{"manual": map[string]interface{}{}}}, "spec", "publish", "files")

workshopFileData, err = yaml.Marshal(&workshop.Object)

if err != nil {
Expand Down

0 comments on commit c3ff20d

Please sign in to comment.