Skip to content

Commit

Permalink
feat: add CRD manifests for the future TestWorkflow schema (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 authored Feb 21, 2024
1 parent f70b2e7 commit c1770f0
Show file tree
Hide file tree
Showing 22 changed files with 11,119 additions and 1 deletion.
20 changes: 20 additions & 0 deletions api/testworkflows/v1/base_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v1

type TestWorkflowSpecBase struct {
// Important: Run "make" to regenerate code after modifying this file

// make the instance configurable with some input data for scheduling it
Config map[string]ParameterSchema `json:"config,omitempty"`

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

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

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

// configuration for the scheduled pod
Pod *PodConfig `json:"pod,omitempty"`
}
47 changes: 47 additions & 0 deletions api/testworkflows/v1/content_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package v1

import (
corev1 "k8s.io/api/core/v1"

testsv3 "github.com/kubeshop/testkube-operator/api/tests/v3"
)

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

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

type Content struct {
// git repository details
Git *ContentGit `json:"git,omitempty"`
// files to load
Files []ContentFile `json:"files,omitempty"`
}
33 changes: 33 additions & 0 deletions api/testworkflows/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2021.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1 contains API Schema definitions for the Test Workflows v1 API group
// +kubebuilder:object:generate=true
// +groupName=testworkflows.testkube.io
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "testworkflows.testkube.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
57 changes: 57 additions & 0 deletions api/testworkflows/v1/parameter_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package v1

import (
"k8s.io/apimachinery/pkg/util/intstr"
)

// +kubebuilder:validation:Enum=string;integer;number;boolean
type ParameterType string

const (
ParameterTypeString ParameterType = "string"
ParameterTypeInteger ParameterType = "integer"
ParameterTypeNumber ParameterType = "number"
ParameterTypeBoolean ParameterType = "boolean"
)

type ParameterStringSchema struct {
// predefined format for the string
Format string `json:"format,omitempty"`
// regular expression to match
Pattern string `json:"pattern,omitempty"`
// minimum length for the string
MinLength *int64 `json:"minLength,omitempty"`
// maximum length for the string
MaxLength *int64 `json:"maxLength,omitempty"`
}

type ParameterNumberSchema struct {
// minimum value for the number (inclusive)
Minimum *int64 `json:"minimum,omitempty"`
// maximum value for the number (inclusive)
Maximum *int64 `json:"maximum,omitempty"`
// minimum value for the number (exclusive)
ExclusiveMinimum *int64 `json:"exclusiveMinimum,omitempty"`
// maximum value for the number (exclusive)
ExclusiveMaximum *int64 `json:"exclusiveMaximum,omitempty"`
// the number needs to be multiple of this value
MultipleOf *int64 `json:"multipleOf,omitempty"`
}

type ParameterSchema struct {
// parameter description
Description string `json:"description,omitempty"`
// type of the parameter
// +kubebuilder:default=string
Type ParameterType `json:"type,omitempty"`
// the list of allowed values, when limited
Enum []string `json:"enum,omitempty"`
// exemplary value
Example *intstr.IntOrString `json:"example,omitempty"`
// default value - if not provided, the parameter is required
// +kubebuilder:validation:XIntOrString
Default *intstr.IntOrString `json:"default,omitempty"`

ParameterStringSchema `json:",inline"`
ParameterNumberSchema `json:",inline"`
}
131 changes: 131 additions & 0 deletions api/testworkflows/v1/step_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package v1

import "k8s.io/apimachinery/pkg/util/intstr"

type RetryPolicy struct {
// how many times at most it should retry
// +kubebuilder:validation:Required
// +kubebuilder:validation:Minimum=1
Count int32 `json:"count,omitempty"`

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

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

// 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"`

// is the step expected to fail
Negative bool `json:"negative,omitempty"`

// is the step optional, so its failure won't affect the TestWorkflow result
Optional bool `json:"optional,omitempty"`

// should not display it as a nested group
VirtualGroup bool `json:"virtualGroup,omitempty"`

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

// 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)?$
Timeout string `json:"timeout,omitempty"`

// delay before the step
// +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)?$
Delay string `json:"delay,omitempty"`

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

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

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

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

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

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

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

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

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

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

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

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

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

type StepRun struct {
ContainerConfig `json:",inline"`
}

type StepExecute struct {
// how many resources could be scheduled in parallel
Parallelism int32 `json:"parallelism,omitempty"`

// only schedule the resources, don't watch the results (unless it is needed for parallelism)
Async bool `json:"async,omitempty"`

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

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

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

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

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

type ArtifactCompression struct {
// artifact name
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
Name string `json:"name"`
}
73 changes: 73 additions & 0 deletions api/testworkflows/v1/testworkflow_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright 2021.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// TestWorkflowSpec defines the desired state of TestWorkflow
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"`

TestWorkflowSpecBase `json:",inline"`

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

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

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

// 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"`
}

// +kubebuilder:object:root=true

// TestWorkflow is the Schema for the workflows API
type TestWorkflow struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// TestWorkflow readable description
Description string `json:"description,omitempty"`

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

//+kubebuilder:object:root=true

// TestWorkflowList contains a list of TestWorkflow
type TestWorkflowList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TestWorkflow `json:"items"`
}

func init() {
SchemeBuilder.Register(&TestWorkflow{}, &TestWorkflowList{})
}
Loading

0 comments on commit c1770f0

Please sign in to comment.