Skip to content

Commit

Permalink
cluster: allow to provide custom agent resources (#262)
Browse files Browse the repository at this point in the history
Fixes #262
  • Loading branch information
zimnx committed Dec 16, 2020
1 parent b8ac59a commit a689d62
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 22 deletions.
27 changes: 25 additions & 2 deletions config/operator/crd/bases/scylla.scylladb.com_scyllaclusters.yaml
Expand Up @@ -121,6 +121,28 @@ spec:
items:
description: RackSpec is the desired state for a Scylla Rack.
properties:
agentResources:
description: AgentResources which Agent container will use.
properties:
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-compute-resources-container/'
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-compute-resources-container/'
type: object
type: object
members:
description: Members is the number of Scylla instances in this rack.
format: int32
Expand Down Expand Up @@ -492,7 +514,7 @@ spec:
type: array
type: object
resources:
description: Resources the Scylla Pods will use.
description: Resources the Scylla container will use.
properties:
limits:
additionalProperties:
Expand Down Expand Up @@ -532,7 +554,7 @@ spec:
- capacity
type: object
volumeMounts:
description: Volume mounts to be added to scylla nodes
description: VolumeMounts to be added to Scylla container.
items:
description: VolumeMount describes a mounting of a Volume within a container.
properties:
Expand Down Expand Up @@ -560,6 +582,7 @@ spec:
type: object
type: array
volumes:
description: Volumes added to Scylla container.
items:
description: Volume represents a named volume in a pod that may be accessed by any container in the pod.
properties:
Expand Down
5 changes: 3 additions & 2 deletions docs/source/scylla_cluster_crd.md
Expand Up @@ -141,12 +141,13 @@ and n nodes in all the other datacenters.
* `capacity`: Capacity of the PersistentVolume to request.
* `storageClassName`: Optional field. [StorageClass](https://kubernetes.io/docs/concepts/storage/storage-classes/) of PersistentVolume to request.
* `resources`: Defines the CPU and RAM resources for the Scylla Pods.
* `requests`: The minimum amount of resources needed to run a Scylla Pod.
* `requests`: The minimum amount of resources needed to run a Scylla container.
* `cpu`: CPU requests.
* `memory`: RAM requests.
* `limits`: The maximum amount of resources that can be used by a Scylla Pod.
* `limits`: The maximum amount of resources that can be used by a Scylla container.
* `cpu`: CPU limits.
* `memory`: RAM limits.
* `agentResources`: Defines the CPU and RAM resources for the Scylla Manager Agent container. See `resources` for details.
* `placement`: Defines the placement of Scylla Pods. Has the following subfields:
* [`nodeAffinity`](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#node-affinity-beta-feature)
* [`podAffinity`](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#inter-pod-affinity-and-anti-affinity-beta-feature)
Expand Down
27 changes: 25 additions & 2 deletions examples/common/operator.yaml
Expand Up @@ -136,6 +136,28 @@ spec:
items:
description: RackSpec is the desired state for a Scylla Rack.
properties:
agentResources:
description: AgentResources which Agent container will use.
properties:
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-compute-resources-container/'
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-compute-resources-container/'
type: object
type: object
members:
description: Members is the number of Scylla instances in this rack.
format: int32
Expand Down Expand Up @@ -507,7 +529,7 @@ spec:
type: array
type: object
resources:
description: Resources the Scylla Pods will use.
description: Resources the Scylla container will use.
properties:
limits:
additionalProperties:
Expand Down Expand Up @@ -547,7 +569,7 @@ spec:
- capacity
type: object
volumeMounts:
description: Volume mounts to be added to scylla nodes
description: VolumeMounts to be added to Scylla container.
items:
description: VolumeMount describes a mounting of a Volume within a container.
properties:
Expand Down Expand Up @@ -575,6 +597,7 @@ spec:
type: object
type: array
volumes:
description: Volumes added to Scylla container.
items:
description: Volume represents a named volume in a pod that may be accessed by any container in the pod.
properties:
Expand Down
9 changes: 6 additions & 3 deletions pkg/api/v1alpha1/cluster_types.go
Expand Up @@ -164,10 +164,13 @@ type RackSpec struct {
Storage StorageSpec `json:"storage"`
// Placement describes restrictions for the nodes Scylla is scheduled on.
Placement *PlacementSpec `json:"placement,omitempty"`
// Resources the Scylla Pods will use.
// Resources the Scylla container will use.
Resources corev1.ResourceRequirements `json:"resources"`
Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name" protobuf:"bytes,1,rep,name=volumes"`
// Volume mounts to be added to scylla nodes
// AgentResources which Agent container will use.
AgentResources corev1.ResourceRequirements `json:"agentResources,omitempty"`
// Volumes added to Scylla container.
Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge,retainKeys" patchMergeKey:"name" protobuf:"bytes,1,rep,name=volumes"`
// VolumeMounts to be added to Scylla container.
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty" patchStrategy:"merge" patchMergeKey:"mountPath" protobuf:"bytes,9,rep,name=volumeMounts"`
// Scylla config map name to customize scylla.yaml
ScyllaConfig string `json:"scyllaConfig"`
Expand Down
20 changes: 20 additions & 0 deletions pkg/api/v1alpha1/cluster_webhook.go
Expand Up @@ -17,6 +17,10 @@ limitations under the License.
package v1alpha1

import (
"reflect"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -40,6 +44,22 @@ var _ webhook.Defaulter = &ScyllaCluster{}
var _ webhook.Validator = &ScyllaCluster{}

func (c *ScyllaCluster) Default() {
for _, r := range c.Spec.Datacenter.Racks {
// Empty agent resources
if reflect.DeepEqual(r.AgentResources, corev1.ResourceRequirements{}) {
r.AgentResources = corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("50m"),
corev1.ResourceMemory: resource.MustParse("10M"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("200M"),
},
}
}
}

for i, repairTask := range c.Spec.Repairs {
if repairTask.StartDate == nil {
c.Spec.Repairs[i].StartDate = pointer.StringPtr("now")
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1alpha1/zz_generated.deepcopy.go

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

17 changes: 4 additions & 13 deletions pkg/controllers/cluster/resource/resource.go
Expand Up @@ -361,7 +361,7 @@ func StatefulSetForRack(r scyllav1alpha1.RackSpec, c *scyllav1alpha1.ScyllaClust
sts.Spec.Template.Spec.Volumes = append(
sts.Spec.Template.Spec.Volumes, *Volume.DeepCopy())
}
sts.Spec.Template.Spec.Containers = append(sts.Spec.Template.Spec.Containers, *agentContainer(c))
sts.Spec.Template.Spec.Containers = append(sts.Spec.Template.Spec.Containers, agentContainer(r, c))
return sts
}

Expand Down Expand Up @@ -436,8 +436,8 @@ func sysctlInitContainer(sysctls []string) *corev1.Container {
}
}

func agentContainer(c *scyllav1alpha1.ScyllaCluster) *corev1.Container {
return &corev1.Container{
func agentContainer(r scyllav1alpha1.RackSpec, c *scyllav1alpha1.ScyllaCluster) corev1.Container {
return corev1.Container{
Name: "scylla-manager-agent",
Image: agentImageForCluster(c),
ImagePullPolicy: "IfNotPresent",
Expand All @@ -464,16 +464,7 @@ func agentContainer(c *scyllav1alpha1.ScyllaCluster) *corev1.Container {
ReadOnly: true,
},
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("50m"),
corev1.ResourceMemory: resource.MustParse("10M"),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("200M"),
},
},
Resources: r.AgentResources,
}
}

Expand Down

0 comments on commit a689d62

Please sign in to comment.