From 607f5f2d85907f583b28b2bc9a4034d480e86eee Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Fri, 24 Apr 2020 07:18:26 +0200 Subject: [PATCH] feature: Use CLUSTER_DOMAIN env to specify cluster domain (#84) --- README.md | 1 + minio-operator.yaml | 4 ++++ pkg/apis/miniocontroller/v1beta1/helper.go | 6 +++--- pkg/constants/constants.go | 11 +++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8fec0f1de6c..1160c45d431 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ These variables may be passed to operator Deployment in order to modify some of | name | default | description | | --- | --- | --- | | `WATCHED_NAMESPACE` | | If set, the operator will watch only MinIO resources deployed in the specified namespace. All namespaces are watched if empty | +| `CLUSTER_DOMAIN` | cluster.local | "cluster domain" of the kubernetes cluster the operator is to be installed on | ### Create a MinIO instance diff --git a/minio-operator.yaml b/minio-operator.yaml index 8983b6dc74e..647bcf7b723 100644 --- a/minio-operator.yaml +++ b/minio-operator.yaml @@ -134,3 +134,7 @@ spec: - name: minio-operator image: minio/k8s-operator:1.0.8 imagePullPolicy: IfNotPresent + # To specify cluster domain, un comment the following: + # env: + # - name: CLUSTER_DOMAIN + # value: mycluster.mydomain diff --git a/pkg/apis/miniocontroller/v1beta1/helper.go b/pkg/apis/miniocontroller/v1beta1/helper.go index f8e058b41ef..34bcc5ad9a3 100644 --- a/pkg/apis/miniocontroller/v1beta1/helper.go +++ b/pkg/apis/miniocontroller/v1beta1/helper.go @@ -163,9 +163,9 @@ func (mi *MinIOInstance) GetHosts() []string { for i, z := range mi.Spec.Zones { max = max + z.Servers if i == 0 { - hosts = append(hosts, fmt.Sprintf("%s-{0..."+strconv.Itoa(int(max)-1)+"}.%s.%s.svc.cluster.local", mi.Name, mi.GetHeadlessServiceName(), mi.Namespace)) + hosts = append(hosts, fmt.Sprintf("%s-{0..."+strconv.Itoa(int(max)-1)+"}.%s.%s.svc."+constants.ClusterDomain, mi.Name, mi.GetHeadlessServiceName(), mi.Namespace)) } else { - hosts = append(hosts, fmt.Sprintf("%s-{"+strconv.Itoa(int(mi.Spec.Zones[i-1].Servers))+"..."+strconv.Itoa(int(max)-1)+"}.%s.%s.svc.cluster.local", mi.Name, mi.GetHeadlessServiceName(), mi.Namespace)) + hosts = append(hosts, fmt.Sprintf("%s-{"+strconv.Itoa(int(mi.Spec.Zones[i-1].Servers))+"..."+strconv.Itoa(int(max)-1)+"}.%s.%s.svc."+constants.ClusterDomain, mi.Name, mi.GetHeadlessServiceName(), mi.Namespace)) } } return hosts @@ -175,7 +175,7 @@ func (mi *MinIOInstance) GetHosts() []string { // current MinIOInstance func (mi *MinIOInstance) GetWildCardName() string { // mi.Name is the headless service name - return fmt.Sprintf("*.%s.%s.svc.cluster.local", mi.GetHeadlessServiceName(), mi.Namespace) + return fmt.Sprintf("*.%s.%s.svc."+constants.ClusterDomain, mi.GetHeadlessServiceName(), mi.Namespace) } // GetTLSSecretName returns the name of Secret that has TLS related Info (Cert & Prviate Key) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index c25a3e5dc7a..849952f7392 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -19,6 +19,7 @@ package constants import ( "crypto/elliptic" + "os" "time" appsv1 "k8s.io/api/apps/v1" @@ -97,3 +98,13 @@ const DefaultVolumesPerServer = 1 // DefaultZoneName specifies the default zone name const DefaultZoneName = "zone-0" + +func getEnv(key, defaultValue string) string { + value := os.Getenv(key) + if len(value) == 0 { + return defaultValue + } + return value +} + +var ClusterDomain = getEnv("CLUSTER_DOMAIN", "cluster.local")