Skip to content

Commit

Permalink
add sentinelConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayouxujin committed Jul 2, 2023
1 parent 60a8edf commit c2aa11b
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 28 deletions.
8 changes: 7 additions & 1 deletion api/v1alpha1/kvrocks_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type KVRocksSpec struct {
Toleration []corev1.Toleration `json:"toleration,omitempty"`
Affinity *corev1.Affinity `json:"affinity,omitempty"`
Storage *KVRocksStorage `json:"storage,omitempty"`
EnableSentinel bool `json:"enableSentinel,omitempty"`
SentinelConfig *SentinelConfig `json:"sentinelConfig,omitempty"`
}

// KVRocksStatus defines the observed state of KVRocks
Expand Down Expand Up @@ -99,6 +99,12 @@ type KVRocksTopology struct {
Failover bool `json:"failover,omitempty"`
}

type SentinelConfig struct {
EnableSentinel bool `json:"enableSentinel"`
Replicas int32 `json:"replicas"`
Resources *corev1.ResourceRequirements `json:"resources"`
}

type ImportMsg struct {
SrcNode string `json:"srcNode"`
Slots []string `json:"slots"`
Expand Down
25 changes: 25 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 60 additions & 2 deletions config/crd/bases/kvrocks.com_kvrocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,6 @@ spec:
type: array
type: object
type: object
enableSentinel:
type: boolean
image:
type: string
imagePullPolicy:
Expand Down Expand Up @@ -936,6 +934,66 @@ spec:
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
sentinelConfig:
properties:
enableSentinel:
type: boolean
replicas:
format: int32
type: integer
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:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Limits describes the maximum amount of compute
resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: 'Requests describes the minimum amount of compute
resources required. If Requests is omitted for a container,
it defaults to Limits if that is explicitly specified, otherwise
to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
required:
- enableSentinel
- replicas
- resources
type: object
storage:
properties:
class:
Expand Down
25 changes: 17 additions & 8 deletions examples/standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ spec:
master: 1
replicas: 3
type: standard
enableSentinel: true
sentinelConfig:
enableSentinel: true
replicas: 3
resources:
limits:
cpu: 10m
memory: 32Mi
requests:
cpu: 10m
memory: 32Mi
password: "123456"
kvrocksConfig:
bind: "0.0.0.0"
Expand Down Expand Up @@ -40,9 +49,9 @@ spec:
rocksdb.compression: "no"
rocksdb.wal_ttl_seconds: "0"
rocksdb.wal_size_limit_mb: "0"
# storage:
# size: 32Gi
# class: local-hostpath
storage:
size: 200Mi
class: standard
toleration:
- key: kvrocks
effect: NoSchedule
Expand All @@ -52,8 +61,8 @@ spec:
operator: Exists
resources:
limits:
cpu: 2
memory: 8Gi
cpu: 100m
memory: 1Gi
requests:
cpu: 1
memory: 4Gi
cpu: 100m
memory: 1Gi
4 changes: 2 additions & 2 deletions pkg/controllers/kvrocks_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ func runIfInitialize(instance *kvrocksv1alpha1.KVRocks, log logr.Logger, k8sClie
return err
}
}
if instance.Spec.Type == kvrocksv1alpha1.ClusterType && !instance.Spec.EnableSentinel {
instance.Spec.EnableSentinel = true
if instance.Spec.Type == kvrocksv1alpha1.ClusterType && !instance.Spec.SentinelConfig.EnableSentinel {
instance.Spec.SentinelConfig.EnableSentinel = true
return k8sClient.UpdateKVRocks(instance)
}
if instance.Status.Status == kvrocksv1alpha1.StatusNone {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/sentinel/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (h *KVRocksSentinelHandler) ensureSentinel() error {
return err
}
for _, kvrocks := range kvrockses.Items {
if !kvrocks.Spec.EnableSentinel {
if !kvrocks.Spec.SentinelConfig.EnableSentinel {
continue
}
if kvrocks.Status.Status != kvrocksv1alpha1.StatusRunning {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/standard/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (h *KVRocksStandardHandler) Requeue() bool {
}

func (h *KVRocksStandardHandler) Finializer() error {
if !h.instance.Spec.EnableSentinel {
if !h.instance.Spec.SentinelConfig.EnableSentinel {
return nil
}
commHandler := common.NewCommandHandler(h.instance, h.k8s, h.kvrocks, h.password)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/standard/kvrocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (h *KVRocksStandardHandler) ensureKVRocksReplication() error {
}
}
h.log.V(1).Info("redis replication ok")
if h.instance.Spec.EnableSentinel {
if h.instance.Spec.SentinelConfig.EnableSentinel {
return h.ensureSentinel(masterIP)
}
return nil
Expand Down
14 changes: 2 additions & 12 deletions pkg/resources/kvrocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/go-logr/logr"
uuid "github.com/satori/go.uuid"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"

Expand Down Expand Up @@ -80,23 +79,14 @@ func GetSentinelInstance(instance *kvrocksv1alpha1.KVRocks) *kvrocksv1alpha1.KVR
ImagePullPolicy: corev1.PullIfNotPresent,
Type: kvrocksv1alpha1.SentinelType,
KVRocksConfig: nil,
Replicas: 3,
Replicas: instance.Spec.SentinelConfig.Replicas,
Password: func(password string) string {
d := []byte(password)
m := md5.New()
m.Write(d)
return hex.EncodeToString(m.Sum(nil))
}(system),
Resources: &corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("10m"),
corev1.ResourceMemory: resource.MustParse("32Mi"),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("10m"),
corev1.ResourceMemory: resource.MustParse("32Mi"),
},
},
Resources: instance.Spec.SentinelConfig.Resources, //sentinel resources
NodeSelector: instance.Spec.NodeSelector,
Toleration: instance.Spec.Toleration,
Affinity: instance.Spec.Affinity,
Expand Down

0 comments on commit c2aa11b

Please sign in to comment.