Skip to content

Commit b2c477b

Browse files
committed
Expose pod property for resource QoS
Add the ability to configure required/allowed CPU and memory consumption for galera pod, by exposing the standard QoS Resources from pod API. The galera type now exposes an optional Resources field to configure galera pod's QoS, similarly to the RabbitMQCluster type. Unlike rabbitmq, no default QoS is enforce, so the default galera pod behaviour doesn't change (QoS Class is BestEffort). Jira: OSPRH-17410
1 parent 0b41a4a commit b2c477b

File tree

6 files changed

+243
-2
lines changed

6 files changed

+243
-2
lines changed

api/bases/mariadb.openstack.org_galeras.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,61 @@ spec:
7878
maximum: 3
7979
minimum: 0
8080
type: integer
81+
resources:
82+
description: Resources QoS configuration for pods
83+
properties:
84+
claims:
85+
description: |-
86+
Claims lists the names of resources, defined in spec.resourceClaims,
87+
that are used by this container.
88+
89+
90+
This is an alpha field and requires enabling the
91+
DynamicResourceAllocation feature gate.
92+
93+
94+
This field is immutable. It can only be set for containers.
95+
items:
96+
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
97+
properties:
98+
name:
99+
description: |-
100+
Name must match the name of one entry in pod.spec.resourceClaims of
101+
the Pod where this field is used. It makes that resource available
102+
inside a container.
103+
type: string
104+
required:
105+
- name
106+
type: object
107+
type: array
108+
x-kubernetes-list-map-keys:
109+
- name
110+
x-kubernetes-list-type: map
111+
limits:
112+
additionalProperties:
113+
anyOf:
114+
- type: integer
115+
- type: string
116+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
117+
x-kubernetes-int-or-string: true
118+
description: |-
119+
Limits describes the maximum amount of compute resources allowed.
120+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
121+
type: object
122+
requests:
123+
additionalProperties:
124+
anyOf:
125+
- type: integer
126+
- type: string
127+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
128+
x-kubernetes-int-or-string: true
129+
description: |-
130+
Requests describes the minimum amount of compute resources required.
131+
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
132+
otherwise to an implementation-defined value. Requests cannot exceed Limits.
133+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
134+
type: object
135+
type: object
81136
secret:
82137
description: Name of the secret to look for password keys
83138
type: string

api/v1beta1/galera_types.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2021
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2122
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
2223
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
23-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
24-
"k8s.io/apimachinery/pkg/util/validation/field"
24+
corev1 "k8s.io/api/core/v1"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/apimachinery/pkg/util/validation/field"
2627
)
2728

2829
const (
@@ -87,6 +88,8 @@ type GaleraSpecCore struct {
8788
// TopologyRef to apply the Topology defined by the associated CR referenced
8889
// by name
8990
TopologyRef *topologyv1.TopoRef `json:"topologyRef,omitempty"`
91+
// Resources QoS configuration for pods
92+
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
9093
}
9194

9295
// GaleraAttributes holds startup information for a Galera host

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/mariadb.openstack.org_galeras.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,61 @@ spec:
7878
maximum: 3
7979
minimum: 0
8080
type: integer
81+
resources:
82+
description: Resources QoS configuration for pods
83+
properties:
84+
claims:
85+
description: |-
86+
Claims lists the names of resources, defined in spec.resourceClaims,
87+
that are used by this container.
88+
89+
90+
This is an alpha field and requires enabling the
91+
DynamicResourceAllocation feature gate.
92+
93+
94+
This field is immutable. It can only be set for containers.
95+
items:
96+
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
97+
properties:
98+
name:
99+
description: |-
100+
Name must match the name of one entry in pod.spec.resourceClaims of
101+
the Pod where this field is used. It makes that resource available
102+
inside a container.
103+
type: string
104+
required:
105+
- name
106+
type: object
107+
type: array
108+
x-kubernetes-list-map-keys:
109+
- name
110+
x-kubernetes-list-type: map
111+
limits:
112+
additionalProperties:
113+
anyOf:
114+
- type: integer
115+
- type: string
116+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
117+
x-kubernetes-int-or-string: true
118+
description: |-
119+
Limits describes the maximum amount of compute resources allowed.
120+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
121+
type: object
122+
requests:
123+
additionalProperties:
124+
anyOf:
125+
- type: integer
126+
- type: string
127+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
128+
x-kubernetes-int-or-string: true
129+
description: |-
130+
Requests describes the minimum amount of compute resources required.
131+
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
132+
otherwise to an implementation-defined value. Requests cannot exceed Limits.
133+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
134+
type: object
135+
type: object
81136
secret:
82137
description: Name of the secret to look for password keys
83138
type: string

pkg/mariadb/statefulset.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ func StatefulSet(g *mariadbv1.Galera, configHash string, topology *topologyv1.To
9494
}
9595

9696
func getGaleraInitContainers(g *mariadbv1.Galera) []corev1.Container {
97+
var galeraRsc corev1.ResourceRequirements
98+
if g.Spec.Resources != nil {
99+
galeraRsc = *g.Spec.Resources
100+
}
97101
return []corev1.Container{{
98102
Image: g.Spec.ContainerImage,
99103
Name: "mysql-bootstrap",
@@ -115,11 +119,16 @@ func getGaleraInitContainers(g *mariadbv1.Galera) []corev1.Container {
115119
},
116120
},
117121
}},
122+
Resources: galeraRsc,
118123
VolumeMounts: getGaleraInitVolumeMounts(g),
119124
}}
120125
}
121126

122127
func getGaleraContainers(g *mariadbv1.Galera, configHash string) []corev1.Container {
128+
var galeraRsc corev1.ResourceRequirements
129+
if g.Spec.Resources != nil {
130+
galeraRsc = *g.Spec.Resources
131+
}
123132
timeout := strconv.Itoa(StartupProbeTimeout)
124133
containers := []corev1.Container{{
125134
Image: g.Spec.ContainerImage,
@@ -149,6 +158,7 @@ func getGaleraContainers(g *mariadbv1.Galera, configHash string) []corev1.Contai
149158
ContainerPort: 4567,
150159
Name: "galera",
151160
}},
161+
Resources: galeraRsc,
152162
VolumeMounts: getGaleraVolumeMounts(g),
153163
StartupProbe: &corev1.Probe{
154164
ProbeHandler: corev1.ProbeHandler{
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Test
3+
metadata:
4+
name: qos
5+
spec:
6+
steps:
7+
- name: Deploy 1-node cluster without pod QoS
8+
description: Deploy a 1-node cluster and wait for readiness
9+
bindings:
10+
- name: replicas
11+
value: 1
12+
try:
13+
- apply:
14+
file: ../../common/galera.yaml
15+
- assert:
16+
# check if all nodes are started and one pod is reacheable via the service endpoint
17+
file: ../../common/galera-assert.yaml
18+
- script: &check
19+
# check if galera can be accessed and cluster is correct
20+
content: |
21+
../../scripts/mysql-cli.sh -sNEe "show status like 'wsrep_cluster_size';" | tail -1 | tr -d '\n'
22+
check:
23+
(to_number($stdout)): ($replicas)
24+
25+
- name: Update QoS to Burstable
26+
description: Ensure that requested resource is configured in the pod
27+
try:
28+
- patch:
29+
resource:
30+
apiVersion: mariadb.openstack.org/v1beta1
31+
kind: Galera
32+
metadata:
33+
name: openstack
34+
spec:
35+
resources: &res_burstable
36+
requests:
37+
memory: "128M"
38+
cpu: "700m"
39+
- assert:
40+
resource:
41+
apiVersion: v1
42+
kind: Pod
43+
metadata:
44+
name: openstack-galera-0
45+
spec:
46+
initContainers:
47+
- resources: *res_burstable
48+
containers:
49+
- name: galera
50+
resources: *res_burstable
51+
status:
52+
qosClass: Burstable
53+
containerStatuses:
54+
- name: galera
55+
ready: true
56+
57+
- name: Update QoS to Guaranteed
58+
description: Ensure that requested and limit resources are configured in the pod
59+
try:
60+
- patch:
61+
resource:
62+
apiVersion: mariadb.openstack.org/v1beta1
63+
kind: Galera
64+
metadata:
65+
name: openstack
66+
spec:
67+
resources: &res_guaranteed
68+
limits:
69+
memory: "256M"
70+
cpu: "700m"
71+
requests:
72+
memory: "256M"
73+
cpu: "700m"
74+
- assert:
75+
resource:
76+
apiVersion: v1
77+
kind: Pod
78+
metadata:
79+
name: openstack-galera-0
80+
spec:
81+
initContainers:
82+
- resources: *res_guaranteed
83+
containers:
84+
- name: galera
85+
resources: *res_guaranteed
86+
status:
87+
qosClass: Guaranteed
88+
containerStatuses:
89+
- name: galera
90+
ready: true
91+
92+
- name: Remove pod QoS
93+
description: Ensure that a pod QoS can be removed
94+
try:
95+
- patch:
96+
resource:
97+
apiVersion: mariadb.openstack.org/v1beta1
98+
kind: Galera
99+
metadata:
100+
name: openstack
101+
spec:
102+
resources:
103+
- assert:
104+
resource:
105+
apiVersion: v1
106+
kind: Pod
107+
metadata:
108+
name: openstack-galera-0
109+
status:
110+
qosClass: BestEffort
111+
containerStatuses:
112+
- name: galera
113+
ready: true

0 commit comments

Comments
 (0)