Skip to content

Commit

Permalink
feat: ensure the mount path is the same as kvrocks' dockerfile (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayouxujin authored Aug 12, 2023
1 parent 14dc9d1 commit 0ece0a6
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 41 deletions.
20 changes: 0 additions & 20 deletions config/crd/bases/kvrocks.apache.org_kvrocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -891,26 +891,6 @@ spec:
resources:
description: ResourceRequirements describes the compute resource requirements.
properties:
claims:
description: "Claims lists the names of resources, defined in
spec.resourceClaims, that are used by this container. \n This
is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
name:
description: Name must match the name of one entry in pod.spec.resourceClaims
of the Pod where this field is used. It makes that resource
available inside a container.
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
limits:
additionalProperties:
anyOf:
Expand Down
6 changes: 3 additions & 3 deletions examples/standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ spec:
rocksdb.compression: "no"
rocksdb.wal_ttl_seconds: "0"
rocksdb.wal_size_limit_mb: "0"
# storage:
# size: 32Gi
# class: local-hostpath
# storage:
# size: 32Gi
# class: local-hostpath
toleration:
- key: kvrocks
effect: NoSchedule
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"

kruise "github.com/openkruise/kruise-api"
uberzap "go.uber.org/zap"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
uberzap "go.uber.org/zap"

kvrocksv1alpha1 "github.com/RocksLabs/kvrocks-operator/api/v1alpha1"
"github.com/RocksLabs/kvrocks-operator/pkg/controllers"
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/standard/kvrocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (h *KVRocksStandardHandler) updateSentinelAnnotationCount(sentinelName stri
if err := h.k8s.UpdateKVRocks(sentinel); err != nil {
return err
}
h.log.V(1).Info("sentinel monitor ready")
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/resources/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ const (
start = `
#!/bin/bash
sleep 15
./bin/kvrocks -c /conf/kvrocks.conf
./bin/kvrocks -c /var/lib/kvrocks/conf/kvrocks.conf
`

readinessProbe = `
#!/bin/sh
timeout 30 redis-cli -a $(cat /conf/password) --no-auth-warning ping || timeout 30 redis-cli --no-auth-warning ping
timeout 30 redis-cli -a $(cat /var/lib/kvrocks/conf/password) --no-auth-warning ping || timeout 30 redis-cli --no-auth-warning ping
`
)

Expand Down Expand Up @@ -92,7 +92,7 @@ func NewKVRocksConfigMap(instance *kvrocksv1alpha1.KVRocks) *corev1.ConfigMap {
// set auth config
buffer.WriteString(fmt.Sprintf("masterauth %s\n", instance.Spec.Password))
buffer.WriteString(fmt.Sprintf("requirepass %s\n", instance.Spec.Password))
buffer.WriteString("dir /data\n")
buffer.WriteString("dir /var/lib/kvrocks\n")
if instance.Spec.Type == kvrocksv1alpha1.ClusterType {
buffer.WriteString("cluster-enabled yes\n")
}
Expand Down
49 changes: 41 additions & 8 deletions pkg/resources/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func NewSentinelContainer(instance *kvrocksv1alpha1.KVRocks) *corev1.Container {
container := newKVRocksContainer(instance)
container := newSentinelContainer(instance)
container.Command = []string{"sh", "-c", "cp -n /conf/sentinel.conf /data/sentinel.conf; redis-server /data/sentinel.conf --sentinel"}
container.Ports = []corev1.ContainerPort{{
Name: "sentinel",
Expand All @@ -22,7 +22,7 @@ func NewSentinelContainer(instance *kvrocksv1alpha1.KVRocks) *corev1.Container {

func NewInstanceContainer(instance *kvrocksv1alpha1.KVRocks) *corev1.Container {
container := newKVRocksContainer(instance)
container.Command = []string{"sh", "/conf/start.sh"}
container.Command = []string{"sh", "/var/lib/kvrocks/conf/start.sh"}
container.Ports = []corev1.ContainerPort{{
Name: "kvrocks",
ContainerPort: kvrocks.KVRocksPort,
Expand All @@ -47,18 +47,15 @@ func NewExporterContainer(instance *kvrocksv1alpha1.KVRocks) *corev1.Container {
}
}

func newKVRocksContainer(instance *kvrocksv1alpha1.KVRocks) *corev1.Container {
cmd := []string{"sh", "/conf/readiness_probe.sh"}
if instance.Spec.Type == kvrocksv1alpha1.SentinelType {
cmd = []string{"redis-cli", "-p", "26379", "ping"}
}
func newSentinelContainer(instance *kvrocksv1alpha1.KVRocks) *corev1.Container {
cmd := []string{"redis-cli", "-p", "26379", "ping"}
handler := corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: cmd,
},
}
container := &corev1.Container{
Name: "kvrocks",
Name: "sentinel",
Image: instance.Spec.Image,
ImagePullPolicy: instance.Spec.ImagePullPolicy,
Resources: *instance.Spec.Resources,
Expand All @@ -85,3 +82,39 @@ func newKVRocksContainer(instance *kvrocksv1alpha1.KVRocks) *corev1.Container {
}
return container
}

func newKVRocksContainer(instance *kvrocksv1alpha1.KVRocks) *corev1.Container {
cmd := []string{"sh", "/var/lib/kvrocks/conf/readiness_probe.sh"}
handler := corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: cmd,
},
}
container := &corev1.Container{
Name: "kvrocks",
Image: instance.Spec.Image,
ImagePullPolicy: instance.Spec.ImagePullPolicy,
Resources: *instance.Spec.Resources,
VolumeMounts: []corev1.VolumeMount{
{
Name: "data",
MountPath: "/var/lib/kvrocks",
},
{
Name: "conf",
MountPath: "/var/lib/kvrocks/conf",
},
},
ReadinessProbe: &corev1.Probe{
TimeoutSeconds: 5,
ProbeHandler: handler,
FailureThreshold: 6,
},
LivenessProbe: &corev1.Probe{
TimeoutSeconds: 5,
ProbeHandler: handler,
FailureThreshold: 6,
},
}
return container
}
10 changes: 5 additions & 5 deletions test/e2e/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const (
)

type Config struct {
KruiseVersion string `yaml:"kruiseVersion"`
ClusterName string `yaml:"clusterName"`
Namespace string `yaml:"namespace"`
KubeConfig string `yaml:"kubeConfig"`
KruiseVersion string `yaml:"kruiseVersion"`
ClusterName string `yaml:"clusterName"`
Namespace string `yaml:"namespace"`
KubeConfig string `yaml:"kubeConfig"`
ChaosMeshEnabled bool `yaml:"chaosMeshEnabled"`
ManifestDir string `yaml:"manifestDir"`
ManifestDir string `yaml:"manifestDir"`
}

func NewConfig(configFilePath string) (*Config, error) {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/util/kubernetes_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"os/exec"
"path/filepath"
"reflect"
"runtime"
"strings"
"time"
"reflect"

kvrocksv1alpha1 "github.com/RocksLabs/kvrocks-operator/api/v1alpha1"
chaosmeshv1alpha1 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
Expand Down

0 comments on commit 0ece0a6

Please sign in to comment.