mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-01 15:59:27 +02:00
Sync clusters states
* move statefulset creation from cluster spec to the separate function * sync cluster state with desired state; * move out from arrays for cluster resources; * recreate pods instead of deleting them in case of statefulset change * check for master while creating cluster/updating pods * simplify retryutil * list pvc while listing resources * name kubernetes resources with capital letter * do rolling update in case of env variables change
This commit is contained in:
@@ -29,12 +29,13 @@ const (
|
||||
PamConfiguration = "https://info.example.com/oauth2/tokeninfo?access_token= uid realm=/employees"
|
||||
PasswordLength = 64
|
||||
TeamsAPIUrl = "https://teams.example.com/api/"
|
||||
UserSecretTemplate = "%s.%s.credentials.%s.%s"
|
||||
UserSecretTemplate = "%s.%s.credentials.%s.%s" // Username, ClusterName, TPRName, TPRVendor
|
||||
|
||||
OAuthTokenSecretName = "postgresql-operator"
|
||||
ServiceAccountName = "operator"
|
||||
DataVolumeName = "pgdata"
|
||||
ZalandoDnsNameAnnotation = "zalando.org/dnsname"
|
||||
|
||||
// TODO: move DbHostedZone to operator configuration
|
||||
DbHostedZone = "db.example.com"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ func listClustersURI(ns string) string {
|
||||
}
|
||||
|
||||
func WaitTPRReady(restclient rest.Interface, interval, timeout time.Duration, ns string) error {
|
||||
return retryutil.Retry(interval, int(timeout/interval), func() (bool, error) {
|
||||
return retryutil.Retry(interval, timeout, func() (bool, error) {
|
||||
_, err := restclient.Get().RequestURI(listClustersURI(ns)).DoRaw()
|
||||
if err != nil {
|
||||
if ResourceNotFound(err) { // not set up yet. wait more.
|
||||
|
||||
@@ -5,24 +5,14 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type RetryError struct {
|
||||
n int
|
||||
}
|
||||
|
||||
func (e *RetryError) Error() string {
|
||||
return fmt.Sprintf("still failing after %d retries", e.n)
|
||||
}
|
||||
|
||||
type ConditionFunc func() (bool, error)
|
||||
|
||||
// Retry retries f every interval until after maxRetries.
|
||||
// The interval won't be affected by how long f takes.
|
||||
// For example, if interval is 3s, f takes 1s, another f will be called 2s later.
|
||||
// However, if f takes longer than interval, it will be delayed.
|
||||
func Retry(interval time.Duration, maxRetries int, f ConditionFunc) error {
|
||||
if maxRetries <= 0 {
|
||||
return fmt.Errorf("maxRetries (%d) should be > 0", maxRetries)
|
||||
func Retry(interval time.Duration, timeout time.Duration, f ConditionFunc) error {
|
||||
//TODO: make the retry exponential
|
||||
if timeout < interval {
|
||||
return fmt.Errorf("timout(%s) should be greater than interval(%s)", timeout, interval)
|
||||
}
|
||||
maxRetries := int(timeout / interval)
|
||||
tick := time.NewTicker(interval)
|
||||
defer tick.Stop()
|
||||
|
||||
@@ -39,5 +29,5 @@ func Retry(interval time.Duration, maxRetries int, f ConditionFunc) error {
|
||||
}
|
||||
<-tick.C
|
||||
}
|
||||
return &RetryError{maxRetries}
|
||||
return fmt.Errorf("Still failing after %d retries", maxRetries)
|
||||
}
|
||||
|
||||
@@ -45,6 +45,10 @@ func PodClusterName(pod *v1.Pod) spec.ClusterName {
|
||||
return spec.ClusterName{}
|
||||
}
|
||||
|
||||
func PodSpiloRole(pod *v1.Pod) string {
|
||||
return pod.Labels["spilo-role"]
|
||||
}
|
||||
|
||||
func ClusterDNSName(clusterName, teamName, hostedZone string) string {
|
||||
return fmt.Sprintf("%s.%s.%s", clusterName, teamName, hostedZone)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user