Skip to content

Commit

Permalink
pipeline: Init pipeline api (#478)
Browse files Browse the repository at this point in the history
* pipeline: add pipeline sync api

Signed-off-by: Xieql <xieqianglong@huawei.com>

* pipeline: update api gen script

Signed-off-by: Xieql <xieqianglong@huawei.com>

* pipeline: make gen api

Signed-off-by: Xieql <xieqianglong@huawei.com>

* pipeline: update api

Signed-off-by: Xieql <xieqianglong@huawei.com>

* pipeline: update make gen

Signed-off-by: Xieql <xieqianglong@huawei.com>

* update

Signed-off-by: Xieql <xieqianglong@huawei.com>

* update

Signed-off-by: Xieql <xieqianglong@huawei.com>

* update

Signed-off-by: Xieql <xieqianglong@huawei.com>

---------

Signed-off-by: Xieql <xieqianglong@huawei.com>
  • Loading branch information
Xieql authored Dec 8, 2023
1 parent 1845798 commit bee332e
Show file tree
Hide file tree
Showing 34 changed files with 2,225 additions and 94 deletions.
477 changes: 477 additions & 0 deletions docs/content/en/references/pipeline_v1alpha1_types.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hack/gen-api-doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if ! [ -x "$(command -v gen-crd-api-reference-docs)" ]; then
util::install_tools github.com/ahmetb/gen-crd-api-reference-docs 45bac9a # 2023-03-28
fi

API_GROUPS=("cluster" "infra" "fleet" "apps" "backups")
API_GROUPS=("cluster" "infra" "fleet" "apps" "backups" "pipeline")

for APIGROUP in "${API_GROUPS[@]}"
do
Expand Down
9 changes: 8 additions & 1 deletion hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ set -o nounset
set -o pipefail

PKG_PATH=kurator.dev/kurator/pkg/client-go
APIS_PATHS=(kurator.dev/kurator/pkg/apis/cluster/v1alpha1 kurator.dev/kurator/pkg/apis/infra/v1alpha1 kurator.dev/kurator/pkg/apis/fleet/v1alpha1 kurator.dev/kurator/pkg/apis/apps/v1alpha1 kurator.dev/kurator/pkg/apis/backups/v1alpha1)
APIS_PATHS=(
kurator.dev/kurator/pkg/apis/cluster/v1alpha1
kurator.dev/kurator/pkg/apis/infra/v1alpha1
kurator.dev/kurator/pkg/apis/fleet/v1alpha1
kurator.dev/kurator/pkg/apis/apps/v1alpha1
kurator.dev/kurator/pkg/apis/backups/v1alpha1
kurator.dev/kurator/pkg/apis/pipeline/v1alpha1
)
ALL_APIS=$(IFS=, ; echo "${APIS_PATHS[*]}")

# For all commands, the working directory is the parent directory(repo root).
Expand Down
7 changes: 6 additions & 1 deletion hack/update-crdgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ kubectl kustomize "${CRD_PATH}" -o "${CRD_PATH}"/infrastructure.cluster.x-k8s.io
mv "${CRD_PATH}"/*.yaml "${OPERATOR_CHART_PATH}"/crds/

echo "Generating crd for fleet manager"
APIS_PATHS=( "./pkg/apis/fleet/..." "./pkg/apis/apps/..." "./pkg/apis/backups/...")
APIS_PATHS=(
"./pkg/apis/fleet/..."
"./pkg/apis/apps/..."
"./pkg/apis/backups/..."
"./pkg/apis/pipeline/..."
)
FLEET_CHART_PATH=${FLEET_CHART_PATH:-"manifests/charts/fleet-manager"}
for APIS_PATH in "${APIS_PATHS[@]}"
do
Expand Down

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions pkg/apis/pipeline/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright Kurator Authors.
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 v1alpha1 contains API Schema definitions for the fleet v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=pipeline.kurator.dev
// +k8s:deepcopy-gen=package
package v1alpha1
196 changes: 196 additions & 0 deletions pkg/apis/pipeline/v1alpha1/type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/*
Copyright Kurator Authors.
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 v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Namespaced,categories=kurator-dev
// +kubebuilder:subresource:status

// Pipeline is the top-level type for Kurator CI Pipeline.
type Pipeline struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec PipelineSpec `json:"spec"`
Status PipelineStatus `json:"status,omitempty"`
}

// PipelineSpec defines the desired state of a Pipeline.
type PipelineSpec struct {
// Description allows an administrator to provide a description of the pipeline.
// +optional
Description string `json:"description,omitempty"`

// Tasks is an ordered list of tasks in the pipeline, containing detailed information about each task.
// The tasks will be executed in the order they are listed.
Tasks []PipelineTask `json:"tasks"`

// SharedWorkspace is the name of the PVC. If not specified, a PVC with the Pipeline's name as prefix will be created by default.
// If not set, Kurator will create a PVC named Pipeline.name using default config
// +optional
SharedWorkspace *string `json:"sharedWorkspace,omitempty"`
}

type PipelineTask struct {
// Name is the name of the task.
Name string `json:"name"`

// PredefinedTask allows users to select a predefined task.
// Users can choose a predefined task from a set list and fill in their own parameters.
// +optional
PredefinedTask *PredefinedTask `json:"predefinedTask,omitempty"`

// CustomTask enables defining a task directly within the CRD if TaskRef is not used.
// This should only be used when TaskRef is not provided.
// +optional
CustomTask *CustomTask `json:"customTask,omitempty"`

// Retries represents how many times this task should be retried in case of task failure.
// default values is zero.
// +optional
Retries int `json:"retries,omitempty"`
}

type TaskTemplate string

const (
// GitClone is typically the first task in the entire pipeline.
// It clones the user's code repository into the workspace. This allows subsequent tasks to operate on this basis.
// Since the pipeline is linked to a specific repository's webhook, Kurator automatically retrieves the repository information when triggered by the webhook.
// Users don't need to configure additional repository information for this task, except for authentication details for private repositories.
// This Predefined Task is origin from https://github.com/tektoncd/catalog/tree/main/task/git-clone/0.9
// Here are the params that user can config:
// - git-secret-name: The name of the secret for Git basic authentication.
// Kurator uses this Git credential to clone private repositories.
// The secret is formatted as follows, and more details can be found at:
// https://kurator.dev/docs/fleet-manager/pipeline/
// - username: <cleartext username>
// - password: <cleartext password>
GitClone TaskTemplate = "git-clone"

// GoTest runs Go tests in specified packages with configurable environment
// This Predefined Task is origin from https://github.com/tektoncd/catalog/tree/main/task/golang-test/0.2/
// Here are the params that user can config:
// - packages: packages to test (default: ./...)
// - context: path to the directory to use as context (default: .)
// - version: golang version to use for builds (default: latest)
// - flags: flags to use for go test command (default: -race -cover -v)
// - GOOS: operating system target (default: linux)
// - GOARCH: architecture target (default: amd64)
// - GO111MODULE: value of module support (default: auto)
// - GOCACHE: value for go caching path (default: "")
// - GOMODCACHE: value for go module caching path (default: "")
GoTest TaskTemplate = "go-test"

// TODO: add more PredefinedTask
)

// PredefinedTask provides a structure for defining a PredefinedTask.
type PredefinedTask struct {
// Name specifies the predefined task template to be used.
// This field is required to select the appropriate PredefinedTask.
// +required
Name TaskTemplate `json:"name"`

// Params contains key-value pairs for task-specific parameters.
// The required parameters vary depending on the TaskType chosen.
// +optional
Params map[string]string `json:"params,omitempty"`
}

// CustomTask defines the specification for a user-defined task.
type CustomTask struct {
// Image specifies the Docker image name.
// More info: https://kubernetes.io/docs/concepts/containers/images
// +optional
Image string `json:"image,omitempty"`

// Command is the entrypoint array. It's not executed in a shell.
// If not provided, the image's ENTRYPOINT is used.
// Environment variables can be used in the format $(VAR_NAME).
// More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
// +optional
// +listType=atomic
Command []string `json:"command,omitempty"`

// Args are the arguments for the entrypoint.
// If not provided, the image's CMD is used.
// Supports environment variable expansion in the format $(VAR_NAME).
// More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell
// +optional
// +listType=atomic
Args []string `json:"args,omitempty"`

// List of environment variables to set in the Step.
// Cannot be updated.
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
// +listType=atomic
Env []corev1.EnvVar `json:"env,omitempty" patchStrategy:"merge" patchMergeKey:"name"`

// ResourceRequirements required by this Step.
// Cannot be updated.
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
// +optional
ResourceRequirements corev1.ResourceRequirements `json:"computeResources,omitempty"`

// Script is the contents of an executable file to execute.
// If Script is not empty, the CustomTask cannot have a Command and the Args will be passed to the Script.
// +optional
Script string `json:"script,omitempty"`
}

type PipelinePhase string

const (
// RunningPhase indicates that the associated resources are currently being created.
RunningPhase PipelinePhase = "Running"

// FailedPhase signifies that the creation of associated resources has failed.
FailedPhase PipelinePhase = "Failed"

// ReadyPhase represents the state where all associated resources have been successfully created.
ReadyPhase PipelinePhase = "Ready"
)

type PipelineStatus struct {
// Phase describes the overall state of the Pipeline.
// +optional
Phase PipelinePhase `json:"phase,omitempty"`

// EventListenerServiceName specifies the name of the service created by Kurator for event listeners.
// This name is useful for users when setting up a gateway service and routing to this service.
// +optional
EventListenerServiceName *string `json:"eventListenerServiceName,omitempty"`
}

// PipelineList contains a list of Pipeline.
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type PipelineList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Pipeline `json:"items"`
}
Loading

0 comments on commit bee332e

Please sign in to comment.