Skip to content

Commit

Permalink
[cilium] Add support for choosing resources
Browse files Browse the repository at this point in the history
Cilium as a CNI is a critical component for cluster so it would be safe
to have some guaranteed resources as well as allowing the users to
define them based on their needs.

In this commit, we init default requested resources and add the
capability of user defined values.

Signed-off-by: dntosas <ntosas@gmail.com>
  • Loading branch information
dntosas committed Apr 17, 2021
1 parent 9786905 commit 34a8109
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 4 deletions.
12 changes: 12 additions & 0 deletions docs/networking/cilium.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ Once the secret has been created, encryption can be enabled by setting `enableEn
enableEncryption: true
```

#### Resources in Cilium
{{ kops_feature_table(kops_added_default='1.21', k8s_min='1.20') }}

As of kOps 1.20, it is possible to choose your own values for Cilium Agents + Operator. Example:
```yaml
networking:
cilium:
cpuRequest: "25m"
memoryRequest: "128Mi"
cpuLimit: "100m"
memoryLimit: "300Mi"
```

## Getting help

Expand Down
32 changes: 32 additions & 0 deletions k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,22 @@ spec:
fetches information from the container runtime and this
field is ignored. Default: none'
type: string
cpuLimit:
anyOf:
- type: integer
- type: string
description: 'CPULimit CPU limit of Cilium agent + operator
container. (default: -)'
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
cpuRequest:
anyOf:
- type: integer
- type: string
description: 'CPURequest CPU request of Cilium agent + operator
container. (default: 25m)'
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
debug:
description: Debug runs Cilium in debug mode.
type: boolean
Expand Down Expand Up @@ -3588,6 +3604,22 @@ spec:
be removed in the future. Setting this has no effect.
format: int32
type: integer
memoryLimit:
anyOf:
- type: integer
- type: string
description: 'MemoryLimit memory limit of Cilium agent + operator
container. (default: -)'
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
memoryRequest:
anyOf:
- type: integer
- type: string
description: 'MemoryRequest memory request of Cilium agent
+ operator container. (default: 128Mi)'
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
monitorAggregation:
description: 'MonitorAggregation sets the level of packet
monitoring. Possible values are "low", "medium", or "maximum".
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/kops/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ type CiliumNetworkingSpec struct {
// Version is the version of the Cilium agent and the Cilium Operator.
Version string `json:"version,omitempty"`

// MemoryRequest memory request of Cilium agent + operator container. (default: 128Mi)
MemoryRequest *resource.Quantity `json:"memoryRequest,omitempty"`
// CPURequest CPU request of Cilium agent + operator container. (default: 25m)
CPURequest *resource.Quantity `json:"cpuRequest,omitempty"`
// MemoryLimit memory limit of Cilium agent + operator container. (default: -)
MemoryLimit *resource.Quantity `json:"memoryLimit,omitempty"`
// CPULimit CPU limit of Cilium agent + operator container. (default: -)
CPULimit *resource.Quantity `json:"cpuLimit,omitempty"`

// AccessLog is not implemented and may be removed in the future.
// Setting this has no effect.
AccessLog string `json:"accessLog,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/kops/v1alpha2/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ type CiliumNetworkingSpec struct {
// Version is the version of the Cilium agent and the Cilium Operator.
Version string `json:"version,omitempty"`

// MemoryRequest memory request of Cilium agent + operator container. (default: 128Mi)
MemoryRequest *resource.Quantity `json:"memoryRequest,omitempty"`
// CPURequest CPU request of Cilium agent + operator container. (default: 25m)
CPURequest *resource.Quantity `json:"cpuRequest,omitempty"`
// MemoryLimit memory limit of Cilium agent + operator container. (default: -)
MemoryLimit *resource.Quantity `json:"memoryLimit,omitempty"`
// CPULimit CPU limit of Cilium agent + operator container. (default: -)
CPULimit *resource.Quantity `json:"cpuLimit,omitempty"`

// AccessLog is not implemented and may be removed in the future.
// Setting this has no effect.
AccessLog string `json:"accessLog,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.conversion.go

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

20 changes: 20 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.deepcopy.go

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

8 changes: 8 additions & 0 deletions pkg/apis/kops/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,14 @@ func validateNetworkingCilium(cluster *kops.Cluster, v *kops.CiliumNetworkingSpe
}
}

if v.CPULimit != nil && (v.CPURequest < v.CPULimit) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("cpuLimit"), v.CPULimit, "Cilium CPU limits can't be lower than the requested ones"))
}

if v.MemoryLimit != nil && (v.MemoryRequest < v.MemoryLimit) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("memoryLimit"), v.MemoryLimit, "Cilium Memory limits can't be lower than the requested ones"))
}

return allErrs
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/kops/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 @@ -522,7 +522,17 @@ spec:
protocol: TCP
{{- end }}
{{ end }}

resources:
requests:
cpu: {{ or .CPURequest "25m" }}
memory: {{ or .MemoryRequest "128Mi" }}
limits:
{{- if .CPULimit }}
cpu: {{ .CPULimit }}
{{- end }}
{{- if .MemoryLimit }}
memory: {{ .MemoryLimit }}
{{- end }}
readinessProbe:
httpGet:
host: '127.0.0.1'
Expand Down Expand Up @@ -772,6 +782,17 @@ spec:
name: prometheus
protocol: TCP
{{ end }}
resources:
requests:
cpu: {{ or .CPURequest "25m" }}
memory: {{ or .MemoryRequest "128Mi" }}
limits:
{{- if .CPULimit }}
cpu: {{ .CPULimit }}
{{- end }}
{{- if .MemoryLimit }}
memory: {{ .MemoryLimit }}
{{- end }}
livenessProbe:
httpGet:
host: "127.0.0.1"
Expand Down Expand Up @@ -915,4 +936,4 @@ spec:
path: /var/run/cilium
type: Directory
name: hubble-sock-dir
{{ end }}
{{ end }}
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,17 @@ spec:
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 5
resources:
requests:
cpu: {{ or .CPURequest "25m" }}
memory: {{ or .MemoryRequest "128Mi" }}
limits:
{{- if .CPULimit }}
cpu: {{ .CPULimit }}
{{- end }}
{{- if .MemoryLimit }}
memory: {{ .MemoryLimit }}
{{- end }}
readinessProbe:
httpGet:
host: '127.0.0.1'
Expand Down Expand Up @@ -823,6 +834,17 @@ spec:
name: prometheus
protocol: TCP
{{ end }}
resources:
requests:
cpu: {{ or .CPURequest "25m" }}
memory: {{ or .MemoryRequest "128Mi" }}
limits:
{{- if .CPULimit }}
cpu: {{ .CPULimit }}
{{- end }}
{{- if .MemoryLimit }}
memory: {{ .MemoryLimit }}
{{- end }}
livenessProbe:
httpGet:
host: '127.0.0.1'
Expand Down Expand Up @@ -891,7 +913,7 @@ spec:
strategy:
rollingUpdate:
maxUnavailable: 1
type: RollingUpdate
type: RollingUpdate
template:
metadata:
labels:
Expand Down Expand Up @@ -951,4 +973,4 @@ spec:
path: config.yaml
name: config
{{ end }}
{{ end }}
{{ end }}
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,17 @@ spec:
name: prometheus
protocol: TCP
{{ end }}
resources:
requests:
cpu: {{ or .CPURequest "25m" }}
memory: {{ or .MemoryRequest "128Mi" }}
limits:
{{- if .CPULimit }}
cpu: {{ .CPULimit }}
{{- end }}
{{- if .MemoryLimit }}
memory: {{ .MemoryLimit }}
{{- end }}
readinessProbe:
exec:
command:
Expand Down Expand Up @@ -750,6 +761,17 @@ spec:
name: prometheus
protocol: TCP
{{ end }}
resources:
requests:
cpu: {{ or .CPURequest "25m" }}
memory: {{ or .MemoryRequest "128Mi" }}
limits:
{{- if .CPULimit }}
cpu: {{ .CPULimit }}
{{- end }}
{{- if .MemoryLimit }}
memory: {{ .MemoryLimit }}
{{- end }}
livenessProbe:
httpGet:
host: "127.0.0.1"
Expand Down

0 comments on commit 34a8109

Please sign in to comment.