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:
Murat Kabilov
2017-05-12 11:41:27 +02:00
parent 1377724b2e
commit 6f7399b36f
13 changed files with 334 additions and 88 deletions
+6 -16
View File
@@ -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)
}