Skip to content

Commit 4c07494

Browse files
authored
deprecate ClusterName field of Postgresql type and remove team from REST endpoints (zalando#2015)
* deprecate ClusterName field of Postgresql type * remove for teamId from operator API endpints /status /logs /history * update dns_format_string and yaml template in UI
1 parent 8937518 commit 4c07494

File tree

13 files changed

+51
-68
lines changed

13 files changed

+51
-68
lines changed

pkg/apis/acid.zalan.do/v1/postgresql_type.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type PostgresSpec struct {
3636
TeamID string `json:"teamId"`
3737
DockerImage string `json:"dockerImage,omitempty"`
3838

39+
// deprecated field storing cluster name without teamId prefix
40+
ClusterName string `json:"-"`
41+
3942
SpiloRunAsUser *int64 `json:"spiloRunAsUser,omitempty"`
4043
SpiloRunAsGroup *int64 `json:"spiloRunAsGroup,omitempty"`
4144
SpiloFSGroup *int64 `json:"spiloFSGroup,omitempty"`
@@ -62,7 +65,6 @@ type PostgresSpec struct {
6265
NumberOfInstances int32 `json:"numberOfInstances"`
6366
MaintenanceWindows []MaintenanceWindow `json:"maintenanceWindows,omitempty"`
6467
Clone *CloneDescription `json:"clone,omitempty"`
65-
ClusterName string `json:"-"`
6668
Databases map[string]string `json:"databases,omitempty"`
6769
PreparedDatabases map[string]PreparedDatabase `json:"preparedDatabases,omitempty"`
6870
SchedulerName *string `json:"schedulerName,omitempty"`

pkg/apiserver/apiserver.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ type controllerInformer interface {
3131
GetOperatorConfig() *config.Config
3232
GetStatus() *spec.ControllerStatus
3333
TeamClusterList() map[string][]spec.NamespacedName
34-
ClusterStatus(team, namespace, cluster string) (*cluster.ClusterStatus, error)
35-
ClusterLogs(team, namespace, cluster string) ([]*spec.LogEntry, error)
36-
ClusterHistory(team, namespace, cluster string) ([]*spec.Diff, error)
34+
ClusterStatus(namespace, cluster string) (*cluster.ClusterStatus, error)
35+
ClusterLogs(namespace, cluster string) ([]*spec.LogEntry, error)
36+
ClusterHistory(namespace, cluster string) ([]*spec.Diff, error)
3737
ClusterDatabasesMap() map[string][]string
3838
WorkerLogs(workerID uint32) ([]*spec.LogEntry, error)
3939
ListQueue(workerID uint32) (*spec.QueueDump, error)
@@ -55,9 +55,9 @@ const (
5555
)
5656

5757
var (
58-
clusterStatusRe = fmt.Sprintf(`^/clusters/%s/%s/%s/?$`, teamRe, namespaceRe, clusterRe)
59-
clusterLogsRe = fmt.Sprintf(`^/clusters/%s/%s/%s/logs/?$`, teamRe, namespaceRe, clusterRe)
60-
clusterHistoryRe = fmt.Sprintf(`^/clusters/%s/%s/%s/history/?$`, teamRe, namespaceRe, clusterRe)
58+
clusterStatusRe = fmt.Sprintf(`^/clusters/%s/%s/?$`, namespaceRe, clusterRe)
59+
clusterLogsRe = fmt.Sprintf(`^/clusters/%s/%s/logs/?$`, namespaceRe, clusterRe)
60+
clusterHistoryRe = fmt.Sprintf(`^/clusters/%s/%s/history/?$`, namespaceRe, clusterRe)
6161
teamURLRe = fmt.Sprintf(`^/clusters/%s/?$`, teamRe)
6262

6363
clusterStatusURL = regexp.MustCompile(clusterStatusRe)
@@ -170,7 +170,7 @@ func (s *Server) clusters(w http.ResponseWriter, req *http.Request) {
170170

171171
if matches := util.FindNamedStringSubmatch(clusterStatusURL, req.URL.Path); matches != nil {
172172
namespace := matches["namespace"]
173-
resp, err = s.controller.ClusterStatus(matches["team"], namespace, matches["cluster"])
173+
resp, err = s.controller.ClusterStatus(namespace, matches["cluster"])
174174
} else if matches := util.FindNamedStringSubmatch(teamURL, req.URL.Path); matches != nil {
175175
teamClusters := s.controller.TeamClusterList()
176176
clusters, found := teamClusters[matches["team"]]
@@ -181,21 +181,21 @@ func (s *Server) clusters(w http.ResponseWriter, req *http.Request) {
181181

182182
clusterNames := make([]string, 0)
183183
for _, cluster := range clusters {
184-
clusterNames = append(clusterNames, cluster.Name[len(matches["team"])+1:])
184+
clusterNames = append(clusterNames, cluster.Name)
185185
}
186186

187187
resp, err = clusterNames, nil
188188
} else if matches := util.FindNamedStringSubmatch(clusterLogsURL, req.URL.Path); matches != nil {
189189
namespace := matches["namespace"]
190-
resp, err = s.controller.ClusterLogs(matches["team"], namespace, matches["cluster"])
190+
resp, err = s.controller.ClusterLogs(namespace, matches["cluster"])
191191
} else if matches := util.FindNamedStringSubmatch(clusterHistoryURL, req.URL.Path); matches != nil {
192192
namespace := matches["namespace"]
193-
resp, err = s.controller.ClusterHistory(matches["team"], namespace, matches["cluster"])
193+
resp, err = s.controller.ClusterHistory(namespace, matches["cluster"])
194194
} else if req.URL.Path == clustersURL {
195195
clusterNamesPerTeam := make(map[string][]string)
196196
for team, clusters := range s.controller.TeamClusterList() {
197197
for _, cluster := range clusters {
198-
clusterNamesPerTeam[team] = append(clusterNamesPerTeam[team], cluster.Name[len(team)+1:])
198+
clusterNamesPerTeam[team] = append(clusterNamesPerTeam[team], cluster.Name)
199199
}
200200
}
201201
resp, err = clusterNamesPerTeam, nil

pkg/apiserver/apiserver_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
)
66

77
const (
8-
clusterStatusTest = "/clusters/test-id/test_namespace/testcluster/"
9-
clusterStatusNumericTest = "/clusters/test-id-1/test_namespace/testcluster/"
10-
clusterLogsTest = "/clusters/test-id/test_namespace/testcluster/logs/"
8+
clusterStatusTest = "/clusters/test-namespace/testcluster/"
9+
clusterStatusNumericTest = "/clusters/test-namespace-1/testcluster/"
10+
clusterLogsTest = "/clusters/test-namespace/testcluster/logs/"
1111
teamTest = "/clusters/test-id/"
1212
)
1313

pkg/cluster/cluster.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,8 @@ func (c *Cluster) GetCurrentProcess() Process {
14781478
// GetStatus provides status of the cluster
14791479
func (c *Cluster) GetStatus() *ClusterStatus {
14801480
status := &ClusterStatus{
1481-
Cluster: c.Spec.ClusterName,
1481+
Cluster: c.Name,
1482+
Namespace: c.Namespace,
14821483
Team: c.Spec.TeamID,
14831484
Status: c.Status,
14841485
Spec: c.Spec,

pkg/cluster/cluster_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ func TestServiceAnnotations(t *testing.T) {
587587
clusterAnnotations: make(map[string]string),
588588
operatorAnnotations: make(map[string]string),
589589
expect: map[string]string{
590-
"external-dns.alpha.kubernetes.io/hostname": "test.test.db.example.com",
590+
"external-dns.alpha.kubernetes.io/hostname": "acid-test.test.db.example.com,test.acid.db.example.com",
591591
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
592592
},
593593
},
@@ -723,7 +723,7 @@ func TestServiceAnnotations(t *testing.T) {
723723
clusterAnnotations: make(map[string]string),
724724
operatorAnnotations: make(map[string]string),
725725
expect: map[string]string{
726-
"external-dns.alpha.kubernetes.io/hostname": "test-repl.test.db.example.com",
726+
"external-dns.alpha.kubernetes.io/hostname": "acid-test-repl.test.db.example.com,test-repl.acid.db.example.com",
727727
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
728728
},
729729
},
@@ -751,11 +751,6 @@ func TestServiceAnnotations(t *testing.T) {
751751
for _, tt := range tests {
752752
t.Run(tt.about, func(t *testing.T) {
753753
cl.OpConfig.EnableTeamIdClusternamePrefix = tt.enableTeamIdClusterPrefix
754-
if tt.enableTeamIdClusterPrefix {
755-
cl.Postgresql.Spec.ClusterName = "test"
756-
} else {
757-
cl.Postgresql.Spec.ClusterName = "acid-test"
758-
}
759754

760755
cl.OpConfig.CustomServiceAnnotations = tt.operatorAnnotations
761756
cl.OpConfig.EnableMasterLoadBalancer = tt.enableMasterLoadBalancerOC
@@ -764,6 +759,7 @@ func TestServiceAnnotations(t *testing.T) {
764759
cl.OpConfig.ReplicaDNSNameFormat = "{cluster}-repl.{namespace}.{hostedzone}"
765760
cl.OpConfig.DbHostedZone = "db.example.com"
766761

762+
cl.Postgresql.Spec.ClusterName = ""
767763
cl.Postgresql.Spec.TeamID = "acid"
768764
cl.Postgresql.Spec.ServiceAnnotations = tt.clusterAnnotations
769765
cl.Postgresql.Spec.EnableMasterLoadBalancer = tt.enableMasterLoadBalancerSpec

pkg/cluster/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type WorkerStatus struct {
5959
type ClusterStatus struct {
6060
Team string
6161
Cluster string
62+
Namespace string
6263
MasterService *v1.Service
6364
ReplicaService *v1.Service
6465
MasterEndpoint *v1.Endpoints

pkg/cluster/util.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,38 +507,38 @@ func (c *Cluster) roleLabelsSet(shouldAddExtraLabels bool, role PostgresRole) la
507507

508508
func (c *Cluster) dnsName(role PostgresRole) string {
509509
var dnsString string
510+
510511
if role == Master {
511512
dnsString = c.masterDNSName()
512513
} else {
513514
dnsString = c.replicaDNSName()
514515
}
515516

516-
// when cluster name starts with teamId prefix create an extra DNS entry
517-
// to support the old format when prefix contraint was enabled (but is disabled now)
518-
if !c.OpConfig.EnableTeamIdClusternamePrefix {
519-
clusterNameWithoutTeamPrefix, _ := acidv1.ExtractClusterName(c.Name, c.Spec.TeamID)
520-
if clusterNameWithoutTeamPrefix != "" {
521-
if role == Replica {
522-
clusterNameWithoutTeamPrefix = fmt.Sprintf("%s-repl", clusterNameWithoutTeamPrefix)
523-
}
524-
dnsString = fmt.Sprintf("%s,%s", dnsString, c.oldDNSFormat(clusterNameWithoutTeamPrefix))
517+
// if cluster name starts with teamID we might need to provide backwards compatibility
518+
clusterNameWithoutTeamPrefix, _ := acidv1.ExtractClusterName(c.Name, c.Spec.TeamID)
519+
if clusterNameWithoutTeamPrefix != "" {
520+
if role == Replica {
521+
clusterNameWithoutTeamPrefix = fmt.Sprintf("%s-repl", clusterNameWithoutTeamPrefix)
525522
}
523+
dnsString = fmt.Sprintf("%s,%s", dnsString, c.oldDNSFormat(clusterNameWithoutTeamPrefix))
526524
}
527525

528526
return dnsString
529527
}
530528

531529
func (c *Cluster) masterDNSName() string {
532530
return strings.ToLower(c.OpConfig.MasterDNSNameFormat.Format(
533-
"cluster", c.Spec.ClusterName,
531+
"cluster", c.Name,
534532
"namespace", c.Namespace,
533+
"team", c.teamName(),
535534
"hostedzone", c.OpConfig.DbHostedZone))
536535
}
537536

538537
func (c *Cluster) replicaDNSName() string {
539538
return strings.ToLower(c.OpConfig.ReplicaDNSNameFormat.Format(
540-
"cluster", c.Spec.ClusterName,
539+
"cluster", c.Name,
541540
"namespace", c.Namespace,
541+
"team", c.teamName(),
542542
"hostedzone", c.OpConfig.DbHostedZone))
543543
}
544544

pkg/controller/logs_and_api.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import (
1515
)
1616

1717
// ClusterStatus provides status of the cluster
18-
func (c *Controller) ClusterStatus(team, namespace, cluster string) (*cluster.ClusterStatus, error) {
18+
func (c *Controller) ClusterStatus(namespace, cluster string) (*cluster.ClusterStatus, error) {
1919

2020
clusterName := spec.NamespacedName{
2121
Namespace: namespace,
22-
Name: team + "-" + cluster,
22+
Name: cluster,
2323
}
2424

2525
c.clustersMu.RLock()
@@ -92,11 +92,11 @@ func (c *Controller) GetStatus() *spec.ControllerStatus {
9292
}
9393

9494
// ClusterLogs dumps cluster ring logs
95-
func (c *Controller) ClusterLogs(team, namespace, name string) ([]*spec.LogEntry, error) {
95+
func (c *Controller) ClusterLogs(namespace, name string) ([]*spec.LogEntry, error) {
9696

9797
clusterName := spec.NamespacedName{
9898
Namespace: namespace,
99-
Name: team + "-" + name,
99+
Name: name,
100100
}
101101

102102
c.clustersMu.RLock()
@@ -215,11 +215,11 @@ func (c *Controller) WorkerStatus(workerID uint32) (*cluster.WorkerStatus, error
215215
}
216216

217217
// ClusterHistory dumps history of cluster changes
218-
func (c *Controller) ClusterHistory(team, namespace, name string) ([]*spec.Diff, error) {
218+
func (c *Controller) ClusterHistory(namespace, name string) ([]*spec.Diff, error) {
219219

220220
clusterName := spec.NamespacedName{
221221
Namespace: namespace,
222-
Name: team + "-" + name,
222+
Name: name,
223223
}
224224

225225
c.clustersMu.RLock()

pkg/controller/postgresql.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,16 @@ func (c *Controller) acquireInitialListOfClusters() error {
159159
}
160160

161161
func (c *Controller) addCluster(lg *logrus.Entry, clusterName spec.NamespacedName, pgSpec *acidv1.Postgresql) (*cluster.Cluster, error) {
162-
var (
163-
extractedClusterName string
164-
err error
165-
)
166-
167162
if c.opConfig.EnableTeamIdClusternamePrefix {
168-
if extractedClusterName, err = acidv1.ExtractClusterName(clusterName.Name, pgSpec.Spec.TeamID); err != nil {
163+
if _, err := acidv1.ExtractClusterName(clusterName.Name, pgSpec.Spec.TeamID); err != nil {
169164
c.KubeClient.SetPostgresCRDStatus(clusterName, acidv1.ClusterStatusInvalid)
170165
return nil, err
171166
}
172-
} else {
173-
extractedClusterName = clusterName.Name
174167
}
175168

176169
cl := cluster.New(c.makeClusterConfig(), c.KubeClient, *pgSpec, lg, c.eventRecorder)
177170
cl.Run(c.stopCh)
178171
teamName := strings.ToLower(cl.Spec.TeamID)
179-
cl.ClusterName = extractedClusterName
180172

181173
defer c.clustersMu.Unlock()
182174
c.clustersMu.Lock()

ui/app/src/new.tag.pug

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ new
6464

6565
a.btn.btn-small.btn-warning(
6666
if='{ clusterExists }'
67-
href='/#/status/{ namespace.state }/{ team }-{ name }'
67+
href='/#/status/{ namespace.state }/{ name }'
6868
)
6969
| Cluster exists (show status)
7070

@@ -137,10 +137,10 @@ new
137137
input.form-control(
138138
ref='name'
139139
type='text'
140-
placeholder='new-cluster (can be { 53 - team.length - 1 } characters long)'
140+
placeholder='new-cluster (can be 53 characters long)'
141141
title='Database cluster name, must be a valid hostname component'
142142
pattern='[a-z0-9]+[a-z0-9\-]+[a-z0-9]+'
143-
maxlength='{ 53 - team.length - 1 }'
143+
maxlength=53
144144
required
145145
value='{ name }'
146146
onchange='{ nameChange }'
@@ -520,7 +520,7 @@ new
520520
apiVersion: "acid.zalan.do/v1"
521521
522522
metadata:
523-
name: "{{ team }}-{{ name }}"
523+
name: "{{ name }}"
524524
namespace: "{{ namespace.state }}"
525525
labels:
526526
team: {{ team }}
@@ -670,13 +670,12 @@ new
670670
this.updateDNSName = () => {
671671
this.dnsName = this.config.dns_format_string.format(
672672
this.name,
673-
this.team,
674673
this.namespace.state,
675674
)
676675
}
677676

678677
this.updateClusterName = () => {
679-
this.clusterName = (this.team + '-' + this.name).toLowerCase()
678+
this.clusterName = (this.name).toLowerCase()
680679
this.checkClusterExists()
681680
this.updateDNSName()
682681
}
@@ -950,7 +949,7 @@ new
950949
this.team = ''
951950
}
952951

953-
this.clusterName = (this.name + '-' + this.team).toLowerCase()
952+
this.clusterName = (this.name + '-').toLowerCase()
954953
this.volumeSize = 10
955954
this.instanceCount = 1
956955
this.ranges = {}

0 commit comments

Comments
 (0)