Skip to content

Commit 44349fa

Browse files
committed
CSPL-3551 Adding tests
1 parent 7134350 commit 44349fa

File tree

15 files changed

+302
-26
lines changed

15 files changed

+302
-26
lines changed

go.mod

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/joho/godotenv v1.5.1
1515
github.com/minio/minio-go/v7 v7.0.16
1616
github.com/onsi/ginkgo/v2 v2.23.4
17-
github.com/onsi/gomega v1.37.0
17+
github.com/onsi/gomega v1.38.0
1818
github.com/pkg/errors v0.9.1
1919
github.com/prometheus/client_golang v1.19.1
2020
github.com/stretchr/testify v1.9.0
@@ -109,24 +109,24 @@ require (
109109
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
110110
go.uber.org/automaxprocs v1.6.0 // indirect
111111
go.uber.org/multierr v1.11.0 // indirect
112-
golang.org/x/crypto v0.36.0 // indirect
112+
golang.org/x/crypto v0.39.0 // indirect
113113
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
114-
golang.org/x/net v0.38.0 // indirect
114+
golang.org/x/net v0.41.0 // indirect
115115
golang.org/x/oauth2 v0.21.0 // indirect
116-
golang.org/x/sync v0.12.0 // indirect
117-
golang.org/x/sys v0.32.0 // indirect
118-
golang.org/x/term v0.30.0 // indirect
119-
golang.org/x/text v0.23.0 // indirect
116+
golang.org/x/sync v0.15.0 // indirect
117+
golang.org/x/sys v0.33.0 // indirect
118+
golang.org/x/term v0.32.0 // indirect
119+
golang.org/x/text v0.26.0 // indirect
120120
golang.org/x/time v0.6.0 // indirect
121-
golang.org/x/tools v0.31.0 // indirect
121+
golang.org/x/tools v0.33.0 // indirect
122122
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
123123
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
124124
google.golang.org/appengine v1.6.7 // indirect
125125
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
126126
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
127127
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect
128128
google.golang.org/grpc v1.65.0 // indirect
129-
google.golang.org/protobuf v1.36.5 // indirect
129+
google.golang.org/protobuf v1.36.6 // indirect
130130
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
131131
gopkg.in/inf.v0 v0.9.1 // indirect
132132
gopkg.in/ini.v1 v1.66.4 // indirect
@@ -141,4 +141,4 @@ require (
141141
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
142142
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
143143
sigs.k8s.io/yaml v1.4.0 // indirect
144-
)
144+
)

go.sum

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ github.com/onsi/ginkgo/v2 v2.23.4 h1:ktYTpKJAVZnDT4VjxSbiBenUjmlL/5QkBEocaWXiQus
217217
github.com/onsi/ginkgo/v2 v2.23.4/go.mod h1:Bt66ApGPBFzHyR+JO10Zbt0Gsp4uWxu5mIOTusL46e8=
218218
github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y=
219219
github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0=
220+
github.com/onsi/gomega v1.38.0 h1:c/WX+w8SLAinvuKKQFh77WEucCnPk4j2OTUr7lt7BeY=
221+
github.com/onsi/gomega v1.38.0/go.mod h1:OcXcwId0b9QsE7Y49u+BTrL4IdKOBOKnD6VQNTJEB6o=
220222
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
221223
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
222224
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -309,6 +311,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
309311
golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
310312
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
311313
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
314+
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
315+
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
312316
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
313317
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU=
314318
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
@@ -336,6 +340,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
336340
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
337341
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
338342
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
343+
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
344+
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
339345
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
340346
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
341347
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
@@ -349,6 +355,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
349355
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
350356
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
351357
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
358+
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
359+
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
352360
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
353361
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
354362
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -365,11 +373,15 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
365373
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
366374
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
367375
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
376+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
377+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
368378
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
369379
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
370380
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
371381
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
372382
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
383+
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
384+
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
373385
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
374386
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
375387
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@@ -378,6 +390,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
378390
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
379391
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
380392
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
393+
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
394+
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
381395
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
382396
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
383397
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -392,6 +406,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
392406
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
393407
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
394408
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
409+
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
410+
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
395411
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
396412
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
397413
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -439,6 +455,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
439455
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
440456
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
441457
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
458+
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
459+
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
442460
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
443461
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
444462
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
@@ -490,4 +508,4 @@ sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h6
490508
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
491509
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
492510
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
493-
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
511+
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

internal/controller/ingestorcluster_controller_test.go

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,227 @@ limitations under the License.
1717
package controller
1818

1919
import (
20+
"context"
21+
"fmt"
22+
"time"
23+
2024
. "github.com/onsi/ginkgo/v2"
25+
. "github.com/onsi/gomega"
26+
enterpriseApi "github.com/splunk/splunk-operator/api/v4"
27+
"github.com/splunk/splunk-operator/internal/controller/testutils"
28+
corev1 "k8s.io/api/core/v1"
29+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"k8s.io/apimachinery/pkg/types"
31+
"k8s.io/client-go/kubernetes/scheme"
32+
"sigs.k8s.io/controller-runtime/pkg/client"
33+
"sigs.k8s.io/controller-runtime/pkg/client/fake"
34+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2135
)
2236

2337
var _ = Describe("IngestorCluster Controller", func() {
38+
BeforeEach(func() {
39+
time.Sleep(2 * time.Second)
40+
})
41+
42+
AfterEach(func() {
43+
44+
})
45+
46+
Context("IngestorCluster Management", func() {
47+
48+
It("Get IngestorCluster custom resource should fail", func() {
49+
namespace := "ns-splunk-ing-1"
50+
ApplyIngestorCluster = func(ctx context.Context, client client.Client, instance *enterpriseApi.IngestorCluster) (reconcile.Result, error) {
51+
return reconcile.Result{}, nil
52+
}
53+
nsSpecs := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
54+
55+
Expect(k8sClient.Create(context.Background(), nsSpecs)).Should(Succeed())
56+
57+
_, err := GetIngestorCluster("test", nsSpecs.Name)
58+
Expect(err.Error()).Should(Equal("ingestorclusters.enterprise.splunk.com \"test\" not found"))
59+
60+
Expect(k8sClient.Delete(context.Background(), nsSpecs)).Should(Succeed())
61+
})
62+
63+
It("Create IngestorCluster custom resource with annotations should pause", func() {
64+
namespace := "ns-splunk-ing-2"
65+
annotations := make(map[string]string)
66+
annotations[enterpriseApi.IngestorClusterPausedAnnotation] = ""
67+
ApplyIngestorCluster = func(ctx context.Context, client client.Client, instance *enterpriseApi.IngestorCluster) (reconcile.Result, error) {
68+
return reconcile.Result{}, nil
69+
}
70+
nsSpecs := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
71+
72+
Expect(k8sClient.Create(context.Background(), nsSpecs)).Should(Succeed())
73+
74+
CreateIngestorCluster("test", nsSpecs.Name, annotations, enterpriseApi.PhaseReady)
75+
icSpec, _ := GetIngestorCluster("test", nsSpecs.Name)
76+
annotations = map[string]string{}
77+
icSpec.Annotations = annotations
78+
icSpec.Status.Phase = "Ready"
79+
UpdateIngestorCluster(icSpec, enterpriseApi.PhaseReady)
80+
DeleteIngestorCluster("test", nsSpecs.Name)
81+
Expect(k8sClient.Delete(context.Background(), nsSpecs)).Should(Succeed())
82+
})
83+
84+
It("Create IngestorCluster custom resource should succeeded", func() {
85+
namespace := "ns-splunk-ing-3"
86+
ApplyIngestorCluster = func(ctx context.Context, client client.Client, instance *enterpriseApi.IngestorCluster) (reconcile.Result, error) {
87+
return reconcile.Result{}, nil
88+
}
89+
nsSpecs := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
90+
91+
Expect(k8sClient.Create(context.Background(), nsSpecs)).Should(Succeed())
92+
93+
annotations := make(map[string]string)
94+
CreateIngestorCluster("test", nsSpecs.Name, annotations, enterpriseApi.PhaseReady)
95+
DeleteIngestorCluster("test", nsSpecs.Name)
96+
Expect(k8sClient.Delete(context.Background(), nsSpecs)).Should(Succeed())
97+
})
98+
99+
It("Cover Unused methods", func() {
100+
namespace := "ns-splunk-ing-4"
101+
ApplyIngestorCluster = func(ctx context.Context, client client.Client, instance *enterpriseApi.IngestorCluster) (reconcile.Result, error) {
102+
return reconcile.Result{}, nil
103+
}
104+
nsSpecs := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
105+
106+
Expect(k8sClient.Create(context.Background(), nsSpecs)).Should(Succeed())
107+
108+
ctx := context.TODO()
109+
builder := fake.NewClientBuilder()
110+
c := builder.Build()
111+
instance := IngestorClusterReconciler{
112+
Client: c,
113+
Scheme: scheme.Scheme,
114+
}
115+
request := reconcile.Request{
116+
NamespacedName: types.NamespacedName{
117+
Name: "test",
118+
Namespace: namespace,
119+
},
120+
}
121+
_, err := instance.Reconcile(ctx, request)
122+
Expect(err).ToNot(HaveOccurred())
123+
124+
icSpec := testutils.NewIngestorCluster("test", namespace, "image")
125+
Expect(c.Create(ctx, icSpec)).Should(Succeed())
126+
127+
annotations := make(map[string]string)
128+
annotations[enterpriseApi.IngestorClusterPausedAnnotation] = ""
129+
icSpec.Annotations = annotations
130+
Expect(c.Update(ctx, icSpec)).Should(Succeed())
131+
132+
_, err = instance.Reconcile(ctx, request)
133+
Expect(err).ToNot(HaveOccurred())
24134

135+
annotations = map[string]string{}
136+
icSpec.Annotations = annotations
137+
Expect(c.Update(ctx, icSpec)).Should(Succeed())
138+
139+
_, err = instance.Reconcile(ctx, request)
140+
Expect(err).ToNot(HaveOccurred())
141+
142+
icSpec.DeletionTimestamp = &metav1.Time{}
143+
_, err = instance.Reconcile(ctx, request)
144+
Expect(err).ToNot(HaveOccurred())
145+
})
146+
147+
})
25148
})
149+
150+
func GetIngestorCluster(name string, namespace string) (*enterpriseApi.IngestorCluster, error) {
151+
By("Expecting IngestorCluster custom resource to be created successfully")
152+
153+
key := types.NamespacedName{
154+
Name: name,
155+
Namespace: namespace,
156+
}
157+
ic := &enterpriseApi.IngestorCluster{}
158+
159+
err := k8sClient.Get(context.Background(), key, ic)
160+
if err != nil {
161+
return nil, err
162+
}
163+
164+
return ic, err
165+
}
166+
167+
func CreateIngestorCluster(name string, namespace string, annotations map[string]string, status enterpriseApi.Phase) *enterpriseApi.IngestorCluster {
168+
By("Expecting IngestorCluster custom resource to be created successfully")
169+
170+
key := types.NamespacedName{
171+
Name: name,
172+
Namespace: namespace,
173+
}
174+
ingSpec := &enterpriseApi.IngestorCluster{
175+
ObjectMeta: metav1.ObjectMeta{
176+
Name: name,
177+
Namespace: namespace,
178+
Annotations: annotations,
179+
},
180+
Spec: enterpriseApi.IngestorClusterSpec{},
181+
}
182+
183+
ingSpec = testutils.NewIngestorCluster(name, namespace, "image")
184+
Expect(k8sClient.Create(context.Background(), ingSpec)).Should(Succeed())
185+
time.Sleep(2 * time.Second)
186+
ic := &enterpriseApi.IngestorCluster{}
187+
Eventually(func() bool {
188+
_ = k8sClient.Get(context.Background(), key, ic)
189+
if status != "" {
190+
fmt.Printf("status is set to %v", status)
191+
ic.Status.Phase = status
192+
Expect(k8sClient.Status().Update(context.Background(), ic)).Should(Succeed())
193+
time.Sleep(2 * time.Second)
194+
}
195+
return true
196+
}, timeout, interval).Should(BeTrue())
197+
198+
return ic
199+
}
200+
201+
func UpdateIngestorCluster(instance *enterpriseApi.IngestorCluster, status enterpriseApi.Phase) *enterpriseApi.IngestorCluster {
202+
By("Expecting IngestorCluster custom resource to be created successfully")
203+
204+
key := types.NamespacedName{
205+
Name: instance.Name,
206+
Namespace: instance.Namespace,
207+
}
208+
209+
icSpec := testutils.NewIngestorCluster(instance.Name, instance.Namespace, "image")
210+
icSpec.ResourceVersion = instance.ResourceVersion
211+
Expect(k8sClient.Update(context.Background(), icSpec)).Should(Succeed())
212+
time.Sleep(2 * time.Second)
213+
214+
ic := &enterpriseApi.IngestorCluster{}
215+
Eventually(func() bool {
216+
_ = k8sClient.Get(context.Background(), key, ic)
217+
if status != "" {
218+
fmt.Printf("status is set to %v", status)
219+
ic.Status.Phase = status
220+
Expect(k8sClient.Status().Update(context.Background(), ic)).Should(Succeed())
221+
time.Sleep(2 * time.Second)
222+
}
223+
return true
224+
}, timeout, interval).Should(BeTrue())
225+
226+
return ic
227+
}
228+
229+
func DeleteIngestorCluster(name string, namespace string) {
230+
By("Expecting IngestorCluster Deleted successfully")
231+
232+
key := types.NamespacedName{
233+
Name: name,
234+
Namespace: namespace,
235+
}
236+
237+
Eventually(func() error {
238+
ic := &enterpriseApi.IngestorCluster{}
239+
_ = k8sClient.Get(context.Background(), key, ic)
240+
err := k8sClient.Delete(context.Background(), ic)
241+
return err
242+
}, timeout, interval).Should(Succeed())
243+
}

internal/controller/suite_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ var _ = BeforeSuite(func(ctx context.Context) {
147147
}).SetupWithManager(k8sManager); err != nil {
148148
Expect(err).NotTo(HaveOccurred())
149149
}
150+
if err := (&IngestorClusterReconciler{
151+
Client: k8sManager.GetClient(),
152+
Scheme: k8sManager.GetScheme(),
153+
}).SetupWithManager(k8sManager); err != nil {
154+
Expect(err).NotTo(HaveOccurred())
155+
}
150156

151157
go func() {
152158
err = k8sManager.Start(ctrl.SetupSignalHandler())

0 commit comments

Comments
 (0)