@@ -32,6 +32,7 @@ import (
32
32
awsuser "github.com/aws/aws-sdk-go/service/iam"
33
33
"github.com/aws/aws-sdk-go/service/s3"
34
34
"github.com/aws/aws-sdk-go/service/s3/s3manager"
35
+ "gopkg.in/yaml.v2"
35
36
36
37
"github.com/golang/glog"
37
38
"github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1"
@@ -40,6 +41,7 @@ import (
40
41
bkterr "github.com/kube-object-storage/lib-bucket-provisioner/pkg/provisioner/api/errors"
41
42
42
43
storageV1 "k8s.io/api/storage/v1"
44
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
43
45
"k8s.io/client-go/kubernetes"
44
46
restclient "k8s.io/client-go/rest"
45
47
"k8s.io/client-go/tools/clientcmd"
@@ -100,6 +102,11 @@ type awsS3Provisioner struct {
100
102
isBucketEncryptionRequired bool
101
103
}
102
104
105
+ type KubeInstalConfig struct {
106
+ BaseDomain string `yaml:"baseDomain"`
107
+ Metadata metav1.ObjectMeta `yaml:"metadata"`
108
+ }
109
+
103
110
func NewAwsS3Provisioner (cfg * restclient.Config , s3Provisioner awsS3Provisioner ) (* libbkt.Provisioner , error ) {
104
111
105
112
const all_namespaces = ""
@@ -326,8 +333,27 @@ func (p *awsS3Provisioner) initializeCreateOrGrant(options *apibkt.BucketOptions
326
333
// get the OBC and its storage class
327
334
obc := options .ObjectBucketClaim
328
335
329
- // set the bucket tags from the obc annotations
330
- p .bucketTags = append (p .bucketTags , p .convertToS3BucketTags (obc .ObjectMeta .Annotations )... )
336
+ // Fetching cluster url (metadata.name + baseDomain) from the kube-system/cluster-config-v1 configmap
337
+ configMap , err := p .clientset .CoreV1 ().ConfigMaps ("kube-system" ).Get ("cluster-config-v1" , metav1.GetOptions {})
338
+ if err != nil {
339
+ glog .Errorf ("failed to get configmap \" kube-system/cluster-config-v1\" : %v" , err )
340
+ return err
341
+ }
342
+ installConfigYaml := configMap .Data ["install-config" ]
343
+ installConfig := KubeInstalConfig {}
344
+ err = yaml .Unmarshal ([]byte (installConfigYaml ), & installConfig )
345
+ if err != nil {
346
+ glog .Errorf ("failed to unmarshal the cluster-configs.yaml: %v" , err )
347
+ return err
348
+ }
349
+
350
+ // set the bucket tags from the obc annotation and add additional tags
351
+ annotations := obc .ObjectMeta .Annotations
352
+ annotations ["Cluster" ] = fmt .Sprintf ("%s.%s" , installConfig .Metadata .Name , installConfig .BaseDomain )
353
+ annotations ["Namespace" ] = obc .Namespace
354
+ annotations ["Name" ] = obc .Name
355
+
356
+ p .bucketTags = p .convertToS3BucketTags (obc .ObjectMeta .Annotations )
331
357
p .cleanseTagValues ()
332
358
333
359
scName := options .ObjectBucketClaim .Spec .StorageClassName
0 commit comments