@@ -72,6 +72,7 @@ var testEnv *envtest.Environment
72
72
var scheme * runtime.Scheme
73
73
var r * IntegrityShieldReconciler
74
74
var iShieldCR * apisv1alpha1.IntegrityShield
75
+ var crBytes []byte
75
76
76
77
// Kubectl executes kubectl commands
77
78
func Kubectl (args ... string ) error {
@@ -166,7 +167,7 @@ var _ = BeforeSuite(func(done Done) {
166
167
167
168
// create ishield cr
168
169
var defaultCR * apisv1alpha1.IntegrityShield
169
- crBytes , err : = ioutil .ReadFile (testIShieldCRPath )
170
+ crBytes , err = ioutil .ReadFile (testIShieldCRPath )
170
171
Expect (err ).Should (BeNil ())
171
172
err = yaml .Unmarshal (crBytes , & defaultCR )
172
173
Expect (err ).Should (BeNil ())
@@ -177,64 +178,16 @@ var _ = BeforeSuite(func(done Done) {
177
178
err = k8sClient .Get (ctx , types.NamespacedName {Name : defaultCR .Name , Namespace : defaultCR .Namespace }, iShieldCR )
178
179
Expect (err ).Should (BeNil ())
179
180
180
- // mgr, err := ctrl.NewManager(cfg, ctrl.Options{
181
- // Scheme: scheme,
182
- // MetricsBindAddress: ":8080",
183
- // Port: 9443,
184
- // LeaderElection: false,
185
- // LeaderElectionID: "b67154b9.integrityshield.io",
186
- // Namespace: defaultCR.Namespace, // namespaced-scope when the value is not an empty string
187
- // })
188
- // Expect(err).Should(BeNil())
189
-
190
181
r = & IntegrityShieldReconciler {
191
182
Client : k8sClient ,
192
183
Log : ctrl .Log .WithName ("controllers" ).WithName ("IntegrityShield" ),
193
184
Scheme : scheme ,
194
185
}
195
186
196
- // err = r.SetupWithManager(mgr)
197
- // Expect(err).Should(BeNil())
198
-
199
187
keyringSecretName := "keyring-secret"
200
188
emptyKeyring := & v1.Secret {ObjectMeta : metav1.ObjectMeta {Namespace : iShieldCR .Namespace , Name : keyringSecretName }, Data : map [string ][]byte {}}
201
189
_ = k8sClient .Create (ctx , emptyKeyring )
202
190
203
- req := reconcile.Request {
204
- NamespacedName : types.NamespacedName {Namespace : iShieldCR .Namespace , Name : iShieldCR .Name },
205
- }
206
-
207
- i := 0
208
- deployFound := & appsv1.Deployment {}
209
- for {
210
- _ , err = r .Reconcile (req )
211
- Expect (err ).Should (BeNil ())
212
- i ++
213
-
214
- if i % 10 == 0 {
215
- fmt .Println ("[DEBUG] reconcile iteration: " , i )
216
- tmpErr := k8sClient .Get (ctx , types.NamespacedName {Name : iShieldCR .GetIShieldServerDeploymentName (), Namespace : iShieldNamespace }, deployFound )
217
- if tmpErr == nil {
218
-
219
- break
220
- }
221
- }
222
- }
223
- fmt .Println ("[DEBUG] reconcile finished: " , i )
224
-
225
- _ = k8sClient .Delete (ctx , iShieldCR )
226
- time .Sleep (time .Second * 10 )
227
-
228
- var newIShieldCR * apiv1alpha1.IntegrityShield
229
- err = yaml .Unmarshal (crBytes , & newIShieldCR )
230
- Expect (err ).Should (BeNil ())
231
- newIShieldCR .SetNamespace (iShieldNamespace )
232
- newIShieldCR = embedRSP (newIShieldCR )
233
- err = k8sClient .Create (ctx , newIShieldCR )
234
- Expect (err ).Should (BeNil ())
235
- iShieldCR = & apisv1alpha1.IntegrityShield {}
236
- err = k8sClient .Get (ctx , types.NamespacedName {Name : newIShieldCR .Name , Namespace : newIShieldCR .Namespace }, iShieldCR )
237
- Expect (err ).Should (BeNil ())
238
191
close (done )
239
192
}, 60 )
240
193
@@ -278,6 +231,48 @@ func doReconcileTest(fn func(*apiv1alpha1.IntegrityShield) (ctrl.Result, error),
278
231
279
232
var _ = Describe ("Test integrity shield" , func () {
280
233
234
+ It ("repeating Reconcile() Test" , func () {
235
+ req := reconcile.Request {
236
+ NamespacedName : types.NamespacedName {Namespace : iShieldCR .Namespace , Name : iShieldCR .Name },
237
+ }
238
+
239
+ i := 0
240
+ deployFound := & appsv1.Deployment {}
241
+ for {
242
+ _ , err := r .Reconcile (req )
243
+ Expect (err ).Should (BeNil ())
244
+ i ++
245
+
246
+ if i % 10 == 0 {
247
+ fmt .Println ("[DEBUG] reconcile iteration: " , i )
248
+ tmpErr := k8sClient .Get (context .Background (), types.NamespacedName {Name : iShieldCR .GetIShieldServerDeploymentName (), Namespace : iShieldNamespace }, deployFound )
249
+ if tmpErr == nil {
250
+
251
+ break
252
+ }
253
+ }
254
+ }
255
+ fmt .Println ("[DEBUG] reconcile finished: " , i )
256
+ })
257
+
258
+ It ("IShiled CR delete & re-create Test" , func () {
259
+ ctx := context .Background ()
260
+ var err error
261
+ _ = k8sClient .Delete (ctx , iShieldCR )
262
+ time .Sleep (time .Second * 10 )
263
+
264
+ var newIShieldCR * apiv1alpha1.IntegrityShield
265
+ err = yaml .Unmarshal (crBytes , & newIShieldCR )
266
+ Expect (err ).Should (BeNil ())
267
+ newIShieldCR .SetNamespace (iShieldNamespace )
268
+ newIShieldCR = embedRSP (newIShieldCR )
269
+ err = k8sClient .Create (ctx , newIShieldCR )
270
+ Expect (err ).Should (BeNil ())
271
+ iShieldCR = & apisv1alpha1.IntegrityShield {}
272
+ err = k8sClient .Get (ctx , types.NamespacedName {Name : newIShieldCR .Name , Namespace : newIShieldCR .Namespace }, iShieldCR )
273
+ Expect (err ).Should (BeNil ())
274
+ })
275
+
281
276
It ("Util Func isDeploymentAvailable() Test" , func () {
282
277
_ = r .isDeploymentAvailable (iShieldCR )
283
278
})
0 commit comments