Skip to content

Commit

Permalink
Control plane pod resources
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Makhov <amakhov@mirantis.com>
  • Loading branch information
makhov committed Aug 29, 2023
1 parent 3b88630 commit 4a7327e
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/k0smotron.io/v1beta1/k0smotroncluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ type ClusterSpec struct {
// them as usual kubernetes pod metrics.
//+kubebuilder:validation:Optional
EnableMonitoring bool `json:"enableMonitoring,omitempty"`

// Resources describes the compute resource requirements for the control plane pods.
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}

// K0smotronClusterStatus defines the observed state of K0smotronCluster
Expand Down
1 change: 1 addition & 0 deletions api/k0smotron.io/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,55 @@ spec:
value is 3.
format: int32
type: integer
resources:
description: Resources describes the compute resource requirements
for the control plane pods.
properties:
claims:
description: "Claims lists the names of resources, defined in
spec.resourceClaims, that are used by this container. \n This
is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable. It can only be set
for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
name:
description: Name must match the name of one entry in pod.spec.resourceClaims
of the Pod where this field is used. It makes that resource
available inside a container.
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
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-resources-containers/'
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. Requests cannot exceed Limits.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
service:
description: Service defines the service configuration.
properties:
Expand Down
49 changes: 49 additions & 0 deletions config/crd/bases/k0smotron.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,55 @@ spec:
value is 3.
format: int32
type: integer
resources:
description: Resources describes the compute resource requirements
for the control plane pods.
properties:
claims:
description: "Claims lists the names of resources, defined in
spec.resourceClaims, that are used by this container. \n This
is an alpha field and requires enabling the DynamicResourceAllocation
feature gate. \n This field is immutable. It can only be set
for containers."
items:
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
properties:
name:
description: Name must match the name of one entry in pod.spec.resourceClaims
of the Pod where this field is used. It makes that resource
available inside a container.
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
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-resources-containers/'
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. Requests cannot exceed Limits.
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
type: object
type: object
service:
description: Service defines the service configuration.
properties:
Expand Down
154 changes: 154 additions & 0 deletions docs/resource-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,13 @@ ClusterSpec defines the desired state of K0smotronCluster
<i>Default</i>: 1<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#k0smotroncontrolplanespecresources">resources</a></b></td>
<td>object</td>
<td>
Resources describes the compute resource requirements for the control plane pods.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#k0smotroncontrolplanespecservice">service</a></b></td>
<td>object</td>
Expand Down Expand Up @@ -4955,6 +4962,76 @@ PersistentVolumeClaimCondition contains details about state of pvc
</table>


### K0smotronControlPlane.spec.resources
<sup><sup>[↩ Parent](#k0smotroncontrolplanespec)</sup></sup>



Resources describes the compute resource requirements for the control plane pods.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b><a href="#k0smotroncontrolplanespecresourcesclaimsindex">claims</a></b></td>
<td>[]object</td>
<td>
Claims lists the names of resources, defined in spec.resourceClaims, that are used by this container.
This is an alpha field and requires enabling the DynamicResourceAllocation feature gate.
This field is immutable. It can only be set for containers.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>limits</b></td>
<td>map[string]int or string</td>
<td>
Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>requests</b></td>
<td>map[string]int or string</td>
<td>
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. Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### K0smotronControlPlane.spec.resources.claims[index]
<sup><sup>[↩ Parent](#k0smotroncontrolplanespecresources)</sup></sup>



ResourceClaim references one entry in PodSpec.ResourceClaims.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>name</b></td>
<td>string</td>
<td>
Name must match the name of one entry in pod.spec.resourceClaims of the Pod where this field is used. It makes that resource available inside a container.<br/>
</td>
<td>true</td>
</tr></tbody>
</table>


### K0smotronControlPlane.spec.service
<sup><sup>[↩ Parent](#k0smotroncontrolplanespec)</sup></sup>

Expand Down Expand Up @@ -5229,6 +5306,13 @@ ClusterSpec defines the desired state of K0smotronCluster
<i>Default</i>: 1<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#clusterspecresources">resources</a></b></td>
<td>object</td>
<td>
Resources describes the compute resource requirements for the control plane pods.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#clusterspecservice">service</a></b></td>
<td>object</td>
Expand Down Expand Up @@ -8681,6 +8765,76 @@ PersistentVolumeClaimCondition contains details about state of pvc
</table>


### Cluster.spec.resources
<sup><sup>[↩ Parent](#clusterspec)</sup></sup>



Resources describes the compute resource requirements for the control plane pods.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b><a href="#clusterspecresourcesclaimsindex">claims</a></b></td>
<td>[]object</td>
<td>
Claims lists the names of resources, defined in spec.resourceClaims, that are used by this container.
This is an alpha field and requires enabling the DynamicResourceAllocation feature gate.
This field is immutable. It can only be set for containers.<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>limits</b></td>
<td>map[string]int or string</td>
<td>
Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>requests</b></td>
<td>map[string]int or string</td>
<td>
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. Requests cannot exceed Limits. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/<br/>
</td>
<td>false</td>
</tr></tbody>
</table>


### Cluster.spec.resources.claims[index]
<sup><sup>[↩ Parent](#clusterspecresources)</sup></sup>



ResourceClaim references one entry in PodSpec.ResourceClaims.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>name</b></td>
<td>string</td>
<td>
Name must match the name of one entry in pod.spec.resourceClaims of the Pod where this field is used. It makes that resource available inside a container.<br/>
</td>
<td>true</td>
</tr></tbody>
</table>


### Cluster.spec.service
<sup><sup>[↩ Parent](#clusterspec)</sup></sup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (r *ClusterReconciler) generateStatefulSet(kmc *km.Cluster) (apps.StatefulS
},
},
}},
Resources: kmc.Spec.Resources,
ReadinessProbe: &v1.Probe{
InitialDelaySeconds: 5,
ProbeHandler: v1.ProbeHandler{Exec: &v1.ExecAction{Command: []string{"k0s", "status"}}},
Expand Down
11 changes: 11 additions & 0 deletions inttest/basic/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func (s *BasicSuite) TestK0sGetsUp() {
s.createK0smotronCluster(s.Context(), kc)
s.Require().NoError(common.WaitForStatefulSet(s.Context(), kc, "kmc-kmc-test", "kmc-test"))

pod, err := kc.CoreV1().Pods("kmc-test").Get(s.Context(), "kmc-kmc-test-0", metav1.GetOptions{})
s.Require().NoError(err)
s.Require().Equal("100m", pod.Spec.Containers[0].Resources.Requests.Cpu().String())
s.Require().Equal("100Mi", pod.Spec.Containers[0].Resources.Requests.Memory().String())

s.T().Log("Generating k0smotron join token")
token, err := util.GetJoinToken(kc, rc, "kmc-kmc-test-0", "kmc-test")
s.Require().NoError(err)
Expand Down Expand Up @@ -158,6 +163,12 @@ metadata:
"configMap": { "name": "manifest-cm" }
}
],
"resources": {
"requests": {
"cpu": "100m",
"memory": "100Mi"
}
},
"k0sConfig": {
"apiVersion": "k0s.k0sproject.io/v1beta1",
"kind": "ClusterConfig",
Expand Down

0 comments on commit 4a7327e

Please sign in to comment.