Skip to content

Commit

Permalink
Merge pull request #1893 from flant/fixBeforeHookCreationHookDeleteTi…
Browse files Browse the repository at this point in the history
…meout

[3-way-merge] Fix before-hook-creation delete policy hook delete timeout
  • Loading branch information
distorhead committed Nov 11, 2019
2 parents b4283ba + 759e8b9 commit 1421c5a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -111,7 +111,7 @@ require (
sigs.k8s.io/yaml v1.1.0
)

replace k8s.io/helm => github.com/flant/helm v0.0.0-20191111093205-70e6eda19a90
replace k8s.io/helm => github.com/flant/helm v0.0.0-20191111155056-4a61afe6bf10

replace k8s.io/api => k8s.io/api v0.0.0-20190918155943-95b840bb6a1f

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -190,6 +190,8 @@ github.com/flant/helm v0.0.0-20191105094743-08972e07b30a h1:ohzjyEeO3773XffYpYv8
github.com/flant/helm v0.0.0-20191105094743-08972e07b30a/go.mod h1:FBJB9Ee3D1KsW2Q54spnyJAihmDmnHKRmVyKscC3++Y=
github.com/flant/helm v0.0.0-20191111093205-70e6eda19a90 h1:xxluXV2xSwrXXLubeF+YuzQVXo3SWjK9UxMCeb5nKag=
github.com/flant/helm v0.0.0-20191111093205-70e6eda19a90/go.mod h1:FBJB9Ee3D1KsW2Q54spnyJAihmDmnHKRmVyKscC3++Y=
github.com/flant/helm v0.0.0-20191111155056-4a61afe6bf10 h1:f3VWpoT09EBq/8WYovzeBweCzJU0okoeENqunib9s24=
github.com/flant/helm v0.0.0-20191111155056-4a61afe6bf10/go.mod h1:FBJB9Ee3D1KsW2Q54spnyJAihmDmnHKRmVyKscC3++Y=
github.com/flant/kubedog v0.3.5-0.20190923111717-5fda2f77f960 h1:RQaVATHub/MgDkqhQ2Zrsumxi73cyvNQt3bW82HFHx4=
github.com/flant/kubedog v0.3.5-0.20190923111717-5fda2f77f960/go.mod h1:o9cSuE3Z/kgxKhLCLUGUc9vPOFQgmY0B+7bdOQq++7o=
github.com/flant/logboek v0.0.0-20190416104940-91fee3a3fc8d/go.mod h1:WirgB39yMTvPGKqrAE3zlsG/02of4rr5lXh1EiwO5P0=
Expand Down
24 changes: 8 additions & 16 deletions integration/helmhooksdeleter/app2/.helm/templates/templates.yaml
Expand Up @@ -21,24 +21,16 @@ spec:
command: [ "/bin/bash", "-c", "while true; do date ; sleep 1 ; done" ]
image: ubuntu:18.04
---
apiVersion: batch/v1
kind: Job
apiVersion: v1
kind: Pod
metadata:
name: migrate
name: myhook
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation
"helm.sh/hook-weight": "10"
"werf.io/recreate": "false"
spec:
backoffLimit: 1
activeDeadlineSeconds: 600
template:
metadata:
name: migrate
spec:
restartPolicy: Never
containers:
- name: main
image: ubuntu:18.04
command: [ "/bin/bash", "-lec", "for i in {1..3}; do date; sleep 1; done" ]
restartPolicy: Never
containers:
- name: main
image: ubuntu:18.04
command: [ "/bin/bash", "-lec", "for i in {1..3}; do date; sleep 1; done" ]
29 changes: 23 additions & 6 deletions integration/helmhooksdeleter/suite_test.go
Expand Up @@ -63,7 +63,7 @@ var _ = Describe("Helm hooks deleter", func() {
}, 120)
})

Context("when releasing a chart containing a hook with before-hook-creation delete policy and the hook already exists in the cluster before release", func() {
Context("when releasing a chart containing a hook with before-hook-creation delete policy", func() {
var namespace, projectName string

BeforeEach(func() {
Expand All @@ -80,18 +80,35 @@ var _ = Describe("Helm hooks deleter", func() {
})

It("should create hook on release install, delete hook on next release upgrade due to before-hook-creation delete policy", func(done Done) {
jobName := "migrate"
hookName := "myhook"

Expect(werfDeploy("app2", werfexec.CommandOptions{})).Should(Succeed())

jobAfterInstall, err := kube.Kubernetes.BatchV1().Jobs(namespace).Get(jobName, metav1.GetOptions{})
hookObj, err := kube.Kubernetes.CoreV1().Pods(namespace).Get(hookName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

delete(hookObj.Annotations, "service.werf.io/owner-release")
newHookObj, err := kube.Kubernetes.CoreV1().Pods(namespace).Update(hookObj)
Expect(err).NotTo(HaveOccurred())
Expect(newHookObj.Annotations["service.werf.io/owner-release"]).To(BeEmpty())
hookObj = newHookObj

gotDeletingHookLine := false
// Update release, hook should be deleted by before-hook-creation policy and created again
Expect(werfDeploy("app2", werfexec.CommandOptions{})).Should(Succeed())
jobAfterUpdate, err := kube.Kubernetes.BatchV1().Jobs(namespace).Get(jobName, metav1.GetOptions{})
Expect(werfDeploy("app2", werfexec.CommandOptions{
OutputLineHandler: func(line string) {
Expect(strings.HasPrefix(line, "│ NOTICE Will not delete Pod/myhook: resource does not belong to the helm release")).ShouldNot(BeTrue(), fmt.Sprintf("Got unexpected output line: %v", line))

if strings.HasPrefix(line, "│ Deleting resource Pod/myhook from release") {
gotDeletingHookLine = true
}
},
})).Should(Succeed())
Expect(gotDeletingHookLine).Should(BeTrue())

newHookObj, err = kube.Kubernetes.CoreV1().Pods(namespace).Get(hookName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(jobAfterUpdate.UID).NotTo(Equal(jobAfterInstall.UID))
Expect(newHookObj.UID).NotTo(Equal(hookObj.UID))

close(done)
}, 120)
Expand Down

0 comments on commit 1421c5a

Please sign in to comment.