-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathrhdh-config_test.go
More file actions
283 lines (232 loc) · 8.69 KB
/
rhdh-config_test.go
File metadata and controls
283 lines (232 loc) · 8.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package integration_tests
import (
"context"
"fmt"
"time"
"github.com/redhat-developer/rhdh-operator/pkg/utils"
appsv1 "k8s.io/api/apps/v1"
"github.com/redhat-developer/rhdh-operator/pkg/model"
bsv1 "github.com/redhat-developer/rhdh-operator/api/v1alpha5"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = When("create default rhdh", func() {
It("tests rhdh config", func() {
if !isProfile("rhdh") {
Skip("Skipped for non rhdh config")
}
ctx := context.Background()
ns := createNamespace(ctx)
backstageName := createAndReconcileBackstage(ctx, ns, bsv1.BackstageSpec{}, "")
Eventually(func(g Gomega) {
deploy, err := backstageDeployment(ctx, k8sClient, ns, backstageName)
g.Expect(err).ShouldNot(HaveOccurred(), controllerMessage())
ss := &appsv1.StatefulSet{}
err = k8sClient.Get(ctx, types.NamespacedName{Namespace: ns, Name: model.DbStatefulSetName(backstageName)}, ss)
g.Expect(err).ShouldNot(HaveOccurred(), controllerMessage())
serv := &corev1.Service{}
err = k8sClient.Get(ctx, types.NamespacedName{Namespace: ns, Name: model.ServiceName(backstageName)}, serv)
g.Expect(err).ShouldNot(HaveOccurred(), controllerMessage())
dpCm := &corev1.ConfigMap{}
err = k8sClient.Get(ctx, types.NamespacedName{Namespace: ns, Name: model.DynamicPluginsDefaultName(backstageName)}, dpCm)
g.Expect(err).ShouldNot(HaveOccurred())
var appConfigCm corev1.ConfigMap
err = k8sClient.Get(ctx, types.NamespacedName{Namespace: ns, Name: model.AppConfigDefaultName(backstageName)}, &appConfigCm)
g.Expect(err).ShouldNot(HaveOccurred())
g.Expect(deploy.PodSpec().InitContainers).To(HaveLen(1))
_, initCont := model.DynamicPluginsInitContainer(deploy.PodSpec().InitContainers)
initContainerExpectedVolumeMounts := []corev1.VolumeMount{
{
Name: "dynamic-plugins-root",
MountPath: "/dynamic-plugins-root",
SubPath: "",
},
{
Name: utils.GenerateRuntimeObjectName(backstageName, "backstage-files"),
MountPath: "/opt/app-root/src/.npmrc.dynamic-plugins",
SubPath: "",
},
// TODO - configure this when have defined dynamic plugins OCI registry
{
Name: "dynamic-plugins-registry-auth",
MountPath: "/opt/app-root/src/.config/containers",
SubPath: "",
},
{
Name: "npmcacache",
MountPath: "/opt/app-root/src/.npm/_cacache",
SubPath: "",
},
{
Name: utils.GenerateVolumeNameFromCmOrSecret(model.DynamicPluginsDefaultName(backstageName)),
MountPath: "/opt/app-root/src/dynamic-plugins.yaml",
SubPath: "dynamic-plugins.yaml",
},
{
Name: "extensions-catalog",
MountPath: "/extensions",
},
{
Name: "temp",
MountPath: "/tmp",
SubPath: "",
},
}
g.Expect(initCont.VolumeMounts).To(HaveLen(len(initContainerExpectedVolumeMounts)))
for _, evm := range initContainerExpectedVolumeMounts {
found := false
for _, vm := range initCont.VolumeMounts {
if vm.Name == evm.Name {
found = true
g.Expect(vm.MountPath).To(Equal(evm.MountPath))
g.Expect(vm.SubPath).To(Equal(evm.SubPath))
}
}
g.Expect(found).To(BeTrue())
}
g.Expect(initCont.Env[0].Name).To(Equal("NPM_CONFIG_USERCONFIG"))
g.Expect(initCont.Env[0].Value).To(Equal("/opt/app-root/src/.npmrc.dynamic-plugins/.npmrc"))
g.Expect(deploy.PodSpec().Volumes).To(HaveLen(8))
g.Expect(deploy.PodSpec().Containers).To(HaveLen(1))
mainCont := backstageContainer(*deploy.PodSpec())
g.Expect(mainCont.Args).To(HaveLen(4))
g.Expect(mainCont.Args[0]).To(Equal("--config"))
g.Expect(mainCont.Args[1]).To(Equal("dynamic-plugins-root/app-config.dynamic-plugins.yaml"))
g.Expect(mainCont.Args[2]).To(Equal("--config"))
g.Expect(mainCont.Args[3]).To(Equal("/opt/app-root/src/default.app-config.yaml"))
mainContainerExpectedVolumeMounts := []corev1.VolumeMount{
{
MountPath: "/opt/app-root/src/dynamic-plugins-root",
SubPath: "",
},
{
MountPath: "/opt/app-root/src/default.app-config.yaml",
SubPath: "default.app-config.yaml",
},
{
MountPath: "/extensions",
},
{
MountPath: "/marketplace",
ReadOnly: true,
},
{
MountPath: "/tmp",
SubPath: "",
},
}
g.Expect(mainCont.VolumeMounts).To(HaveLen(len(mainContainerExpectedVolumeMounts)))
for _, evm := range mainContainerExpectedVolumeMounts {
found := false
for _, vm := range mainCont.VolumeMounts {
if evm.MountPath == vm.MountPath {
found = true
g.Expect(vm.MountPath).To(Equal(evm.MountPath))
g.Expect(vm.SubPath).To(Equal(evm.SubPath))
}
}
g.Expect(found).To(BeTrue())
}
if currentPlatform.IsOpenshift() {
// no patch, so default
By("not applying any platform-specific patches", func() {
g.Expect(deploy.PodSpec().SecurityContext.FSGroup).To(BeNil())
g.Expect(ss.Spec.Template.Spec.SecurityContext.FSGroup).To(BeNil())
g.Expect(serv.Spec.Type).To(Equal(corev1.ServiceTypeClusterIP))
})
By("updating the baseUrls in the default app-config CM (RHIDP-6192)", func() {
g.Expect(appConfigCm).To(
HaveAppConfigBaseUrl(MatchRegexp(fmt.Sprintf(`^https://%s-%s.+`, model.RouteName(backstageName), ns))))
})
} else {
// k8s (patched)
By("applying k8s-specific patches for security context", func() {
g.Expect(deploy.PodSpec().SecurityContext.FSGroup).To(Not(BeNil()))
g.Expect(ss.Spec.Template.Spec.SecurityContext.FSGroup).To(Not(BeNil()))
g.Expect(serv.Spec.Type).To(Equal(corev1.ServiceTypeNodePort))
})
By("not updating the baseUrls in the default app-config CM", func() {
g.Expect(appConfigCm).To(HaveAppConfigBaseUrl(BeEmpty()))
})
}
}, 20*time.Second, time.Second).Should(Succeed())
deleteNamespace(ctx, ns)
})
It("replaces dynamic-plugins-root volume", func() {
// This test relies on the fact that RHDH default config for deployment contains
// volumes:
// - ephemeral:
// name: dynamic-plugins-root
// and check if it replaced with one defined in spec.deployment
ctx := context.Background()
ns := createNamespace(ctx)
bs2 := &bsv1.Backstage{}
err := readYamlFile("testdata/rhdh-replace-dynaplugin-root.yaml", bs2)
Expect(err).To(Not(HaveOccurred()))
backstageName := createAndReconcileBackstage(ctx, ns, bs2.Spec, "")
Eventually(func(g Gomega) {
By("getting the Pod ")
deploy, err := backstageDeployment(ctx, k8sClient, ns, backstageName)
//bpod, err := getBackstagePod(ctx, k8sClient, ns, backstageName)
g.Expect(err).To(Not(HaveOccurred()))
var bsvolume *corev1.Volume
for _, v := range deploy.PodSpec().Volumes {
if v.Name == "dynamic-plugins-root" {
bsvolume = &v
break
}
}
g.Expect(bsvolume).NotTo(BeNil())
g.Expect(bsvolume.Ephemeral).To(BeNil())
g.Expect(bsvolume.PersistentVolumeClaim).NotTo(BeNil())
}, 10*time.Second, time.Second).Should(Succeed())
})
It("replaces .npmrc", func() {
// This test relies on the fact that RHDH default config contains secret-files.yaml for .nmrc with:
// name: dynamic-plugins-npmrc
// annotations:
// rhdh.redhat.com/mount-path: /opt/app-root/src/.npmrc.dynamic-plugins
// rhdh.redhat.com/containers: install-dynamic-plugins
// and check if it replaced with one defined in spec.deployment
if !isProfile("rhdh") {
Skip("Skipped for non rhdh config")
}
ctx := context.Background()
ns := createNamespace(ctx)
npmrcSecret := generateSecret(ctx, k8sClient, "my-dynamic-plugins-npmrc", ns, map[string]string{".npmrc": "new-npmrc"}, nil, nil)
bsSpec := bsv1.BackstageSpec{
Application: &bsv1.Application{
ExtraFiles: &bsv1.ExtraFiles{
Secrets: []bsv1.FileObjectRef{
{
Name: npmrcSecret,
MountPath: "/opt/app-root/src/.npmrc.dynamic-plugins",
Containers: []string{
"install-dynamic-plugins",
},
},
},
},
},
}
backstageName := createAndReconcileBackstage(ctx, ns, bsSpec, "")
Eventually(func(g Gomega) {
By("getting the Deployment ")
deploy, err := backstageDeployment(ctx, k8sClient, ns, backstageName)
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(len(deploy.PodSpec().InitContainers)).To(Equal(1))
initCont := deploy.PodSpec().InitContainers[0]
g.Expect(initCont.Name).To(Equal("install-dynamic-plugins"))
found := 0
for i := range initCont.VolumeMounts {
if initCont.VolumeMounts[i].MountPath == "/opt/app-root/src/.npmrc.dynamic-plugins" {
g.Expect(initCont.VolumeMounts[i].Name).To(Equal(npmrcSecret))
found++
}
}
g.Expect(found).To(Equal(1))
}, 10*time.Second, time.Second).Should(Succeed())
})
})