Skip to content

Commit 75eed5d

Browse files
author
Brian Mendoza
committed
add e2e tests for LinodeObjectStorageKey
1 parent a3c69dd commit 75eed5d

File tree

10 files changed

+202
-15
lines changed

10 files changed

+202
-15
lines changed

api/v1alpha2/linodeobjectstoragekey_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ type BucketAccessRef struct {
3636

3737
// LinodeObjectStorageKeySpec defines the desired state of LinodeObjectStorageKey
3838
type LinodeObjectStorageKeySpec struct {
39-
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
40-
// Important: Run "make" to regenerate code after modifying this file
41-
4239
// BucketAccess is the list of object storage bucket labels which can be accessed using the key
4340
// +kubebuilder:validation:MinItems=1
4441
BucketAccess []BucketAccessRef `json:"bucketAccess"`
@@ -61,9 +58,6 @@ type LinodeObjectStorageKeySpec struct {
6158

6259
// LinodeObjectStorageKeyStatus defines the observed state of LinodeObjectStorageKey
6360
type LinodeObjectStorageKeyStatus struct {
64-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
65-
// Important: Run "make" to regenerate code after modifying this file
66-
6761
// Ready denotes that the key has been provisioned.
6862
// +optional
6963
// +kubebuilder:default=false
@@ -87,7 +81,7 @@ type LinodeObjectStorageKeyStatus struct {
8781
// +optional
8882
LastKeyGeneration *int `json:"lastKeyGeneration,omitempty"`
8983

90-
// KeySecretName specifies the name of the Secret containing the access key.
84+
// KeySecretName specifies the name of the Secret containing access key data.
9185
// +optional
9286
KeySecretName *string `json:"keySecretName,omitempty"`
9387

@@ -97,7 +91,13 @@ type LinodeObjectStorageKeyStatus struct {
9791
}
9892

9993
// +kubebuilder:object:root=true
94+
// +kubebuilder:resource:path=linodeobjectstoragekeys,scope=Namespaced,categories=cluster-api,shortName=lobjkey
10095
// +kubebuilder:subresource:status
96+
// +kubebuilder:metadata:labels="clusterctl.cluster.x-k8s.io/move-hierarchy=true"
97+
// +kubebuilder:printcolumn:name="ID",type="string",JSONPath=".status.accessKeyRef",description="The ID assigned to the access key"
98+
// +kubebuilder:printcolumn:name="Label",type="string",JSONPath=".metadata.name",description="The label of the access key"
99+
// +kubebuilder:printcolumn:name="Secret",type="string",JSONPath=".metadata.name",description="The name of the Secret containing access key data"
100+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Whether the access key is synced in the Linode API"
101101

102102
// LinodeObjectStorageKey is the Schema for the linodeobjectstoragekeys API
103103
type LinodeObjectStorageKey struct {

config/crd/bases/infrastructure.cluster.x-k8s.io_linodeobjectstoragekeys.yaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,40 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.14.0
7+
labels:
8+
clusterctl.cluster.x-k8s.io/move-hierarchy: "true"
79
name: linodeobjectstoragekeys.infrastructure.cluster.x-k8s.io
810
spec:
911
group: infrastructure.cluster.x-k8s.io
1012
names:
13+
categories:
14+
- cluster-api
1115
kind: LinodeObjectStorageKey
1216
listKind: LinodeObjectStorageKeyList
1317
plural: linodeobjectstoragekeys
18+
shortNames:
19+
- lobjkey
1420
singular: linodeobjectstoragekey
1521
scope: Namespaced
1622
versions:
17-
- name: v1alpha2
23+
- additionalPrinterColumns:
24+
- description: The ID assigned to the access key
25+
jsonPath: .status.accessKeyRef
26+
name: ID
27+
type: string
28+
- description: The label of the access key
29+
jsonPath: .metadata.name
30+
name: Label
31+
type: string
32+
- description: The name of the Secret containing access key data
33+
jsonPath: .metadata.name
34+
name: Secret
35+
type: string
36+
- description: Whether the access key is synced in the Linode API
37+
jsonPath: .status.ready
38+
name: Ready
39+
type: string
40+
name: v1alpha2
1841
schema:
1942
openAPIV3Schema:
2043
description: LinodeObjectStorageKey is the Schema for the linodeobjectstoragekeys
@@ -155,7 +178,7 @@ spec:
155178
type: string
156179
keySecretName:
157180
description: KeySecretName specifies the name of the Secret containing
158-
the access key.
181+
access key data.
159182
type: string
160183
lastKeyGeneration:
161184
description: LastKeyGeneration tracks the last known value of .spec.keyGeneration.

config/rbac/role.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rules:
2121
- secrets
2222
verbs:
2323
- create
24+
- delete
2425
- get
2526
- list
2627
- patch
@@ -123,7 +124,7 @@ rules:
123124
- apiGroups:
124125
- infrastructure.cluster.x-k8s.io
125126
resources:
126-
- linodeobjectstoragekey
127+
- linodeobjectstoragekeys
127128
verbs:
128129
- create
129130
- delete
@@ -135,13 +136,13 @@ rules:
135136
- apiGroups:
136137
- infrastructure.cluster.x-k8s.io
137138
resources:
138-
- linodeobjectstoragekey/finalizers
139+
- linodeobjectstoragekeys/finalizers
139140
verbs:
140141
- update
141142
- apiGroups:
142143
- infrastructure.cluster.x-k8s.io
143144
resources:
144-
- linodeobjectstoragekey/status
145+
- linodeobjectstoragekeys/status
145146
verbs:
146147
- get
147148
- patch

controller/linodeobjectstoragekey_controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ type LinodeObjectStorageKeyReconciler struct {
6060
ReconcileTimeout time.Duration
6161
}
6262

63-
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragekey,verbs=get;list;watch;create;update;patch;delete
64-
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragekey/status,verbs=get;update;patch
65-
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragekey/finalizers,verbs=update
63+
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragekeys,verbs=get;list;watch;create;update;patch;delete
64+
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragekeys/status,verbs=get;update;patch
65+
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragekeys/finalizers,verbs=update
66+
67+
// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch
68+
// +kubebuilder:rbac:groups="",resources=secrets;,verbs=get;list;watch;create;update;patch;delete
6669

6770
// Reconcile is part of the main kubernetes reconciliation loop which aims to
6871
// move the current state of the cluster closer to the desired state.

docs/src/developers/testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ There are other selectors you can use to invoke specfic tests. Please look at th
236236
| Linode Cluster Controller | `linodecluster` |
237237
| Linode Machine Controller | `linodemachine` |
238238
| Linode Obj Controller | `linodeobj` |
239+
| Linode Obj Key Controller | `linodeobjkey` |
239240
| Linode VPC Controller | `linodevpc` |
240241

241242
*Note: For any flavor e2e tests, please set the required env variables*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: capi-controller-manager
5+
namespace: capi-system
6+
status:
7+
availableReplicas: 1
8+
---
9+
apiVersion: apps/v1
10+
kind: Deployment
11+
metadata:
12+
name: capl-controller-manager
13+
namespace: capl-system
14+
status:
15+
availableReplicas: 1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
3+
kind: LinodeObjectStorageKey
4+
metadata:
5+
name: ($key)
6+
spec:
7+
bucketAccess:
8+
- bucketName: ($key)
9+
permissions: read_only
10+
region: us-sea
11+
keyGeneration: 0
12+
status:
13+
ready: true
14+
keySecretName: ($access_key_secret)
15+
lastKeyGeneration: 0
16+
---
17+
apiVersion: v1
18+
kind: Secret
19+
metadata:
20+
name: ($access_key_secret)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
name: minimal-linodeobjectstoragekey
6+
# Label to trigger the test on every PR
7+
labels:
8+
all:
9+
quick:
10+
linodeobjkey:
11+
spec:
12+
bindings:
13+
# A short identifier for the E2E test run
14+
- name: run
15+
value: (join('-', ['e2e', 'min-obj', env('GIT_REF')]))
16+
- name: key
17+
# Format the key name into a valid Kubernetes object name
18+
# TODO: This is over-truncated to account for the Kubernetes access key Secret
19+
value: (trim((truncate(($run), `52`)), '-'))
20+
- name: access_key_secret
21+
value: (join('-', [($key), 'etcd-backup']))
22+
template: true
23+
steps:
24+
- name: Check if CAPI provider resources exist
25+
try:
26+
- assert:
27+
file: assert-capi-resources.yaml
28+
- name: Create bucket
29+
try:
30+
- script:
31+
env:
32+
- name: URI
33+
value: object-storage/buckets
34+
- name: BUCKET_LABEL
35+
value: ($key)
36+
content: |
37+
set -e
38+
39+
curl -s \
40+
-X POST \
41+
-H "Authorization: Bearer $LINODE_TOKEN" \
42+
-H "Content-Type: application/json" \
43+
-d "{\"label\":\"$BUCKET_LABEL\",\"region\":\"us-sea\"}" \
44+
"https://api.linode.com/v4/$URI"
45+
check:
46+
($error): ~
47+
- name: Create LinodeObjectStorageKey
48+
try:
49+
- apply:
50+
file: create-linodeobjectstoragekey.yaml
51+
- assert:
52+
file: assert-key-and-secret.yaml
53+
catch:
54+
- describe:
55+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
56+
kind: LinodeObjectStorageKey
57+
- describe:
58+
apiVersion: v1
59+
kind: Secret
60+
- name: Ensure the access key was created
61+
try:
62+
- script:
63+
env:
64+
- name: URI
65+
value: object-storage/keys
66+
- name: OBJ_KEY
67+
value: ($key)
68+
content: |
69+
set -e
70+
71+
export KEY_ID=$(kubectl -n $NAMESPACE get lobjkey $OBJ_KEY -ojson | jq '.status.accessKeyRef')
72+
73+
curl -s \
74+
-H "Authorization: Bearer $LINODE_TOKEN" \
75+
-H "Content-Type: application/json" \
76+
"https://api.linode.com/v4/$URI/$KEY_ID"
77+
check:
78+
($error): ~
79+
- name: Delete LinodeObjectStorageKey
80+
try:
81+
- delete:
82+
ref:
83+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
84+
kind: LinodeObjectStorageKey
85+
name: ($key)
86+
- name: Check if the LinodeObjectStorageKey and Secret were deleted
87+
try:
88+
- error:
89+
file: check-key-and-secret-deletion.yaml
90+
- name: Delete bucket
91+
try:
92+
- script:
93+
env:
94+
- name: URI
95+
value: object-storage/buckets/us-sea
96+
- name: BUCKET_LABEL
97+
value: ($key)
98+
content: |
99+
set -e
100+
101+
curl -s \
102+
-X DELETE \
103+
-H "Authorization: Bearer $LINODE_TOKEN" \
104+
"https://api.linode.com/v4/$URI/$BUCKET_LABEL"
105+
check:
106+
($error): ~
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
2+
kind: LinodeObjectStorageKey
3+
metadata:
4+
name: ($key)
5+
---
6+
apiVersion: v1
7+
kind: Secret
8+
metadata:
9+
name: ($access_key_secret)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
2+
kind: LinodeObjectStorageKey
3+
metadata:
4+
name: ($key)
5+
spec:
6+
bucketAccess:
7+
- bucketName: ($key)
8+
permissions: read_only
9+
region: us-sea

0 commit comments

Comments
 (0)