Skip to content

Commit 5955f8e

Browse files
committed
Add test for takeOwnership
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
1 parent 481cc56 commit 5955f8e

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

test/suite/helm_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,70 @@ var _ = Describe("HelmChart Controller Tests", Ordered, func() {
162162
})
163163
})
164164

165+
Context("When a HelmChart is created with spec.takeOwnership=true", func() {
166+
var (
167+
err error
168+
chart *v1.HelmChart
169+
service *corev1.Service
170+
)
171+
BeforeAll(func() {
172+
service = &corev1.Service{
173+
ObjectMeta: metav1.ObjectMeta{
174+
Name: "traefik-example",
175+
Namespace: framework.Namespace,
176+
},
177+
Spec: corev1.ServiceSpec{
178+
ClusterIP: "None",
179+
Type: corev1.ServiceTypeClusterIP,
180+
},
181+
}
182+
service, err = framework.ClientSet.CoreV1().Services(framework.Namespace).Create(context.TODO(), service, metav1.CreateOptions{})
183+
Expect(err).ToNot(HaveOccurred())
184+
185+
chart = framework.NewHelmChart("traefik-example",
186+
"stable/traefik",
187+
"1.86.1",
188+
"v3",
189+
"metrics:\n prometheus:\n enabled: true\nkubernetes:\n ingressEndpoint:\n useDefaultPublishedService: true\nimage: docker.io/rancher/library-traefik\n",
190+
map[string]intstr.IntOrString{
191+
"rbac.enabled": {
192+
Type: intstr.String,
193+
StrVal: "true",
194+
},
195+
"ssl.enabled": {
196+
Type: intstr.String,
197+
StrVal: "true",
198+
},
199+
})
200+
chart.Spec.TakeOwnership = true
201+
chart, err = framework.CreateHelmChart(chart, framework.Namespace)
202+
Expect(err).ToNot(HaveOccurred())
203+
})
204+
205+
It("Should create a release for the chart", func() {
206+
Eventually(framework.ListReleases, 120*time.Second, 5*time.Second).WithArguments(chart).Should(HaveLen(1))
207+
})
208+
209+
It("Should take ownership of existing resources", func() {
210+
Eventually(func(g Gomega) {
211+
service, err = framework.ClientSet.CoreV1().Services(framework.Namespace).Get(context.TODO(), service.Name, metav1.GetOptions{})
212+
g.Expect(err).ToNot(HaveOccurred())
213+
g.Expect(service).To(HaveField("ObjectMeta.Annotations", HaveKeyWithValue("meta.helm.sh/release-name", "traefik-example")))
214+
}, 120*time.Second, 5*time.Second).Should(Succeed())
215+
})
216+
217+
AfterAll(func() {
218+
err = framework.DeleteHelmChart(chart.Name, chart.Namespace)
219+
Expect(err).ToNot(HaveOccurred())
220+
221+
Eventually(func(g Gomega) {
222+
g.Expect(framework.GetHelmChart(chart.Name, chart.Namespace)).Error().Should(MatchError(apierrors.IsNotFound, "IsNotFound"))
223+
}, 120*time.Second, 5*time.Second).Should(Succeed())
224+
225+
Eventually(framework.ListReleases, 120*time.Second, 5*time.Second).WithArguments(chart).Should(HaveLen(0))
226+
})
227+
})
228+
165229
Context("When a HelmChart specifies a timeout", func() {
166230
var (
167231
err error

0 commit comments

Comments
 (0)