forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaluefrom.go
135 lines (104 loc) · 5.75 KB
/
valuefrom.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
129
130
131
132
133
134
135
package builds
import (
"path/filepath"
"strings"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
exutil "github.com/openshift/origin/test/extended/util"
)
var _ = g.Describe("[Feature:Builds][Conformance][valueFrom] process valueFrom in build strategy environment variables", func() {
var (
valueFromBaseDir = exutil.FixturePath("testdata", "builds", "valuefrom")
testImageStreamFixture = filepath.Join(valueFromBaseDir, "test-is.json")
secretFixture = filepath.Join(valueFromBaseDir, "test-secret.yaml")
configmapFixture = filepath.Join(valueFromBaseDir, "test-configmap.yaml")
successfulSTIBuildValueFrom = filepath.Join(valueFromBaseDir, "successful-sti-build-value-from-config.yaml")
successfulDockerBuildValueFrom = filepath.Join(valueFromBaseDir, "successful-docker-build-value-from-config.yaml")
failedSTIBuildValueFrom = filepath.Join(valueFromBaseDir, "failed-sti-build-value-from-config.yaml")
failedDockerBuildValueFrom = filepath.Join(valueFromBaseDir, "failed-docker-build-value-from-config.yaml")
oc = exutil.NewCLI("build-valuefrom", exutil.KubeConfigPath())
)
g.Context("", func() {
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("", oc)
}
})
g.JustBeforeEach(func() {
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeClient().Core().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for openshift namespace imagestreams")
err = exutil.WaitForOpenShiftNamespaceImageStreams(oc)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("creating test image stream")
err = oc.Run("create").Args("-f", testImageStreamFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("creating test secret")
err = oc.Run("create").Args("-f", secretFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("creating test configmap")
err = oc.Run("create").Args("-f", configmapFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
})
g.It("should successfully resolve valueFrom in s2i build environment variables", func() {
g.By("creating test successful build config")
err := oc.Run("create").Args("-f", successfulSTIBuildValueFrom).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting test build")
br, err := exutil.StartBuildAndWait(oc, "mys2itest")
o.Expect(err).NotTo(o.HaveOccurred())
br.AssertSuccess()
logs, _ := br.Logs()
o.Expect(logs).To(o.ContainSubstring("FIELDREF_ENV=mys2itest-1"))
o.Expect(logs).To(o.ContainSubstring("CONFIGMAPKEYREF_ENV=myvalue"))
o.Expect(logs).To(o.ContainSubstring("SECRETKEYREF_ENV=developer"))
o.Expect(logs).To(o.ContainSubstring("FIELDREF_CLONE_ENV=mys2itest-1"))
o.Expect(logs).To(o.ContainSubstring("FIELDREF_CLONE_CLONE_ENV=mys2itest-1"))
o.Expect(logs).To(o.ContainSubstring("UNAVAILABLE_ENV=$(SOME_OTHER_ENV"))
o.Expect(logs).To(o.ContainSubstring("ESCAPED_ENV=$(MY_ESCAPED_VALUE)"))
})
g.It("should successfully resolve valueFrom in docker build environment variables", func() {
g.By("creating test successful build config")
err := oc.Run("create").Args("-f", successfulDockerBuildValueFrom).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting test build")
br, err := exutil.StartBuildAndWait(oc, "mydockertest")
o.Expect(err).NotTo(o.HaveOccurred())
br.AssertSuccess()
logs, _ := br.Logs()
o.Expect(logs).To(o.ContainSubstring("\"FIELDREF_ENV\" \"mydockertest-1\""))
o.Expect(logs).To(o.ContainSubstring("\"CONFIGMAPKEYREF_ENV\" \"myvalue\""))
o.Expect(logs).To(o.ContainSubstring("\"SECRETKEYREF_ENV\" \"developer\""))
o.Expect(logs).To(o.ContainSubstring("\"FIELDREF_CLONE_ENV\" \"mydockertest-1\""))
o.Expect(logs).To(o.ContainSubstring("\"FIELDREF_CLONE_CLONE_ENV\" \"mydockertest-1\""))
o.Expect(logs).To(o.ContainSubstring("\"UNAVAILABLE_ENV\" \"$(SOME_OTHER_ENV)\""))
o.Expect(logs).To(o.ContainSubstring("\"ESCAPED_ENV\" \"$(MY_ESCAPED_VALUE)\""))
})
g.It("should fail resolving unresolvable valueFrom in sti build environment variable references", func() {
g.By("creating test build config")
err := oc.Run("create").Args("-f", failedSTIBuildValueFrom).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting test build")
br, _ := exutil.StartBuildAndWait(oc, "mys2itest")
br.AssertFailure()
o.Expect(strings.Contains(string(br.Build.Status.Reason), "UnresolvableEnvironmentVariable")).To(o.BeTrue())
o.Expect(strings.Contains(br.Build.Status.Message, "unsupported fieldPath: metadata.nofield")).To(o.BeTrue())
o.Expect(strings.Contains(br.Build.Status.Message, "key nokey not found in config map myconfigmap")).To(o.BeTrue())
o.Expect(strings.Contains(br.Build.Status.Message, "key nousername not found in secret mysecret")).To(o.BeTrue())
})
g.It("should fail resolving unresolvable valueFrom in docker build environment variable references", func() {
g.By("creating test build config")
err := oc.Run("create").Args("-f", failedDockerBuildValueFrom).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting test build")
br, _ := exutil.StartBuildAndWait(oc, "mydockertest")
br.AssertFailure()
o.Expect(strings.Contains(string(br.Build.Status.Reason), "UnresolvableEnvironmentVariable")).To(o.BeTrue())
o.Expect(strings.Contains(br.Build.Status.Message, "unsupported fieldPath: metadata.nofield")).To(o.BeTrue())
o.Expect(strings.Contains(br.Build.Status.Message, "key nokey not found in config map myconfigmap")).To(o.BeTrue())
o.Expect(strings.Contains(br.Build.Status.Message, "key nousername not found in secret mysecret")).To(o.BeTrue())
})
})
})