Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9daffd1
feat(k8s): Define PipelinePodsTemplate CRD
cognifloyd Mar 12, 2022
19a183a
chore: Add crd generation targets to Makefile
cognifloyd Mar 18, 2022
718d9bd
chore: Generate client for PipelinePodsTemplate CRD
cognifloyd Mar 12, 2022
ed28cf6
chore: Generate PipelinePodsTemplate CRD manifest
cognifloyd Mar 21, 2022
5dcb8a3
feat(k8s): Add PipelinePodsTemplate loading opts
cognifloyd Mar 17, 2022
7d7f1e9
feat(k8s): Get PipelinePodsTemplate from k8s API
cognifloyd Mar 18, 2022
020421a
feat(k8s): Get defaults from PipelinePodTemplate
cognifloyd Mar 17, 2022
7c261a2
chore: Add tests for runtime WithPodsTemplate opt
cognifloyd Mar 23, 2022
f5837d7
chore: Add tests for runtime WithPodsTemplate opt (failure path)
cognifloyd Mar 23, 2022
040cbae
chore: Extend k8s SetupBuild test to use WithPodsTemplate
cognifloyd Mar 23, 2022
f8b4d5f
chore: Extend k8s SetupBuild test PipelinePodsTemplate missing in k8s
cognifloyd Mar 23, 2022
1552e6e
chore: Extend k8s SetupBuild test with mocked PipelinePodsTemplate in…
cognifloyd Mar 23, 2022
6703202
fix(kubernetes): use sigs.k8s.io/yaml instead of buildkite/yaml
cognifloyd Mar 23, 2022
77ed714
feat(kubernetes): ensure local PipelinePodsTemplate YAML is valid
cognifloyd Mar 23, 2022
5558f17
Merge branch 'master' into k8s-pods-templates
cognifloyd Mar 23, 2022
e7ca84a
chore: test ignoring k8s labels from PipelinePodsTemplate
cognifloyd Mar 23, 2022
3ac92fb
chore: test CRD with DNS or node selection
cognifloyd Mar 23, 2022
504c15f
refactor(k8s): simplify setting container.SecurityContext
cognifloyd Mar 23, 2022
2574d97
chore(kubernetes): ensure PipelinePodsTemplate contents get into Pod …
cognifloyd Mar 23, 2022
eabfd5b
chore(kubernetes): test SetupContainer with privileged container
cognifloyd Mar 23, 2022
2e6d35b
chore: satisfy lint
cognifloyd Mar 23, 2022
060d1f8
chore: Add instructional comments with links to docs
cognifloyd Mar 24, 2022
8bdca0b
Merge branch 'master' into k8s-pods-templates
cognifloyd Mar 24, 2022
097973a
Adjust comment location
cognifloyd Apr 4, 2022
156980a
chore: update opts FilePath to use _ over -
cognifloyd Apr 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(k8s): Define PipelinePodsTemplate CRD
The CRD is defined under runtime/kurbernetes/apis
Other pieces will be generated under runtime/kubernetes/generated
  • Loading branch information
cognifloyd committed Mar 21, 2022
commit 9daffd1e9a3e7f376b7abbaa0d76890710aae640
10 changes: 10 additions & 0 deletions runtime/kubernetes/apis/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

// Package apis defines the worker-config CRD and related utilities.
//
// Usage:
//
// import "github.com/go-vela/worker/runtime/kubernetes/apis"
package apis
10 changes: 10 additions & 0 deletions runtime/kubernetes/apis/vela/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

package vela

// GroupName is the group name used in this package.
const (
GroupName = "go-vela.github.io"
)
10 changes: 10 additions & 0 deletions runtime/kubernetes/apis/vela/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

// Package v1alpha1 defines version 1alpha1 of the worker-config CRD.
//
// Usage:
//
// import "github.com/go-vela/worker/runtime/kubernetes/apis/v1alpha1"
package v1alpha1
44 changes: 44 additions & 0 deletions runtime/kubernetes/apis/vela/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/go-vela/worker/runtime/kubernetes/apis/vela"
)

// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = schema.GroupVersion{Group: vela.GroupName, Version: "v1alpha1"}

// Kind takes an unqualified kind and returns a Group qualified GroupKind.
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource.
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
// SchemeBuilder initializes a scheme builder.
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme is a global function that registers this API group & version to a scheme.
AddToScheme = SchemeBuilder.AddToScheme
)

// addKnownTypes adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&PipelinePodsTemplate{},
&PipelinePodsTemplateList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)

return nil
}
116 changes: 116 additions & 0 deletions runtime/kubernetes/apis/vela/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

package v1alpha1

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

// PipelinePodsTemplate defines the config for a given worker.
type PipelinePodsTemplate struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec defines the PipelinePodsTemplate configuration for Vela Workers.
Spec PipelinePodsTemplateSpec `json:"spec,omitempty"`
}

// PipelinePodsTemplateSpec configures creation of Pipeline Pods by Vela Workers.
type PipelinePodsTemplateSpec struct {
// Template defines defaults for Pipeline Pod creation in Vela Workers.
Template PipelinePodTemplate `json:"template"`
}

// PipelinePodTemplate describes the data defaults to use when creating each pipeline pod.
type PipelinePodTemplate struct {
// Meta contains a subset of the standard object metadata (see: metav1.ObjectMeta).
Meta PipelinePodTemplateMeta `json:"metadata,omitempty"`

// Spec contains a subset of the pod configuration options (see: v1.PodSpec).
Spec PipelinePodTemplateSpec `json:"spec,omitempty"`
}

// PipelinePodTemplateMeta is a subset of metav1.ObjectMeta with meta defaults for pipeline pods.
type PipelinePodTemplateMeta struct {
// Labels is a key value map of strings to organize and categorize pods.
// More info: http://kubernetes.io/docs/user-guide/labels
Labels map[string]string `json:"labels,omitempty"`

// Annotations is a key value map of strings to store additional info on pods.
// More info: http://kubernetes.io/docs/user-guide/annotations
Annotations map[string]string `json:"annotations,omitempty"`
}

// PipelinePodTemplateSpec is (loosely) a subset of v1.PodSpec with spec defaults for pipeline pods.
type PipelinePodTemplateSpec struct {
// NodeSelector is a selector which must be true for the pipeline pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +mapType=atomic
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Affinity specifies the pipeline pod's scheduling constraints, if any.
Affinity *v1.Affinity `json:"affinity,omitempty"`
// Affinity specifies the pipeline pod's tolerations, if any.
Tolerations []v1.Toleration `json:"tolerations,omitempty"`

// DNSPolicy sets DNS policy for the pipeline pod.
// Defaults to "ClusterFirst".
// Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'.
DNSPolicy v1.DNSPolicy `json:"dnsPolicy,omitempty"`
// DNSConfig specifies the DNS parameters of a pod.
// Parameters specified here will be merged to the generated DNS
// configuration based on DNSPolicy.
DNSConfig *v1.PodDNSConfig `json:"dnsConfig,omitempty"`

// Container defines a limited set of defaults to apply to each PipelinePodsTemplate container.
// This is analogous to one entry in v1.PodSpec.Containers.
Container *PipelineContainer `json:"container,omitempty"`

// SecurityContext holds pod-level security attributes and common container settings.
// Optional: Defaults to empty. See type description for default values of each field.
SecurityContext *PipelinePodSecurityContext `json:"securityContext,omitempty"`
}

// PipelineContainer has defaults for containers in a PipelinePodsTemplate.
type PipelineContainer struct {
// SecurityContext defines the security options the container should be run with.
// If set, the fields of SecurityContext override the equivalent fields of PodSecurityContext.
// More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
SecurityContext *PipelineContainerSecurityContext `json:"securityContext,omitempty"`
}

// PipelinePodSecurityContext holds pod-level security attributes and common container settings.
type PipelinePodSecurityContext struct {
// RunAsNonRoot indicates that the container must run as a non-root user.
// If true, the Kubelet will validate the image at runtime to ensure that it
// does not run as UID 0 (root) and fail to start the container if it does.
// If unset or false, no such validation will be performed.
RunAsNonRoot *bool `json:"runAsNonRoot,omitempty"`
// Sysctls hold a list of namespaced sysctls used for the pod. Pods with unsupported
// sysctls (by the container runtime) might fail to launch.
// Note that this field cannot be set when spec.os.name is windows.
Sysctls []v1.Sysctl `json:"sysctls,omitempty"`
}

// PipelineContainerSecurityContext holds container-level security configuration.
type PipelineContainerSecurityContext struct {
// Capabilities contains the capabilities to add/drop when running containers.
// Defaults to the default set of capabilities granted by the container runtime.
// Note that this field cannot be set when spec.os.name is windows.
Capabilities *v1.Capabilities `json:"capabilities,omitempty"`
}

// PipelinePodsTemplateList is a list of Deployments.
type PipelinePodsTemplateList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata.
metav1.ListMeta `json:"metadata,omitempty"`

// Items is the list of Deployments.
Items []PipelinePodsTemplate `json:"items"`
}