11/*
22Copyright AppsCode Inc. and Contributors
33
4- Licensed under the AppsCode Free Trial License 1.0 .0 (the "License");
4+ Licensed under the Apache License, Version 2 .0 (the "License");
55you may not use this file except in compliance with the License.
66You may obtain a copy of the License at
77
8- https ://github.com/appscode/ licenses/raw/1.0.0/AppsCode-Free-Trial-1.0.0.md
8+ http ://www.apache.org/ licenses/LICENSE-2.0
99
1010Unless required by applicable law or agreed to in writing, software
1111distributed under the License is distributed on an "AS IS" BASIS,
@@ -27,21 +27,20 @@ import (
2727 "path"
2828 "strings"
2929
30+ api "kmodules.xyz/objectstore-api/api/v1"
31+
3032 aws2 "github.com/aws/aws-sdk-go-v2/aws"
3133 "github.com/aws/aws-sdk-go-v2/config"
3234 "github.com/aws/aws-sdk-go-v2/credentials"
3335 "github.com/aws/aws-sdk-go-v2/service/s3"
34- "k8s.io/apimachinery/pkg/types"
35- v2 "kmodules.xyz/objectstore-api/api/v1"
36-
3736 "gocloud.dev/blob"
3837 _ "gocloud.dev/blob/azureblob"
3938 _ "gocloud.dev/blob/fileblob"
4039 _ "gocloud.dev/blob/gcsblob"
4140 "gocloud.dev/blob/s3blob"
42- _ "gocloud.dev/blob/s3blob"
43- v1 "k8s.io/api/core/v1"
41+ core "k8s.io/api/core/v1"
4442 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
43+ "k8s.io/apimachinery/pkg/types"
4544 "k8s.io/apimachinery/pkg/util/errors"
4645 "k8s.io/klog/v2"
4746 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -67,16 +66,16 @@ const (
6766type Blob struct {
6867 prefix string
6968 storageURL string
70- secret * v1 .Secret
71- bConfig * v2 .Backend
69+ secret * core .Secret
70+ bConfig * api .Backend
7271}
7372
74- func NewBlob (ctx context.Context , c client.Client , namespace string , bConfig * v2 .Backend ) (* Blob , error ) {
73+ func NewBlob (ctx context.Context , c client.Client , namespace string , bConfig * api .Backend ) (* Blob , error ) {
7574 provider , err := bConfig .Provider ()
7675 if err != nil {
7776 return nil , err
7877 }
79- var secret * v1 .Secret
78+ var secret * core .Secret
8079 if bConfig .StorageSecretName != "" {
8180 secret , err = getStorageSecret (ctx , c , types.NamespacedName {
8281 Namespace : namespace ,
@@ -88,28 +87,28 @@ func NewBlob(ctx context.Context, c client.Client, namespace string, bConfig *v2
8887 }
8988
9089 switch provider {
91- case v2 .ProviderS3 :
90+ case api .ProviderS3 :
9291 return s3Blob (secret , bConfig ), nil
93- case v2 .ProviderGCS :
92+ case api .ProviderGCS :
9493 return gcsBlob (secret , bConfig )
95- case v2 .ProviderAzure :
94+ case api .ProviderAzure :
9695 return azureBlob (secret , bConfig )
97- case v2 .ProviderLocal :
96+ case api .ProviderLocal :
9897 return localBlob (bConfig )
9998 default :
10099 return nil , fmt .Errorf ("unknown provider: %s" , provider )
101100 }
102101}
103102
104- func s3Blob (secret * v1 .Secret , bConfig * v2 .Backend ) * Blob {
103+ func s3Blob (secret * core .Secret , bConfig * api .Backend ) * Blob {
105104 return & Blob {
106105 secret : secret ,
107106 bConfig : bConfig ,
108107 prefix : bConfig .S3 .Prefix ,
109108 }
110109}
111110
112- func gcsBlob (secret * v1 .Secret , bConfig * v2 .Backend ) (* Blob , error ) {
111+ func gcsBlob (secret * core .Secret , bConfig * api .Backend ) (* Blob , error ) {
113112 if secret != nil {
114113 if err := setGcsCredentialsToEnv (secret ); err != nil {
115114 return nil , err
@@ -122,7 +121,7 @@ func gcsBlob(secret *v1.Secret, bConfig *v2.Backend) (*Blob, error) {
122121 }, nil
123122}
124123
125- func azureBlob (secret * v1 .Secret , bConfig * v2 .Backend ) (* Blob , error ) {
124+ func azureBlob (secret * core .Secret , bConfig * api .Backend ) (* Blob , error ) {
126125 if secret != nil {
127126 if err := setAzureCredentialsToEnv (secret ); err != nil {
128127 return nil , err
@@ -134,14 +133,14 @@ func azureBlob(secret *v1.Secret, bConfig *v2.Backend) (*Blob, error) {
134133 }, nil
135134}
136135
137- func localBlob (bConfig * v2 .Backend ) (* Blob , error ) {
136+ func localBlob (bConfig * api .Backend ) (* Blob , error ) {
138137 return & Blob {
139138 storageURL : fmt .Sprintf ("%s%s?no_tmp_dir=true" , localPrefix , bConfig .Local .MountPath ),
140139 }, nil
141140}
142141
143- func getStorageSecret (ctx context.Context , c client.Client , nsName types.NamespacedName ) (* v1 .Secret , error ) {
144- secret := & v1 .Secret {
142+ func getStorageSecret (ctx context.Context , c client.Client , nsName types.NamespacedName ) (* core .Secret , error ) {
143+ secret := & core .Secret {
145144 ObjectMeta : metav1.ObjectMeta {
146145 Namespace : nsName .Namespace ,
147146 Name : nsName .Name ,
@@ -153,7 +152,7 @@ func getStorageSecret(ctx context.Context, c client.Client, nsName types.Namespa
153152 return secret , nil
154153}
155154
156- func setGcsCredentialsToEnv (secret * v1 .Secret ) error {
155+ func setGcsCredentialsToEnv (secret * core .Secret ) error {
157156 if val , ok := secret .Data [googleServiceAccountJsonKey ]; ! ok {
158157 return fmt .Errorf ("storage secret missing %s key" , googleServiceAccountJsonKey )
159158 } else {
@@ -168,7 +167,7 @@ func setGcsCredentialsToEnv(secret *v1.Secret) error {
168167 return nil
169168}
170169
171- func setAzureCredentialsToEnv (secret * v1 .Secret ) error {
170+ func setAzureCredentialsToEnv (secret * core .Secret ) error {
172171 if val , ok := secret .Data [azureAccountKey ]; ! ok {
173172 return fmt .Errorf ("storage secret missing %s key" , azureAccountKey )
174173 } else {
@@ -427,7 +426,7 @@ func (b *Blob) openBucketWithDebug(ctx context.Context, dir string, debug bool)
427426 return nil , err
428427 }
429428
430- if provider == v2 .ProviderS3 {
429+ if provider == api .ProviderS3 {
431430 cfg , err := b .getS3Config (ctx , debug )
432431 if err != nil {
433432 return nil , err
0 commit comments