@@ -41,105 +41,23 @@ var _ = Describe("kubebuilder", func() {
41
41
kbc , err = utils .NewTestContext (util .KubebuilderBinName , "GO111MODULE=on" )
42
42
Expect (err ).NotTo (HaveOccurred ())
43
43
Expect (kbc .Prepare ()).To (Succeed ())
44
-
45
- By ("installing prometheus operator" )
46
- Expect (kbc .InstallPrometheusOperManager ()).To (Succeed ())
47
-
48
- By ("creating manager namespace" )
49
- err = kbc .CreateManagerNamespace ()
50
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
51
-
52
- By ("labeling all namespaces to warn about restricted" )
53
- err = kbc .LabelAllNamespacesToWarnAboutRestricted ()
54
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
55
-
56
- By ("enforce that namespace where the sample will be applied can only run restricted containers" )
57
- _ , err = kbc .Kubectl .Command ("label" , "--overwrite" , "ns" , kbc .Kubectl .Namespace ,
58
- "pod-security.kubernetes.io/audit=restricted" ,
59
- "pod-security.kubernetes.io/enforce-version=v1.24" ,
60
- "pod-security.kubernetes.io/enforce=restricted" )
61
- Expect (err ).To (Not (HaveOccurred ()))
62
44
})
63
45
64
46
AfterEach (func () {
65
47
By ("clean up API objects created during the test" )
66
48
kbc .CleanupManifests (filepath .Join ("config" , "default" ))
67
49
68
- By ("uninstalling the Prometheus manager bundle" )
69
- kbc .UninstallPrometheusOperManager ()
70
-
71
50
By ("removing controller image and working dir" )
72
51
kbc .Destroy ()
73
52
})
74
53
75
54
It ("should generate a runnable project with deploy-image/v1-alpha options " , func () {
76
- var err error
77
-
78
- By ("initializing a project with go/v4" )
79
- err = kbc .Init (
80
- "--plugins" , "go/v4" ,
81
- "--project-version" , "3" ,
82
- "--domain" , kbc .Domain ,
83
- )
84
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
85
-
86
- By ("creating API definition with deploy-image/v1-alpha plugin" )
87
- err = kbc .CreateAPI (
88
- "--group" , kbc .Group ,
89
- "--version" , kbc .Version ,
90
- "--kind" , kbc .Kind ,
91
- "--plugins" , "deploy-image/v1-alpha" ,
92
- "--image" , "memcached:1.6.26-alpine3.19" ,
93
- "--image-container-port" , "11211" ,
94
- "--image-container-command" , "memcached,-m=64,-o,modern,-v" ,
95
- "--run-as-user" , "1001" ,
96
- "--make=false" ,
97
- "--manifests=false" ,
98
- )
99
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
100
-
101
- By ("uncomment kustomization.yaml to enable prometheus" )
102
- ExpectWithOffset (1 , util .UncommentCode (
103
- filepath .Join (kbc .Dir , "config" , "default" , "kustomization.yaml" ),
104
- "#- ../prometheus" , "#" )).To (Succeed ())
105
-
106
- By ("uncomment kustomize files to ensure that pods are restricted" )
107
- uncommentPodStandards (kbc )
108
-
55
+ GenerateDeployImageWithOptions (kbc )
109
56
Run (kbc )
110
57
})
111
58
112
59
It ("should generate a runnable project with deploy-image/v1-alpha without options " , func () {
113
- var err error
114
-
115
- By ("initializing a project with go/v4" )
116
- err = kbc .Init (
117
- "--plugins" , "go/v4" ,
118
- "--project-version" , "3" ,
119
- "--domain" , kbc .Domain ,
120
- )
121
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
122
-
123
- By ("creating API definition with deploy-image/v1-alpha plugin" )
124
- err = kbc .CreateAPI (
125
- "--group" , kbc .Group ,
126
- "--version" , kbc .Version ,
127
- "--kind" , kbc .Kind ,
128
- "--plugins" , "deploy-image/v1-alpha" ,
129
- "--image" , "busybox:1.36.1" ,
130
- "--make=false" ,
131
- "--manifests=false" ,
132
- )
133
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
134
-
135
- By ("uncomment kustomization.yaml to enable prometheus" )
136
- ExpectWithOffset (1 , util .UncommentCode (
137
- filepath .Join (kbc .Dir , "config" , "default" , "kustomization.yaml" ),
138
- "#- ../prometheus" , "#" )).To (Succeed ())
139
-
140
- By ("uncomment kustomize files to ensure that pods are restricted" )
141
- uncommentPodStandards (kbc )
142
-
60
+ GenerateDeployImage (kbc )
143
61
Run (kbc )
144
62
})
145
63
})
@@ -258,7 +176,7 @@ func Run(kbc *utils.TestContext) {
258
176
}
259
177
Eventually (getStatus , time .Minute , time .Second ).Should (Succeed ())
260
178
261
- // Testing the finalizer
179
+ By ( "validating the finalizer" )
262
180
EventuallyWithOffset (1 , func () error {
263
181
_ , err = kbc .Kubectl .Delete (true , "-f" , sampleFilePath )
264
182
return err
@@ -275,19 +193,3 @@ func Run(kbc *utils.TestContext) {
275
193
return nil
276
194
}, time .Minute , time .Second ).Should (Succeed ())
277
195
}
278
-
279
- func uncommentPodStandards (kbc * utils.TestContext ) {
280
- configManager := filepath .Join (kbc .Dir , "config" , "manager" , "manager.yaml" )
281
-
282
- //nolint:lll
283
- if err := util .ReplaceInFile (configManager , `# TODO(user): For common cases that do not require escalating privileges
284
- # it is recommended to ensure that all your Pods/Containers are restrictive.
285
- # More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
286
- # Please uncomment the following code if your project does NOT have to work on old Kubernetes
287
- # versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
288
- # seccompProfile:
289
- # type: RuntimeDefault` , `seccompProfile:
290
- type: RuntimeDefault` ); err == nil {
291
- ExpectWithOffset (1 , err ).NotTo (HaveOccurred ())
292
- }
293
- }
0 commit comments