Skip to content

Commit de22fb1

Browse files
committed
Introducing the const pkg
1 parent d4075d3 commit de22fb1

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

container-object-storage-interface-provisioner-sidecar/pkg/bucket/bucket_controller.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"sigs.k8s.io/container-object-storage-interface-api/apis/objectstorage.k8s.io/v1alpha1"
2828
buckets "sigs.k8s.io/container-object-storage-interface-api/clientset"
2929
bucketapi "sigs.k8s.io/container-object-storage-interface-api/clientset/typed/objectstorage.k8s.io/v1alpha1"
30+
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/const"
3031
cosi "sigs.k8s.io/container-object-storage-interface-spec"
3132
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3233

@@ -35,10 +36,6 @@ import (
3536
"google.golang.org/grpc/status"
3637
)
3738

38-
const (
39-
bcFinalizer = "cosi.objectstorage.k8s.io/bucketclaim-protection"
40-
)
41-
4239
// BucketListener manages Bucket objects
4340
type BucketListener struct {
4441
provisionerClient cosi.ProvisionerClient
@@ -155,7 +152,7 @@ func (b *BucketListener) Update(ctx context.Context, old, new *v1alpha1.Bucket)
155152
klog.V(3).InfoS("Update Bucket",
156153
"name", old.Name)
157154

158-
if !new.GetDeletionTimestamp.IsZero() {
155+
if !new.GetDeletionTimestamp().IsZero() {
159156
if len(new.ObjectMeta.Finalizers) > 0 {
160157
bucketClaimNs := new.Spec.BucketClaim.Namespace
161158
bucketClaimName := new.Spec.BucketClaim.Name
@@ -219,7 +216,7 @@ func (b *BucketListener) Delete(ctx context.Context, inputBucket *v1alpha1.Bucke
219216
return err
220217
}
221218

222-
if controllerutil.RemoveFinalizer(bucketClaim, bcFinalizer) {
219+
if controllerutil.RemoveFinalizer(bucketClaim, const.BcFinalizer) {
223220
if _, err := b.BucketClaims(bucketClaim.Namespace).Update(ctx, bucketClaim, metav1.UpdateOptions{}); err != nil {
224221
return err
225222
}

container-object-storage-interface-provisioner-sidecar/pkg/bucketaccess/bucketaccess_controller.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,14 @@ import (
3333
"sigs.k8s.io/container-object-storage-interface-api/apis/objectstorage.k8s.io/v1alpha1"
3434
buckets "sigs.k8s.io/container-object-storage-interface-api/clientset"
3535
bucketapi "sigs.k8s.io/container-object-storage-interface-api/clientset/typed/objectstorage.k8s.io/v1alpha1"
36+
"sigs.k8s.io/container-object-storage-interface-provisioner-sidecar/pkg/const"
3637
cosi "sigs.k8s.io/container-object-storage-interface-spec"
3738

3839
"github.com/pkg/errors"
3940
"google.golang.org/grpc/codes"
4041
"google.golang.org/grpc/status"
4142
)
4243

43-
const (
44-
accountNamePrefix = "ba-"
45-
baFinalizer = "cosi.objectstorage.k8s.io/bucketaccess-protection-"
46-
secretFinalizer = "cosi.objectstorage.k8s.io/secret-protection"
47-
)
48-
4944
// BucketAccessListener manages Bucket objects
5045
type BucketAccessListener struct {
5146
provisionerClient cosi.ProvisionerClient
@@ -155,7 +150,7 @@ func (bal *BucketAccessListener) Add(ctx context.Context, inputBucketAccess *v1a
155150
return errors.New("BucketAccess can't be granted to bucket not in Ready state and without a bucketID")
156151
}
157152

158-
accountName := accountNamePrefix + string(bucketAccess.UID)
153+
accountName := const.AccountNamePrefix + string(bucketAccess.UID)
159154

160155
req := &cosi.DriverGrantBucketAccessRequest{
161156
BucketId: bucket.Status.BucketID,
@@ -214,7 +209,7 @@ func (bal *BucketAccessListener) Add(ctx context.Context, inputBucketAccess *v1a
214209
ObjectMeta: metav1.ObjectMeta{
215210
Name: secretCredName,
216211
Namespace: namespace,
217-
Finalizers: []string{secretFinalizer},
212+
Finalizers: []string{const.SecretFinalizer},
218213
},
219214
StringData: map[string]string{
220215
BucketInfo: string(stringData),
@@ -231,7 +226,7 @@ func (bal *BucketAccessListener) Add(ctx context.Context, inputBucketAccess *v1a
231226
}
232227
}
233228

234-
bucketFinalizer := baFinalizer + string(bucketAccess.ObjectMeta.UID)
229+
bucketFinalizer := const.BaFinalizer + string(bucketAccess.ObjectMeta.UID)
235230
finalizers := bucket.ObjectMeta.Finalizers
236231
finalizers = append(finalizers, bucketFinalizer)
237232
bucket.ObjectMeta.Finalizers = finalizers
@@ -281,7 +276,7 @@ func (bal *BucketAccessListener) Delete(ctx context.Context, bucketAccess *v1alp
281276
return err
282277
}
283278

284-
if controllerutil.RemoveFinalizer(secret, secretFinalizer) {
279+
if controllerutil.RemoveFinalizer(secret, const.SecretFinalizer) {
285280
_, err = bal.Secrets(bucketAccess.ObjectMeta.Namespace).Update(ctx, credSecretName, metav1.UpdateOptions{})
286281
if err != nil {
287282
return err
@@ -299,7 +294,7 @@ func (bal *BucketAccessListener) Delete(ctx context.Context, bucketAccess *v1alp
299294
return err
300295
}
301296

302-
bucketFinalizer := baFinalizer + string(bucketAccess.ObjectMeta.UID)
297+
bucketFinalizer := const.BaFinalizer + string(bucketAccess.ObjectMeta.UID)
303298
if controllerutil.RemoveFinalizer(bucketFinalizer) {
304299
_, err = bal.Buckets().Update(ctx, bucket, metav1.UpdateOptions{})
305300
if err != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* Copyright 2022 The Kubernetes Authors.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package const
17+
18+
const (
19+
AccountNamePrefix = "ba-"
20+
BaFinalizer = "cosi.objectstorage.k8s.io/bucketaccess-protection-"
21+
BcFinalizer = "cosi.objectstorage.k8s.io/bucketclaim-protection"
22+
SecretFinalizer = "cosi.objectstorage.k8s.io/secret-protection"
23+
)

0 commit comments

Comments
 (0)