Skip to content

Commit ebf188d

Browse files
committed
Shipwright-Triggers
1 parent d50bf5d commit ebf188d

File tree

5 files changed

+287
-0
lines changed

5 files changed

+287
-0
lines changed

deploy/crds/shipwright.io_buildruns.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,64 @@ spec:
723723
should take to execute.
724724
format: duration
725725
type: string
726+
trigger:
727+
description: Trigger defines the scenarios where a new build should
728+
be triggered.
729+
properties:
730+
secretRef:
731+
description: SecretRef points to a local object carrying the
732+
secret token to validate webhook request.
733+
properties:
734+
name:
735+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
736+
TODO: Add other useful fields. apiVersion, kind, uid?'
737+
type: string
738+
type: object
739+
when:
740+
description: When the list of scenarios when a new build should
741+
take place.
742+
items:
743+
description: TriggerWhen a given scenario where the webhook
744+
trigger is applicable.
745+
properties:
746+
branches:
747+
description: Branches slice of branch names where the
748+
event applies.
749+
items:
750+
type: string
751+
type: array
752+
images:
753+
description: Images slice of image names where the event
754+
applies.
755+
items:
756+
type: string
757+
type: array
758+
objectRef:
759+
description: ObjectRef describes how to match a foreign
760+
resource, either by namespace/name or by label selector,
761+
plus the given object status.
762+
properties:
763+
name:
764+
description: Name target object name.
765+
type: string
766+
selector:
767+
additionalProperties:
768+
type: string
769+
description: Selector label selector.
770+
type: object
771+
status:
772+
description: Status object status.
773+
items:
774+
type: string
775+
type: array
776+
type: object
777+
type:
778+
description: Type the event type, the name of the webhook
779+
event.
780+
type: string
781+
type: object
782+
type: array
783+
type: object
726784
required:
727785
- output
728786
- source

deploy/crds/shipwright.io_builds.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,64 @@ spec:
411411
should take to execute.
412412
format: duration
413413
type: string
414+
trigger:
415+
description: Trigger defines the scenarios where a new build should
416+
be triggered.
417+
properties:
418+
secretRef:
419+
description: SecretRef points to a local object carrying the secret
420+
token to validate webhook request.
421+
properties:
422+
name:
423+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
424+
TODO: Add other useful fields. apiVersion, kind, uid?'
425+
type: string
426+
type: object
427+
when:
428+
description: When the list of scenarios when a new build should
429+
take place.
430+
items:
431+
description: TriggerWhen a given scenario where the webhook
432+
trigger is applicable.
433+
properties:
434+
branches:
435+
description: Branches slice of branch names where the event
436+
applies.
437+
items:
438+
type: string
439+
type: array
440+
images:
441+
description: Images slice of image names where the event
442+
applies.
443+
items:
444+
type: string
445+
type: array
446+
objectRef:
447+
description: ObjectRef describes how to match a foreign
448+
resource, either by namespace/name or by label selector,
449+
plus the given object status.
450+
properties:
451+
name:
452+
description: Name target object name.
453+
type: string
454+
selector:
455+
additionalProperties:
456+
type: string
457+
description: Selector label selector.
458+
type: object
459+
status:
460+
description: Status object status.
461+
items:
462+
type: string
463+
type: array
464+
type: object
465+
type:
466+
description: Type the event type, the name of the webhook
467+
event.
468+
type: string
469+
type: object
470+
type: array
471+
type: object
414472
required:
415473
- output
416474
- source

pkg/apis/build/v1alpha1/build_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ type BuildSpec struct {
103103
// +optional
104104
Sources []BuildSource `json:"sources,omitempty"`
105105

106+
// Trigger defines the scenarios where a new build should be triggered.
107+
//
108+
// +optional
109+
Trigger *Trigger `json:"trigger,omitempty"`
110+
106111
// Strategy references the BuildStrategy to use to build the container
107112
// image.
108113
Strategy Strategy `json:"strategy"`

pkg/apis/build/v1alpha1/trigger.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright The Shipwright Contributors
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
package v1alpha1
5+
6+
import (
7+
corev1 "k8s.io/api/core/v1"
8+
)
9+
10+
// WhenType represents the webhook event type.
11+
type WhenType string
12+
13+
const (
14+
// WhenPullRequest github pull-request webhook event.
15+
WhenPullRequest WhenType = "PullRequest"
16+
17+
// WhenPush git push webhook event .
18+
WhenPush WhenType = "Push"
19+
20+
// WhenImage image change event.
21+
WhenImage WhenType = "Image"
22+
23+
// WhenPipeline tekton pipeline event.
24+
WhenPipeline WhenType = "Pipeline"
25+
)
26+
27+
// ObjectRef references a local object.
28+
type ObjectRef struct {
29+
// Name target object name.
30+
//
31+
// +optional
32+
Name string `json:"name,omitempty"`
33+
34+
// Status object status.
35+
Status []string `json:"status,omitempty"`
36+
37+
// Selector label selector.
38+
//
39+
// +optional
40+
Selector map[string]string `json:"selector,omitempty"`
41+
}
42+
43+
// TriggerWhen a given scenario where the webhook trigger is applicable.
44+
type TriggerWhen struct {
45+
// Type the event type, the name of the webhook event.
46+
Type WhenType `json:"type,omitempty"`
47+
48+
// Branches slice of branch names where the event applies.
49+
//
50+
// +optional
51+
Branches []string `json:"branches,omitempty"`
52+
53+
// Images slice of image names where the event applies.
54+
//
55+
// +optional
56+
Images []string `json:"images,omitempty"`
57+
58+
// ObjectRef describes how to match a foreign resource, either by namespace/name or by label
59+
// selector, plus the given object status.
60+
//
61+
// +optional
62+
ObjectRef *ObjectRef `json:"objectRef,omitempty"`
63+
}
64+
65+
// Trigger represents the webhook trigger configuration for a Build.
66+
type Trigger struct {
67+
// When the list of scenarios when a new build should take place.
68+
When []TriggerWhen `json:"when,omitempty"`
69+
70+
// SecretRef points to a local object carrying the secret token to validate webhook request.
71+
//
72+
// +optional
73+
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"`
74+
}

pkg/apis/build/v1alpha1/zz_generated.deepcopy.go

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)