@@ -16,10 +16,13 @@ package e2e_ansible_test
16
16
17
17
import (
18
18
"fmt"
19
+ "os/exec"
19
20
"path/filepath"
20
21
"strings"
21
22
"testing"
22
23
24
+ kbtestutils "sigs.k8s.io/kubebuilder/test/e2e/utils"
25
+
23
26
. "github.com/onsi/ginkgo"
24
27
. "github.com/onsi/gomega"
25
28
@@ -47,8 +50,15 @@ var _ = BeforeSuite(func() {
47
50
tc , err = testutils .NewTestContext (testutils .BinaryName , "GO111MODULE=on" )
48
51
Expect (err ).NotTo (HaveOccurred ())
49
52
50
- By ("creating the repository" )
51
- Expect (tc .Prepare ()).To (Succeed ())
53
+ tc .Domain = "example.com"
54
+ tc .Version = "v1alpha1"
55
+ tc .Group = "cache"
56
+ tc .Kind = "Memcached"
57
+ tc .ProjectName = "memcached-operator"
58
+ tc .Kubectl .Namespace = fmt .Sprintf ("%s-system" , tc .ProjectName )
59
+
60
+ By ("copying sample to a temporary e2e directory" )
61
+ Expect (exec .Command ("cp" , "-r" , "../../testdata/ansible/memcached-operator" , tc .Dir ).Run ()).To (Succeed ())
52
62
53
63
By ("fetching the current-context" )
54
64
tc .Kubectx , err = tc .Kubectl .Command ("config" , "current-context" )
@@ -57,50 +67,17 @@ var _ = BeforeSuite(func() {
57
67
By ("preparing the prerequisites on cluster" )
58
68
tc .InstallPrerequisites ()
59
69
60
- By ("setting domain and GVK" )
61
- tc .Domain = "example.com"
62
- tc .Version = "v1alpha1"
63
- tc .Group = "ansible"
64
- tc .Kind = "Memcached"
65
-
66
- By ("initializing a ansible project" )
67
- err = tc .Init (
68
- "--plugins" , "ansible" ,
69
- "--project-version" , "3-alpha" ,
70
- "--domain" , tc .Domain )
71
- Expect (err ).NotTo (HaveOccurred ())
72
-
73
70
By ("using dev image for scorecard-test" )
74
71
err = tc .ReplaceScorecardImagesForDev ()
75
72
Expect (err ).NotTo (HaveOccurred ())
76
73
77
- By ("creating the Memcached API" )
78
- err = tc .CreateAPI (
79
- "--group" , tc .Group ,
80
- "--version" , tc .Version ,
81
- "--kind" , tc .Kind ,
82
- "--generate-playbook" ,
83
- "--generate-role" )
84
- Expect (err ).NotTo (HaveOccurred ())
85
-
86
74
By ("replacing project Dockerfile to use ansible base image with the dev tag" )
87
75
err = testutils .ReplaceRegexInFile (filepath .Join (tc .Dir , "Dockerfile" ), "quay.io/operator-framework/ansible-operator:.*" , "quay.io/operator-framework/ansible-operator:dev" )
88
76
Expect (err ).Should (Succeed ())
89
77
90
78
By ("adding Memcached mock task to the role" )
91
- err = testutils .ReplaceInFile (filepath .Join (tc .Dir , "roles" , strings .ToLower (tc .Kind ), "tasks" , "main.yml" ),
92
- fmt .Sprintf ("# tasks file for %s" , tc .Kind ), memcachedWithBlackListTask )
93
- Expect (err ).NotTo (HaveOccurred ())
94
-
95
- By ("setting defaults to Memcached" )
96
- err = testutils .ReplaceInFile (filepath .Join (tc .Dir , "roles" , strings .ToLower (tc .Kind ), "defaults" , "main.yml" ),
97
- fmt .Sprintf ("# defaults file for %s" , tc .Kind ), "size: 1" )
98
- Expect (err ).NotTo (HaveOccurred ())
99
-
100
- By ("updating Memcached sample" )
101
- memcachedSampleFile := filepath .Join (tc .Dir , "config" , "samples" ,
102
- fmt .Sprintf ("%s_%s_%s.yaml" , tc .Group , tc .Version , strings .ToLower (tc .Kind )))
103
- err = testutils .ReplaceInFile (memcachedSampleFile , "foo: bar" , "size: 1" )
79
+ err = kbtestutils .InsertCode (filepath .Join (tc .Dir , "roles" , strings .ToLower (tc .Kind ), "tasks" , "main.yml" ),
80
+ "periodSeconds: 3" , memcachedWithBlackListTask )
104
81
Expect (err ).NotTo (HaveOccurred ())
105
82
106
83
By ("creating an API definition to add a task to delete the config map" )
@@ -134,15 +111,6 @@ var _ = BeforeSuite(func() {
134
111
"# +kubebuilder:scaffold:rules" , rolesForBaseOperator )
135
112
Expect (err ).NotTo (HaveOccurred ())
136
113
137
- By ("turning off interactive prompts for all generation tasks." )
138
- replace := "operator-sdk generate kustomize manifests"
139
- err = testutils .ReplaceInFile (filepath .Join (tc .Dir , "Makefile" ), replace , replace + " --interactive=false" )
140
- Expect (err ).NotTo (HaveOccurred ())
141
-
142
- By ("checking the kustomize setup" )
143
- err = tc .Make ("kustomize" )
144
- Expect (err ).NotTo (HaveOccurred ())
145
-
146
114
By ("building the project image" )
147
115
err = tc .Make ("docker-build" , "IMG=" + tc .ImageName )
148
116
Expect (err ).NotTo (HaveOccurred ())
@@ -168,45 +136,10 @@ var _ = AfterSuite(func() {
168
136
tc .Destroy ()
169
137
})
170
138
171
- const memcachedWithBlackListTask = `- name: start memcached
172
- community.kubernetes.k8s:
173
- definition:
174
- kind: Deployment
175
- apiVersion: apps/v1
176
- metadata:
177
- name: '{{ ansible_operator_meta.name }}-memcached'
178
- namespace: '{{ ansible_operator_meta.namespace }}'
179
- labels:
180
- app: memcached
181
- spec:
182
- replicas: "{{size}}"
183
- selector:
184
- matchLabels:
185
- app: memcached
186
- template:
187
- metadata:
188
- labels:
189
- app: memcached
190
- spec:
191
- containers:
192
- - name: memcached
193
- command:
194
- - memcached
195
- - -m=64
196
- - -o
197
- - modern
198
- - -v
199
- image: "docker.io/memcached:1.4.36-alpine"
200
- ports:
201
- - containerPort: 11211
202
- readinessProbe:
203
- tcpSocket:
204
- port: 11211
205
- initialDelaySeconds: 3
206
- periodSeconds: 3
139
+ const memcachedWithBlackListTask = `
207
140
208
141
- operator_sdk.util.k8s_status:
209
- api_version: ansible .example.com/v1alpha1
142
+ api_version: cache .example.com/v1alpha1
210
143
kind: Memcached
211
144
name: "{{ ansible_operator_meta.name }}"
212
145
namespace: "{{ ansible_operator_meta.namespace }}"
@@ -257,7 +190,7 @@ const taskToDeleteConfigMap = `- name: delete configmap for test
257
190
258
191
const memcachedWatchCustomizations = `playbook: playbooks/memcached.yml
259
192
finalizer:
260
- name: finalizer.ansible .example.com
193
+ name: finalizer.cache .example.com
261
194
role: memfin
262
195
blacklist:
263
196
- group: ""
0 commit comments