Skip to content

Commit 1b4a2b9

Browse files
author
bcm820
authored
[feat] Add ObjectStorageKey (#426)
1 parent bd77f69 commit 1b4a2b9

29 files changed

+2804
-4
lines changed

PROJECT

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,16 @@ resources:
153153
conversion: true
154154
validation: true
155155
webhookVersion: v1
156+
- api:
157+
crdVersion: v1
158+
namespaced: true
159+
controller: true
160+
domain: cluster.x-k8s.io
161+
group: infrastructure
162+
kind: LinodeObjectStorageKey
163+
path: github.com/linode/cluster-api-provider-linode/api/v1alpha2
164+
version: v1alpha2
165+
webhooks:
166+
validation: true
167+
webhookVersion: v1
156168
version: "3"
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
Copyright 2023 Akamai Technologies, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha2
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
23+
)
24+
25+
const (
26+
// ObjectStorageKeyFinalizer allows ReconcileLinodeObjectStorageKey to clean up Linode resources associated
27+
// with LinodeObjectStorageKey before removing it from the apiserver.
28+
ObjectStorageKeyFinalizer = "linodeobjectstoragekey.infrastructure.cluster.x-k8s.io"
29+
)
30+
31+
type BucketAccessRef struct {
32+
BucketName string `json:"bucketName"`
33+
Permissions string `json:"permissions"`
34+
Region string `json:"region"`
35+
}
36+
37+
// LinodeObjectStorageKeySpec defines the desired state of LinodeObjectStorageKey
38+
type LinodeObjectStorageKeySpec struct {
39+
// BucketAccess is the list of object storage bucket labels which can be accessed using the key
40+
// +kubebuilder:validation:MinItems=1
41+
BucketAccess []BucketAccessRef `json:"bucketAccess"`
42+
43+
// CredentialsRef is a reference to a Secret that contains the credentials to use for generating access keys.
44+
// If not supplied then the credentials of the controller will be used.
45+
// +optional
46+
CredentialsRef *corev1.SecretReference `json:"credentialsRef"`
47+
48+
// KeyGeneration may be modified to trigger a rotation of the access key.
49+
// +kubebuilder:default=0
50+
KeyGeneration int `json:"keyGeneration"`
51+
52+
// SecretType instructs the controller what type of secret to generate containing access key details.
53+
// +kubebuilder:validation:Enum=Opaque;addons.cluster.x-k8s.io/resource-set
54+
// +kubebuilder:default=Opaque
55+
// +optional
56+
SecretType corev1.SecretType `json:"secretType,omitempty"`
57+
}
58+
59+
// LinodeObjectStorageKeyStatus defines the observed state of LinodeObjectStorageKey
60+
type LinodeObjectStorageKeyStatus struct {
61+
// Ready denotes that the key has been provisioned.
62+
// +optional
63+
// +kubebuilder:default=false
64+
Ready bool `json:"ready"`
65+
66+
// FailureMessage will be set in the event that there is a terminal problem
67+
// reconciling the Object Storage Key and will contain a verbose string
68+
// suitable for logging and human consumption.
69+
// +optional
70+
FailureMessage *string `json:"failureMessage,omitempty"`
71+
72+
// Conditions specify the service state of the LinodeObjectStorageKey.
73+
// +optional
74+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
75+
76+
// CreationTime specifies the creation timestamp for the secret.
77+
// +optional
78+
CreationTime *metav1.Time `json:"creationTime,omitempty"`
79+
80+
// LastKeyGeneration tracks the last known value of .spec.keyGeneration.
81+
// +optional
82+
LastKeyGeneration *int `json:"lastKeyGeneration,omitempty"`
83+
84+
// SecretName specifies the name of the Secret containing access key data.
85+
// +optional
86+
SecretName *string `json:"secretName,omitempty"`
87+
88+
// AccessKeyRef stores the ID for Object Storage key provisioned.
89+
// +optional
90+
AccessKeyRef *int `json:"accessKeyRef,omitempty"`
91+
}
92+
93+
// +kubebuilder:object:root=true
94+
// +kubebuilder:resource:path=linodeobjectstoragekeys,scope=Namespaced,categories=cluster-api,shortName=lobjkey
95+
// +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="Secret",type="string",JSONPath=".status.secretName",description="The name of the Secret containing access key data"
99+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Whether the access key is synced in the Linode API"
100+
101+
// LinodeObjectStorageKey is the Schema for the linodeobjectstoragekeys API
102+
type LinodeObjectStorageKey struct {
103+
metav1.TypeMeta `json:",inline"`
104+
metav1.ObjectMeta `json:"metadata,omitempty"`
105+
106+
Spec LinodeObjectStorageKeySpec `json:"spec,omitempty"`
107+
Status LinodeObjectStorageKeyStatus `json:"status,omitempty"`
108+
}
109+
110+
func (b *LinodeObjectStorageKey) GetConditions() clusterv1.Conditions {
111+
return b.Status.Conditions
112+
}
113+
114+
func (b *LinodeObjectStorageKey) SetConditions(conditions clusterv1.Conditions) {
115+
b.Status.Conditions = conditions
116+
}
117+
118+
// +kubebuilder:object:root=true
119+
120+
// LinodeObjectStorageKeyList contains a list of LinodeObjectStorageKey
121+
type LinodeObjectStorageKeyList struct {
122+
metav1.TypeMeta `json:",inline"`
123+
metav1.ListMeta `json:"metadata,omitempty"`
124+
Items []LinodeObjectStorageKey `json:"items"`
125+
}
126+
127+
func init() {
128+
SchemeBuilder.Register(&LinodeObjectStorageKey{}, &LinodeObjectStorageKeyList{})
129+
}

api/v1alpha2/zz_generated.deepcopy.go

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

cloud/scope/object_storage_bucket.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func validateObjectStorageBucketScopeParams(params ObjectStorageBucketScopeParam
6565
return nil
6666
}
6767

68+
//nolint:dupl // TODO: Remove fields related to key provisioning from the bucket resource.
6869
func NewObjectStorageBucketScope(ctx context.Context, apiKey string, params ObjectStorageBucketScopeParams) (*ObjectStorageBucketScope, error) {
6970
if err := validateObjectStorageBucketScopeParams(params); err != nil {
7071
return nil, err

cloud/scope/object_storage_bucket_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func TestObjectStorageBucketScopeMethods(t *testing.T) {
296296
}
297297
}
298298

299-
func TestGenerateKeySecret(t *testing.T) {
299+
func TestGenerateKeySecretBucket(t *testing.T) {
300300
t.Parallel()
301301
tests := []struct {
302302
name string

0 commit comments

Comments
 (0)