mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-29 16:01:48 +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
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ghodss/yaml"
|
"encoding/json"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ func (wt *WorkflowTemplate) GetWorkflowManifestBytes() ([]byte, error) {
|
|||||||
Labels: wt.LatestArgo.ObjectMeta.Labels,
|
Labels: wt.LatestArgo.ObjectMeta.Labels,
|
||||||
}
|
}
|
||||||
|
|
||||||
return yaml.Marshal(wt.LatestArgo)
|
return json.Marshal(wt.LatestArgo)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -198,3 +199,32 @@ func FilePathToExtension(path string) string {
|
|||||||
|
|
||||||
return path[dotIndex+1:]
|
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) {
|
func (c *Client) CreateWorkflowTemplate(namespace string, workflowTemplate *WorkflowTemplate) (*WorkflowTemplate, error) {
|
||||||
// validate workflow template
|
// 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{
|
log.WithFields(log.Fields{
|
||||||
"Namespace": namespace,
|
"Namespace": namespace,
|
||||||
"WorkflowTemplate": workflowTemplate,
|
"WorkflowTemplate": workflowTemplate,
|
||||||
@@ -305,7 +310,7 @@ func (c *Client) CreateWorkflowTemplate(namespace string, workflowTemplate *Work
|
|||||||
return nil, util.NewUserError(codes.InvalidArgument, err.Error())
|
return nil, util.NewUserError(codes.InvalidArgument, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
workflowTemplate, err := c.createWorkflowTemplate(namespace, workflowTemplate)
|
workflowTemplate, err = c.createWorkflowTemplate(namespace, workflowTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"Namespace": namespace,
|
"Namespace": namespace,
|
||||||
@@ -320,7 +325,12 @@ func (c *Client) CreateWorkflowTemplate(namespace string, workflowTemplate *Work
|
|||||||
|
|
||||||
func (c *Client) CreateWorkflowTemplateVersion(namespace string, workflowTemplate *WorkflowTemplate) (*WorkflowTemplate, error) {
|
func (c *Client) CreateWorkflowTemplateVersion(namespace string, workflowTemplate *WorkflowTemplate) (*WorkflowTemplate, error) {
|
||||||
// validate workflow template
|
// 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{
|
log.WithFields(log.Fields{
|
||||||
"Namespace": namespace,
|
"Namespace": namespace,
|
||||||
"WorkflowTemplate": workflowTemplate,
|
"WorkflowTemplate": workflowTemplate,
|
||||||
@@ -513,7 +523,12 @@ func createArgoWorkflowTemplate(workflowTemplate *WorkflowTemplate, version stri
|
|||||||
var jsonOpts []argojson.JSONOpt
|
var jsonOpts []argojson.JSONOpt
|
||||||
jsonOpts = append(jsonOpts, argojson.DisallowUnknownFields)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"github.com/onepanelio/core/pkg/util"
|
"github.com/onepanelio/core/pkg/util"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -59,12 +60,17 @@ func apiWorkflowExecution(wf *v1.WorkflowExecution) (workflow *api.WorkflowExecu
|
|||||||
}
|
}
|
||||||
|
|
||||||
func apiWorkflowTemplate(wft *v1.WorkflowTemplate) *api.WorkflowTemplate {
|
func apiWorkflowTemplate(wft *v1.WorkflowTemplate) *api.WorkflowTemplate {
|
||||||
|
manifest, err := v1.RemoveAllButSpec(wft.GetManifestBytes())
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error - TODO @todo")
|
||||||
|
}
|
||||||
|
|
||||||
return &api.WorkflowTemplate{
|
return &api.WorkflowTemplate{
|
||||||
Uid: wft.UID,
|
Uid: wft.UID,
|
||||||
CreatedAt: wft.CreatedAt.UTC().Format(time.RFC3339),
|
CreatedAt: wft.CreatedAt.UTC().Format(time.RFC3339),
|
||||||
Name: wft.Name,
|
Name: wft.Name,
|
||||||
Version: wft.Version,
|
Version: wft.Version,
|
||||||
Manifest: wft.Manifest,
|
Manifest: string(manifest),
|
||||||
IsLatest: wft.IsLatest,
|
IsLatest: wft.IsLatest,
|
||||||
IsArchived: wft.IsArchived,
|
IsArchived: wft.IsArchived,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user