Skip to content

Commit fcecd38

Browse files
authored
Fix code generation (#1536)
**Description of the change** Code generation wasn't working. This PR fixes it and updates the generated code: - Use latest version of `controller-gen` to generate the manifests for the CRD - Use `kube_codegen.sh` to generate the client code. The `generate_groups.sh` script we were using previously has been deprecated and removed. - Code generation is now done from a `hack` directory following the [Kubernetes sample-controller example](https://github.com/kubernetes/sample-controller/blob/master/hack/update-codegen.sh). - `make manifests` has been run to update the manifests. - `make generate` has been run to update the generated code. --------- Signed-off-by: Alejandro Moreno <[email protected]>
1 parent 908cd3e commit fcecd38

File tree

10 files changed

+120
-48
lines changed

10 files changed

+120
-48
lines changed

Makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ GO_FLAGS =
1010
KUBECFG = kubecfg
1111
DOCKER = docker
1212
GINKGO = ginkgo -p
13-
CONTROLLER_GEN ?= controller-gen
13+
CONTROLLER_GEN ?= go run sigs.k8s.io/controller-tools/cmd/controller-gen@latest
1414

1515
REGISTRY ?= docker.io
1616
CONTROLLER_IMAGE = $(REGISTRY)/bitnami/sealed-secrets-controller:latest
@@ -45,8 +45,10 @@ GO_LD_FLAGS = -X main.VERSION=$(VERSION)
4545

4646
all: controller kubeseal
4747

48-
generate: $(GO_FILES)
49-
$(GO) generate $(GO_PACKAGES)
48+
generate:
49+
$(GO) mod vendor
50+
./hack/update-codegen.sh
51+
rm -rf vendor
5052

5153
manifests:
5254
$(CONTROLLER_GEN) crd:generateEmbeddedObjectMeta=true paths="./pkg/apis/..." output:stdout | tail -n +2 > helm/sealed-secrets/crds/bitnami.com_sealedsecrets.yaml
@@ -128,7 +130,7 @@ lint:
128130
$(GOLANGCILINT) run --enable goimports --timeout=5m
129131

130132
lint-gosec:
131-
$(GOSEC) -r --severity low
133+
$(GOSEC) -r -severity low -exclude-generated
132134

133135
clean:
134136
$(RM) ./controller ./kubeseal

tools.go renamed to hack/tools.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//go:build tools
66
// +build tools
77

8-
package sealedsecrets
8+
package tools
99

1010
import (
1111
_ "k8s.io/code-generator"

hack/update-codegen.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
8+
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
9+
10+
source "${CODEGEN_PKG}/kube_codegen.sh"
11+
12+
THIS_PKG="github.com/bitnami-labs/sealed-secrets"
13+
14+
kube::codegen::gen_helpers \
15+
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
16+
"${SCRIPT_ROOT}/pkg/apis"
17+
18+
kube::codegen::gen_client \
19+
--with-watch \
20+
--output-dir "${SCRIPT_ROOT}/pkg/client" \
21+
--output-pkg "${THIS_PKG}/pkg/client" \
22+
--boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \
23+
"${SCRIPT_ROOT}/pkg/apis"

helm/sealed-secrets/crds/bitnami.com_sealedsecrets.yaml

+37-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
22
kind: CustomResourceDefinition
33
metadata:
44
annotations:
5-
controller-gen.kubebuilder.io/version: v0.12.0
5+
controller-gen.kubebuilder.io/version: v0.15.0
66
name: sealedsecrets.bitnami.com
77
spec:
88
group: bitnami.com
@@ -26,24 +26,30 @@ spec:
2626
name: v1alpha1
2727
schema:
2828
openAPIV3Schema:
29-
description: SealedSecret is the K8s representation of a "sealed Secret" -
30-
a regular k8s Secret that has been sealed (encrypted) using the controller's
31-
key.
29+
description: |-
30+
SealedSecret is the K8s representation of a "sealed Secret" - a
31+
regular k8s Secret that has been sealed (encrypted) using the
32+
controller's key.
3233
properties:
3334
apiVersion:
34-
description: 'APIVersion defines the versioned schema of this representation
35-
of an object. Servers should convert recognized schemas to the latest
36-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
35+
description: |-
36+
APIVersion defines the versioned schema of this representation of an object.
37+
Servers should convert recognized schemas to the latest internal value, and
38+
may reject unrecognized values.
39+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
3740
type: string
3841
kind:
39-
description: 'Kind is a string value representing the REST resource this
40-
object represents. Servers may infer this from the endpoint the client
41-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
42+
description: |-
43+
Kind is a string value representing the REST resource this object represents.
44+
Servers may infer this from the endpoint the client submits requests to.
45+
Cannot be updated.
46+
In CamelCase.
47+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
4248
type: string
4349
metadata:
4450
type: object
4551
spec:
46-
description: SealedSecretSpec is the specification of a SealedSecret
52+
description: SealedSecretSpec is the specification of a SealedSecret.
4753
properties:
4854
data:
4955
description: Data is deprecated and will be removed eventually. Use
@@ -56,17 +62,27 @@ spec:
5662
type: object
5763
x-kubernetes-preserve-unknown-fields: true
5864
template:
59-
description: Template defines the structure of the Secret that will
60-
be created from this sealed secret.
65+
description: |-
66+
Template defines the structure of the Secret that will be
67+
created from this sealed secret.
6168
properties:
6269
data:
6370
additionalProperties:
6471
type: string
65-
description: Keys that should be templated using decrypted data
72+
description: Keys that should be templated using decrypted data.
6673
nullable: true
6774
type: object
75+
immutable:
76+
description: |-
77+
Immutable, if set to true, ensures that data stored in the Secret cannot
78+
be updated (only object metadata can be modified).
79+
If not set to true, the field can be modified at any time.
80+
Defaulted to nil.
81+
type: boolean
6882
metadata:
69-
description: 'Standard object''s metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
83+
description: |-
84+
Standard object's metadata.
85+
More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
7086
nullable: true
7187
properties:
7288
annotations:
@@ -91,10 +107,6 @@ spec:
91107
description: Used to facilitate programmatic handling of secret
92108
data.
93109
type: string
94-
immutable:
95-
description: 'Immutable, if set to true, ensures that data stored in the Secret cannot be updated (only object metadata can be modified).
96-
If not set to true, the field can be modified at any time. Defaulted to nil.'
97-
type: boolean
98110
type: object
99111
required:
100112
- encryptedData
@@ -127,12 +139,14 @@ spec:
127139
description: The reason for the condition's last transition.
128140
type: string
129141
status:
130-
description: 'Status of the condition for a sealed secret. Valid
131-
values for "Synced": "True", "False", or "Unknown".'
142+
description: |-
143+
Status of the condition for a sealed secret.
144+
Valid values for "Synced": "True", "False", or "Unknown".
132145
type: string
133146
type:
134-
description: 'Type of condition for a sealed secret. Valid value:
135-
"Synced"'
147+
description: |-
148+
Type of condition for a sealed secret.
149+
Valid value: "Synced"
136150
type: string
137151
required:
138152
- status

pkg/apis/sealedsecrets/v1alpha1/doc.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// go mod vendor doesn't preserve executable perm bits
2-
//go:generate bash -c "go mod download && cd ../../../.. && bash $(go list -mod=mod -m -f '{{.Dir}}' k8s.io/code-generator)/generate-groups.sh deepcopy,client,informer,lister github.com/bitnami-labs/sealed-secrets/pkg/client github.com/bitnami-labs/sealed-secrets/pkg/apis sealedsecrets:v1alpha1 --go-header-file pkg/apis/sealedsecrets/v1alpha1/boilerplate.go.txt --trim-path-prefix github.com/bitnami-labs/sealed-secrets"
31
// +k8s:deepcopy-gen=package,register
42

53
// +groupName=bitnami.com

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

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/doc.go

-4
This file was deleted.

pkg/client/informers/externalversions/factory.go

+12-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema-v1alpha1.yaml

+36-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
openAPIV3Schema:
2-
description: SealedSecret is the K8s representation of a "sealed Secret" - a regular k8s Secret that has been sealed (encrypted) using the controller's key.
2+
description: |-
3+
SealedSecret is the K8s representation of a "sealed Secret" - a
4+
regular k8s Secret that has been sealed (encrypted) using the
5+
controller's key.
36
properties:
47
apiVersion:
5-
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
8+
description: |-
9+
APIVersion defines the versioned schema of this representation of an object.
10+
Servers should convert recognized schemas to the latest internal value, and
11+
may reject unrecognized values.
12+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
613
type: string
714
kind:
8-
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
15+
description: |-
16+
Kind is a string value representing the REST resource this object represents.
17+
Servers may infer this from the endpoint the client submits requests to.
18+
Cannot be updated.
19+
In CamelCase.
20+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
921
type: string
1022
metadata:
1123
type: object
1224
spec:
13-
description: SealedSecretSpec is the specification of a SealedSecret
25+
description: SealedSecretSpec is the specification of a SealedSecret.
1426
properties:
1527
data:
1628
description: Data is deprecated and will be removed eventually. Use per-value EncryptedData instead.
@@ -22,16 +34,27 @@ openAPIV3Schema:
2234
type: object
2335
x-kubernetes-preserve-unknown-fields: true
2436
template:
25-
description: Template defines the structure of the Secret that will be created from this sealed secret.
37+
description: |-
38+
Template defines the structure of the Secret that will be
39+
created from this sealed secret.
2640
properties:
2741
data:
2842
additionalProperties:
2943
type: string
30-
description: Keys that should be templated using decrypted data
44+
description: Keys that should be templated using decrypted data.
3145
nullable: true
3246
type: object
47+
immutable:
48+
description: |-
49+
Immutable, if set to true, ensures that data stored in the Secret cannot
50+
be updated (only object metadata can be modified).
51+
If not set to true, the field can be modified at any time.
52+
Defaulted to nil.
53+
type: boolean
3354
metadata:
34-
description: 'Standard object''s metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
55+
description: |-
56+
Standard object's metadata.
57+
More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
3558
nullable: true
3659
properties:
3760
annotations:
@@ -55,9 +78,6 @@ openAPIV3Schema:
5578
type:
5679
description: Used to facilitate programmatic handling of secret data.
5780
type: string
58-
immutable:
59-
description: 'Immutable, if set to true, ensures that data stored in the Secret cannot be updated (only object metadata can be modified). If not set to true, the field can be modified at any time. Defaulted to nil.'
60-
type: boolean
6181
type: object
6282
required:
6383
- encryptedData
@@ -85,10 +105,14 @@ openAPIV3Schema:
85105
description: The reason for the condition's last transition.
86106
type: string
87107
status:
88-
description: 'Status of the condition for a sealed secret. Valid values for "Synced": "True", "False", or "Unknown".'
108+
description: |-
109+
Status of the condition for a sealed secret.
110+
Valid values for "Synced": "True", "False", or "Unknown".
89111
type: string
90112
type:
91-
description: 'Type of condition for a sealed secret. Valid value: "Synced"'
113+
description: |-
114+
Type of condition for a sealed secret.
115+
Valid value: "Synced"
92116
type: string
93117
required:
94118
- status

0 commit comments

Comments
 (0)