@@ -23,6 +23,7 @@ import (
2323const (
2424 dnodeGrpName = "dnode"
2525 enodeGrpName = "enode"
26+ mlClusterNs = "ednode"
2627)
2728
2829var (
5859 },
5960 ObjectMeta : metav1.ObjectMeta {
6061 Name : "mlclusterednode" ,
61- Namespace : mlNamespace ,
62+ Namespace : mlClusterNs ,
6263 },
6364 Spec : databasev1alpha1.MarklogicClusterSpec {
6465 Image : marklogicImage ,
@@ -77,9 +78,17 @@ func TestMlClusterWithEdnode(t *testing.T) {
7778 // Setup for MarklogicCluster creation
7879 feature .Setup (func (ctx context.Context , t * testing.T , c * envconf.Config ) context.Context {
7980 client := c .Client ()
80- databasev1alpha1 .AddToScheme (client .Resources (mlNamespace ).GetScheme ())
81+ namespace := & corev1.Namespace {
82+ ObjectMeta : metav1.ObjectMeta {
83+ Name : mlClusterNs ,
84+ },
85+ }
86+ if err := client .Resources ().Create (ctx , namespace ); err != nil {
87+ t .Fatalf ("Failed to create namespace: %s" , err )
88+ }
89+ databasev1alpha1 .AddToScheme (client .Resources (mlClusterNs ).GetScheme ())
8190
82- if err := client .Resources (mlNamespace ).Create (ctx , mlcluster ); err != nil {
91+ if err := client .Resources (mlClusterNs ).Create (ctx , mlcluster ); err != nil {
8392 t .Fatalf ("Failed to create MarklogicCluster: %s" , err )
8493 }
8594 // wait for resource to be created
@@ -99,7 +108,7 @@ func TestMlClusterWithEdnode(t *testing.T) {
99108 feature .Assess ("MarklogicCluster with 2 MarkLogicGroups deployed Ok" , func (ctx context.Context , t * testing.T , c * envconf.Config ) context.Context {
100109 client := c .Client ()
101110 var mlcluster databasev1alpha1.MarklogicCluster
102- if err := client .Resources ().Get (ctx , "mlclusterednode" , mlNamespace , & mlcluster ); err != nil {
111+ if err := client .Resources ().Get (ctx , "mlclusterednode" , mlClusterNs , & mlcluster ); err != nil {
103112 t .Log ("====MarklogicCluster not found====" )
104113 t .Fatal (err )
105114 }
@@ -110,12 +119,12 @@ func TestMlClusterWithEdnode(t *testing.T) {
110119 client := c .Client ()
111120
112121 podName := "dnode-0"
113- err := utils .WaitForPod (ctx , t , client , mlNamespace , podName , 90 * time .Second )
122+ err := utils .WaitForPod (ctx , t , client , mlClusterNs , podName , 90 * time .Second )
114123 if err != nil {
115124 t .Fatalf ("Failed to wait for pod creation: %v" , err )
116125 }
117126 epodName := "enode-0"
118- err = utils .WaitForPod (ctx , t , client , mlNamespace , epodName , 150 * time .Second )
127+ err = utils .WaitForPod (ctx , t , client , mlClusterNs , epodName , 150 * time .Second )
119128 if err != nil {
120129 t .Fatalf ("Failed to wait for pod creation: %v" , err )
121130 }
@@ -129,7 +138,7 @@ func TestMlClusterWithEdnode(t *testing.T) {
129138 url := "http://localhost:8002/manage/v2/groups"
130139 curlCommand := fmt .Sprintf ("curl %s -u %s:%s" , url , adminUsername , adminPassword )
131140
132- output , err := utils .ExecCurlInPod (podName , mlNamespace , containerName , curlCommand )
141+ output , err := utils .ExecCmdInPod (podName , mlClusterNs , containerName , curlCommand )
133142 if err != nil {
134143 t .Fatalf ("Failed to execute curl command in pod: %v" , err )
135144 }
@@ -143,7 +152,7 @@ func TestMlClusterWithEdnode(t *testing.T) {
143152 feature .Setup (func (ctx context.Context , t * testing.T , c * envconf.Config ) context.Context {
144153 client := c .Client ()
145154 var mlcluster databasev1alpha1.MarklogicCluster
146- if err := client .Resources ().Get (ctx , "mlclusterednode" , mlNamespace , & mlcluster ); err != nil {
155+ if err := client .Resources ().Get (ctx , "mlclusterednode" , mlClusterNs , & mlcluster ); err != nil {
147156 t .Fatal (err )
148157 }
149158 // Scale the MarkLogic groups to 2
@@ -158,12 +167,12 @@ func TestMlClusterWithEdnode(t *testing.T) {
158167 feature .Assess ("New Pods created" , func (ctx context.Context , t * testing.T , c * envconf.Config ) context.Context {
159168 client := c .Client ()
160169 podNameOne := "dnode-1"
161- err := utils .WaitForPod (ctx , t , client , mlNamespace , podNameOne , 60 * time .Second )
170+ err := utils .WaitForPod (ctx , t , client , mlClusterNs , podNameOne , 60 * time .Second )
162171 if err != nil {
163172 t .Fatalf ("Failed to wait for pod %s creation: %v" , podNameOne , err )
164173 }
165174 epodNameTwo := "enode-1"
166- err = utils .WaitForPod (ctx , t , client , mlNamespace , epodNameTwo , 120 * time .Second )
175+ err = utils .WaitForPod (ctx , t , client , mlClusterNs , epodNameTwo , 120 * time .Second )
167176 if err != nil {
168177 t .Fatalf ("Failed to wait for pod %s creation: %v" , epodNameTwo , err )
169178 }
@@ -175,6 +184,7 @@ func TestMlClusterWithEdnode(t *testing.T) {
175184 podList := & corev1.PodList {}
176185 if err := client .Resources ().List (ctx , podList , func (lo * metav1.ListOptions ) {
177186 lo .LabelSelector = "app.kubernetes.io/name=marklogic"
187+ lo .FieldSelector = "metadata.namespace=" + mlClusterNs
178188 }); err != nil {
179189 t .Fatal (err )
180190 }
@@ -189,6 +199,13 @@ func TestMlClusterWithEdnode(t *testing.T) {
189199
190200 // Using feature.Teardown to clean up
191201 feature .Teardown (func (ctx context.Context , t * testing.T , c * envconf.Config ) context.Context {
202+ client := c .Client ()
203+ if err := client .Resources (mlClusterNs ).Delete (ctx , mlcluster ); err != nil {
204+ t .Fatalf ("Failed to delete MarklogicCluster: %s" , err )
205+ }
206+ if err := client .Resources ().Delete (ctx , & corev1.Namespace {ObjectMeta : metav1.ObjectMeta {Name : mlClusterNs }}); err != nil {
207+ t .Fatalf ("Failed to delete namespace: %s" , err )
208+ }
192209 return ctx
193210 })
194211
0 commit comments