Skip to content

Commit 6bd7d3c

Browse files
author
Brendan Shephard
committed
Add functional tests for ICSP integration
This change registers the two OpenShift CRs required to test integration with OpenShifts ImageContentSourcePolicy and the MachineConfig type required to retrieve the registries.conf file. It adds two basic tests to ensure the Ansible variables have been added to the inventory secret when a ImageContentSourcePolicy CR is detected. Signed-off-by: Brendan Shephard <bshephar@redhat.com>
1 parent b9d4c93 commit 6bd7d3c

4 files changed

Lines changed: 96 additions & 6 deletions

File tree

apis/go.mod

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ require (
3535
go.uber.org/zap v1.27.0 // indirect
3636
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
3737
golang.org/x/tools v0.24.0 // indirect
38+
k8s.io/api v0.29.9
3839
k8s.io/apimachinery v0.29.9
3940
k8s.io/client-go v0.29.9
40-
sigs.k8s.io/controller-runtime v0.17.6
41-
)
42-
43-
require (
44-
k8s.io/api v0.29.9
4541
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
42+
sigs.k8s.io/controller-runtime v0.17.6
4643
)
4744

4845
require (

tests/functional/dataplane/base_test.go

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,48 @@ var DefaultEdpmServiceAnsibleVarList = []string{
3030
var CustomEdpmServiceDomainTag = "test-image:latest"
3131
var DefaultBackoffLimit = int32(6)
3232

33+
func CreateICSP(name types.NamespacedName, spec map[string]interface{}) client.Object {
34+
raw := map[string]interface{}{
35+
"apiVersion": "operator.openshift.io/v1alpha1",
36+
"kind": "ImageContentSourcePolicy",
37+
"metadata": map[string]interface{}{
38+
"name": name.Name,
39+
"namespace": name.Namespace,
40+
},
41+
"spec": spec,
42+
}
43+
return th.CreateUnstructured(raw)
44+
}
45+
46+
func CreateMachineConfig() client.Object {
47+
raw := map[string]interface{}{
48+
"apiVersion": "machineconfiguration.openshift.io/v1",
49+
"kind": "MachineConfig",
50+
"metadata": map[string]interface{}{
51+
"name": "99-master-generated-registries",
52+
},
53+
"spec": map[string]interface{}{
54+
"config": map[string]interface{}{
55+
"storage": map[string]interface{}{
56+
"files": []interface{}{
57+
map[string]interface{}{
58+
"contents": map[string]interface{}{
59+
"source": "data:text/plain;charset=utf-8;base64,dW5xdWFsaWZpZWQtc2VhcmNoLXJlZ2lzdHJpZXMgPSBbInJlZ2lzdHJ5LmFjY2Vzcy5yZWRoYXQuY29tIiwgImRvY2tlci5pbyJdCnNob3J0LW5hbWUtbW9kZSA9ICIiCgpbW3JlZ2lzdHJ5XV0KICBwcmVmaXggPSAiIgogIGxvY2F0aW9uID0gInJlZ2lzdHJ5LmNpLm9wZW5zaGlmdC5vcmcvb3JpZ2luLzQuMTMtMjAyMy0wMi0yNi0xNjMwMzAiCgogIFtbcmVnaXN0cnkubWlycm9yXV0KICAgIGxvY2F0aW9uID0gInJlZ2lzdHJ5Lm9rZC5ibmUtc2hpZnQubmV0Ojg0NDMvb2tkIgogICAgcHVsbC1mcm9tLW1pcnJvciA9ICJkaWdlc3Qtb25seSIKCltbcmVnaXN0cnldXQogIHByZWZpeCA9ICIiCiAgbG9jYXRpb24gPSAicmVnaXN0cnkuY2kub3BlbnNoaWZ0Lm9yZy9vcmlnaW4vNC4xMy0yMDIzLTAzLTA3LTA5NDQwNiIKCiAgW1tyZWdpc3RyeS5taXJyb3JdXQogICAgbG9jYXRpb24gPSAicmVnaXN0cnkub2tkLmJuZS1zaGlmdC5uZXQ6ODQ0My9va2QiCiAgICBwdWxsLWZyb20tbWlycm9yID0gImRpZ2VzdC1vbmx5IgoKW1tyZWdpc3RyeV1dCiAgcHJlZml4ID0gIiIKICBsb2NhdGlvbiA9ICJyZWdpc3RyeS5jaS5vcGVuc2hpZnQub3JnL29yaWdpbi9yZWxlYXNlIgoKICBbW3JlZ2lzdHJ5Lm1pcnJvcl1dCiAgICBsb2NhdGlvbiA9ICJyZWdpc3RyeS5va2QuYm5lLXNoaWZ0Lm5ldDo4NDQzL29rZCIKICAgIHB1bGwtZnJvbS1taXJyb3IgPSAiZGlnZXN0LW9ubHkiCg==",
60+
"compression": "",
61+
},
62+
},
63+
},
64+
},
65+
},
66+
"overwrite": true,
67+
"mode": 420,
68+
"path": "/etc/containers/registries.conf",
69+
},
70+
}
71+
72+
return th.CreateUnstructured(raw)
73+
}
74+
3375
// Create OpenstackDataPlaneNodeSet in k8s and test that no errors occur
3476
func CreateDataplaneNodeSet(name types.NamespacedName, spec map[string]interface{}) *unstructured.Unstructured {
3577
instance := DefaultDataplaneNodeSetTemplate(name, spec)
@@ -128,7 +170,6 @@ func CreateOpenStackVersion(name types.NamespacedName) *unstructured.Unstructure
128170
}
129171

130172
// Struct initialization
131-
132173
func DefaultOpenStackVersion(name types.NamespacedName) map[string]interface{} {
133174
return map[string]interface{}{
134175
"apiVersion": "core.openstack.org/v1beta1",
@@ -146,6 +187,19 @@ func DefaultOpenStackVersion(name types.NamespacedName) map[string]interface{} {
146187
}
147188
}
148189

190+
func DefaultICSPSpec() map[string]interface{} {
191+
return map[string]interface{}{
192+
"repositoryDigestMirrors": []interface{}{
193+
map[string]interface{}{
194+
"mirrors": []interface{}{
195+
"registry.okd.bne-shift.net:8443/okd", // Change to a string
196+
},
197+
"source": "registry.ci.openshift.org/origin/release", // Move "source" here
198+
},
199+
},
200+
}
201+
}
202+
149203
// Build OpenStackDataPlaneNodeSetSpec struct and fill it with preset values
150204
func DefaultDataPlaneNodeSetSpec(nodeSetName string) map[string]interface{} {
151205

tests/functional/dataplane/openstackdataplanenodeset_controller_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,4 +1369,29 @@ var _ = Describe("Dataplane NodeSet Test", func() {
13691369
}, th.Timeout, th.Interval).Should(Succeed())
13701370
})
13711371
})
1372+
1373+
When("A ImageContentSourcePolicy exists in the cluster", func() {
1374+
BeforeEach(func() {
1375+
nodeSetSpec := DefaultDataPlaneNodeSetSpec("edpm-compute")
1376+
nodeSetSpec["preProvisioned"] = true
1377+
DeferCleanup(th.DeleteInstance, CreateNetConfig(dataplaneNetConfigName, DefaultNetConfigSpec()))
1378+
DeferCleanup(th.DeleteInstance, CreateDNSMasq(dnsMasqName, DefaultDNSMasqSpec()))
1379+
DeferCleanup(th.DeleteInstance, CreateDataplaneNodeSet(dataplaneNodeSetName, nodeSetSpec))
1380+
DeferCleanup(th.DeleteInstance, CreateDataplaneDeployment(dataplaneDeploymentName, DefaultDataPlaneDeploymentSpec()))
1381+
CreateSSHSecret(dataplaneSSHSecretName)
1382+
CreateICSP(dataplaneNodeSetName, DefaultICSPSpec())
1383+
CreateMachineConfig()
1384+
SimulateDNSMasqComplete(dnsMasqName)
1385+
SimulateIPSetComplete(dataplaneNodeName)
1386+
SimulateDNSDataComplete(dataplaneNodeSetName)
1387+
1388+
})
1389+
It("Should set edpm_podman_disconnected_ocp variable", func() {
1390+
secret := th.GetSecret(dataplaneSecretName)
1391+
Expect(secret.Data["inventory"]).Should(
1392+
ContainSubstring("edpm_podman_disconnected_ocp"))
1393+
Expect(secret.Data["inventory"]).Should(
1394+
ContainSubstring("edpm_podman_registries_conf"))
1395+
})
1396+
})
13721397
})

tests/functional/dataplane/suite_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ import (
4949

5050
certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
5151

52+
machineconfig "github.com/openshift/api/machineconfiguration/v1"
53+
ocp_image "github.com/openshift/api/operator/v1alpha1"
54+
5255
//revive:disable-next-line:dot-imports
5356
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
5457
test "github.com/openstack-k8s-operators/lib-common/modules/test"
@@ -101,6 +104,10 @@ var _ = BeforeSuite(func() {
101104
openstackCRDs, err := test.GetCRDDirFromModule(
102105
"github.com/openstack-k8s-operators/openstack-operator/apis", gomod, "bases")
103106
Expect(err).ShouldNot(HaveOccurred())
107+
imageContentSourcePolicyCRDs, err := test.GetCRDDirFromModule("github.com/openshift/api", gomod, "operator/v1alpha1/zz_generated.crd-manifests/")
108+
Expect(err).ShouldNot(HaveOccurred())
109+
machineConfigCRDs, err := test.GetCRDDirFromModule("github.com/openshift/api", gomod, "machineconfiguration/v1/zz_generated.crd-manifests/0000_80_machine-config_01_machineconfigs.crd.yaml")
110+
Expect(err).ShouldNot(HaveOccurred())
104111

105112
By("bootstrapping test environment")
106113
testEnv = &envtest.Environment{
@@ -110,6 +117,8 @@ var _ = BeforeSuite(func() {
110117
infraCRDs,
111118
certmgrv1CRDs,
112119
openstackCRDs,
120+
imageContentSourcePolicyCRDs,
121+
machineConfigCRDs,
113122
},
114123
WebhookInstallOptions: envtest.WebhookInstallOptions{
115124
Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")},
@@ -145,6 +154,11 @@ var _ = BeforeSuite(func() {
145154
Expect(err).NotTo(HaveOccurred())
146155
err = certmgrv1.AddToScheme(scheme.Scheme)
147156
Expect(err).NotTo(HaveOccurred())
157+
err = machineconfig.AddToScheme(scheme.Scheme)
158+
Expect(err).NotTo(HaveOccurred())
159+
err = ocp_image.AddToScheme(scheme.Scheme)
160+
Expect(err).NotTo(HaveOccurred())
161+
148162
// +kubebuilder:scaffold:scheme
149163

150164
logger = ctrl.Log.WithName("---DataPlane Test---")

0 commit comments

Comments
 (0)