Skip to content

Commit

Permalink
feature: Use CLUSTER_DOMAIN env to specify cluster domain (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
reneluria authored Apr 24, 2020
1 parent 9aff199 commit 607f5f2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions minio-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions pkg/apis/miniocontroller/v1beta1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package constants

import (
"crypto/elliptic"
"os"
"time"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -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")

0 comments on commit 607f5f2

Please sign in to comment.