Skip to content

Commit

Permalink
feat(TKC-1466): define initial expressions language tags schema in th…
Browse files Browse the repository at this point in the history
…e TestWorkflow objects (#221)
  • Loading branch information
rangoo94 authored Feb 27, 2024
1 parent 6396dbe commit 1852257
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 319 deletions.
8 changes: 4 additions & 4 deletions api/testworkflows/v1/base_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ type TestWorkflowSpecBase struct {
Config map[string]ParameterSchema `json:"config,omitempty"`

// global content that should be fetched into all containers
Content *Content `json:"content,omitempty"`
Content *Content `json:"content,omitempty" expr:"include"`

// defaults for the containers for all the TestWorkflow steps
Container *ContainerConfig `json:"container,omitempty"`
Container *ContainerConfig `json:"container,omitempty" expr:"include"`

// configuration for the scheduled job
Job *JobConfig `json:"job,omitempty"`
Job *JobConfig `json:"job,omitempty" expr:"include"`

// configuration for the scheduled pod
Pod *PodConfig `json:"pod,omitempty"`
Pod *PodConfig `json:"pod,omitempty" expr:"include"`
}
22 changes: 11 additions & 11 deletions api/testworkflows/v1/content_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ import (

type ContentGit struct {
// uri for the Git repository
Uri string `json:"uri,omitempty"`
Uri string `json:"uri,omitempty" expr:"template"`
// branch, commit or a tag name to fetch
Revision string `json:"revision,omitempty"`
Revision string `json:"revision,omitempty" expr:"template"`
// plain text username to fetch with
Username string `json:"username,omitempty"`
Username string `json:"username,omitempty" expr:"template"`
// external username to fetch with
UsernameFrom *corev1.EnvVarSource `json:"usernameFrom,omitempty"`
// plain text token to fetch with
Token string `json:"token,omitempty"`
Token string `json:"token,omitempty" expr:"template"`
// external token to fetch with
TokenFrom *corev1.EnvVarSource `json:"tokenFrom,omitempty"`
// authorization type for the credentials
AuthType testsv3.GitAuthType `json:"authType,omitempty"`
AuthType testsv3.GitAuthType `json:"authType,omitempty" expr:"template"`
// where to mount the fetched repository contents (defaults to "repo" directory in the data volume)
MountPath string `json:"mountPath,omitempty"`
MountPath string `json:"mountPath,omitempty" expr:"template"`
// paths to fetch for the sparse checkout
Paths []string `json:"paths,omitempty"`
Paths []string `json:"paths,omitempty" expr:"template"`
}

type ContentFile struct {
// path where the file should be accessible at
// +kubebuilder:validation:MinLength=1
Path string `json:"path"`
Path string `json:"path" expr:"template"`
// plain-text content to put inside
Content string `json:"content,omitempty"`
Content string `json:"content,omitempty" expr:"template"`
// external source to use
ContentFrom *corev1.EnvVarSource `json:"contentFrom,omitempty"`
// mode to use for the file
Expand All @@ -41,7 +41,7 @@ type ContentFile struct {

type Content struct {
// git repository details
Git *ContentGit `json:"git,omitempty"`
Git *ContentGit `json:"git,omitempty" expr:"include"`
// files to load
Files []ContentFile `json:"files,omitempty"`
Files []ContentFile `json:"files,omitempty" expr:"include"`
}
50 changes: 25 additions & 25 deletions api/testworkflows/v1/step_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ type RetryPolicy struct {
Count int32 `json:"count,omitempty"`

// until when it should retry (defaults to: "passed")
Until Expression `json:"until,omitempty"`
Until string `json:"until,omitempty" expr:"expression"`
}

type StepBase struct {
// readable name for the step
Name string `json:"name,omitempty"`
Name string `json:"name,omitempty" expr:"template"`

// expression to declare under which conditions the step should be run
// defaults to: "passed", except artifacts where it defaults to "always"
Condition Expression `json:"condition,omitempty"`
Condition string `json:"condition,omitempty" expr:"expression"`

// is the step expected to fail
Negative bool `json:"negative,omitempty"`
Expand All @@ -30,7 +30,7 @@ type StepBase struct {
VirtualGroup bool `json:"virtualGroup,omitempty"`

// policy for retrying the step
Retry *RetryPolicy `json:"retry,omitempty"`
Retry *RetryPolicy `json:"retry,omitempty" expr:"include"`

// maximum time this step may take
// +kubebuilder:validation:Pattern=^((0|[1-9][0-9]*)h)?((0|[1-9][0-9]*)m)?((0|[1-9][0-9]*)s)?((0|[1-9][0-9]*)ms)?$
Expand All @@ -41,49 +41,49 @@ type StepBase struct {
Delay string `json:"delay,omitempty"`

// content that should be fetched for this step
Content *Content `json:"content,omitempty"`
Content *Content `json:"content,omitempty" expr:"include"`

// script to run in a default shell for the container
Shell string `json:"shell,omitempty"`
Shell string `json:"shell,omitempty" expr:"template"`

// run specific container in the current step
Run *StepRun `json:"run,omitempty"`
Run *StepRun `json:"run,omitempty" expr:"include"`

// working directory to use for this step
WorkingDir *string `json:"workingDir,omitempty"`
WorkingDir *string `json:"workingDir,omitempty" expr:"template"`

// defaults for the containers in this step
Container *ContainerConfig `json:"container,omitempty"`
Container *ContainerConfig `json:"container,omitempty" expr:"include"`

// execute other Testkube resources
Execute *StepExecute `json:"execute,omitempty"`
Execute *StepExecute `json:"execute,omitempty" expr:"include"`

// scrape artifacts from the volumes
Artifacts *StepArtifacts `json:"artifacts,omitempty"`
Artifacts *StepArtifacts `json:"artifacts,omitempty" expr:"include"`
}

type IndependentStep struct {
StepBase `json:",inline"`
StepBase `json:",inline" expr:"include"`

// sub-steps to run
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Steps []IndependentStep `json:"steps,omitempty"`
Steps []IndependentStep `json:"steps,omitempty" expr:"include"`
}

type Step struct {
StepBase `json:",inline"`
StepBase `json:",inline" expr:"include"`

// multiple templates to include in this step
Use []TemplateRef `json:"use,omitempty"`
Use []TemplateRef `json:"use,omitempty" expr:"include"`

// single template to run in this step
Template *TemplateRef `json:"template,omitempty"`
Template *TemplateRef `json:"template,omitempty" expr:"include"`

// sub-steps to run
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Steps []Step `json:"steps,omitempty"`
Steps []Step `json:"steps,omitempty" expr:"include"`
}

type StepRun struct {
Expand All @@ -98,34 +98,34 @@ type StepExecute struct {
Async bool `json:"async,omitempty"`

// tests to run
Tests []StepExecuteTest `json:"tests,omitempty"`
Tests []StepExecuteTest `json:"tests,omitempty" expr:"include"`

// workflows to run
Workflows []StepExecuteWorkflow `json:"workflows,omitempty"`
Workflows []StepExecuteWorkflow `json:"workflows,omitempty" expr:"include"`
}

type StepExecuteTest struct {
// test name to run
Name string `json:"name,omitempty"`
Name string `json:"name,omitempty" expr:"template"`
}

type StepExecuteWorkflow struct {
// workflow name to run
Name string `json:"name,omitempty"`
Name string `json:"name,omitempty" expr:"template"`
// configuration to pass for the workflow
Config map[string]intstr.IntOrString `json:"config,omitempty"`
Config map[string]intstr.IntOrString `json:"config,omitempty" expr:"template"`
}

type StepArtifacts struct {
// compression options for the artifacts
Compress *ArtifactCompression `json:"compress,omitempty"`
Compress *ArtifactCompression `json:"compress,omitempty" expr:"include"`
// paths to fetch from the container
Paths []string `json:"paths,omitempty"`
Paths []string `json:"paths,omitempty" expr:"template"`
}

type ArtifactCompression struct {
// artifact name
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
Name string `json:"name" expr:"template"`
}
16 changes: 8 additions & 8 deletions api/testworkflows/v1/testworkflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ type TestWorkflowSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// templates to include at a top-level of workflow
Use []TemplateRef `json:"use,omitempty"`
Use []TemplateRef `json:"use,omitempty" expr:"include"`

TestWorkflowSpecBase `json:",inline"`
TestWorkflowSpecBase `json:",inline" expr:"include"`

// steps for setting up the workflow
Setup []Step `json:"setup,omitempty"`
Setup []Step `json:"setup,omitempty" expr:"include"`

// steps to execute in the workflow
Steps []Step `json:"steps,omitempty"`
Steps []Step `json:"steps,omitempty" expr:"include"`

// steps to run at the end of the workflow
After []Step `json:"after,omitempty"`
After []Step `json:"after,omitempty" expr:"include"`
}

// TemplateRef is the reference for the template inclusion
type TemplateRef struct {
// name of the template to include
Name string `json:"name"`
// trait configuration values if needed
Config map[string]intstr.IntOrString `json:"config,omitempty"`
Config map[string]intstr.IntOrString `json:"config,omitempty" expr:"template"`
}

// +kubebuilder:object:root=true
Expand All @@ -56,7 +56,7 @@ type TestWorkflow struct {
Description string `json:"description,omitempty"`

// TestWorkflow specification
Spec TestWorkflowSpec `json:"spec"`
Spec TestWorkflowSpec `json:"spec" expr:"include"`
}

//+kubebuilder:object:root=true
Expand All @@ -65,7 +65,7 @@ type TestWorkflow struct {
type TestWorkflowList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TestWorkflow `json:"items"`
Items []TestWorkflow `json:"items" expr:"include"`
}

func init() {
Expand Down
12 changes: 6 additions & 6 deletions api/testworkflows/v1/testworkflowtemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
type TestWorkflowTemplateSpec struct {
// Important: Run "make" to regenerate code after modifying this file

TestWorkflowSpecBase `json:",inline"`
TestWorkflowSpecBase `json:",inline" expr:"include"`

// steps for setting up the workflow
Setup []IndependentStep `json:"setup,omitempty"`
Setup []IndependentStep `json:"setup,omitempty" expr:"include"`

// steps to execute in the workflow
Steps []IndependentStep `json:"steps,omitempty"`
Steps []IndependentStep `json:"steps,omitempty" expr:"include"`

// steps to run at the end of the workflow
After []IndependentStep `json:"after,omitempty"`
After []IndependentStep `json:"after,omitempty" expr:"include"`
}

// +kubebuilder:object:root=true
Expand All @@ -44,7 +44,7 @@ type TestWorkflowTemplate struct {
Description string `json:"description,omitempty"`

// TestWorkflowTemplate specification
Spec TestWorkflowTemplateSpec `json:"spec"`
Spec TestWorkflowTemplateSpec `json:"spec" expr:"include"`
}

//+kubebuilder:object:root=true
Expand All @@ -53,7 +53,7 @@ type TestWorkflowTemplate struct {
type TestWorkflowTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TestWorkflowTemplate `json:"items"`
Items []TestWorkflowTemplate `json:"items" expr:"include"`
}

func init() {
Expand Down
41 changes: 25 additions & 16 deletions api/testworkflows/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,75 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

type Expression string
type EnvVar struct {
// name of the environment variable. Must be a C_IDENTIFIER.
Name string `json:"name,omitempty" expr:"template"`

// value for the environment variable
Value string `json:"value,omitempty" expr:"template"`

// external value for the environment variable
ValueFrom *corev1.EnvVarSource `json:"valueFrom,omitempty"`
}

type ContainerConfig struct {
// override default working directory in the image (empty string to default WORKDIR for the image)
WorkingDir *string `json:"workingDir,omitempty"`
WorkingDir *string `json:"workingDir,omitempty" expr:"template"`

// image to be used for the container
Image string `json:"image,omitempty"`
Image string `json:"image,omitempty" expr:"template"`

// pulling policy for the image
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty" expr:"template"`

// environment variables to append to the container
Env []corev1.EnvVar `json:"env,omitempty"`
Env []EnvVar `json:"env,omitempty" expr:"include"`

// external environment variables to append to the container
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`

// override default command in the image (empty string to default ENTRYPOINT of the image)
Command *[]string `json:"command,omitempty"`
Command *[]string `json:"command,omitempty" expr:"template"`

// override default command in the image (empty string to default CMD of the image)
Args *[]string `json:"args,omitempty"`
Args *[]string `json:"args,omitempty" expr:"template"`

// expected resources for the container
Resources *Resources `json:"resources,omitempty"`
Resources *Resources `json:"resources,omitempty" expr:"include"`

// security context for the container
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
}

type Resources struct {
// resource limits for the container
Limits map[corev1.ResourceName]intstr.IntOrString `json:"limits,omitempty"`
Limits map[corev1.ResourceName]intstr.IntOrString `json:"limits,omitempty" expr:"template,template"`

// resource requests for the container
Requests map[corev1.ResourceName]intstr.IntOrString `json:"requests,omitempty"`
Requests map[corev1.ResourceName]intstr.IntOrString `json:"requests,omitempty" expr:"template,template"`
}

type JobConfig struct {
// labels added to the scheduled job
Labels map[string]string `json:"labels,omitempty"`
Labels map[string]string `json:"labels,omitempty" expr:"template,template"`

// annotations added to the scheduled job
Annotations map[string]string `json:"annotations,omitempty"`
Annotations map[string]string `json:"annotations,omitempty" expr:"template,template"`
}

type PodConfig struct {
// default service account name for the scheduled pod
ServiceAccountName string `json:"serviceAccountName,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty" expr:"template"`

// references to secrets with credentials for pulling the images from registry
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`

// node selector to define on which node the pod should land
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty" expr:"template,template"`

// labels added to the scheduled pod
Labels map[string]string `json:"labels,omitempty"`
Labels map[string]string `json:"labels,omitempty" expr:"template,template"`

// annotations added to the scheduled pod
Annotations map[string]string `json:"annotations,omitempty"`
Annotations map[string]string `json:"annotations,omitempty" expr:"template,template"`
}
Loading

0 comments on commit 1852257

Please sign in to comment.