Skip to content

Commit e2eac40

Browse files
authored
Merge pull request fluxcd#1068 from kathleenfrench/kfrench/provider-commit-expr
feat: support CEL string expressions for custom commit statuses in v1beta3 provider type
2 parents 2763e54 + 1967bc0 commit e2eac40

30 files changed

+1053
-280
lines changed

api/v1beta3/provider_types.go

+9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const (
5555
)
5656

5757
// ProviderSpec defines the desired state of the Provider.
58+
// +kubebuilder:validation:XValidation:rule="self.type == 'github' || self.type == 'gitlab' || self.type == 'gitea' || self.type == 'bitbucketserver' || self.type == 'bitbucket' || self.type == 'azuredevops' || !has(self.commitStatusExpr)", message="spec.commitStatusExpr is only supported for the 'github', 'gitlab', 'gitea', 'bitbucketserver', 'bitbucket', 'azuredevops' provider types"
5859
type ProviderSpec struct {
5960
// Type specifies which Provider implementation to use.
6061
// +kubebuilder:validation:Enum=slack;discord;msteams;rocket;generic;generic-hmac;github;gitlab;gitea;bitbucketserver;bitbucket;azuredevops;googlechat;googlepubsub;webex;sentry;azureeventhub;telegram;lark;matrix;opsgenie;alertmanager;grafana;githubdispatch;pagerduty;datadog;nats
@@ -119,6 +120,14 @@ type ProviderSpec struct {
119120
// events handling for this Provider.
120121
// +optional
121122
Suspend bool `json:"suspend,omitempty"`
123+
124+
// CommitStatusExpr is a CEL expression that evaluates to a string value
125+
// that can be used to generate a custom commit status message for use
126+
// with eligible Provider types (github, gitlab, gitea, bitbucketserver,
127+
// bitbucket, azuredevops). Supported variables are: event, provider,
128+
// and alert.
129+
// +optional
130+
CommitStatusExpr string `json:"commitStatusExpr,omitempty"`
122131
}
123132

124133
// +genclient

config/crd/bases/notification.toolkit.fluxcd.io_providers.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,14 @@ spec:
460460
should be posted.
461461
maxLength: 2048
462462
type: string
463+
commitStatusExpr:
464+
description: |-
465+
CommitStatusExpr is a CEL expression that evaluates to a string value
466+
that can be used to generate a custom commit status message for use
467+
with eligible Provider types (github, gitlab, gitea, bitbucketserver,
468+
bitbucket, azuredevops). Supported variables are: event, provider,
469+
and alert.
470+
type: string
463471
interval:
464472
description: |-
465473
Interval at which to reconcile the Provider with its Secret references.
@@ -529,6 +537,12 @@ spec:
529537
required:
530538
- type
531539
type: object
540+
x-kubernetes-validations:
541+
- message: spec.commitStatusExpr is only supported for the 'github', 'gitlab',
542+
'gitea', 'bitbucketserver', 'bitbucket', 'azuredevops' provider types
543+
rule: self.type == 'github' || self.type == 'gitlab' || self.type ==
544+
'gitea' || self.type == 'bitbucketserver' || self.type == 'bitbucket'
545+
|| self.type == 'azuredevops' || !has(self.commitStatusExpr)
532546
type: object
533547
served: true
534548
storage: true

docs/api/v1beta3/notification.md

+32
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,22 @@ bool
378378
events handling for this Provider.</p>
379379
</td>
380380
</tr>
381+
<tr>
382+
<td>
383+
<code>commitStatusExpr</code><br>
384+
<em>
385+
string
386+
</em>
387+
</td>
388+
<td>
389+
<em>(Optional)</em>
390+
<p>CommitStatusExpr is a CEL expression that evaluates to a string value
391+
that can be used to generate a custom commit status message for use
392+
with eligible Provider types (github, gitlab, gitea, bitbucketserver,
393+
bitbucket, azuredevops). Supported variables are: event, provider,
394+
and alert.</p>
395+
</td>
396+
</tr>
381397
</table>
382398
</td>
383399
</tr>
@@ -667,6 +683,22 @@ bool
667683
events handling for this Provider.</p>
668684
</td>
669685
</tr>
686+
<tr>
687+
<td>
688+
<code>commitStatusExpr</code><br>
689+
<em>
690+
string
691+
</em>
692+
</td>
693+
<td>
694+
<em>(Optional)</em>
695+
<p>CommitStatusExpr is a CEL expression that evaluates to a string value
696+
that can be used to generate a custom commit status message for use
697+
with eligible Provider types (github, gitlab, gitea, bitbucketserver,
698+
bitbucket, azuredevops). Supported variables are: event, provider,
699+
and alert.</p>
700+
</td>
701+
</tr>
670702
</tbody>
671703
</table>
672704
</div>

docs/spec/v1beta3/providers.md

+27
Original file line numberDiff line numberDiff line change
@@ -1639,3 +1639,30 @@ You can create the secret with `kubectl` like this:
16391639
```shell
16401640
kubectl create secret generic azuredevops-token --from-literal=token=<AZURE-TOKEN>
16411641
```
1642+
1643+
#### Custom Commit Status Messages
1644+
1645+
Git providers supporting commit status updates can use a CEL expression to build a custom commit status message by setting the optional field `spec.commitStatusExpr`:
1646+
1647+
```yaml
1648+
apiVersion: notification.toolkit.fluxcd.io/v1beta3
1649+
kind: Provider
1650+
metadata:
1651+
name: github-status
1652+
namespace: flux-system
1653+
spec:
1654+
type: github
1655+
address: https://github.com/my-gh-org/my-gh-repo
1656+
secretRef:
1657+
name: github-token
1658+
commitStatusExpr: "(event.involvedObject.kind + '/' + event.involvedObject.name + '/' + event.metadata.foo + '/' + provider.metadata.uid.split('-').first().value()).lowerAscii()"
1659+
```
1660+
1661+
The CEL expression can access the following variables:
1662+
- `event`: The Flux event object containing metadata about the reconciliation
1663+
- `provider`: The Provider object
1664+
- `alert`: The Alert object
1665+
1666+
If the `spec.commitStatusExpr` field is not specified, the notification-controller will use a default commit status message based on the involved object kind, name, and a truncated provider UID to generate a commit status (e.g. `kustomization/gitops-system/0c9c2e41`).
1667+
1668+
A useful tool for building and testing CEL expressions is the [CEL Playground](https://playcel.undistro.io/).

go.mod

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/fluxcd/pkg/apis/meta v1.10.0
2222
github.com/fluxcd/pkg/git v0.24.0
2323
github.com/fluxcd/pkg/masktoken v0.6.0
24-
github.com/fluxcd/pkg/runtime v0.53.1
24+
github.com/fluxcd/pkg/runtime v0.55.0
2525
github.com/fluxcd/pkg/ssa v0.45.1
2626
github.com/getsentry/sentry-go v0.31.1
2727
github.com/go-logr/logr v1.4.2
@@ -38,14 +38,14 @@ require (
3838
github.com/spf13/pflag v1.0.6
3939
github.com/stretchr/testify v1.10.0
4040
gitlab.com/gitlab-org/api/client-go v0.122.0
41-
golang.org/x/oauth2 v0.26.0
41+
golang.org/x/oauth2 v0.27.0
4242
golang.org/x/text v0.22.0
4343
google.golang.org/api v0.221.0
44-
k8s.io/api v0.32.1
45-
k8s.io/apimachinery v0.32.1
46-
k8s.io/client-go v0.32.1
44+
k8s.io/api v0.32.2
45+
k8s.io/apimachinery v0.32.2
46+
k8s.io/client-go v0.32.2
4747
k8s.io/utils v0.0.0-20241210054802-24370beab758
48-
sigs.k8s.io/controller-runtime v0.20.1
48+
sigs.k8s.io/controller-runtime v0.20.2
4949
sigs.k8s.io/yaml v1.4.0
5050
)
5151

@@ -118,7 +118,7 @@ require (
118118
github.com/golang/protobuf v1.5.4 // indirect
119119
github.com/google/btree v1.1.3 // indirect
120120
github.com/google/gnostic-models v0.6.9 // indirect
121-
github.com/google/go-cmp v0.6.0 // indirect
121+
github.com/google/go-cmp v0.7.0 // indirect
122122
github.com/google/go-github/v68 v68.0.0 // indirect
123123
github.com/google/go-querystring v1.1.0 // indirect
124124
github.com/google/gofuzz v1.2.0 // indirect
@@ -157,7 +157,7 @@ require (
157157
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
158158
github.com/pkg/errors v0.9.1 // indirect
159159
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
160-
github.com/prometheus/client_golang v1.20.5 // indirect
160+
github.com/prometheus/client_golang v1.21.0 // indirect
161161
github.com/prometheus/client_model v0.6.1 // indirect
162162
github.com/prometheus/common v0.62.0 // indirect
163163
github.com/prometheus/procfs v0.15.1 // indirect
@@ -193,12 +193,12 @@ require (
193193
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
194194
gopkg.in/inf.v0 v0.9.1 // indirect
195195
gopkg.in/yaml.v3 v3.0.1 // indirect
196-
k8s.io/apiextensions-apiserver v0.32.1 // indirect
197-
k8s.io/cli-runtime v0.32.1 // indirect
198-
k8s.io/component-base v0.32.1 // indirect
196+
k8s.io/apiextensions-apiserver v0.32.2 // indirect
197+
k8s.io/cli-runtime v0.32.2 // indirect
198+
k8s.io/component-base v0.32.2 // indirect
199199
k8s.io/klog/v2 v2.130.1 // indirect
200200
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 // indirect
201-
k8s.io/kubectl v0.32.1 // indirect
201+
k8s.io/kubectl v0.32.2 // indirect
202202
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
203203
sigs.k8s.io/kustomize/api v0.19.0 // indirect
204204
sigs.k8s.io/kustomize/kyaml v0.19.0 // indirect

go.sum

+24-24
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ github.com/fluxcd/pkg/git v0.24.0 h1:aMAL8MUNPZXyRia+LVVudTpmLHIpzmz9F5tedvhhLzs
160160
github.com/fluxcd/pkg/git v0.24.0/go.mod h1:vxUhjBwnkvbAByN7UC5Go33/mgrLSIIg1rH+dyOZVRo=
161161
github.com/fluxcd/pkg/masktoken v0.6.0 h1:ijSqMl2L9jBR3QFcHA0FX7kxV0xgSB4PY5p//8FdVR4=
162162
github.com/fluxcd/pkg/masktoken v0.6.0/go.mod h1:bMj45KySJ2gLeFiFaXD5nQLNFlvDqGbZolsiurZKVUU=
163-
github.com/fluxcd/pkg/runtime v0.53.1 h1:S+QRSoiU+LH1sTvJLNvT1x3E5hBq/sjOsRHazA7OqTo=
164-
github.com/fluxcd/pkg/runtime v0.53.1/go.mod h1:8vkIhS1AhkmjC98LRm5xM+CRG5KySFTXpJWk+ZdtT4I=
163+
github.com/fluxcd/pkg/runtime v0.55.0 h1:bjXz7t1g9DsXUtIbOWZAqAKOo/qccEPQ5JlHMeSO7bk=
164+
github.com/fluxcd/pkg/runtime v0.55.0/go.mod h1:PC73Yn/AaBQXnd2YYq0cnQqF3RmQKoM265crrjFJnKI=
165165
github.com/fluxcd/pkg/ssa v0.45.1 h1:ISl84TJwRP/GuZXrKiR9Tf8JOnG5XFgtjcYoR4XQYf4=
166166
github.com/fluxcd/pkg/ssa v0.45.1/go.mod h1:8Anf7XVZ0zxOve7HXbDaW1s0gfmP95ksJBlKfDYinhQ=
167167
github.com/fluxcd/pkg/ssh v0.16.0 h1:dhSWNp30p05EJ86bhICezad9pG3fJi4CAVKnZ3EmUV8=
@@ -244,8 +244,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
244244
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
245245
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
246246
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
247-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
248-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
247+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
248+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
249249
github.com/google/go-github/v64 v64.0.0 h1:4G61sozmY3eiPAjjoOHponXDBONm+utovTKbyUb2Qdg=
250250
github.com/google/go-github/v64 v64.0.0/go.mod h1:xB3vqMQNdHzilXBiO2I+M7iEFtHf+DP/omBOv6tQzVo=
251251
github.com/google/go-github/v68 v68.0.0 h1:ZW57zeNZiXTdQ16qrDiZ0k6XucrxZ2CGmoTvcCyQG6s=
@@ -372,8 +372,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
372372
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
373373
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
374374
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
375-
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
376-
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
375+
github.com/prometheus/client_golang v1.21.0 h1:DIsaGmiaBkSangBgMtWdNfxbMNdku5IK6iNhrEqWvdA=
376+
github.com/prometheus/client_golang v1.21.0/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg=
377377
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
378378
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
379379
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
@@ -502,8 +502,8 @@ golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
502502
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
503503
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
504504
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
505-
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
506-
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
505+
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
506+
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
507507
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
508508
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
509509
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -614,28 +614,28 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
614614
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
615615
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
616616
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
617-
k8s.io/api v0.32.1 h1:f562zw9cy+GvXzXf0CKlVQ7yHJVYzLfL6JAS4kOAaOc=
618-
k8s.io/api v0.32.1/go.mod h1:/Yi/BqkuueW1BgpoePYBRdDYfjPF5sgTr5+YqDZra5k=
619-
k8s.io/apiextensions-apiserver v0.32.1 h1:hjkALhRUeCariC8DiVmb5jj0VjIc1N0DREP32+6UXZw=
620-
k8s.io/apiextensions-apiserver v0.32.1/go.mod h1:sxWIGuGiYov7Io1fAS2X06NjMIk5CbRHc2StSmbaQto=
621-
k8s.io/apimachinery v0.32.1 h1:683ENpaCBjma4CYqsmZyhEzrGz6cjn1MY/X2jB2hkZs=
622-
k8s.io/apimachinery v0.32.1/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
623-
k8s.io/cli-runtime v0.32.1 h1:19nwZPlYGJPUDbhAxDIS2/oydCikvKMHsxroKNGA2mM=
624-
k8s.io/cli-runtime v0.32.1/go.mod h1:NJPbeadVFnV2E7B7vF+FvU09mpwYlZCu8PqjzfuOnkY=
625-
k8s.io/client-go v0.32.1 h1:otM0AxdhdBIaQh7l1Q0jQpmo7WOFIk5FFa4bg6YMdUU=
626-
k8s.io/client-go v0.32.1/go.mod h1:aTTKZY7MdxUaJ/KiUs8D+GssR9zJZi77ZqtzcGXIiDg=
627-
k8s.io/component-base v0.32.1 h1:/5IfJ0dHIKBWysGV0yKTFfacZ5yNV1sulPh3ilJjRZk=
628-
k8s.io/component-base v0.32.1/go.mod h1:j1iMMHi/sqAHeG5z+O9BFNCF698a1u0186zkjMZQ28w=
617+
k8s.io/api v0.32.2 h1:bZrMLEkgizC24G9eViHGOPbW+aRo9duEISRIJKfdJuw=
618+
k8s.io/api v0.32.2/go.mod h1:hKlhk4x1sJyYnHENsrdCWw31FEmCijNGPJO5WzHiJ6Y=
619+
k8s.io/apiextensions-apiserver v0.32.2 h1:2YMk285jWMk2188V2AERy5yDwBYrjgWYggscghPCvV4=
620+
k8s.io/apiextensions-apiserver v0.32.2/go.mod h1:GPwf8sph7YlJT3H6aKUWtd0E+oyShk/YHWQHf/OOgCA=
621+
k8s.io/apimachinery v0.32.2 h1:yoQBR9ZGkA6Rgmhbp/yuT9/g+4lxtsGYwW6dR6BDPLQ=
622+
k8s.io/apimachinery v0.32.2/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE=
623+
k8s.io/cli-runtime v0.32.2 h1:aKQR4foh9qeyckKRkNXUccP9moxzffyndZAvr+IXMks=
624+
k8s.io/cli-runtime v0.32.2/go.mod h1:a/JpeMztz3xDa7GCyyShcwe55p8pbcCVQxvqZnIwXN8=
625+
k8s.io/client-go v0.32.2 h1:4dYCD4Nz+9RApM2b/3BtVvBHw54QjMFUl1OLcJG5yOA=
626+
k8s.io/client-go v0.32.2/go.mod h1:fpZ4oJXclZ3r2nDOv+Ux3XcJutfrwjKTCHz2H3sww94=
627+
k8s.io/component-base v0.32.2 h1:1aUL5Vdmu7qNo4ZsE+569PV5zFatM9hl+lb3dEea2zU=
628+
k8s.io/component-base v0.32.2/go.mod h1:PXJ61Vx9Lg+P5mS8TLd7bCIr+eMJRQTyXe8KvkrvJq0=
629629
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
630630
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
631631
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=
632632
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7/go.mod h1:GewRfANuJ70iYzvn+i4lezLDAFzvjxZYK1gn1lWcfas=
633-
k8s.io/kubectl v0.32.1 h1:/btLtXLQUU1rWx8AEvX9jrb9LaI6yeezt3sFALhB8M8=
634-
k8s.io/kubectl v0.32.1/go.mod h1:sezNuyWi1STk4ZNPVRIFfgjqMI6XMf+oCVLjZen/pFQ=
633+
k8s.io/kubectl v0.32.2 h1:TAkag6+XfSBgkqK9I7ZvwtF0WVtUAvK8ZqTt+5zi1Us=
634+
k8s.io/kubectl v0.32.2/go.mod h1:+h/NQFSPxiDZYX/WZaWw9fwYezGLISP0ud8nQKg+3g8=
635635
k8s.io/utils v0.0.0-20241210054802-24370beab758 h1:sdbE21q2nlQtFh65saZY+rRM6x6aJJI8IUa1AmH/qa0=
636636
k8s.io/utils v0.0.0-20241210054802-24370beab758/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
637-
sigs.k8s.io/controller-runtime v0.20.1 h1:JbGMAG/X94NeM3xvjenVUaBjy6Ui4Ogd/J5ZtjZnHaE=
638-
sigs.k8s.io/controller-runtime v0.20.1/go.mod h1:BrP3w158MwvB3ZbNpaAcIKkHQ7YGpYnzpoSTZ8E14WU=
637+
sigs.k8s.io/controller-runtime v0.20.2 h1:/439OZVxoEc02psi1h4QO3bHzTgu49bb347Xp4gW1pc=
638+
sigs.k8s.io/controller-runtime v0.20.2/go.mod h1:xg2XB0K5ShQzAgsoujxuKN4LNXR2LfwwHsPj7Iaw+XY=
639639
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=
640640
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
641641
sigs.k8s.io/kustomize/api v0.19.0 h1:F+2HB2mU1MSiR9Hp1NEgoU2q9ItNOaBJl0I4Dlus5SQ=

internal/controller/provider_controller_test.go

+82
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,85 @@ func TestProviderReconciler(t *testing.T) {
117117
return false
118118
}, timeout).Should(BeTrue())
119119
}
120+
121+
func TestProviderReconciler_APIServerValidation(t *testing.T) {
122+
tests := []struct {
123+
name string
124+
providerType string
125+
commitStatusExpr string
126+
err string
127+
}{
128+
{
129+
name: "github provider types can create providers with commitStatusExpr",
130+
providerType: "github",
131+
commitStatusExpr: "event.metadata.namespace + '/' + event.metadata.name + '/' + provider.metadata.uid",
132+
},
133+
{
134+
name: "gitlab provider types can create providers with commitStatusExpr",
135+
providerType: "gitlab",
136+
commitStatusExpr: "event.metadata.namespace + '/' + event.metadata.name + '/' + provider.metadata.uid",
137+
},
138+
{
139+
name: "gitea provider types can create providers with commitStatusExpr",
140+
providerType: "gitea",
141+
commitStatusExpr: "event.metadata.namespace + '/' + event.metadata.name + '/' + provider.metadata.uid",
142+
},
143+
{
144+
name: "bitbucketserver provider types can create providers with commitStatusExpr",
145+
providerType: "bitbucketserver",
146+
commitStatusExpr: "event.metadata.namespace + '/' + event.metadata.name + '/' + provider.metadata.uid",
147+
},
148+
{
149+
name: "bitbucket provider types can create providers with commitStatusExpr",
150+
providerType: "bitbucket",
151+
commitStatusExpr: "event.metadata.namespace + '/' + event.metadata.name + '/' + provider.metadata.uid",
152+
},
153+
{
154+
name: "azuredevops provider types can create providers with commitStatusExpr",
155+
providerType: "azuredevops",
156+
commitStatusExpr: "event.metadata.namespace + '/' + event.metadata.name + '/' + provider.metadata.uid",
157+
},
158+
{
159+
name: "unsupported provider types cannot create providers with commitStatusExpr",
160+
providerType: "slack",
161+
commitStatusExpr: "event.metadata.namespace + '/' + event.metadata.name + '/' + provider.metadata.uid",
162+
err: "spec.commitStatusExpr is only supported for the 'github', 'gitlab', 'gitea', 'bitbucketserver', 'bitbucket', 'azuredevops' provider types",
163+
},
164+
{
165+
name: "github provider types can create providers without commitStatusExpr",
166+
providerType: "github",
167+
commitStatusExpr: "",
168+
},
169+
}
170+
171+
for _, tt := range tests {
172+
t.Run(tt.name, func(t *testing.T) {
173+
g := NewWithT(t)
174+
175+
obj := &apiv1beta3.Provider{
176+
ObjectMeta: metav1.ObjectMeta{
177+
GenerateName: "provider-reconcile-",
178+
Namespace: "default",
179+
},
180+
Spec: apiv1beta3.ProviderSpec{
181+
Type: tt.providerType,
182+
CommitStatusExpr: tt.commitStatusExpr,
183+
},
184+
}
185+
186+
err := testEnv.Create(ctx, obj)
187+
if err == nil {
188+
defer func() {
189+
err := testEnv.Delete(ctx, obj)
190+
g.Expect(err).ToNot(HaveOccurred())
191+
}()
192+
}
193+
194+
if tt.err != "" {
195+
g.Expect(err.Error()).To(ContainSubstring(tt.err))
196+
} else {
197+
g.Expect(err).NotTo(HaveOccurred())
198+
}
199+
})
200+
}
201+
}

0 commit comments

Comments
 (0)