Skip to content

Commit

Permalink
feat: separate resources section for leader and follower
Browse files Browse the repository at this point in the history
Signed-off-by: Husni Alhamdani <[email protected]>
  • Loading branch information
husnialhamdani committed Dec 24, 2024
1 parent c02c7c9 commit 0df4494
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 4 deletions.
10 changes: 6 additions & 4 deletions api/v1beta2/rediscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ func (cr *RedisClusterSpec) GetReplicaCounts(t string) int32 {
// RedisLeader interface will have the redis leader configuration
type RedisLeader struct {
common.RedisLeader `json:",inline"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
}

// RedisFollower interface will have the redis follower configuration
type RedisFollower struct {
common.RedisFollower `json:",inline"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
}

// RedisClusterStatus defines the observed state of RedisCluster
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

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

112 changes: 112 additions & 0 deletions config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8727,6 +8727,62 @@ spec:
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.


This is an alpha field and requires enabling the
DynamicResourceAllocation feature gate.


This field is immutable. It can only be set for containers.
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. Requests cannot exceed Limits.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
securityContext:
description: |-
SecurityContext holds security configuration that will be applied to a container.
Expand Down Expand Up @@ -10346,6 +10402,62 @@ spec:
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.


This is an alpha field and requires enabling the
DynamicResourceAllocation feature gate.


This field is immutable. It can only be set for containers.
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. Requests cannot exceed Limits.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
type: object
type: object
securityContext:
description: |-
SecurityContext holds security configuration that will be applied to a container.
Expand Down
3 changes: 3 additions & 0 deletions pkg/k8sutils/redis-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type RedisClusterSTS struct {
RedisStateFulType string
ExternalConfig *string
Resources *corev1.ResourceRequirements
SecurityContext *corev1.SecurityContext
Affinity *corev1.Affinity `json:"affinity,omitempty"`
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
Expand Down Expand Up @@ -217,6 +218,7 @@ func generateRedisClusterContainerParams(ctx context.Context, cl kubernetes.Inte
func CreateRedisLeader(ctx context.Context, cr *redisv1beta2.RedisCluster, cl kubernetes.Interface) error {
prop := RedisClusterSTS{
RedisStateFulType: "leader",
Resources: cr.Spec.RedisLeader.Resources,

Check warning on line 221 in pkg/k8sutils/redis-cluster.go

View check run for this annotation

Codecov / codecov/patch

pkg/k8sutils/redis-cluster.go#L221

Added line #L221 was not covered by tests
SecurityContext: cr.Spec.RedisLeader.SecurityContext,
Affinity: cr.Spec.RedisLeader.Affinity,
TerminationGracePeriodSeconds: cr.Spec.RedisLeader.TerminationGracePeriodSeconds,
Expand All @@ -237,6 +239,7 @@ func CreateRedisLeader(ctx context.Context, cr *redisv1beta2.RedisCluster, cl ku
func CreateRedisFollower(ctx context.Context, cr *redisv1beta2.RedisCluster, cl kubernetes.Interface) error {
prop := RedisClusterSTS{
RedisStateFulType: "follower",
Resources: cr.Spec.RedisFollower.Resources,

Check warning on line 242 in pkg/k8sutils/redis-cluster.go

View check run for this annotation

Codecov / codecov/patch

pkg/k8sutils/redis-cluster.go#L242

Added line #L242 was not covered by tests
SecurityContext: cr.Spec.RedisFollower.SecurityContext,
Affinity: cr.Spec.RedisFollower.Affinity,
TerminationGracePeriodSeconds: cr.Spec.RedisFollower.TerminationGracePeriodSeconds,
Expand Down

0 comments on commit 0df4494

Please sign in to comment.