From c701c2e727c2ab4d988513417289ab01709f1f43 Mon Sep 17 00:00:00 2001 From: Lee Bernick Date: Wed, 3 Aug 2022 09:33:20 -0400 Subject: [PATCH] Add v1 version to Task CRD 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. --- cmd/webhook/main.go | 21 ++++++++++++++++++++- config/300-task.yaml | 14 +++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 71d3e8135fc..30c53565662 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -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" @@ -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 { @@ -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 { diff --git a/config/300-task.yaml b/config/300-task.yaml index 2332a331bd5..1a5724b1b99 100644 --- a/config/300-task.yaml +++ b/config/300-task.yaml @@ -43,6 +43,18 @@ spec: # starts to increment subresources: status: {} + - name: v1 + served: false + storage: false + schema: + openAPIV3Schema: + type: object + # TODO: OpenAPIV3 schema + x-kubernetes-preserve-unknown-fields: true + # Opt into the status subresource so metadata.generation + # starts to increment + subresources: + status: {} names: kind: Task plural: tasks @@ -54,7 +66,7 @@ spec: conversion: strategy: Webhook webhook: - conversionReviewVersions: ["v1beta1"] + conversionReviewVersions: ["v1beta1", "v1"] clientConfig: service: name: tekton-pipelines-webhook