generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: d-kuro <[email protected]>
- Loading branch information
Showing
3 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package e2e | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
appsv1 "k8s.io/api/apps/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
//go:embed testdata/stop.yaml | ||
var stopYAML string | ||
|
||
//go:embed testdata/stop_changed.yaml | ||
var stopChangedYAML string | ||
|
||
var _ = Context("stop", func() { | ||
if doUpgrade { | ||
return | ||
} | ||
|
||
It("should construct a 3-instance cluster", func() { | ||
kubectlSafe(fillTemplate(stopYAML), "apply", "-f", "-") | ||
Eventually(func() error { | ||
cluster, err := getCluster("stop", "test") | ||
if err != nil { | ||
return err | ||
} | ||
for _, cond := range cluster.Status.Conditions { | ||
if cond.Type != mocov1beta2.ConditionHealthy { | ||
continue | ||
} | ||
if cond.Status == metav1.ConditionTrue { | ||
return nil | ||
} | ||
return fmt.Errorf("cluster is not healthy: %s", cond.Status) | ||
} | ||
return errors.New("no health condition") | ||
}).Should(Succeed()) | ||
|
||
kubectlSafe(nil, "moco", "mysql", "test", | ||
"-n", "stop", | ||
"-u", "moco-writable", | ||
"--", "-e", "CREATE DATABASE test;") | ||
kubectlSafe(nil, "moco", "mysql", "test", | ||
"-n", "stop", | ||
"-u", "moco-writable", | ||
"--", "-e", "CREATE TABLE test.t1 (foo int);") | ||
kubectlSafe(nil, "moco", "mysql", "test", | ||
"-n", "stop", | ||
"-u", "moco-writable", | ||
"--", "-e", "INSERT INTO test.t1 (foo) VALUES (1); COMMIT;") | ||
}) | ||
|
||
It("should stop reconciliation", func() { | ||
kubectlSafe(nil, "moco", "stop", "reconciliation", "test", "-n", "stop") | ||
Eventually(func() error { | ||
cluster, err := getCluster("stop", "test") | ||
if err != nil { | ||
return err | ||
} | ||
for _, cond := range cluster.Status.Conditions { | ||
if cond.Type != mocov1beta2.ConditionReconciliationActive { | ||
continue | ||
} | ||
if cond.Status == metav1.ConditionFalse { | ||
return nil | ||
} | ||
return fmt.Errorf("reconciliation is active: %s", cond.Status) | ||
} | ||
return errors.New("no reconciliation condition") | ||
}).Should(Succeed()) | ||
|
||
kubectlSafe(fillTemplate(stopChangedYAML), "apply", "-f", "-") | ||
|
||
timeout := 30 * time.Second | ||
Consistently(func() error { | ||
out, err := kubectl(nil, "get", "-n", "stop", "statefulset", "moco-test", "-o", "json") | ||
if err != nil { | ||
return err | ||
} | ||
sts := &appsv1.StatefulSet{} | ||
err = json.Unmarshal(out, sts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if _, ok := sts.Spec.Template.Labels["foo"]; ok { | ||
return errors.New("label exists") | ||
} | ||
return nil | ||
}, timeout).Should(Succeed()) | ||
}) | ||
|
||
It("should restart reconciliation", func() { | ||
kubectlSafe(nil, "moco", "start", "reconciliation", "test", "-n", "stop") | ||
Eventually(func() error { | ||
cluster, err := getCluster("stop", "test") | ||
if err != nil { | ||
return err | ||
} | ||
for _, cond := range cluster.Status.Conditions { | ||
if cond.Type != mocov1beta2.ConditionReconciliationActive { | ||
continue | ||
} | ||
if cond.Status == metav1.ConditionTrue { | ||
return nil | ||
} | ||
return fmt.Errorf("reconciliation is not active: %s", cond.Status) | ||
} | ||
return errors.New("no reconciliation condition") | ||
}).Should(Succeed()) | ||
|
||
Eventually(func() error { | ||
out, err := kubectl(nil, "get", "-n", "stop", "statefulset", "moco-test", "-o", "json") | ||
if err != nil { | ||
return err | ||
} | ||
sts := &appsv1.StatefulSet{} | ||
err = json.Unmarshal(out, sts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if _, ok := sts.Spec.Template.Labels["foo"]; !ok { | ||
return errors.New("label does not exists") | ||
} | ||
|
||
return nil | ||
}).Should(Succeed()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: stop | ||
--- | ||
apiVersion: moco.cybozu.com/v1beta2 | ||
kind: MySQLCluster | ||
metadata: | ||
namespace: stop | ||
name: test | ||
spec: | ||
replicas: 3 | ||
podTemplate: | ||
spec: | ||
containers: | ||
- name: mysqld | ||
image: ghcr.io/cybozu-go/moco/mysql:{{ . }} | ||
volumeClaimTemplates: | ||
- metadata: | ||
name: mysql-data | ||
spec: | ||
accessModes: [ "ReadWriteOnce" ] | ||
resources: | ||
requests: | ||
storage: 1Gi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: stop | ||
--- | ||
apiVersion: moco.cybozu.com/v1beta2 | ||
kind: MySQLCluster | ||
metadata: | ||
namespace: stop | ||
name: test | ||
spec: | ||
replicas: 3 | ||
podTemplate: | ||
metadata: | ||
labels: | ||
foo: bar | ||
spec: | ||
containers: | ||
- name: mysqld | ||
image: ghcr.io/cybozu-go/moco/mysql:{{ . }} | ||
volumeClaimTemplates: | ||
- metadata: | ||
name: mysql-data | ||
spec: | ||
accessModes: [ "ReadWriteOnce" ] | ||
resources: | ||
requests: | ||
storage: 1Gi |