Skip to content

Commit

Permalink
fix CNI plugin configuration issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamas-Biro1 committed Jan 9, 2024
1 parent 5a59102 commit 1d839d4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 44 deletions.
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

0 comments on commit 1d839d4

Please sign in to comment.