Skip to content

Commit c507445

Browse files
authored
feat: support custom labels and annotations on generated secrets (#29)
* enable integration with [Jenkins' Kubernetes Credentials Provider Plugin](https://jenkinsci.github.io/kubernetes-credentials-provider-plugin/) and similar use cases.
1 parent e994541 commit c507445

File tree

9 files changed

+213
-92
lines changed

9 files changed

+213
-92
lines changed

api/v1/clustertoken_types.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ClusterTokenSpec struct {
3333
// Important: Run "make" to regenerate code after modifying this file
3434

3535
// +kubebuilder:validation:Required
36-
Secret clusterTokenSecretSpec `json:"secret"`
36+
Secret ClusterTokenSecretSpec `json:"secret"`
3737

3838
// +optional
3939
// +kubebuilder:example:="123456789"
@@ -63,7 +63,7 @@ type ClusterTokenSpec struct {
6363
RepositoryIDs []int64 `json:"repositoryIDs,omitempty"`
6464
}
6565

66-
type clusterTokenSecretSpec struct {
66+
type ClusterTokenSecretSpec struct {
6767
// +kubebuilder:validation:Required
6868
// +kubebuilder:validation:MaxLength:=253
6969
// +kubebuilder:example:="default"
@@ -75,6 +75,14 @@ type clusterTokenSecretSpec struct {
7575
// Name for the Secret managed by this ClusterToken (defaults to the name of the ClusterToken)
7676
Name string `json:"name,omitempty"`
7777

78+
// +optional
79+
// Extra labels for the Secret managed by this Token
80+
Labels map[string]string `json:"labels,omitempty"`
81+
82+
// +optional
83+
// Extra annotations for the Secret managed by this Token
84+
Annotations map[string]string `json:"annotations,omitempty"`
85+
7886
// +optional
7987
// Create a secret with 'username' and 'password' fields for HTTP Basic Auth rather than simply 'token'
8088
BasicAuth bool `json:"basicAuth,omitempty"`
@@ -133,6 +141,14 @@ func (t *ClusterToken) GetSecretName() string {
133141
return secretName
134142
}
135143

144+
func (t *ClusterToken) GetSecretLabels() map[string]string {
145+
return t.Spec.Secret.Labels
146+
}
147+
148+
func (t *ClusterToken) GetSecretAnnotations() map[string]string {
149+
return t.Spec.Secret.Annotations
150+
}
151+
136152
func (t *ClusterToken) GetSecretBasicAuth() bool {
137153
return t.Spec.Secret.BasicAuth
138154
}

api/v1/token_types.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type TokenSpec struct {
3434

3535
// +optional
3636
// Override the default token secret name and type
37-
Secret tokenSecretSpec `json:"secret,omitempty"`
37+
Secret TokenSecretSpec `json:"secret,omitempty"`
3838

3939
// +optional
4040
// +kubebuilder:example:="123456789"
@@ -64,12 +64,20 @@ type TokenSpec struct {
6464
RepositoryIDs []int64 `json:"repositoryIDs,omitempty"`
6565
}
6666

67-
type tokenSecretSpec struct {
67+
type TokenSecretSpec struct {
6868
// +optional
6969
// +kubebuilder:validation:MaxLength:=253
70-
// Name for the Secret managed by this ClusterToken (defaults to the name of the Token)
70+
// Name for the Secret managed by this Token (defaults to the name of the Token)
7171
Name string `json:"name,omitempty"`
7272

73+
// +optional
74+
// Extra labels for the Secret managed by this Token
75+
Labels map[string]string `json:"labels,omitempty"`
76+
77+
// +optional
78+
// Extra annotations for the Secret managed by this Token
79+
Annotations map[string]string `json:"annotations,omitempty"`
80+
7381
// +optional
7482
// Create a secret with 'username' and 'password' fields for HTTP Basic Auth rather than simply 'token'
7583
BasicAuth bool `json:"basicAuth,omitempty"`
@@ -126,6 +134,14 @@ func (t *Token) GetSecretName() string {
126134
return secretName
127135
}
128136

137+
func (t *Token) GetSecretLabels() map[string]string {
138+
return t.Spec.Secret.Labels
139+
}
140+
141+
func (t *Token) GetSecretAnnotations() map[string]string {
142+
return t.Spec.Secret.Annotations
143+
}
144+
129145
func (t *Token) GetSecretBasicAuth() bool {
130146
return t.Spec.Secret.BasicAuth
131147
}

api/v1/zz_generated.deepcopy.go

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

config/crd/bases/github.as-code.io_clustertokens.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,23 @@ spec:
260260
type: array
261261
secret:
262262
properties:
263+
annotations:
264+
additionalProperties:
265+
type: string
266+
description:
267+
Extra annotations for the Secret managed by this
268+
Token
269+
type: object
263270
basicAuth:
264271
description:
265272
Create a secret with 'username' and 'password' fields
266273
for HTTP Basic Auth rather than simply 'token'
267274
type: boolean
275+
labels:
276+
additionalProperties:
277+
type: string
278+
description: Extra labels for the Secret managed by this Token
279+
type: object
268280
name:
269281
description:
270282
Name for the Secret managed by this ClusterToken

config/crd/bases/github.as-code.io_tokens.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,27 @@ spec:
261261
secret:
262262
description: Override the default token secret name and type
263263
properties:
264+
annotations:
265+
additionalProperties:
266+
type: string
267+
description:
268+
Extra annotations for the Secret managed by this
269+
Token
270+
type: object
264271
basicAuth:
265272
description:
266273
Create a secret with 'username' and 'password' fields
267274
for HTTP Basic Auth rather than simply 'token'
268275
type: boolean
276+
labels:
277+
additionalProperties:
278+
type: string
279+
description: Extra labels for the Secret managed by this Token
280+
type: object
269281
name:
270282
description:
271-
Name for the Secret managed by this ClusterToken
272-
(defaults to the name of the Token)
283+
Name for the Secret managed by this Token (defaults
284+
to the name of the Token)
273285
maxLength: 253
274286
type: string
275287
type: object

go.mod

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/go-logr/logr v1.4.2
77
github.com/google/go-github/v66 v66.0.0
88
github.com/isometry/ghait v0.1.1
9-
github.com/onsi/ginkgo/v2 v2.20.2
9+
github.com/onsi/ginkgo/v2 v2.21.0
1010
github.com/onsi/gomega v1.34.2
1111
github.com/spf13/viper v1.19.0
1212
k8s.io/api v0.31.2
@@ -17,25 +17,25 @@ require (
1717

1818
require (
1919
cloud.google.com/go v0.116.0 // indirect
20-
cloud.google.com/go/auth v0.9.8 // indirect
21-
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
20+
cloud.google.com/go/auth v0.10.0 // indirect
21+
cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect
2222
cloud.google.com/go/compute/metadata v0.5.2 // indirect
23-
cloud.google.com/go/iam v1.2.1 // indirect
24-
cloud.google.com/go/kms v1.20.0 // indirect
25-
cloud.google.com/go/longrunning v0.6.1 // indirect
26-
github.com/aws/aws-sdk-go-v2 v1.32.2 // indirect
27-
github.com/aws/aws-sdk-go-v2/config v1.27.43 // indirect
28-
github.com/aws/aws-sdk-go-v2/credentials v1.17.41 // indirect
29-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.17 // indirect
30-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect
31-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect
23+
cloud.google.com/go/iam v1.2.2 // indirect
24+
cloud.google.com/go/kms v1.20.1 // indirect
25+
cloud.google.com/go/longrunning v0.6.2 // indirect
26+
github.com/aws/aws-sdk-go-v2 v1.32.3 // indirect
27+
github.com/aws/aws-sdk-go-v2/config v1.28.1 // indirect
28+
github.com/aws/aws-sdk-go-v2/credentials v1.17.42 // indirect
29+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18 // indirect
30+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22 // indirect
31+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22 // indirect
3232
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
3333
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect
34-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.2 // indirect
35-
github.com/aws/aws-sdk-go-v2/service/kms v1.37.2 // indirect
36-
github.com/aws/aws-sdk-go-v2/service/sso v1.24.2 // indirect
37-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.2 // indirect
38-
github.com/aws/aws-sdk-go-v2/service/sts v1.32.2 // indirect
34+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3 // indirect
35+
github.com/aws/aws-sdk-go-v2/service/kms v1.37.3 // indirect
36+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.3 // indirect
37+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3 // indirect
38+
github.com/aws/aws-sdk-go-v2/service/sts v1.32.3 // indirect
3939
github.com/aws/smithy-go v1.22.0 // indirect
4040
github.com/beorn7/perks v1.0.1 // indirect
4141
github.com/bradleyfalzon/ghinstallation/v2 v2.11.0 // indirect
@@ -45,7 +45,7 @@ require (
4545
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
4646
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
4747
github.com/felixge/httpsnoop v1.0.4 // indirect
48-
github.com/fsnotify/fsnotify v1.7.0 // indirect
48+
github.com/fsnotify/fsnotify v1.8.0 // indirect
4949
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
5050
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
5151
github.com/go-logr/stdr v1.2.2 // indirect
@@ -63,7 +63,7 @@ require (
6363
github.com/google/go-github/v62 v62.0.0 // indirect
6464
github.com/google/go-querystring v1.1.0 // indirect
6565
github.com/google/gofuzz v1.2.0 // indirect
66-
github.com/google/pprof v0.0.0-20241009165004-a3522334989c // indirect
66+
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
6767
github.com/google/s2a-go v0.1.8 // indirect
6868
github.com/google/uuid v1.6.0 // indirect
6969
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
@@ -78,7 +78,7 @@ require (
7878
github.com/hashicorp/go-sockaddr v1.0.7 // indirect
7979
github.com/hashicorp/hcl v1.0.0 // indirect
8080
github.com/hashicorp/vault/api v1.15.0 // indirect
81-
github.com/imdario/mergo v1.0.0 // indirect
81+
github.com/imdario/mergo v1.0.1 // indirect
8282
github.com/josharian/intern v1.0.0 // indirect
8383
github.com/json-iterator/go v1.1.12 // indirect
8484
github.com/klauspost/compress v1.17.11 // indirect
@@ -91,9 +91,9 @@ require (
9191
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
9292
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
9393
github.com/pkg/errors v0.9.1 // indirect
94-
github.com/prometheus/client_golang v1.20.4 // indirect
94+
github.com/prometheus/client_golang v1.20.5 // indirect
9595
github.com/prometheus/client_model v0.6.1 // indirect
96-
github.com/prometheus/common v0.60.0 // indirect
96+
github.com/prometheus/common v0.60.1 // indirect
9797
github.com/prometheus/procfs v0.15.1 // indirect
9898
github.com/ryanuber/go-glob v1.0.0 // indirect
9999
github.com/sagikazarmark/locafero v0.6.0 // indirect
@@ -123,17 +123,17 @@ require (
123123
golang.org/x/time v0.7.0 // indirect
124124
golang.org/x/tools v0.26.0 // indirect
125125
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
126-
google.golang.org/api v0.200.0 // indirect
127-
google.golang.org/genproto v0.0.0-20241007155032-5fefd90f89a9 // indirect
128-
google.golang.org/genproto/googleapis/api v0.0.0-20241007155032-5fefd90f89a9 // indirect
129-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
126+
google.golang.org/api v0.203.0 // indirect
127+
google.golang.org/genproto v0.0.0-20241021214115-324edc3d5d38 // indirect
128+
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 // indirect
129+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
130130
google.golang.org/grpc v1.67.1 // indirect
131131
google.golang.org/protobuf v1.35.1 // indirect
132132
gopkg.in/inf.v0 v0.9.1 // indirect
133133
gopkg.in/ini.v1 v1.67.0 // indirect
134134
gopkg.in/yaml.v2 v2.4.0 // indirect
135135
gopkg.in/yaml.v3 v3.0.1 // indirect
136-
k8s.io/apiextensions-apiserver v0.31.1 // indirect
136+
k8s.io/apiextensions-apiserver v0.31.2 // indirect
137137
k8s.io/klog/v2 v2.130.1 // indirect
138138
k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094 // indirect
139139
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 // indirect

0 commit comments

Comments
 (0)