mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-27 23:31:27 +08:00
Revert "removed template manifest formatting based on potential need for metadata provided by user."
This reverts commit d4c919c9be.
This commit is contained in:
34
pkg/types.go
34
pkg/types.go
@@ -1,7 +1,8 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/ghodss/yaml"
|
||||
"encoding/json"
|
||||
"gopkg.in/yaml.v2"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -89,7 +90,7 @@ func (wt *WorkflowTemplate) GetWorkflowManifestBytes() ([]byte, error) {
|
||||
Labels: wt.LatestArgo.ObjectMeta.Labels,
|
||||
}
|
||||
|
||||
return yaml.Marshal(wt.LatestArgo)
|
||||
return json.Marshal(wt.LatestArgo)
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -198,3 +199,32 @@ func FilePathToExtension(path string) string {
|
||||
|
||||
return path[dotIndex+1:]
|
||||
}
|
||||
|
||||
func WrapSpecInK8s(data []byte) ([]byte, error) {
|
||||
mapping := make(map[interface{}]interface{})
|
||||
if err := yaml.Unmarshal(data, mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
contentMap := map[interface{}]interface{}{
|
||||
"metadata": make(map[interface{}]interface{}),
|
||||
"spec": mapping,
|
||||
}
|
||||
|
||||
finalBytes, err := yaml.Marshal(contentMap)
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return finalBytes, nil
|
||||
}
|
||||
|
||||
func RemoveAllButSpec(manifest []byte) ([]byte, error) {
|
||||
mapping := make(map[interface{}]interface{})
|
||||
|
||||
if err := yaml.Unmarshal(manifest, mapping); err != nil {
|
||||
return []byte{}, nil
|
||||
}
|
||||
|
||||
return yaml.Marshal(mapping["spec"])
|
||||
}
|
||||
|
||||
@@ -296,7 +296,12 @@ func (c *Client) archiveWorkflowTemplate(namespace, uid string) (bool, error) {
|
||||
|
||||
func (c *Client) CreateWorkflowTemplate(namespace string, workflowTemplate *WorkflowTemplate) (*WorkflowTemplate, error) {
|
||||
// validate workflow template
|
||||
if err := c.ValidateWorkflowExecution(namespace, workflowTemplate.GetManifestBytes()); err != nil {
|
||||
finalBytes, err := WrapSpecInK8s(workflowTemplate.GetManifestBytes())
|
||||
if err != nil {
|
||||
return nil, util.NewUserError(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
if err := c.ValidateWorkflowExecution(namespace, finalBytes); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"Namespace": namespace,
|
||||
"WorkflowTemplate": workflowTemplate,
|
||||
@@ -305,7 +310,7 @@ func (c *Client) CreateWorkflowTemplate(namespace string, workflowTemplate *Work
|
||||
return nil, util.NewUserError(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
workflowTemplate, err := c.createWorkflowTemplate(namespace, workflowTemplate)
|
||||
workflowTemplate, err = c.createWorkflowTemplate(namespace, workflowTemplate)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"Namespace": namespace,
|
||||
@@ -320,7 +325,12 @@ func (c *Client) CreateWorkflowTemplate(namespace string, workflowTemplate *Work
|
||||
|
||||
func (c *Client) CreateWorkflowTemplateVersion(namespace string, workflowTemplate *WorkflowTemplate) (*WorkflowTemplate, error) {
|
||||
// validate workflow template
|
||||
if err := c.ValidateWorkflowExecution(namespace, workflowTemplate.GetManifestBytes()); err != nil {
|
||||
finalBytes, err := WrapSpecInK8s(workflowTemplate.GetManifestBytes())
|
||||
if err != nil {
|
||||
return nil, util.NewUserError(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
if err := c.ValidateWorkflowExecution(namespace, finalBytes); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"Namespace": namespace,
|
||||
"WorkflowTemplate": workflowTemplate,
|
||||
@@ -513,7 +523,12 @@ func createArgoWorkflowTemplate(workflowTemplate *WorkflowTemplate, version stri
|
||||
var jsonOpts []argojson.JSONOpt
|
||||
jsonOpts = append(jsonOpts, argojson.DisallowUnknownFields)
|
||||
|
||||
err := yaml.Unmarshal(workflowTemplate.GetManifestBytes(), &argoWft)
|
||||
finalBytes, err := WrapSpecInK8s(workflowTemplate.GetManifestBytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal(finalBytes, &argoWft)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"github.com/onepanelio/core/pkg/util"
|
||||
"google.golang.org/grpc/codes"
|
||||
"log"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -59,12 +60,17 @@ func apiWorkflowExecution(wf *v1.WorkflowExecution) (workflow *api.WorkflowExecu
|
||||
}
|
||||
|
||||
func apiWorkflowTemplate(wft *v1.WorkflowTemplate) *api.WorkflowTemplate {
|
||||
manifest, err := v1.RemoveAllButSpec(wft.GetManifestBytes())
|
||||
if err != nil {
|
||||
log.Printf("Error - TODO @todo")
|
||||
}
|
||||
|
||||
return &api.WorkflowTemplate{
|
||||
Uid: wft.UID,
|
||||
CreatedAt: wft.CreatedAt.UTC().Format(time.RFC3339),
|
||||
Name: wft.Name,
|
||||
Version: wft.Version,
|
||||
Manifest: wft.Manifest,
|
||||
Manifest: string(manifest),
|
||||
IsLatest: wft.IsLatest,
|
||||
IsArchived: wft.IsArchived,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user