Skip to content

Commit 2df3d6b

Browse files
committed
Add feature to fetch the cluster url from the kube-system/cluster-config-v1 configmap
2 parents 91e4534 + 16f6fce commit 2df3d6b

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

cmd/aws-s3-provisioner.go

+28-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
awsuser "github.com/aws/aws-sdk-go/service/iam"
3333
"github.com/aws/aws-sdk-go/service/s3"
3434
"github.com/aws/aws-sdk-go/service/s3/s3manager"
35+
"gopkg.in/yaml.v2"
3536

3637
"github.com/golang/glog"
3738
"github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1"
@@ -40,6 +41,7 @@ import (
4041
bkterr "github.com/kube-object-storage/lib-bucket-provisioner/pkg/provisioner/api/errors"
4142

4243
storageV1 "k8s.io/api/storage/v1"
44+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4345
"k8s.io/client-go/kubernetes"
4446
restclient "k8s.io/client-go/rest"
4547
"k8s.io/client-go/tools/clientcmd"
@@ -100,6 +102,11 @@ type awsS3Provisioner struct {
100102
isBucketEncryptionRequired bool
101103
}
102104

105+
type KubeInstalConfig struct {
106+
BaseDomain string `yaml:"baseDomain"`
107+
Metadata metav1.ObjectMeta `yaml:"metadata"`
108+
}
109+
103110
func NewAwsS3Provisioner(cfg *restclient.Config, s3Provisioner awsS3Provisioner) (*libbkt.Provisioner, error) {
104111

105112
const all_namespaces = ""
@@ -326,8 +333,27 @@ func (p *awsS3Provisioner) initializeCreateOrGrant(options *apibkt.BucketOptions
326333
// get the OBC and its storage class
327334
obc := options.ObjectBucketClaim
328335

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)
331357
p.cleanseTagValues()
332358

333359
scName := options.ObjectBucketClaim.Spec.StorageClassName

0 commit comments

Comments
 (0)