Skip to content

Commit 1502af5

Browse files
committed
chore: add cni plugins test
Add unit-test to CNI plugins state. Signed-off-by: Fred Rolland <[email protected]>
1 parent 4a98cec commit 1502af5

6 files changed

+451
-3
lines changed

pkg/state/common_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
2024 NVIDIA CORPORATION & AFFILIATES
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package state_test
18+
19+
import (
20+
"github.com/Mellanox/network-operator/pkg/clustertype"
21+
"github.com/Mellanox/network-operator/pkg/nodeinfo"
22+
"github.com/Mellanox/network-operator/pkg/state"
23+
"github.com/Mellanox/network-operator/pkg/staticconfig"
24+
)
25+
26+
type testProvider struct {
27+
isOpenshift bool
28+
cniBinDir string
29+
}
30+
31+
func (tp *testProvider) GetClusterType() clustertype.Type {
32+
if tp.isOpenshift {
33+
return clustertype.Openshift
34+
}
35+
return clustertype.Kubernetes
36+
}
37+
38+
func (tp *testProvider) IsKubernetes() bool {
39+
return !tp.isOpenshift
40+
}
41+
42+
func (tp *testProvider) IsOpenshift() bool {
43+
return tp.isOpenshift
44+
}
45+
46+
func (tp *testProvider) GetStaticConfig() staticconfig.StaticConfig {
47+
return staticconfig.StaticConfig{CniBinDirectory: tp.cniBinDir}
48+
}
49+
50+
func (tp *testProvider) GetNodesAttributes(...nodeinfo.Filter) []nodeinfo.NodeAttributes {
51+
nodeAttr := make(map[nodeinfo.AttributeType]string)
52+
nodeAttr[nodeinfo.AttrTypeCPUArch] = "amd64"
53+
nodeAttr[nodeinfo.AttrTypeOSName] = "ubuntu"
54+
nodeAttr[nodeinfo.AttrTypeOSVer] = "20.04"
55+
56+
return []nodeinfo.NodeAttributes{{Attributes: nodeAttr}}
57+
}
58+
59+
func getTestCatalog() state.InfoCatalog {
60+
catalog := state.NewInfoCatalog()
61+
tp := &testProvider{isOpenshift: false, cniBinDir: ""}
62+
catalog.Add(state.InfoTypeNodeInfo, tp)
63+
catalog.Add(state.InfoTypeStaticConfig, tp)
64+
catalog.Add(state.InfoTypeClusterType, tp)
65+
66+
return catalog
67+
}

pkg/state/state_cni_plugins.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,17 @@ func (s *stateCNIPlugins) GetManifestObjects(
146146
if staticConfig == nil {
147147
return nil, errors.New("staticConfig provider required")
148148
}
149+
clusterInfo := catalog.GetClusterTypeProvider()
150+
if clusterInfo == nil {
151+
return nil, errors.New("clusterInfo provider required")
152+
}
149153
renderData := &CNIPluginsManifestRenderData{
150154
CrSpec: cr.Spec.SecondaryNetwork.CniPlugins,
151155
Tolerations: cr.Spec.Tolerations,
152156
NodeAffinity: cr.Spec.NodeAffinity,
153157
RuntimeSpec: &cniRuntimeSpec{
154158
runtimeSpec: runtimeSpec{config.FromEnv().State.NetworkOperatorResourceNamespace},
155-
CniBinDirectory: utils.GetCniBinDirectory(staticConfig, nil),
159+
CniBinDirectory: utils.GetCniBinDirectory(staticConfig, clusterInfo),
156160
ContainerResources: createContainerResourcesMap(cr.Spec.SecondaryNetwork.CniPlugins.ContainerResources),
157161
},
158162
}

0 commit comments

Comments
 (0)