-
Notifications
You must be signed in to change notification settings - Fork 101
/
helm_test.go
128 lines (111 loc) · 2.93 KB
/
helm_test.go
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
// Copyright 2020 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
package e2e
import (
"fmt"
"reflect"
"strings"
"testing"
"github.com/ghodss/yaml"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/k14s/kapp-controller/pkg/apis/kappctrl/v1alpha1"
)
func TestHelm(t *testing.T) {
env := BuildEnv(t)
logger := Logger{}
kapp := Kapp{t, env.Namespace, logger}
sas := ServiceAccounts{env.Namespace}
yaml1 := fmt.Sprintf(`
apiVersion: kappctrl.k14s.io/v1alpha1
kind: App
metadata:
name: test-helm
annotations:
kapp.k14s.io/change-group: kappctrl-e2e.k14s.io/apps
spec:
serviceAccountName: kappctrl-e2e-ns-sa
fetch:
- helmChart:
name: stable/redis
template:
- helmTemplate:
valuesFrom:
- secretRef:
name: test-helm-values
deploy:
- kapp:
intoNs: %s
delete:
rawOptions: ["--apply-ignored=true"]
---
apiVersion: v1
kind: Secret
metadata:
name: test-helm-values
stringData:
data.yml: |
password: "1234567891234"
`, env.Namespace)+sas.ForNamespaceYAML()
name := "test-helm"
cleanUp := func() {
kapp.Run([]string{"delete", "-a", name})
}
cleanUp()
defer cleanUp()
logger.Section("deploy", func() {
kapp.RunWithOpts([]string{"deploy", "-f", "-", "-a", name},
RunOpts{IntoNs: true, StdinReader: strings.NewReader(yaml1)})
out := kapp.Run([]string{"inspect", "-a", name, "--raw", "--tty=false", "--filter-kind=App"})
var cr v1alpha1.App
err := yaml.Unmarshal([]byte(out), &cr)
if err != nil {
t.Fatalf("Failed to unmarshal: %s", err)
}
expectedStatus := v1alpha1.AppStatus{
Conditions: []v1alpha1.AppCondition{{
Type: v1alpha1.ReconcileSucceeded,
Status: corev1.ConditionTrue,
}},
Deploy: &v1alpha1.AppStatusDeploy{
ExitCode: 0,
Finished: true,
},
Fetch: &v1alpha1.AppStatusFetch{
ExitCode: 0,
},
Inspect: &v1alpha1.AppStatusInspect{
ExitCode: 0,
},
Template: &v1alpha1.AppStatusTemplate{
ExitCode: 0,
},
ObservedGeneration: 1,
FriendlyDescription: "Reconcile succeeded",
}
{
// deploy
if !strings.Contains(cr.Status.Deploy.Stdout, "Wait to:") {
t.Fatalf("Expected non-empty deploy output: '%s'", cr.Status.Deploy.Stdout)
}
cr.Status.Deploy.StartedAt = metav1.Time{}
cr.Status.Deploy.UpdatedAt = metav1.Time{}
cr.Status.Deploy.Stdout = ""
// fetch
cr.Status.Fetch.StartedAt = metav1.Time{}
cr.Status.Fetch.UpdatedAt = metav1.Time{}
// inspect
if !strings.Contains(cr.Status.Inspect.Stdout, "Resources in app 'test-helm-ctrl'") {
t.Fatalf("Expected non-empty inspect output: '%s'", cr.Status.Inspect.Stdout)
}
cr.Status.Inspect.UpdatedAt = metav1.Time{}
cr.Status.Inspect.Stdout = ""
// template
cr.Status.Template.UpdatedAt = metav1.Time{}
cr.Status.Template.Stderr = ""
}
if !reflect.DeepEqual(expectedStatus, cr.Status) {
t.Fatalf("Status is not same: %#v vs %#v", expectedStatus, cr.Status)
}
})
}