-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reconciler, event, config, webhook support for CustomRuns
This adds a reconciler for `CustomRun`s, and adds support for events and cloud events for `CustomRun`s as well. It also adds the actual CRD for `CustomRun` to `config/`, along with cluster role changes for `CustomRun`s, and adds support for `CustomRun` to the webhook. Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
- Loading branch information
Showing
23 changed files
with
706 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright 2020 The Tekton 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 | ||
# | ||
# https://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. | ||
|
||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
name: customruns.tekton.dev | ||
labels: | ||
app.kubernetes.io/instance: default | ||
app.kubernetes.io/part-of: tekton-pipelines | ||
pipeline.tekton.dev/release: "devel" | ||
version: "devel" | ||
spec: | ||
group: tekton.dev | ||
preserveUnknownFields: false | ||
versions: | ||
- name: v1beta1 | ||
served: true | ||
storage: true | ||
schema: | ||
openAPIV3Schema: | ||
type: object | ||
# One can use x-kubernetes-preserve-unknown-fields: true | ||
# at the root of the schema (and inside any properties, additionalProperties) | ||
# to get the traditional CRD behaviour that nothing is pruned, despite | ||
# setting spec.preserveUnknownProperties: false. | ||
# | ||
# See https://kubernetes.io/blog/2019/06/20/crd-structural-schema/ | ||
# See issue: https://github.com/knative/serving/issues/912 | ||
x-kubernetes-preserve-unknown-fields: true | ||
additionalPrinterColumns: | ||
- name: Succeeded | ||
type: string | ||
jsonPath: ".status.conditions[?(@.type==\"Succeeded\")].status" | ||
- name: Reason | ||
type: string | ||
jsonPath: ".status.conditions[?(@.type==\"Succeeded\")].reason" | ||
- name: StartTime | ||
type: date | ||
jsonPath: .status.startTime | ||
- name: CompletionTime | ||
type: date | ||
jsonPath: .status.completionTime | ||
# Opt into the status subresource so metadata.generation | ||
# starts to increment | ||
subresources: | ||
status: {} | ||
names: | ||
kind: CustomRun | ||
plural: customruns | ||
singular: customrun | ||
categories: | ||
- tekton | ||
- tekton-pipelines | ||
scope: Namespaced |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ rules: | |
- pipelineruns | ||
- pipelineresources | ||
- runs | ||
- customruns | ||
verbs: | ||
- create | ||
- delete | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ rules: | |
- pipelineruns | ||
- pipelineresources | ||
- runs | ||
- customruns | ||
verbs: | ||
- get | ||
- list | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright 2022 The Tekton 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 customrun | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tektoncd/pipeline/pkg/apis/config" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline" | ||
customruninformer "github.com/tektoncd/pipeline/pkg/client/injection/informers/pipeline/v1beta1/customrun" | ||
customrunreconciler "github.com/tektoncd/pipeline/pkg/client/injection/reconciler/pipeline/v1beta1/customrun" | ||
cacheclient "github.com/tektoncd/pipeline/pkg/reconciler/events/cache" | ||
cloudeventclient "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" | ||
"knative.dev/pkg/configmap" | ||
"knative.dev/pkg/controller" | ||
"knative.dev/pkg/logging" | ||
) | ||
|
||
// NewController instantiates a new controller.Impl from knative.dev/pkg/controller | ||
// This is a read-only controller, hence the SkipStatusUpdates set to true | ||
func NewController() func(context.Context, configmap.Watcher) *controller.Impl { | ||
return func(ctx context.Context, cmw configmap.Watcher) *controller.Impl { | ||
logger := logging.FromContext(ctx) | ||
customRunInformer := customruninformer.Get(ctx) | ||
|
||
configStore := config.NewStore(logger.Named("config-store")) | ||
configStore.WatchConfigs(cmw) | ||
|
||
c := &Reconciler{ | ||
cloudEventClient: cloudeventclient.Get(ctx), | ||
cacheClient: cacheclient.Get(ctx), | ||
} | ||
impl := customrunreconciler.NewImpl(ctx, c, func(impl *controller.Impl) controller.Options { | ||
return controller.Options{ | ||
AgentName: pipeline.CustomRunControllerName, | ||
ConfigStore: configStore, | ||
SkipStatusUpdates: true, | ||
} | ||
}) | ||
|
||
customRunInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue)) | ||
|
||
return impl | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
Copyright 2019 The Tekton 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 customrun | ||
|
||
import ( | ||
"context" | ||
|
||
lru "github.com/hashicorp/golang-lru" | ||
"github.com/tektoncd/pipeline/pkg/apis/config" | ||
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
customrunreconciler "github.com/tektoncd/pipeline/pkg/client/injection/reconciler/pipeline/v1beta1/customrun" | ||
"github.com/tektoncd/pipeline/pkg/reconciler/events" | ||
"github.com/tektoncd/pipeline/pkg/reconciler/events/cache" | ||
"github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" | ||
_ "github.com/tektoncd/pipeline/pkg/taskrunmetrics/fake" // Make sure the taskrunmetrics are setup | ||
"knative.dev/pkg/apis" | ||
"knative.dev/pkg/logging" | ||
pkgreconciler "knative.dev/pkg/reconciler" | ||
) | ||
|
||
// Reconciler implements controller.Reconciler for Configuration resources. | ||
type Reconciler struct { | ||
cloudEventClient cloudevent.CEClient | ||
cacheClient *lru.Cache | ||
} | ||
|
||
// Check that our Reconciler implements customrunreconciler.Interface | ||
var ( | ||
_ customrunreconciler.Interface = (*Reconciler)(nil) | ||
) | ||
|
||
// ReconcileKind compares the actual state with the desired, and attempts to | ||
// converge the two. It then updates the Status block of the CustomRun | ||
// resource with the current status of the resource. | ||
func (c *Reconciler) ReconcileKind(ctx context.Context, customRun *v1beta1.CustomRun) pkgreconciler.Event { | ||
logger := logging.FromContext(ctx) | ||
configs := config.FromContextOrDefaults(ctx) | ||
ctx = cloudevent.ToContext(ctx, c.cloudEventClient) | ||
ctx = cache.ToContext(ctx, c.cacheClient) | ||
logger.Infof("Reconciling %s", customRun.Name) | ||
|
||
// Create a copy of the CustomRun object, just in case, to avoid sync'ing changes | ||
customRunEvents := *customRun.DeepCopy() | ||
|
||
if configs.FeatureFlags.SendCloudEventsForRuns { | ||
// Custom task controllers may be sending events for "CustomRuns" associated | ||
// to the custom tasks they control. To avoid sending duplicate events, | ||
// CloudEvents for "CustomRuns" are only sent when enabled | ||
|
||
// Read and log the condition | ||
condition := customRunEvents.Status.GetCondition(apis.ConditionSucceeded) | ||
logger.Debugf("Emitting cloudevent for %s, condition: %s", customRunEvents.Name, condition) | ||
|
||
events.EmitCloudEvents(ctx, &customRunEvents) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.