Skip to content

Commit 71b138b

Browse files
committed
Add network attachments specific EnvTests
This change is an addition to the main change that adds more envTests to test-operator. It is specifically adding the testing needed for Tempest and Tobiko when network attachments are specified.
1 parent 10c5214 commit 71b138b

5 files changed

Lines changed: 66 additions & 1 deletion

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ require (
5858
github.com/modern-go/reflect2 v1.0.2 // indirect
5959
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6060
github.com/openshift/api v3.9.0+incompatible // indirect
61+
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.0
6162
github.com/pkg/errors v0.9.1 // indirect
6263
github.com/prometheus/client_golang v1.20.4 // indirect
6364
github.com/prometheus/client_model v0.6.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.2026020508
119119
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260205083029-d03e9df035ef/go.mod h1:ndqfy1KbVorHH6+zlUFPIrCRhMSxO3ImYJUGaooE0x0=
120120
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20260205083029-d03e9df035ef h1:2wJUSZ2ybE6JVjEyuk/HEaJ1in64jf/lrPOs8NrRHFo=
121121
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20260205083029-d03e9df035ef/go.mod h1:jofj+VqDszxLCZSBYo794KGkCjMo01xzhQ/gffYzf3I=
122+
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.0 h1:heoPZJrNVCbcrc2J60ysp4W7Wp3EcnuRnX16xOXg13Q=
123+
github.com/openstack-k8s-operators/lib-common/modules/test v0.6.0/go.mod h1:oKvVb28i6wwBR5uQO2B2KMzZnCFTPCUCj31c5Zvz2lo=
122124
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
123125
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
124126
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

test/functional/suite_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import (
2727

2828
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
2929

30+
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
3031
common_test "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
32+
"github.com/openstack-k8s-operators/lib-common/modules/test"
3133
testv1 "github.com/openstack-k8s-operators/test-operator/api/v1beta1"
3234
controller "github.com/openstack-k8s-operators/test-operator/internal/controller"
3335
webhookv1beta1 "github.com/openstack-k8s-operators/test-operator/internal/webhook/v1beta1"
@@ -68,11 +70,20 @@ var _ = BeforeSuite(func() {
6870

6971
ctx, cancel = context.WithCancel(context.TODO())
7072

73+
networkv1CRD, err := test.GetCRDDirFromModule(
74+
"github.com/k8snetworkplumbingwg/network-attachment-definition-client", "../../go.mod", "artifacts/networks-crd.yaml")
75+
Expect(err).ShouldNot(HaveOccurred())
76+
7177
By("bootstrapping test environment")
7278
testEnv = &envtest.Environment{
7379
CRDDirectoryPaths: []string{
7480
filepath.Join("..", "..", "config", "crd", "bases"),
7581
},
82+
CRDInstallOptions: envtest.CRDInstallOptions{
83+
Paths: []string{
84+
networkv1CRD,
85+
},
86+
},
7687
ErrorIfCRDPathMissing: true,
7788
WebhookInstallOptions: envtest.WebhookInstallOptions{
7889
Paths: []string{filepath.Join("..", "..", "config", "webhook")},
@@ -86,14 +97,16 @@ var _ = BeforeSuite(func() {
8697
logger = ctrl.Log.WithName("---Test---")
8798

8899
// cfg is defined in this file globally.
89-
var err error
90100
cfg, err = testEnv.Start()
91101
Expect(err).NotTo(HaveOccurred())
92102
Expect(cfg).NotTo(BeNil())
93103

94104
err = testv1.AddToScheme(scheme.Scheme)
95105
Expect(err).NotTo(HaveOccurred())
96106

107+
err = networkv1.AddToScheme(scheme.Scheme)
108+
Expect(err).NotTo(HaveOccurred())
109+
97110
//+kubebuilder:scaffold:scheme
98111

99112
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})

test/functional/tempest_controller_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,27 @@ var _ = Describe("Tempest controller", func() {
169169
)
170170
})
171171
})
172+
173+
When("Tempest is created with network attachments", func() {
174+
BeforeEach(func() {
175+
openstackConfigMap, openstackSecret := CreateCommonOpenstackResources(namespace)
176+
Expect(k8sClient.Create(ctx, openstackConfigMap)).Should(Succeed())
177+
Expect(k8sClient.Create(ctx, openstackSecret)).Should(Succeed())
178+
179+
nad := th.CreateNetworkAttachmentDefinition(types.NamespacedName{
180+
Namespace: namespace,
181+
Name: "ctlplane",
182+
})
183+
DeferCleanup(th.DeleteInstance, nad)
184+
185+
spec := GetDefaultTempestSpec()
186+
spec["networkAttachments"] = []string{"ctlplane"}
187+
DeferCleanup(th.DeleteInstance, CreateTempest(tempestName, spec))
188+
})
189+
190+
It("should add network annotation to pod", func() {
191+
pod := GetTestOperatorPod(namespace, tempestName.Name)
192+
Expect(pod.Annotations).To(HaveKey("k8s.v1.cni.cncf.io/networks"))
193+
})
194+
})
172195
})

test/functional/tobiko_controller_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,30 @@ var _ = Describe("Tobiko controller", func() {
138138
)
139139
})
140140
})
141+
142+
When("Tobiko is created with network attachments", func() {
143+
BeforeEach(func() {
144+
openstackConfigMap, openstackSecret := CreateCommonOpenstackResources(namespace)
145+
Expect(k8sClient.Create(ctx, openstackConfigMap)).Should(Succeed())
146+
Expect(k8sClient.Create(ctx, openstackSecret)).Should(Succeed())
147+
148+
testOperatorConfigMap := CreateTestOperatorConfigMap(namespace)
149+
Expect(k8sClient.Create(ctx, testOperatorConfigMap)).Should(Succeed())
150+
151+
nad := th.CreateNetworkAttachmentDefinition(types.NamespacedName{
152+
Namespace: namespace,
153+
Name: "ctlplane",
154+
})
155+
DeferCleanup(th.DeleteInstance, nad)
156+
157+
spec := GetDefaultTobikoSpec()
158+
spec["networkAttachments"] = []string{"ctlplane"}
159+
DeferCleanup(th.DeleteInstance, CreateTobiko(tobikoName, spec))
160+
})
161+
162+
It("should add network annotation to pod", func() {
163+
pod := GetTestOperatorPod(namespace, tobikoName.Name)
164+
Expect(pod.Annotations).To(HaveKey("k8s.v1.cni.cncf.io/networks"))
165+
})
166+
})
141167
})

0 commit comments

Comments
 (0)