Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit e43a6b8

Browse files
authored
fix!: require .spec field in CRD validation (#682)
* fix(e2e): correctly validate CRD rejection * fix(e2e): add test validating template.type
1 parent 483fb90 commit e43a6b8

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

charts/kubernetes-external-secrets/crds/kubernetes-client.io_externalsecrets_crd.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ spec:
3131

3232
validation:
3333
openAPIV3Schema:
34+
required:
35+
- spec
3436
properties:
3537
spec:
3638
type: object

e2e/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM node:12-alpine
44
RUN mkdir /app
55
WORKDIR /app
66
COPY package.json package-lock.json /app/
7-
RUN npm install
7+
RUN npm ci
88

99
# Copy app to source directory
1010
COPY . /app

e2e/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To better understand how they are being run take a look at `run-e2e-suite.sh`.
2121
kind create cluster \
2222
--name es-dev-cluster \
2323
--config ./kind.yaml \
24-
--image "kindest/node:v1.15.3"
24+
--image "kindest/node:v1.16.15"
2525
2626
export KUBECONFIG="$(kind get kubeconfig-path --name="es-dev-cluster")"
2727

e2e/run-e2e-suite.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ trap cleanup EXIT
6868
kubectl apply -f ${DIR}/localstack.deployment.yaml
6969

7070
CHART_DIR="$(dirname "$DIR")/charts/kubernetes-external-secrets"
71-
HELM_TEMPLATE_ARGS="e2e ${CHART_DIR}"
7271

73-
helm template ${HELM_TEMPLATE_ARGS} \
74-
--include-crds \
72+
helm install e2e ${CHART_DIR} \
7573
--set image.repository=external-secrets \
7674
--set image.tag=test \
7775
--set env.LOG_LEVEL=debug \
@@ -83,7 +81,7 @@ helm template ${HELM_TEMPLATE_ARGS} \
8381
--set env.AWS_DEFAULT_REGION=us-east-1 \
8482
--set env.AWS_REGION=us-east-1 \
8583
--set env.POLLER_INTERVAL_MILLISECONDS=1000 \
86-
--set env.LOCALSTACK_STS_URL=http://sts | kubectl apply -f -
84+
--set env.LOCALSTACK_STS_URL=http://sts
8785

8886
echo -e "${BGREEN}Granting permissions to external-secrets e2e service account...${NC}"
8987
kubectl create serviceaccount external-secrets-e2e || true

e2e/tests/crd.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('CRD', () => {
2727
})
2828

2929
it('should reject invalid ExternalSecret manifests', async () => {
30-
kubeClient
30+
return kubeClient
3131
.apis[customResourceManifest.spec.group]
3232
.v1.namespaces('default')[customResourceManifest.spec.names.plural]
3333
.post({
@@ -48,6 +48,7 @@ describe('CRD', () => {
4848
}
4949
}
5050
})
51-
.catch(err => expect(err).to.be.an('error'))
51+
.then(() => { throw new Error('was not supposed to succeed') })
52+
.catch((err) => expect(err).to.match(/spec: Required value/))
5253
})
5354
})

e2e/tests/secrets-manager.test.js

+50-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ describe('secretsmanager', async () => {
124124
expect(secret.body.metadata.labels.secretLabel).to.equal('Hellofoo123')
125125
})
126126

127-
it('should pull TLS secret from secretsmanager', async () => {
127+
it('should pull TLS secret from secretsmanager - type', async () => {
128128
let result = await createSecret({
129129
Name: `e2e/${uuid}/tls/cert`,
130130
SecretString: '{"crt":"foo","key":"bar"}'
@@ -171,6 +171,55 @@ describe('secretsmanager', async () => {
171171
expect(secret.body.type).to.equal('kubernetes.io/tls')
172172
})
173173

174+
it('should pull TLS secret from secretsmanager - template', async () => {
175+
let result = await createSecret({
176+
Name: `e2e/${uuid}/tls/cert-template`,
177+
SecretString: '{"crt":"foo","key":"bar"}'
178+
}).catch(err => {
179+
expect(err).to.equal(null)
180+
})
181+
182+
result = await kubeClient
183+
.apis[customResourceManifest.spec.group]
184+
.v1.namespaces('default')[customResourceManifest.spec.names.plural]
185+
.post({
186+
body: {
187+
apiVersion: 'kubernetes-client.io/v1',
188+
kind: 'ExternalSecret',
189+
metadata: {
190+
name: `e2e-secretmanager-tls-template-${uuid}`
191+
},
192+
spec: {
193+
backendType: 'secretsManager',
194+
template: {
195+
type: 'kubernetes.io/tls'
196+
},
197+
data: [
198+
{
199+
key: `e2e/${uuid}/tls/cert-template`,
200+
property: 'crt',
201+
name: 'tls.crt'
202+
},
203+
{
204+
key: `e2e/${uuid}/tls/cert-template`,
205+
property: 'key',
206+
name: 'tls.key'
207+
}
208+
]
209+
}
210+
}
211+
})
212+
213+
expect(result).to.not.equal(undefined)
214+
expect(result.statusCode).to.equal(201)
215+
216+
const secret = await waitForSecret('default', `e2e-secretmanager-tls-template-${uuid}`)
217+
expect(secret).to.not.equal(undefined)
218+
expect(secret.body.data['tls.crt']).to.equal('Zm9v')
219+
expect(secret.body.data['tls.key']).to.equal('YmFy')
220+
expect(secret.body.type).to.equal('kubernetes.io/tls')
221+
})
222+
174223
it('should pull existing secret from secretsmanager in the correct region', async () => {
175224
const smEU = awsConfig.secretsManagerFactory({
176225
region: 'eu-west-1'

0 commit comments

Comments
 (0)