Skip to content

Commit d1321fa

Browse files
Merge pull request #2825 from bradbehle/keep-custom-resource-requests
CORENET-6488: Preserve custom resource requests on ovn-control-plane pods
2 parents 05d6f46 + d1f2484 commit d1321fa

File tree

3 files changed

+89
-19
lines changed

3 files changed

+89
-19
lines changed

bindata/network/ovn-kubernetes/managed/ovnkube-control-plane.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ spec:
119119
- --kubeconfig=/etc/kubernetes/kubeconfig
120120
resources:
121121
requests:
122-
cpu: 10m
123-
memory: 30Mi
122+
cpu: {{ .TokenMinterResourceRequestCPU | default "10" }}m
123+
memory: {{ .TokenMinterResourceRequestMemory | default "30" }}Mi
124124
volumeMounts:
125125
- mountPath: /etc/kubernetes
126126
name: admin-kubeconfig
@@ -260,8 +260,8 @@ spec:
260260
readOnly: True
261261
resources:
262262
requests:
263-
cpu: 10m
264-
memory: 200Mi
263+
cpu: {{ .OVNControlPlaneResourceRequestCPU | default "10" }}m
264+
memory: {{ .OVNControlPlaneResourceRequestMemory | default "200" }}Mi
265265
env:
266266
- name: OVN_KUBE_LOG_LEVEL
267267
value: "4"
@@ -301,8 +301,8 @@ spec:
301301
readOnly: true
302302
resources:
303303
requests:
304-
cpu: 10m
305-
memory: 10Mi
304+
cpu: {{ .Socks5ProxyResourceRequestCPU | default "10" }}m
305+
memory: {{ .Socks5ProxyResourceRequestMemory | default "10" }}Mi
306306
env:
307307
- name: KUBECONFIG
308308
value: "/etc/kubernetes/kubeconfig"

pkg/bootstrap/types.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@ import (
88
)
99

1010
type OVNHyperShiftBootstrapResult struct {
11-
Enabled bool
12-
ClusterID string
13-
Namespace string
14-
RunAsUser string
15-
HCPNodeSelector map[string]string
16-
HCPLabels map[string]string
17-
HCPTolerations []string
18-
ControlPlaneReplicas int
19-
ReleaseImage string
20-
ControlPlaneImage string
21-
CAConfigMap string
22-
CAConfigMapKey string
23-
PriorityClass string
11+
Enabled bool
12+
ClusterID string
13+
Namespace string
14+
RunAsUser string
15+
HCPNodeSelector map[string]string
16+
HCPLabels map[string]string
17+
HCPTolerations []string
18+
ControlPlaneReplicas int
19+
ReleaseImage string
20+
ControlPlaneImage string
21+
CAConfigMap string
22+
CAConfigMapKey string
23+
PriorityClass string
24+
TokenMinterResourceRequestCPU string
25+
TokenMinterResourceRequestMemory string
26+
OVNControlPlaneResourceRequestCPU string
27+
OVNControlPlaneResourceRequestMemory string
28+
Socks5ProxyResourceRequestCPU string
29+
Socks5ProxyResourceRequestMemory string
2430
}
2531

2632
type OVNConfigBoostrapResult struct {

pkg/network/ovn_kubernetes.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ func renderOVNKubernetes(conf *operv1.NetworkSpec, bootstrapResult *bootstrap.Bo
244244
data.Data["CAConfigMapKey"] = bootstrapResult.OVN.OVNKubernetesConfig.HyperShiftConfig.CAConfigMapKey
245245
data.Data["RunAsUser"] = bootstrapResult.OVN.OVNKubernetesConfig.HyperShiftConfig.RunAsUser
246246
data.Data["PriorityClass"] = bootstrapResult.OVN.OVNKubernetesConfig.HyperShiftConfig.PriorityClass
247+
data.Data["TokenMinterResourceRequestCPU"] = bootstrapResult.OVN.OVNKubernetesConfig.HyperShiftConfig.TokenMinterResourceRequestCPU
248+
data.Data["TokenMinterResourceRequestMemory"] = bootstrapResult.OVN.OVNKubernetesConfig.HyperShiftConfig.TokenMinterResourceRequestMemory
249+
data.Data["OVNControlPlaneResourceRequestCPU"] = bootstrapResult.OVN.OVNKubernetesConfig.HyperShiftConfig.OVNControlPlaneResourceRequestCPU
250+
data.Data["OVNControlPlaneResourceRequestMemory"] = bootstrapResult.OVN.OVNKubernetesConfig.HyperShiftConfig.OVNControlPlaneResourceRequestMemory
251+
data.Data["Socks5ProxyResourceRequestCPU"] = bootstrapResult.OVN.OVNKubernetesConfig.HyperShiftConfig.Socks5ProxyResourceRequestCPU
252+
data.Data["Socks5ProxyResourceRequestMemory"] = bootstrapResult.OVN.OVNKubernetesConfig.HyperShiftConfig.Socks5ProxyResourceRequestMemory
247253
data.Data["OVN_NB_INACTIVITY_PROBE"] = nb_inactivity_probe
248254
data.Data["OVN_CERT_CN"] = OVN_CERT_CN
249255
data.Data["OVN_NORTHD_PROBE_INTERVAL"] = os.Getenv("OVN_NORTHD_PROBE_INTERVAL")
@@ -749,9 +755,67 @@ func bootstrapOVNHyperShiftConfig(hc *hypershift.HyperShiftConfig, kubeClient cn
749755
default:
750756
ovnHypershiftResult.ControlPlaneReplicas = 1
751757
}
758+
759+
// Preserve any customizations to the resource requests on the three containers in the ovn-control-plane pod
760+
controlPlaneClient := kubeClient.ClientFor(names.ManagementClusterName)
761+
tokenMinterCPURequest, tokenMinterMemoryRequest := getResourceRequestsForDeployment(controlPlaneClient.CRClient(), hc.Namespace, util.OVN_CONTROL_PLANE, "token-minter")
762+
if tokenMinterCPURequest > 0 {
763+
ovnHypershiftResult.TokenMinterResourceRequestCPU = strconv.FormatInt(tokenMinterCPURequest, 10)
764+
}
765+
if tokenMinterMemoryRequest > 0 {
766+
ovnHypershiftResult.TokenMinterResourceRequestMemory = strconv.FormatInt(tokenMinterMemoryRequest, 10)
767+
}
768+
769+
ovnControlPlaneCPURequest, ovnControlPlaneMemoryRequest := getResourceRequestsForDeployment(controlPlaneClient.CRClient(), hc.Namespace, util.OVN_CONTROL_PLANE, "ovnkube-control-plane")
770+
if ovnControlPlaneCPURequest > 0 {
771+
ovnHypershiftResult.OVNControlPlaneResourceRequestCPU = strconv.FormatInt(ovnControlPlaneCPURequest, 10)
772+
}
773+
if ovnControlPlaneMemoryRequest > 0 {
774+
ovnHypershiftResult.OVNControlPlaneResourceRequestMemory = strconv.FormatInt(ovnControlPlaneMemoryRequest, 10)
775+
}
776+
777+
socksProxyCPURequest, socksProxyMemoryRequest := getResourceRequestsForDeployment(controlPlaneClient.CRClient(), hc.Namespace, util.OVN_CONTROL_PLANE, "socks-proxy")
778+
if socksProxyCPURequest > 0 {
779+
ovnHypershiftResult.Socks5ProxyResourceRequestCPU = strconv.FormatInt(socksProxyCPURequest, 10)
780+
}
781+
if socksProxyMemoryRequest > 0 {
782+
ovnHypershiftResult.Socks5ProxyResourceRequestMemory = strconv.FormatInt(socksProxyMemoryRequest, 10)
783+
}
784+
752785
return ovnHypershiftResult, nil
753786
}
754787

788+
// getResourceRequestsForDeployment gets the cpu and memory resource requests for the specified deployment
789+
// If the deployment or container is not found, or if the container doesn't have a cpu or memory resource request, then 0 is returned
790+
func getResourceRequestsForDeployment(cl crclient.Reader, namespace string, deploymentName string, containerName string) (cpu int64, memory int64) {
791+
deployment := &appsv1.Deployment{}
792+
if err := cl.Get(context.TODO(), types.NamespacedName{
793+
Namespace: namespace,
794+
Name: deploymentName,
795+
}, deployment); err != nil {
796+
if !apierrors.IsNotFound(err) {
797+
klog.Warningf("Error fetching %s deployment: %v", deploymentName, err)
798+
}
799+
return cpu, memory
800+
}
801+
802+
for _, container := range deployment.Spec.Template.Spec.Containers {
803+
if container.Name == containerName {
804+
if container.Resources.Requests != nil {
805+
if !container.Resources.Requests.Cpu().IsZero() {
806+
cpu = container.Resources.Requests.Cpu().MilliValue()
807+
}
808+
if !container.Resources.Requests.Memory().IsZero() {
809+
memory = container.Resources.Requests.Memory().Value() / bytesInMiB
810+
}
811+
}
812+
break
813+
}
814+
}
815+
816+
return cpu, memory
817+
}
818+
755819
func getDisableUDPAggregation(cl crclient.Reader) bool {
756820
disable := false
757821

0 commit comments

Comments
 (0)