remove type PostgresClusterStatus

This commit is contained in:
Felix Kunde 2019-04-11 12:31:50 +02:00
parent 0c5eadccda
commit c3834df57a
6 changed files with 125 additions and 115 deletions

View File

@ -2,14 +2,14 @@ package v1
// ClusterStatusUnknown etc : status of a Postgres cluster known to the operator // ClusterStatusUnknown etc : status of a Postgres cluster known to the operator
const ( const (
ClusterStatusUnknown PostgresClusterStatus = "" ClusterStatusUnknown = ""
ClusterStatusCreating PostgresClusterStatus = "Creating" ClusterStatusCreating = "Creating"
ClusterStatusUpdating PostgresClusterStatus = "Updating" ClusterStatusUpdating = "Updating"
ClusterStatusUpdateFailed PostgresClusterStatus = "UpdateFailed" ClusterStatusUpdateFailed = "UpdateFailed"
ClusterStatusSyncFailed PostgresClusterStatus = "SyncFailed" ClusterStatusSyncFailed = "SyncFailed"
ClusterStatusAddFailed PostgresClusterStatus = "CreateFailed" ClusterStatusAddFailed = "CreateFailed"
ClusterStatusRunning PostgresClusterStatus = "Running" ClusterStatusRunning = "Running"
ClusterStatusInvalid PostgresClusterStatus = "Invalid" ClusterStatusInvalid = "Invalid"
) )
const ( const (

View File

@ -130,8 +130,5 @@ type UserFlags []string
// PostgresStatus contains status of the PostgreSQL cluster (running, creation failed etc.) // PostgresStatus contains status of the PostgreSQL cluster (running, creation failed etc.)
type PostgresStatus struct { type PostgresStatus struct {
PostgresClusterStatus PostgresClusterStatus `json:"PostgresClusterStatus,omitempty"` PostgresClusterStatus string `json:"PostgresClusterStatus,omitempty"`
} }
// PostgresClusterStatus defines the status of the PostgreSQL cluster (running, creation failed etc.)
type PostgresClusterStatus string

View File

@ -91,6 +91,11 @@ func (postgresStatus PostgresStatus) Success() bool {
postgresStatus.PostgresClusterStatus != ClusterStatusSyncFailed postgresStatus.PostgresClusterStatus != ClusterStatusSyncFailed
} }
// Running status of cluster
func (postgresStatus PostgresStatus) Running() bool {
return postgresStatus.PostgresClusterStatus == ClusterStatusRunning
}
func (postgresStatus PostgresStatus) String() string { func (postgresStatus PostgresStatus) String() string {
return string(postgresStatus.PostgresClusterStatus) return string(postgresStatus.PostgresClusterStatus)
} }

View File

@ -116,96 +116,99 @@ var unmarshalCluster = []struct {
out Postgresql out Postgresql
marshal []byte marshal []byte
err error err error
}{{ }{
[]byte(`{ {
"kind": "Postgresql","apiVersion": "acid.zalan.do/v1", in: []byte(`{
"metadata": {"name": "acid-testcluster1"}, "spec": {"teamId": 100}}`), "kind": "Postgresql","apiVersion": "acid.zalan.do/v1",
Postgresql{ "metadata": {"name": "acid-testcluster1"}, "spec": {"teamId": 100}}`),
TypeMeta: metav1.TypeMeta{ out: Postgresql{
Kind: "Postgresql", TypeMeta: metav1.TypeMeta{
APIVersion: "acid.zalan.do/v1", Kind: "Postgresql",
APIVersion: "acid.zalan.do/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "acid-testcluster1",
},
Status: PostgresStatus{PostgresClusterStatus: ClusterStatusInvalid},
// This error message can vary between Go versions, so compute it for the current version.
Error: json.Unmarshal([]byte(`{"teamId": 0}`), &PostgresSpec{}).Error(),
}, },
ObjectMeta: metav1.ObjectMeta{ marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{}},"status":{"PostgresClusterStatus":"Invalid"}}`),
Name: "acid-testcluster1", err: nil},
}, {
Status: PostgresStatus{PostgresClusterStatus: ClusterStatusInvalid}, in: []byte(`{
// This error message can vary between Go versions, so compute it for the current version. "kind": "Postgresql",
Error: json.Unmarshal([]byte(`{"teamId": 0}`), &PostgresSpec{}).Error(), "apiVersion": "acid.zalan.do/v1",
}, "metadata": {
[]byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{}},"status":{"PostgresClusterStatus":"Invalid"}}`), nil}, "name": "acid-testcluster1"
{[]byte(`{ },
"kind": "Postgresql", "spec": {
"apiVersion": "acid.zalan.do/v1", "teamId": "ACID",
"metadata": { "volume": {
"name": "acid-testcluster1" "size": "5Gi",
}, "storageClass": "SSD"
"spec": { },
"teamId": "ACID", "numberOfInstances": 2,
"volume": { "users": {
"size": "5Gi", "zalando": [
"storageClass": "SSD" "superuser",
}, "createdb"
"numberOfInstances": 2, ]
"users": { },
"zalando": [ "allowedSourceRanges": [
"superuser", "127.0.0.1/32"
"createdb" ],
] "postgresql": {
}, "version": "9.6",
"allowedSourceRanges": [ "parameters": {
"127.0.0.1/32" "shared_buffers": "32MB",
], "max_connections": "10",
"postgresql": { "log_statement": "all"
"version": "9.6", }
"parameters": { },
"shared_buffers": "32MB", "resources": {
"max_connections": "10", "requests": {
"log_statement": "all" "cpu": "10m",
} "memory": "50Mi"
}, },
"resources": { "limits": {
"requests": { "cpu": "300m",
"cpu": "10m", "memory": "3000Mi"
"memory": "50Mi" }
}, },
"limits": { "clone" : {
"cpu": "300m", "cluster": "acid-batman"
"memory": "3000Mi" },
} "patroni": {
}, "initdb": {
"clone" : { "encoding": "UTF8",
"cluster": "acid-batman" "locale": "en_US.UTF-8",
}, "data-checksums": "true"
"patroni": { },
"initdb": { "pg_hba": [
"encoding": "UTF8", "hostssl all all 0.0.0.0/0 md5",
"locale": "en_US.UTF-8", "host all all 0.0.0.0/0 md5"
"data-checksums": "true" ],
}, "ttl": 30,
"pg_hba": [ "loop_wait": 10,
"hostssl all all 0.0.0.0/0 md5", "retry_timeout": 10,
"host all all 0.0.0.0/0 md5" "maximum_lag_on_failover": 33554432,
], "slots" : {
"ttl": 30, "permanent_logical_1" : {
"loop_wait": 10, "type" : "logical",
"retry_timeout": 10, "database" : "foo",
"maximum_lag_on_failover": 33554432, "plugin" : "pgoutput"
"slots" : { }
"permanent_logical_1" : { }
"type" : "logical", },
"database" : "foo", "maintenanceWindows": [
"plugin" : "pgoutput" "Mon:01:00-06:00",
} "Sat:00:00-04:00",
"05:00-05:15"
]
} }
}, }`),
"maintenanceWindows": [ out: Postgresql{
"Mon:01:00-06:00",
"Sat:00:00-04:00",
"05:00-05:15"
]
}
}`),
Postgresql{
TypeMeta: metav1.TypeMeta{ TypeMeta: metav1.TypeMeta{
Kind: "Postgresql", Kind: "Postgresql",
APIVersion: "acid.zalan.do/v1", APIVersion: "acid.zalan.do/v1",
@ -273,10 +276,11 @@ var unmarshalCluster = []struct {
}, },
Error: "", Error: "",
}, },
[]byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"9.6","parameters":{"log_statement":"all","max_connections":"10","shared_buffers":"32MB"}},"volume":{"size":"5Gi","storageClass":"SSD"},"patroni":{"initdb":{"data-checksums":"true","encoding":"UTF8","locale":"en_US.UTF-8"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"],"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}}},"resources":{"requests":{"cpu":"10m","memory":"50Mi"},"limits":{"cpu":"300m","memory":"3000Mi"}},"teamId":"ACID","allowedSourceRanges":["127.0.0.1/32"],"numberOfInstances":2,"users":{"zalando":["superuser","createdb"]},"maintenanceWindows":["Mon:01:00-06:00","Sat:00:00-04:00","05:00-05:15"],"clone":{"cluster":"acid-batman"}},"status":{}}`), nil}, marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"9.6","parameters":{"log_statement":"all","max_connections":"10","shared_buffers":"32MB"}},"volume":{"size":"5Gi","storageClass":"SSD"},"patroni":{"initdb":{"data-checksums":"true","encoding":"UTF8","locale":"en_US.UTF-8"},"pg_hba":["hostssl all all 0.0.0.0/0 md5","host all all 0.0.0.0/0 md5"],"ttl":30,"loop_wait":10,"retry_timeout":10,"maximum_lag_on_failover":33554432,"slots":{"permanent_logical_1":{"database":"foo","plugin":"pgoutput","type":"logical"}}},"resources":{"requests":{"cpu":"10m","memory":"50Mi"},"limits":{"cpu":"300m","memory":"3000Mi"}},"teamId":"ACID","allowedSourceRanges":["127.0.0.1/32"],"numberOfInstances":2,"users":{"zalando":["superuser","createdb"]},"maintenanceWindows":["Mon:01:00-06:00","Sat:00:00-04:00","05:00-05:15"],"clone":{"cluster":"acid-batman"}},"status":{}}`),
err: nil},
{ {
[]byte(`{"kind": "Postgresql","apiVersion": "acid.zalan.do/v1","metadata": {"name": "teapot-testcluster1"}, "spec": {"teamId": "acid"}}`), in: []byte(`{"kind": "Postgresql","apiVersion": "acid.zalan.do/v1","metadata": {"name": "teapot-testcluster1"}, "spec": {"teamId": "acid"}}`),
Postgresql{ out: Postgresql{
TypeMeta: metav1.TypeMeta{ TypeMeta: metav1.TypeMeta{
Kind: "Postgresql", Kind: "Postgresql",
APIVersion: "acid.zalan.do/v1", APIVersion: "acid.zalan.do/v1",
@ -288,7 +292,8 @@ var unmarshalCluster = []struct {
Status: PostgresStatus{PostgresClusterStatus: ClusterStatusInvalid}, Status: PostgresStatus{PostgresClusterStatus: ClusterStatusInvalid},
Error: errors.New("name must match {TEAM}-{NAME} format").Error(), Error: errors.New("name must match {TEAM}-{NAME} format").Error(),
}, },
[]byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"teapot-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"acid","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{}},"status":{"PostgresClusterStatus":"Invalid"}}`), nil}, marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"teapot-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"acid","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{}},"status":{"PostgresClusterStatus":"Invalid"}}`),
err: nil},
{ {
in: []byte(`{"kind": "Postgresql","apiVersion": "acid.zalan.do/v1","metadata": {"name": "acid-testcluster1"}, "spec": {"teamId": "acid", "clone": {"cluster": "team-batman"}}}`), in: []byte(`{"kind": "Postgresql","apiVersion": "acid.zalan.do/v1","metadata": {"name": "acid-testcluster1"}, "spec": {"teamId": "acid", "clone": {"cluster": "team-batman"}}}`),
out: Postgresql{ out: Postgresql{
@ -308,15 +313,18 @@ var unmarshalCluster = []struct {
}, },
Error: "", Error: "",
}, },
marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"acid","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{"cluster":"team-batman"}},"status":{}}`), err: nil}, marshal: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster1","creationTimestamp":null},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"acid","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{"cluster":"team-batman"}},"status":{}}`),
{[]byte(`{"kind": "Postgresql","apiVersion": "acid.zalan.do/v1"`), err: nil},
Postgresql{}, {
[]byte{}, in: []byte(`{"kind": "Postgresql","apiVersion": "acid.zalan.do/v1"`),
errors.New("unexpected end of JSON input")}, out: Postgresql{},
{[]byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster","creationTimestamp":qaz},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"acid","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{}},"status":{"PostgresClusterStatus":"Invalid"}}`), marshal: []byte{},
Postgresql{}, err: errors.New("unexpected end of JSON input")},
[]byte{}, {
errors.New("invalid character 'q' looking for beginning of value")}} in: []byte(`{"kind":"Postgresql","apiVersion":"acid.zalan.do/v1","metadata":{"name":"acid-testcluster","creationTimestamp":qaz},"spec":{"postgresql":{"version":"","parameters":null},"volume":{"size":"","storageClass":""},"patroni":{"initdb":null,"pg_hba":null,"ttl":0,"loop_wait":0,"retry_timeout":0,"maximum_lag_on_failover":0,"slots":null},"resources":{"requests":{"cpu":"","memory":""},"limits":{"cpu":"","memory":""}},"teamId":"acid","allowedSourceRanges":null,"numberOfInstances":0,"users":null,"clone":{}},"status":{"PostgresClusterStatus":"Invalid"}}`),
out: Postgresql{},
marshal: []byte{},
err: errors.New("invalid character 'q' looking for beginning of value")}}
var postgresqlList = []struct { var postgresqlList = []struct {
in []byte in []byte

View File

@ -149,7 +149,7 @@ func (c *Cluster) setProcessName(procName string, args ...interface{}) {
} }
} }
func (c *Cluster) setStatus(status acidv1.PostgresClusterStatus) { func (c *Cluster) setStatus(status string) {
// TODO: eventually switch to updateStatus() for kubernetes 1.11 and above // TODO: eventually switch to updateStatus() for kubernetes 1.11 and above
var ( var (
err error err error

View File

@ -28,7 +28,7 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
if err != nil { if err != nil {
c.logger.Warningf("error while syncing cluster state: %v", err) c.logger.Warningf("error while syncing cluster state: %v", err)
c.setStatus(acidv1.ClusterStatusSyncFailed) c.setStatus(acidv1.ClusterStatusSyncFailed)
} else if c.Status.PostgresClusterStatus != acidv1.ClusterStatusRunning { } else if !c.Status.Running() {
c.setStatus(acidv1.ClusterStatusRunning) c.setStatus(acidv1.ClusterStatusRunning)
} }
}() }()