From 9bfa4dde5bfd88c63965c1288e6e4e2a35f355c4 Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Tue, 7 Sep 2021 10:50:28 +0800 Subject: [PATCH] Support to create workspacetemplate automatically (#191) --- kubectl-plugin/pipeline/create.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kubectl-plugin/pipeline/create.go b/kubectl-plugin/pipeline/create.go index 43f9883..ebe873e 100644 --- a/kubectl-plugin/pipeline/create.go +++ b/kubectl-plugin/pipeline/create.go @@ -315,7 +315,19 @@ func (o *pipelineCreateOption) checkWorkspace() (ws *unstructured.Unstructured, } // TODO check workspaceTemplate when ks in a multi-cluster environment - ws, err = o.Client.Resource(types.GetWorkspaceTemplate()).Get(ctx, o.Workspace, metav1.GetOptions{}) + if ws, err = o.Client.Resource(types.GetWorkspaceTemplate()).Get(ctx, o.Workspace, metav1.GetOptions{}); err != nil { + // create workspacetemplate + var wsTemplate *unstructured.Unstructured + if wsTemplate, err = types.GetObjectFromYaml(fmt.Sprintf(`apiVersion: tenant.kubesphere.io/v1alpha2 +kind: WorkspaceTemplate +metadata: + name: %s`, o.Workspace)); err != nil { + err = fmt.Errorf("failed to unmarshal yaml to DevOpsProject object, %v", err) + return + } + + ws, err = o.Client.Resource(types.GetWorkspaceTemplate()).Create(ctx, wsTemplate, metav1.CreateOptions{}) + } return }