Skip to content

Commit

Permalink
Move resources management to defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
tomp21 committed Dec 25, 2024
1 parent 8ba72d8 commit 804b0d9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
1 change: 0 additions & 1 deletion api/v1alpha1/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type RedisSpec struct {

// +kubebuilder:validation:Minimum=1
Replicas int32 `json:"replicas,omitempty"`
Memory resource.Quantity `json:"memory,omitempty"`
Version string `json:"version,omitempty"`
VolumeStorage resource.Quantity `json:"volumeStorage,omitempty"`
}
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 0 additions & 6 deletions config/crd/bases/cache.yazio.com_redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ spec:
spec:
description: RedisSpec defines the desired state of Redis
properties:
memory:
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
replicas:
format: int32
minimum: 1
Expand Down
1 change: 0 additions & 1 deletion config/samples/cache_v1alpha1_redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ metadata:
name: redis-sample
spec:
replicas: 3
memory: 2G
version: "7.4.1"
volumeStorage: 2Gi
18 changes: 18 additions & 0 deletions internal/controller/redis_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const (
passwordLength = 12
redisImage = "bitnami/redis"
redisPasswordSecretKey = "redis-password"
defaultMemoryRequest = "512Mi"
defaultCpuRequest = "100m"
defaultMemoryLimit = "512Mi"
)

var BaseLabels = map[string]string{
Expand Down Expand Up @@ -407,6 +410,7 @@ func (r *RedisReconciler) createOrUpdateMasterSS(ctx context.Context, redis *cac
MountPath: "/data",
},
},
Resources: getResources(),
},
},
Volumes: []corev1.Volume{
Expand Down Expand Up @@ -552,6 +556,7 @@ func (r *RedisReconciler) createOrUpdateReplicasSS(ctx context.Context, redis *c
MountPath: "/data",
},
},
Resources: getResources(),
},
},
Volumes: []corev1.Volume{
Expand Down Expand Up @@ -655,6 +660,19 @@ func (r *RedisReconciler) createOrUpdateConfigMaps(ctx context.Context, redis *c
return nil
}

// Making this a method in case this needs to be calculated in some other way in the future
func getResources() corev1.ResourceRequirements {
return corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse(defaultMemoryRequest),
corev1.ResourceCPU: resource.MustParse(defaultCpuRequest),
},
Limits: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse(defaultMemoryLimit),
},
}
}

func generateSecureRedisPassword() string {
var password []byte
//TODO improve this, it works fine but the code is ugly and will only have 1 uppercase character, though it is good enough for now
Expand Down

0 comments on commit 804b0d9

Please sign in to comment.