mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 20:02:14 +02:00
Improve behavior on node decomissionining (#184)
* Trigger the node migration on the lack of the readiness label. * Examine the node's readiness status on node add. Make sure we don't miss the not ready node, especially when the operator is killed during the migration.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/spec"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
readyLabel = "lifecycle-status"
|
||||
readyValue = "ready"
|
||||
)
|
||||
|
||||
func initializeController() *Controller {
|
||||
var c = NewController(&spec.ControllerConfig{})
|
||||
c.opConfig.NodeReadinessLabel = map[string]string{readyLabel: readyValue}
|
||||
return c
|
||||
}
|
||||
|
||||
func makeNode(labels map[string]string, isSchedulable bool) *v1.Node {
|
||||
return &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: v1.NamespaceDefault,
|
||||
Labels: labels,
|
||||
},
|
||||
Spec: v1.NodeSpec{
|
||||
Unschedulable: !isSchedulable,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
var c = initializeController()
|
||||
|
||||
func TestNodeIsReady(t *testing.T) {
|
||||
testName := "TestNodeIsReady"
|
||||
var testTable = []struct {
|
||||
in *v1.Node
|
||||
out bool
|
||||
}{
|
||||
{
|
||||
in: makeNode(map[string]string{"foo": "bar"}, true),
|
||||
out: true,
|
||||
},
|
||||
{
|
||||
in: makeNode(map[string]string{"foo": "bar"}, false),
|
||||
out: false,
|
||||
},
|
||||
{
|
||||
in: makeNode(map[string]string{readyLabel: readyValue}, false),
|
||||
out: true,
|
||||
},
|
||||
{
|
||||
in: makeNode(map[string]string{"foo": "bar", "master": "true"}, false),
|
||||
out: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range testTable {
|
||||
if isReady := c.nodeIsReady(tt.in); isReady != tt.out {
|
||||
t.Errorf("%s: expected response %t doesn't match the actual %t for the node %#v",
|
||||
testName, tt.out, isReady, tt.in)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user