Skip to content

Commit 9bfe69a

Browse files
Add e2e tests with updates and rw checks
1 parent f43a68e commit 9bfe69a

File tree

13 files changed

+295
-86
lines changed

13 files changed

+295
-86
lines changed

Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local_resource(
1111
labels=["makefile"],
1212
)
1313

14-
docker_build('controller', '.',
14+
docker_build('clickhouse.com/clickhouse-operator', '.',
1515
dockerfile='Dockerfile',
1616
ignore=[
1717
'config',

api/v1alpha1/keepercluster_conditions.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ const (
1717
KeeperConditionTypeReady KeeperConditionType = "Ready"
1818
)
1919

20+
var (
21+
AllConditionTypes = []KeeperConditionType{
22+
KeeperConditionTypeReconcileSucceeded,
23+
KeeperConditionTypeReplicaStartupSucceeded,
24+
KeeperConditionTypeHealthy,
25+
KeeperConditionTypeClusterSizeAligned,
26+
KeeperConditionTypeConfigurationInSync,
27+
KeeperConditionTypeReady,
28+
}
29+
)
30+
2031
type KeeperConditionReason string
2132

2233
const (

api/v1alpha1/keepercluster_types.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -142,42 +142,6 @@ func (s *KeeperClusterSpec) WithDefaults() {
142142
}
143143
}
144144

145-
// KeeperReplicaState
146-
// +kubebuilder:validation:Enum=Pending;Provisioning;Ready;Degraded;OutOfSync;Error
147-
type KeeperReplicaState string
148-
149-
const (
150-
// ReplicaStatePending - Waiting for workload creation to be initiated.
151-
ReplicaStatePending KeeperReplicaState = "Pending"
152-
// ReplicaStateProvisioning - Starting StatefulSet, replica may not be able to accept connections.
153-
ReplicaStateProvisioning KeeperReplicaState = "Provisioning"
154-
// ReplicaStateDegraded - Pod is running, but replica is not healthy.
155-
ReplicaStateDegraded KeeperReplicaState = "Degraded"
156-
// ReplicaStateOutOfSync - Some changes were not applied yet.
157-
ReplicaStateOutOfSync KeeperReplicaState = "OutOfSync"
158-
// ReplicaStateReady - Pods are running and replica should be able to take connections.
159-
ReplicaStateReady KeeperReplicaState = "Ready"
160-
// ReplicaStateDeprovisioning - Replica is being deleted from cluster.
161-
ReplicaStateDeprovisioning KeeperReplicaState = "Deprovisioning"
162-
// ReplicaStateError - A persistent error is causing pods to fail.
163-
ReplicaStateError KeeperReplicaState = "Error"
164-
)
165-
166-
var activeReplicaStates = map[KeeperReplicaState]bool{
167-
ReplicaStatePending: false,
168-
ReplicaStateDeprovisioning: false,
169-
ReplicaStateProvisioning: true,
170-
ReplicaStateDegraded: true,
171-
ReplicaStateOutOfSync: true,
172-
ReplicaStateReady: true,
173-
ReplicaStateError: true,
174-
}
175-
176-
// Active replica state means that pod is expected to exist and other replicas aware of this replica.
177-
func (s KeeperReplicaState) Active() bool {
178-
return activeReplicaStates[s]
179-
}
180-
181145
// KeeperClusterStatus defines the observed state of KeeperCluster.
182146
type KeeperClusterStatus struct {
183147
// +listType=map

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
88
github.com/go-logr/logr v1.4.2
99
github.com/go-logr/zapr v1.3.0
10+
github.com/go-zookeeper/zk v1.0.4
1011
github.com/google/go-cmp v0.6.0
1112
github.com/onsi/ginkgo/v2 v2.19.0
1213
github.com/onsi/gomega v1.33.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogB
4444
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
4545
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
4646
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
47+
github.com/go-zookeeper/zk v1.0.4 h1:DPzxraQx7OrPyXq2phlGlNSIyWEsAox0RJmjTseMV6I=
48+
github.com/go-zookeeper/zk v1.0.4/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw=
4749
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
4850
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
4951
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=

internal/controller/keeper/constants.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ const (
2020
QuorumConfigFileName = "config.yaml"
2121
QuorumConfigVolumeName = "clickhouse-keeper-quorum-config-volume"
2222

23+
PersistentVolumeName = "keeper-storage-volume"
24+
2325
ConfigPath = QuorumConfigPath + "config.d/"
2426
ConfigFileName = "00-config.yaml"
2527
ConfigVolumeName = "clickhouse-keeper-config-volume"
2628

27-
BasePath = "/var/lib/clickhouse-keeper/"
28-
StoragePath = BasePath + "storage/"
29-
StorageLogPath = BasePath + "coordination/log/"
30-
StorageSnapshotPath = BasePath + "coordination/snapshots/"
29+
BaseDataPath = "/var/lib/clickhouse/"
30+
StorageLogPath = BaseDataPath + "coordination/log/"
31+
StorageSnapshotPath = BaseDataPath + "coordination/snapshots/"
3132

3233
ContainerName = "clickhouse-keeper"
3334
DefaultRevisionHistory = 10

internal/controller/keeper/sync.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (r replicaState) Ready(ctx reconcileContext) bool {
8080
}
8181

8282
stsReady := r.StatefulSet.Status.ReadyReplicas == 1 // Not reliable, but allows to wait until pod is `green`
83-
if ctx.KeeperCluster.Replicas() == 1 {
83+
if len(ctx.KeeperCluster.Status.Replicas) == 1 {
8484
return stsReady && r.Status.ServerState == ModeStandalone
8585
}
8686

@@ -704,6 +704,13 @@ func (r *ClusterReconciler) reconcileConditions(ctx reconcileContext) (*ctrl.Res
704704
}
705705

706706
setCondition(ctx, v1.KeeperConditionTypeReady, status, reason, message)
707+
708+
for _, condition := range ctx.KeeperCluster.Status.Conditions {
709+
if condition.Status != metav1.ConditionTrue {
710+
return &ctrl.Result{RequeueAfter: RequeueOnRefreshTimeout}, nil
711+
}
712+
}
713+
707714
return &ctrl.Result{}, nil
708715
}
709716

internal/controller/keeper/templates.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func TemplateStatefulSet(cr *v1.KeeperCluster, replicaID string) *appsv1.Statefu
353353
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{
354354
{
355355
ObjectMeta: metav1.ObjectMeta{
356-
Name: "ch-storage-volume",
356+
Name: PersistentVolumeName,
357357
},
358358
Spec: cr.Spec.Storage,
359359
},
@@ -386,7 +386,7 @@ func TemplateStatefulSet(cr *v1.KeeperCluster, replicaID string) *appsv1.Statefu
386386
func generateConfigForSingleReplica(cr *v1.KeeperCluster, replicaID string) Config {
387387
config := Config{
388388
ListenHost: "0.0.0.0",
389-
Path: BasePath,
389+
Path: BaseDataPath,
390390
Prometheus: PrometheusConfig{
391391
Endpoint: "/metrics",
392392
Port: PortPrometheusScrape,
@@ -401,7 +401,7 @@ func generateConfigForSingleReplica(cr *v1.KeeperCluster, replicaID string) Conf
401401
KeeperServer: KeeperServer{
402402
TcpPort: PortNative,
403403
ServerID: replicaID,
404-
StoragePath: StoragePath,
404+
StoragePath: BaseDataPath,
405405
DigestEnabled: true,
406406
LogStoragePath: StorageLogPath,
407407
SnapshotStoragePath: StorageSnapshotPath,
@@ -441,12 +441,12 @@ func buildVolumes(cr *v1.KeeperCluster, replicaID string) ([]corev1.Volume, []co
441441
MountPath: ConfigPath,
442442
},
443443
{
444-
Name: "ch-storage-volume",
445-
MountPath: StoragePath,
444+
Name: PersistentVolumeName,
445+
MountPath: BaseDataPath,
446446
SubPath: "var-lib-clickhouse",
447447
},
448448
{
449-
Name: "ch-storage-volume",
449+
Name: PersistentVolumeName,
450450
MountPath: "/var/log/clickhouse-keeper",
451451
SubPath: "var-log-clickhouse",
452452
},

internal/util/common.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ func ApplyDefault[T any](source *T, defaults T) error {
5656
func applyDefaultRecursive(sourceValue reflect.Value, defaults reflect.Value) error {
5757
if sourceValue.Kind() == reflect.Struct {
5858
for i := range sourceValue.NumField() {
59+
if !sourceValue.Field(i).CanSet() {
60+
continue
61+
}
5962
if err := applyDefaultRecursive(sourceValue.Field(i), defaults.Field(i)); err != nil {
6063
return fmt.Errorf("apply default value for field %s: %w", sourceValue.Type().Field(i).Name, err)
6164
}

test/e2e/e2e_suite_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ var _ = BeforeSuite(func() {
7373
By("installing the cert-manager")
7474
Expect(utils.InstallCertManager()).To(Succeed())
7575

76-
By("installing prometheus operator")
77-
Expect(utils.InstallPrometheusOperator()).To(Succeed())
76+
// By("installing prometheus operator")
77+
// Expect(utils.InstallPrometheusOperator()).To(Succeed())
7878

7979
By("creating manager namespace")
8080
cmd := exec.Command("kubectl", "create", "ns", namespace)
@@ -98,7 +98,7 @@ var _ = BeforeSuite(func() {
9898
err = utils.LoadImageToKindClusterWithName(projectimage)
9999
Expect(err).NotTo(HaveOccurred())
100100

101-
// In minukube cert-manager root CA may not be injected at this moment.
101+
// In kind cert-manager root CA may not be injected at this moment.
102102
By("deploying the controller-manager")
103103
Eventually(func() error {
104104
cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage))
@@ -153,11 +153,8 @@ var _ = BeforeSuite(func() {
153153
var _ = AfterSuite(func() {
154154
cancel()
155155

156-
By("uninstalling the Prometheus manager bundle")
157-
utils.UninstallPrometheusOperator()
158-
159-
By("uninstalling the cert-manager bundle")
160-
utils.UninstallCertManager()
156+
// By("uninstalling the Prometheus manager bundle")
157+
// utils.UninstallPrometheusOperator()
161158

162159
By("removing manager namespace")
163160
cmd := exec.Command("kubectl", "delete", "ns", namespace)

0 commit comments

Comments
 (0)