Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CNI plugin configuration issue #3087

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/controller/migration/convert/network.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 Tigera, Inc. All rights reserved.
// Copyright (c) 2023, 2024 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -201,8 +201,8 @@ func handleCalicoCNI(c *components, install *operatorv1.Installation) error {
}

type TuningSpec struct {
Sysctl []operatorv1.Sysctl `json:"sysctl,omitempty"`
Type string `json:"type"`
Sysctl *map[string]string `json:"sysctl,omitempty"`
Type string `json:"type"`
}

// CNI tuning plugin
Expand All @@ -219,10 +219,10 @@ func handleCalicoCNI(c *components, install *operatorv1.Installation) error {
}

sysctlTuning := []operatorv1.Sysctl{}
for _, setting := range tuningSpecData.Sysctl {
for k, v := range *tuningSpecData.Sysctl {
sysctl := operatorv1.Sysctl{
Key: setting.Key,
Value: setting.Value,
Key: k,
Value: v,
}
sysctlTuning = append(sysctlTuning, sysctl)
}
Expand Down
32 changes: 10 additions & 22 deletions pkg/controller/migration/convert/network_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023 Tigera, Inc. All rights reserved.
// Copyright (c) 2023, 2024 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -782,20 +782,11 @@ var _ = Describe("Convert network tests", func() {
},
{
"type": "tuning",
"sysctl": [
{
"key": "net.ipv4.tcp_keepalive_intvl",
"value": "15"
},
{
"key": "net.ipv4.tcp_keepalive_probes",
"value": "6"
},
{
"key": "net.ipv4.tcp_keepalive_time",
"value": "40"
}
]
"sysctl": {
"net.ipv4.tcp_keepalive_intvl": "15",
"net.ipv4.tcp_keepalive_probes": "6",
"net.ipv4.tcp_keepalive_time": "40"
}
}
]
}`,
Expand Down Expand Up @@ -846,13 +837,10 @@ var _ = Describe("Convert network tests", func() {
},
{
"type": "tuning",
"sysctl": [
{
"key": "net.ipv4.not_allowed",
"value": "40"
}
]
}
"sysctl": {
"net.ipv4.not_allowed": "40"
}
}
]
}`,
}}
Expand Down
12 changes: 9 additions & 3 deletions pkg/render/node.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2023 Tigera, Inc. All rights reserved.
// Copyright (c) 2019-2024 Tigera, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -708,12 +708,18 @@ func (c *nodeComponent) createPortmapPlugin() map[string]interface{} {

func (c *nodeComponent) createTuningPlugin() map[string]interface{} {
// tuning plugin (sysctl)
sysctl := map[string]string{}
tuningPlugin := map[string]interface{}{
"type": "tuning",
"sysctl": []operatorv1.Sysctl{},
"sysctl": sysctl,
}
tuningPlugin["sysctl"] = c.cfg.Installation.CalicoNetwork.Sysctl

// convert []operatorv1.Sysctl{} to map[string]string for CNI definition
// details: https://www.cni.dev/plugins/current/meta/tuning/#system-controls-operation
for _, v := range c.cfg.Installation.CalicoNetwork.Sysctl {
sysctl[v.Key] = v.Value
}
tuningPlugin["sysctl"] = sysctl
return tuningPlugin
}

Expand Down
18 changes: 5 additions & 13 deletions pkg/render/node_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2023 Tigera, Inc. All rights reserved.
// Copyright (c) 2019-2024 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2748,20 +2748,12 @@ var _ = Describe("Node rendering tests", func() {
"type": "portmap"
},
{
"sysctl": [
"sysctl":
{
"key": "net.ipv4.tcp_keepalive_intvl",
"value": "15"
"net.ipv4.tcp_keepalive_intvl": "15",
"net.ipv4.tcp_keepalive_probes": "6",
"net.ipv4.tcp_keepalive_time": "40"
},
{
"key": "net.ipv4.tcp_keepalive_probes",
"value": "6"
},
{
"key": "net.ipv4.tcp_keepalive_time",
"value": "40"
}
],
"type": "tuning"
}
]
Expand Down
Loading