From c3ff20d6bcbb3707350c13afbb4a39394806afbf Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Tue, 8 Aug 2023 15:00:20 +1000 Subject: [PATCH] Add temporary block on publishing workshop if set as manually managed. --- .../config/11-session-manager/01-crds-workshop.yaml | 4 ++++ .../pkg/cmd/cluster_workshop_update_cmd.go | 6 ++++++ client-programs/pkg/cmd/workshop_export_cmd.go | 6 ++++++ client-programs/pkg/cmd/workshop_publish_cmd.go | 12 ++++++++++++ 4 files changed, 28 insertions(+) diff --git a/carvel-packages/training-platform/bundle/config/11-session-manager/01-crds-workshop.yaml b/carvel-packages/training-platform/bundle/config/11-session-manager/01-crds-workshop.yaml index 772a5344..866c9b06 100644 --- a/carvel-packages/training-platform/bundle/config/11-session-manager/01-crds-workshop.yaml +++ b/carvel-packages/training-platform/bundle/config/11-session-manager/01-crds-workshop.yaml @@ -88,6 +88,8 @@ spec: - helmChart - required: - directory + - required: + - manual properties: path: type: string @@ -116,6 +118,8 @@ spec: directory: type: object x-kubernetes-preserve-unknown-fields: true + manual: + type: object includePaths: type: array items: diff --git a/client-programs/pkg/cmd/cluster_workshop_update_cmd.go b/client-programs/pkg/cmd/cluster_workshop_update_cmd.go index 767f5e2b..68f3b2e8 100644 --- a/client-programs/pkg/cmd/cluster_workshop_update_cmd.go +++ b/client-programs/pkg/cmd/cluster_workshop_update_cmd.go @@ -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 } diff --git a/client-programs/pkg/cmd/workshop_export_cmd.go b/client-programs/pkg/cmd/workshop_export_cmd.go index 780a4bdf..fa37d8d5 100644 --- a/client-programs/pkg/cmd/workshop_export_cmd.go +++ b/client-programs/pkg/cmd/workshop_export_cmd.go @@ -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) diff --git a/client-programs/pkg/cmd/workshop_publish_cmd.go b/client-programs/pkg/cmd/workshop_publish_cmd.go index 983b85c5..b5722fb0 100644 --- a/client-programs/pkg/cmd/workshop_publish_cmd.go +++ b/client-programs/pkg/cmd/workshop_publish_cmd.go @@ -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 { @@ -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 {