Merge branch 'dev' into feat/onepanelio.core.386-migrations.update

This commit is contained in:
Andrey Melnikov
2020-08-14 14:34:20 -07:00
committed by GitHub
4 changed files with 73 additions and 39 deletions

View File

@@ -2,6 +2,7 @@ package v1
import (
"fmt"
"github.com/onepanelio/core/pkg/util/ptr"
"gopkg.in/yaml.v2"
)
@@ -78,6 +79,14 @@ func ParseParametersFromManifest(manifest []byte) ([]Parameter, error) {
return nil, err
}
// Default parameter value
for i := range manifestResult.Arguments.Parameters {
parameter := &manifestResult.Arguments.Parameters[i]
if parameter.Visibility == nil {
parameter.Visibility = ptr.String("public")
}
}
if err := IsValidParameters(manifestResult.Arguments.Parameters); err != nil {
return nil, err
}

View File

@@ -173,8 +173,25 @@ func injectContainerResourceQuotas(wf *wfv1.Workflow, template *wfv1.Template, s
if option != nil && option.Resources.Limits != nil {
// If a node is selected specifically, match the resources request to limits
option.Resources.Requests = option.Resources.Limits
if template.Container != nil {
template.Container.Resources = option.Resources
}
if template.Script != nil {
template.Script.Container.Resources = option.Resources
}
}
}
func injectEnvironmentVariables(container *corev1.Container, systemConfig SystemConfig) {
//Generate ENV vars from secret, if there is a container present in the workflow
//Get template ENV vars, avoid over-writing them with secret values
env.AddDefaultEnvVarsToContainer(container)
env.PrependEnvVarToContainer(container, "ONEPANEL_API_URL", systemConfig["ONEPANEL_API_URL"])
env.PrependEnvVarToContainer(container, "ONEPANEL_FQDN", systemConfig["ONEPANEL_FQDN"])
env.PrependEnvVarToContainer(container, "ONEPANEL_DOMAIN", systemConfig["ONEPANEL_DOMAIN"])
env.PrependEnvVarToContainer(container, "ONEPANEL_PROVIDER", systemConfig["ONEPANEL_PROVIDER"])
env.PrependEnvVarToContainer(container, "ONEPANEL_RESOURCE_NAMESPACE", "{{workflow.namespace}}")
env.PrependEnvVarToContainer(container, "ONEPANEL_RESOURCE_UID", "{{workflow.name}}")
}
func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts *WorkflowExecutionOptions) (err error) {
@@ -226,16 +243,25 @@ func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts
}
template.Metadata.Annotations["sidecar.istio.io/inject"] = "false"
if template.Container == nil {
continue
}
if template.Container != nil {
// Mount dev/shm
template.Container.VolumeMounts = append(template.Container.VolumeMounts, corev1.VolumeMount{
Name: "sys-dshm",
MountPath: "/dev/shm",
})
injectContainerResourceQuotas(wf, template, systemConfig)
injectEnvironmentVariables(template.Container, systemConfig)
}
if template.Script != nil {
injectContainerResourceQuotas(wf, template, systemConfig)
injectEnvironmentVariables(&template.Script.Container, systemConfig)
}
if template.Container != nil || template.Script != nil {
// Always add output artifacts for metrics but make them optional
template.Outputs.Artifacts = append(template.Outputs.Artifacts, wfv1.Artifact{
Name: "sys-metrics",
@@ -256,18 +282,7 @@ func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts
injectArtifactRepositoryConfig(&artifact, namespaceConfig)
template.Inputs.Artifacts[j] = artifact
}
injectContainerResourceQuotas(wf, template, systemConfig)
//Generate ENV vars from secret, if there is a container present in the workflow
//Get template ENV vars, avoid over-writing them with secret values
env.AddDefaultEnvVarsToContainer(template.Container)
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_API_URL", systemConfig["ONEPANEL_API_URL"])
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_FQDN", systemConfig["ONEPANEL_FQDN"])
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_DOMAIN", systemConfig["ONEPANEL_DOMAIN"])
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_PROVIDER", systemConfig["ONEPANEL_PROVIDER"])
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_RESOURCE_NAMESPACE", "{{workflow.namespace}}")
env.PrependEnvVarToContainer(template.Container, "ONEPANEL_RESOURCE_UID", "{{workflow.name}}")
}
}
return

View File

@@ -138,6 +138,16 @@ func injectWorkspaceSystemParameters(namespace string, workspace *Workspace, wor
// WorkspaceTemplate.WorkflowTemplate.UID
// WorkspaceTemplate.WorkflowTemplate.Version
func (c *Client) createWorkspace(namespace string, parameters []byte, workspace *Workspace) (*Workspace, error) {
if workspace == nil {
return nil, fmt.Errorf("workspace is nil")
}
if workspace.WorkspaceTemplate == nil {
return nil, fmt.Errorf("workspace.WorkspaceTemplate is nil")
}
if workspace.WorkspaceTemplate.WorkflowTemplate == nil {
return nil, fmt.Errorf("workspace.WorkspaceTemplate.WorkflowTemplate is nil")
}
systemConfig, err := c.GetSystemConfig()
if err != nil {
return nil, err
@@ -250,7 +260,7 @@ func (c *Client) CreateWorkspace(namespace string, workspace *Workspace) (*Works
}
workspaceTemplate, err := c.GetWorkspaceTemplate(namespace, workspace.WorkspaceTemplate.UID, workspace.WorkspaceTemplate.Version)
if err != nil {
if err != nil || workspaceTemplate == nil {
return nil, util.NewUserError(codes.NotFound, "Workspace template not found.")
}
workspace.WorkspaceTemplate = workspaceTemplate

View File

@@ -137,7 +137,7 @@ func UnaryInterceptor(kubeConfig *v1.Config, db *v1.DB, sysConfig v1.SystemConfi
if dotIndex != -1 {
workspaceAndNamespace := xOriginalAuth[0:dotIndex]
pieces := strings.Split(workspaceAndNamespace, "--")
if len(pieces) > 0 {
if len(pieces) > 1 {
workspaceName := pieces[0]
namespace := pieces[1]