Skip to content

Commit c909c3e

Browse files
Squashed commit of the following:
commit a93ca3b Author: hirokuni-kitahara <[email protected]> Date: Thu Jan 21 19:37:51 2021 +0900 fix e2e test delete error & fix op unit test timeout error (IBM#263) commit 02c7d25 Author: Kugamoorthy Gajananan <[email protected]> Date: Thu Jan 21 15:39:59 2021 +0900 Added make target and script to update version in nessary files after building bundle based on new version (IBM#261) commit 6546dc1 Author: hirokuni-kitahara <[email protected]> Date: Thu Jan 21 15:37:29 2021 +0900 fix integrity shield roles/cert config and add event type annotation to IntegrityShieldEvent (IBM#262) * update role & cert duration and fix e2e test issue * add event type annotation and fix e2e test commit 121e937 Author: hirokuni-kitahara <[email protected]> Date: Wed Jan 20 22:29:17 2021 +0900 fix patch functions and add troubleshooting doc (IBM#259) * fix patch functions and add troubleshooting doc * fix scripts and some parts in doc commit 0ef8683 Author: Yuji Watanabe <[email protected]> Date: Wed Jan 20 22:18:16 2021 +0900 change from K8s to k8s (IBM#260) * change from K8s to k8s * fix tested cluster version
1 parent 385bce0 commit c909c3e

File tree

2 files changed

+46
-50
lines changed

2 files changed

+46
-50
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ setup-test-env:
297297
delete-test-env:
298298
@echo
299299
@echo deleting test namespace
300-
kubectl delete ns $(TEST_NS)
300+
# $TEST_NS will be deleted in e2e test usually, so ignore not found error.
301+
kubectl delete ns $(TEST_NS) --ignore-not-found=true
301302
kubectl delete ns $(TEST_NS_NEW)
302303
kubectl delete ns $(TEST_UNPROTECTED_NS)
303304

integrity-shield-operator/controllers/suite_test.go

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var testEnv *envtest.Environment
7272
var scheme *runtime.Scheme
7373
var r *IntegrityShieldReconciler
7474
var iShieldCR *apisv1alpha1.IntegrityShield
75+
var crBytes []byte
7576

7677
// Kubectl executes kubectl commands
7778
func Kubectl(args ...string) error {
@@ -166,7 +167,7 @@ var _ = BeforeSuite(func(done Done) {
166167

167168
// create ishield cr
168169
var defaultCR *apisv1alpha1.IntegrityShield
169-
crBytes, err := ioutil.ReadFile(testIShieldCRPath)
170+
crBytes, err = ioutil.ReadFile(testIShieldCRPath)
170171
Expect(err).Should(BeNil())
171172
err = yaml.Unmarshal(crBytes, &defaultCR)
172173
Expect(err).Should(BeNil())
@@ -177,64 +178,16 @@ var _ = BeforeSuite(func(done Done) {
177178
err = k8sClient.Get(ctx, types.NamespacedName{Name: defaultCR.Name, Namespace: defaultCR.Namespace}, iShieldCR)
178179
Expect(err).Should(BeNil())
179180

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-
190181
r = &IntegrityShieldReconciler{
191182
Client: k8sClient,
192183
Log: ctrl.Log.WithName("controllers").WithName("IntegrityShield"),
193184
Scheme: scheme,
194185
}
195186

196-
// err = r.SetupWithManager(mgr)
197-
// Expect(err).Should(BeNil())
198-
199187
keyringSecretName := "keyring-secret"
200188
emptyKeyring := &v1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: iShieldCR.Namespace, Name: keyringSecretName}, Data: map[string][]byte{}}
201189
_ = k8sClient.Create(ctx, emptyKeyring)
202190

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())
238191
close(done)
239192
}, 60)
240193

@@ -278,6 +231,48 @@ func doReconcileTest(fn func(*apiv1alpha1.IntegrityShield) (ctrl.Result, error),
278231

279232
var _ = Describe("Test integrity shield", func() {
280233

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+
281276
It("Util Func isDeploymentAvailable() Test", func() {
282277
_ = r.isDeploymentAvailable(iShieldCR)
283278
})

0 commit comments

Comments
 (0)