Skip to content

Commit

Permalink
Add v1 version to Task CRD
Browse files Browse the repository at this point in the history
This commit adds a v1 version of the Task CRD, and support to the webhook.
Since this version is not served, it will not be available to users.
  • Loading branch information
lbernick committed Aug 12, 2022
1 parent b754e71 commit dd90617
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"os"

defaultconfig "github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
resourcev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/resource/v1alpha1"
Expand Down Expand Up @@ -54,6 +56,8 @@ var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
v1beta1.SchemeGroupVersion.WithKind("ClusterTask"): &v1beta1.ClusterTask{},
v1beta1.SchemeGroupVersion.WithKind("TaskRun"): &v1beta1.TaskRun{},
v1beta1.SchemeGroupVersion.WithKind("PipelineRun"): &v1beta1.PipelineRun{},
// v1
v1.SchemeGroupVersion.WithKind("Task"): &v1.Task{},
}

func newDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
Expand Down Expand Up @@ -126,12 +130,27 @@ func newConfigValidationController(ctx context.Context, cmw configmap.Watcher) *
}

func newConversionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
// nolint: revive
var (
v1beta1GroupVersion = v1beta1.SchemeGroupVersion.Version
v1GroupVersion = v1.SchemeGroupVersion.Version
)
return conversion.NewConversionController(ctx,
// The path on which to serve the webhook
"/resource-conversion",

// Specify the types of custom resource definitions that should be converted
map[schema.GroupKind]conversion.GroupKindConversion{},
// "HubVersion" is the stored version, and "Zygotes" are the supported versions
map[schema.GroupKind]conversion.GroupKindConversion{
v1.Kind("Task"): {
DefinitionName: pipeline.TaskResource.String(),
HubVersion: v1beta1GroupVersion,
Zygotes: map[string]conversion.ConvertibleObject{
v1beta1GroupVersion: &v1beta1.Task{},
v1GroupVersion: &v1.Task{},
},
},
},

// A function that infuses the context passed to ConvertTo/ConvertFrom/SetDefaults with custom metadata
func(ctx context.Context) context.Context {
Expand Down
21 changes: 20 additions & 1 deletion config/300-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ spec:
# starts to increment
subresources:
status: {}
- name: v1
served: false
storage: false
schema:
openAPIV3Schema:
type: object
# TODO(#1461): Add OpenAPIV3 schema
# OpenAPIV3 schema allows Kubernetes to perform validation on the schema fields
# and use the schema in tooling such as `kubectl explain`.
# Using "x-kubernetes-preserve-unknown-fields: true"
# at the root of the schema (or within it) allows arbitrary fields.
# We currently perform our own validation separately.
# See https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#specifying-a-structural-schema
# for more info.
x-kubernetes-preserve-unknown-fields: true
# Opt into the status subresource so metadata.generation
# starts to increment
subresources:
status: {}
names:
kind: Task
plural: tasks
Expand All @@ -54,7 +73,7 @@ spec:
conversion:
strategy: Webhook
webhook:
conversionReviewVersions: ["v1beta1"]
conversionReviewVersions: ["v1beta1", "v1"]
clientConfig:
service:
name: tekton-pipelines-webhook
Expand Down

0 comments on commit dd90617

Please sign in to comment.