diff --git a/manifests/configmap.yaml b/manifests/configmap.yaml index 9c467f196..89c352b5e 100644 --- a/manifests/configmap.yaml +++ b/manifests/configmap.yaml @@ -9,7 +9,7 @@ data: pod_role_label: spilo-role db_hosted_zone: db.example.com debug_logging: "true" - dns_name_format: '%s.%s.staging.%s' + dns_name_format: '{cluster}.{team}.staging.{hostedzone}' docker_image: registry.opensource.zalan.do/acid/spiloprivate-9.6:1.2-p4 etcd_host: etcd-client.default.svc.cluster.local:2379 infrastructure_roles_secret_name: postgresql-infrastructure-roles diff --git a/pkg/cluster/util.go b/pkg/cluster/util.go index c76e844e9..cfa2def35 100644 --- a/pkg/cluster/util.go +++ b/pkg/cluster/util.go @@ -245,11 +245,10 @@ func (c *Cluster) labelsSet() labels.Set { } func (c *Cluster) dnsName() string { - return strings.ToLower(fmt.Sprintf( - c.OpConfig.DNSNameFormat, - c.Spec.ClusterName, - c.teamName(), - c.OpConfig.DbHostedZone)) + return strings.ToLower(c.OpConfig.DNSNameFormat.Format( + "cluster", c.Spec.ClusterName, + "team", c.teamName(), + "hostedzone", c.OpConfig.DbHostedZone)) } func (c *Cluster) credentialSecretName(username string) string { diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index 7ed7c76aa..e61848b3e 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -43,19 +43,19 @@ type Config struct { TPR Resources Auth - Namespace string `name:"namespace"` - EtcdHost string `name:"etcd_host" default:"etcd-client.default.svc.cluster.local:2379"` - DockerImage string `name:"docker_image" default:"registry.opensource.zalan.do/acid/spiloprivate-9.6:1.2-p4"` - ServiceAccountName string `name:"service_account_name" default:"operator"` - DbHostedZone string `name:"db_hosted_zone" default:"db.example.com"` - EtcdScope string `name:"etcd_scope" default:"service"` - WALES3Bucket string `name:"wal_s3_bucket"` - KubeIAMRole string `name:"kube_iam_role"` - DebugLogging bool `name:"debug_logging" default:"false"` - EnableDBAccess bool `name:"enable_database_access" default:"true"` - EnableTeamsAPI bool `name:"enable_teams_api" default:"true"` - DNSNameFormat string `name:"dns_name_format" default:"%s.%s.%s"` - Workers uint32 `name:"workers" default:"4"` + Namespace string `name:"namespace"` + EtcdHost string `name:"etcd_host" default:"etcd-client.default.svc.cluster.local:2379"` + DockerImage string `name:"docker_image" default:"registry.opensource.zalan.do/acid/spiloprivate-9.6:1.2-p4"` + ServiceAccountName string `name:"service_account_name" default:"operator"` + DbHostedZone string `name:"db_hosted_zone" default:"db.example.com"` + EtcdScope string `name:"etcd_scope" default:"service"` + WALES3Bucket string `name:"wal_s3_bucket"` + KubeIAMRole string `name:"kube_iam_role"` + DebugLogging bool `name:"debug_logging" default:"true"` + EnableDBAccess bool `name:"enable_database_access" default:"true"` + EnableTeamsAPI bool `name:"enable_teams_api" default:"true"` + DNSNameFormat stringTemplate `name:"dns_name_format" default:"{cluster}.{team}.{hostedzone}"` + Workers uint32 `name:"workers" default:"4"` } func (c Config) MustMarshal() string { diff --git a/pkg/util/config/util.go b/pkg/util/config/util.go index 40d9e6ed9..de3d55e24 100644 --- a/pkg/util/config/util.go +++ b/pkg/util/config/util.go @@ -1,6 +1,7 @@ package config import ( + "encoding/json" "fmt" "reflect" "strconv" @@ -18,6 +19,8 @@ type fieldInfo struct { Field reflect.Value } +type stringTemplate string + func decoderFrom(field reflect.Value) (d Decoder) { // it may be impossible for a struct field to fail this check if !field.CanInterface() { @@ -162,3 +165,23 @@ func processField(value string, field reflect.Value) error { return nil } + +func (f *stringTemplate) Decode(value string) error { + *f = stringTemplate(value) + + return nil +} + +func (f *stringTemplate) Format(a ...string) string { + res := string(*f) + + for i := 0; i < len(a); i += 2 { + res = strings.Replace(res, "{"+a[i]+"}", a[i+1], -1) + } + + return res +} + +func (f stringTemplate) MarshalJSON() ([]byte, error) { + return json.Marshal(string(f)) +}