Skip to content

Commit

Permalink
Merge pull request #464 from ScheererJ/enhancement/static-resource-re…
Browse files Browse the repository at this point in the history
…quests

Add support for static resource requests
  • Loading branch information
axel7born authored Sep 2, 2024
2 parents 74b702e + 5311ae6 commit c621d19
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 40 deletions.
2 changes: 1 addition & 1 deletion charts/internal/calico/templates/kube-controller/vpa.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.config.kubeControllers.enabled }}
{{- if .Values.vpa.enabled }}
{{- if .Values.autoscaling.kubeControllers }}
apiVersion: "autoscaling.k8s.io/v1"
kind: VerticalPodAutoscaler
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if not .Values.vpa.node }}
{{- if not ( or .Values.autoscaling.node .Values.autoscaling.staticRequests ) }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if not .Values.vpa.node }}
{{- if not ( or .Values.autoscaling.node .Values.autoscaling.staticRequests ) }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if not .Values.vpa.node }}
{{- if not ( or .Values.autoscaling.node .Values.autoscaling.staticRequests ) }}
---
kind: ConfigMap
apiVersion: v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if not .Values.vpa.node }}
{{- if not ( or .Values.autoscaling.node .Values.autoscaling.staticRequests ) }}
---
kind: Deployment
apiVersion: apps/v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if not .Values.vpa.node }}
{{- if not ( or .Values.autoscaling.node .Values.autoscaling.staticRequests ) }}
---
apiVersion: v1
kind: ServiceAccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ metadata:
k8s-app: calico-node
gardener.cloud/role: system-component
node.gardener.cloud/critical-component: "true"
{{- if not .Values.autoscaling.staticRequests }}
annotations:
resources.gardener.cloud/preserve-resources: 'true'
{{- end }}
spec:
revisionHistoryLimit: 5
selector:
Expand Down Expand Up @@ -416,8 +418,8 @@ spec:
{{- end }}
resources:
requests:
cpu: 250m
memory: 100Mi
cpu: {{ if and .Values.autoscaling.staticRequests .Values.autoscaling.resourceRequests.node.cpu }}{{ .Values.autoscaling.resourceRequests.node.cpu }}{{ else }}250m{{ end }}
memory: {{ if and .Values.autoscaling.staticRequests .Values.autoscaling.resourceRequests.node.memory }}{{ .Values.autoscaling.resourceRequests.node.memory }}{{ else }}100Mi{{ end }}
limits:
memory: 2800Mi
lifecycle:
Expand Down
2 changes: 1 addition & 1 deletion charts/internal/calico/templates/node/vpa.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.vpa.node }}
{{- if .Values.autoscaling.node }}
apiVersion: "autoscaling.k8s.io/v1"
kind: VerticalPodAutoscaler
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.config.typha.enabled }}
{{- if not .Values.vpa.typha }}
{{- if not ( or .Values.autoscaling.typha .Values.autoscaling.staticRequests ) }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.config.typha.enabled }}
{{- if not .Values.vpa.typha }}
{{- if not ( or .Values.autoscaling.typha .Values.autoscaling.staticRequests ) }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.config.typha.enabled }}
{{- if not .Values.vpa.typha }}
{{- if not ( or .Values.autoscaling.typha .Values.autoscaling.staticRequests ) }}
---
apiVersion: v1
kind: ConfigMap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.config.typha.enabled }}
{{- if not .Values.vpa.typha }}
{{- if not ( or .Values.autoscaling.typha .Values.autoscaling.staticRequests ) }}
---
apiVersion: apps/v1
kind: Deployment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.config.typha.enabled }}
{{- if not .Values.vpa.typha }}
{{- if not ( or .Values.autoscaling.typha .Values.autoscaling.staticRequests ) }}
---
apiVersion: v1
kind: ServiceAccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ metadata:
namespace: kube-system
annotations:
cluster-autoscaler.kubernetes.io/safe-to-evict: 'true'
{{- if not .Values.autoscaling.staticRequests }}
resources.gardener.cloud/preserve-resources: 'true'
{{- end }}
labels:
k8s-app: calico-typha
gardener.cloud/role: system-component
Expand Down Expand Up @@ -122,8 +124,8 @@ spec:
# value: "9093"
resources:
requests:
cpu: 200m
memory: 100Mi
cpu: {{ if and .Values.autoscaling.staticRequests .Values.autoscaling.resourceRequests.typha.cpu }}{{ .Values.autoscaling.resourceRequests.typha.cpu }}{{ else }}200m{{ end }}
memory: {{ if and .Values.autoscaling.staticRequests .Values.autoscaling.resourceRequests.typha.memory }}{{ .Values.autoscaling.resourceRequests.typha.memory }}{{ else }}100Mi{{ end }}
limits:
memory: 4000Mi
livenessProbe:
Expand Down
2 changes: 1 addition & 1 deletion charts/internal/calico/templates/typha/vpa.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.vpa.typha }}
{{- if .Values.autoscaling.typha }}
apiVersion: "autoscaling.k8s.io/v1"
kind: VerticalPodAutoscaler
metadata:
Expand Down
12 changes: 10 additions & 2 deletions charts/internal/calico/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ images:
calico-cpva: "image-repository:image-tag"
calico-cpa: "image-repository:image-tag"

vpa:
enabled: false
autoscaling:
kubeControllers: false
node: false
typha: false
staticRequests: false
resourceRequests:
node: {}
#cpu: 250m # Only set when available
#memory: 100Mi # Only set when available
typha: {}
#cpu: 200m # Only set when available
#memory: 100Mi # Only set when available
27 changes: 23 additions & 4 deletions docs/usage/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ spec:

## AutoScaling

Autoscaling defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
Autoscaling defines how the calico components are automatically scaled. It allows to use either static resource assignment, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).

The cluster-proportional autoscaling mode is preferable when conditions require minimimal disturbances and vpa mode for improved cluster resource utilization.
The cluster-proportional autoscaling mode is preferable when conditions require minimal disturbances and vpa mode for improved cluster resource utilization. Static resource assignments causes no disruptions due to autoscaling, but has no dynamics to handle changing demands.

Please note VPA must be enabled on the shoot as a pre-requisite to enabling vpa mode.


An example AutoScaling `NetworkingConfig` manifest:
An example `NetworkingConfig` manifest for vertical pod autoscaling:

```yaml
apiVersion: calico.networking.extensions.gardener.cloud/v1alpha1
Expand All @@ -81,6 +80,26 @@ autoScaling:
mode: "vpa"
```

An example `NetworkingConfig` manifest for static resource assignment:

```yaml
apiVersion: calico.networking.extensions.gardener.cloud/v1alpha1
kind: NetworkConfig
autoScaling:
mode: "static"
resources:
node:
cpu: 100m
memory: 100Mi
typha:
cpu: 100m
memory: 100Mi
```

> ℹ️ Please note that in static mode, you have the option to configure the resource requests for calico-node and calico-typha. If not specified, default settings will be used.
> If the resource requests are chosen too low, it might impact the stability/performance of the cluster.
> Specifying the resource requests for any other autoscaling mode has no effect.

## Example `NetworkingConfig` manifest

An example `NetworkingConfig` for the Calico extension looks as follows:
Expand Down
64 changes: 61 additions & 3 deletions hack/api-reference/calico.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ AutoScaling
</td>
<td>
<em>(Optional)</em>
<p>AutoScaling defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).</p>
<p>AutoScaling defines how the calico components are automatically scaled. It allows to use static configuration, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -232,7 +232,7 @@ bool
<a href="#calico.networking.extensions.gardener.cloud/v1alpha1.NetworkConfig">NetworkConfig</a>)
</p>
<p>
<p>AutoScaling defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).</p>
<p>AutoScaling defines how the calico components are automatically scaled. It allows to use static configuration, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).</p>
</p>
<table>
<thead>
Expand All @@ -252,7 +252,20 @@ AutoscalingMode
</em>
</td>
<td>
<p>Mode defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).</p>
<p>Mode defines how the calico components are automatically scaled. It allows to use static configuration, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).</p>
</td>
</tr>
<tr>
<td>
<code>resources</code></br>
<em>
<a href="#calico.networking.extensions.gardener.cloud/v1alpha1.StaticResources">
StaticResources
</a>
</em>
</td>
<td>
<p>Resources optionally defines the amount of resources to statically allocate for the calico components.</p>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -586,6 +599,51 @@ bool
</tr>
</tbody>
</table>
<h3 id="calico.networking.extensions.gardener.cloud/v1alpha1.StaticResources">StaticResources
</h3>
<p>
(<em>Appears on:</em>
<a href="#calico.networking.extensions.gardener.cloud/v1alpha1.AutoScaling">AutoScaling</a>)
</p>
<p>
<p>StaticResources optionally defines the amount of resources to statically allocate for the calico components.</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>node</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#resourcelist-v1-core">
Kubernetes core/v1.ResourceList
</a>
</em>
</td>
<td>
<p>Node optionally defines the amount of resources to statically allocate for the calico node component.</p>
</td>
</tr>
<tr>
<td>
<code>typha</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#resourcelist-v1-core">
Kubernetes core/v1.ResourceList
</a>
</em>
</td>
<td>
<p>Node optionally defines the amount of resources to statically allocate for the calico typha component.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="calico.networking.extensions.gardener.cloud/v1alpha1.Typha">Typha
</h3>
<p>
Expand Down
19 changes: 16 additions & 3 deletions pkg/apis/calico/types_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package calico

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -86,7 +87,7 @@ type NetworkConfig struct {
Overlay *Overlay
// SnatToUpstreamDNS enables the masquerading of packets to the upstream dns server (default: enabled)
SnatToUpstreamDNS *SnatToUpstreamDNS
// AutoScaling defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
// AutoScaling defines how the calico components are automatically scaled. It allows to use static configuration, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
// +optional
AutoScaling *AutoScaling

Expand Down Expand Up @@ -155,10 +156,22 @@ const (
AutoscalingModeClusterProportional AutoscalingMode = "cluster-proportional"
// AutoscalingModeVPA is a constant for vertical pod autoscaling mode.
AutoscalingModeVPA AutoscalingMode = "vpa"
// AutoscalingModeStatic is a constant for static resource allocation as autoscaling mode.
AutoscalingModeStatic AutoscalingMode = "static"
)

// AutoScaling defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
// AutoScaling defines how the calico components are automatically scaled. It allows to use static configuration, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
type AutoScaling struct {
// Mode defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
// Mode defines how the calico components are automatically scaled. It allows to use static configuration, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
Mode AutoscalingMode
// Resources optionally defines the amount of resources to statically allocate for the calico components.
Resources *StaticResources
}

// StaticResources optionally defines the amount of resources to statically allocate for the calico components.
type StaticResources struct {
// Node optionally defines the amount of resources to statically allocate for the calico node component.
Node *corev1.ResourceList
// Node optionally defines the amount of resources to statically allocate for the calico typha component.
Typha *corev1.ResourceList
}
19 changes: 16 additions & 3 deletions pkg/apis/calico/v1alpha1/types_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -103,7 +104,7 @@ type NetworkConfig struct {
// SnatToUpstreamDNS enables the masquerading of packets to the upstream dns server (default: enabled)
// +optional
SnatToUpstreamDNS *SnatToUpstreamDNS `json:"snatToUpstreamDNS,omitempty"`
// AutoScaling defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
// AutoScaling defines how the calico components are automatically scaled. It allows to use static configuration, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
// +optional
AutoScaling *AutoScaling `json:"autoScaling,omitempty"`

Expand Down Expand Up @@ -176,10 +177,22 @@ const (
AutoscalingModeClusterProportional AutoscalingMode = "cluster-proportional"
// AutoscalingModeVPA is a constant for vertical pod autoscaling mode.
AutoscalingModeVPA AutoscalingMode = "vpa"
// AutoscalingModeStatic is a constant for static resource allocation as autoscaling mode.
AutoscalingModeStatic AutoscalingMode = "static"
)

// AutoScaling defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
// AutoScaling defines how the calico components are automatically scaled. It allows to use static configuration, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
type AutoScaling struct {
// Mode defines how the calico components are automatically scaled. It allows to use either vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
// Mode defines how the calico components are automatically scaled. It allows to use static configuration, vertical pod or cluster-proportional autoscaler (default: cluster-proportional).
Mode AutoscalingMode `json:"mode"`
// Resources optionally defines the amount of resources to statically allocate for the calico components.
Resources *StaticResources `json:"resources,omitempty"`
}

// StaticResources optionally defines the amount of resources to statically allocate for the calico components.
type StaticResources struct {
// Node optionally defines the amount of resources to statically allocate for the calico node component.
Node *corev1.ResourceList `json:"node,omitempty"`
// Node optionally defines the amount of resources to statically allocate for the calico typha component.
Typha *corev1.ResourceList `json:"typha,omitempty"`
}
Loading

0 comments on commit c621d19

Please sign in to comment.