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 15, 2020
1 parent 48deb98 commit 8f4635a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 20 deletions.
27 changes: 25 additions & 2 deletions config/operator/crd/bases/scylla.scylladb.com_scyllaclusters.yaml
Original file line number Diff line number Diff line change
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
27 changes: 25 additions & 2 deletions examples/common/operator.yaml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
31 changes: 18 additions & 13 deletions pkg/controllers/cluster/resource/resource.go
Original file line number Diff line number Diff line change
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,22 @@ 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 {
resources := r.AgentResources
if resources == nil {
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"),
},
}
}

return corev1.Container{
Name: "scylla-manager-agent",
Image: agentImageForCluster(c),
ImagePullPolicy: "IfNotPresent",
Expand All @@ -464,16 +478,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: *resources,
}
}

Expand Down

0 comments on commit 8f4635a

Please sign in to comment.