Skip to content

Commit 78effb0

Browse files
Merge pull request #339 from dciabrin/OSPRH-17410
Expose pod property for resource QoS
2 parents 0b41a4a + 752e8b3 commit 78effb0

File tree

7 files changed

+234
-3
lines changed

7 files changed

+234
-3
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: 6 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,9 @@ 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+
// +kubebuilder:validation:Optional
92+
// Resources QoS configuration for pods
93+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
9094
}
9195

9296
// GaleraAttributes holds startup information for a Galera host

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 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

hack/crd-schema-checker.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ for crd in config/crd/bases/*.yaml; do
1717
if git show "$BASE_REF:$crd" > "$TMP_DIR/$crd"; then
1818
$CHECKER check-manifests \
1919
--existing-crd-filename="$TMP_DIR/$crd" \
20-
--new-crd-filename="$crd"
20+
--new-crd-filename="$crd" \
21+
--disabled-validators NoMaps
2122
fi
2223
done

pkg/mariadb/statefulset.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func getGaleraInitContainers(g *mariadbv1.Galera) []corev1.Container {
115115
},
116116
},
117117
}},
118+
Resources: g.Spec.Resources,
118119
VolumeMounts: getGaleraInitVolumeMounts(g),
119120
}}
120121
}
@@ -149,6 +150,7 @@ func getGaleraContainers(g *mariadbv1.Galera, configHash string) []corev1.Contai
149150
ContainerPort: 4567,
150151
Name: "galera",
151152
}},
153+
Resources: g.Spec.Resources,
152154
VolumeMounts: getGaleraVolumeMounts(g),
153155
StartupProbe: &corev1.Probe{
154156
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)