forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_pruning.go
185 lines (141 loc) · 7.54 KB
/
build_pruning.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
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
package builds
import (
"fmt"
"path/filepath"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
exutil "github.com/openshift/origin/test/extended/util"
)
var _ = g.Describe("[builds][pruning] prune builds based on settings in the buildconfig", func() {
var (
buildPruningBaseDir = exutil.FixturePath("testdata", "build-pruning")
isFixture = filepath.Join(buildPruningBaseDir, "imagestream.yaml")
successfulBuildConfig = filepath.Join(buildPruningBaseDir, "successful-build-config.yaml")
failedBuildConfig = filepath.Join(buildPruningBaseDir, "failed-build-config.yaml")
erroredBuildConfig = filepath.Join(buildPruningBaseDir, "errored-build-config.yaml")
legacyBuildConfig = filepath.Join(buildPruningBaseDir, "default-legacy-build-config.yaml")
groupBuildConfig = filepath.Join(buildPruningBaseDir, "default-group-build-config.yaml")
oc = exutil.NewCLI("build-pruning", exutil.KubeConfigPath())
)
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", isFixture).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
})
g.It("should prune completed builds based on the successfulBuildsHistoryLimit setting", func() {
g.By("creating test successful build config")
err := oc.Run("create").Args("-f", successfulBuildConfig).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting three test builds")
br, _ := exutil.StartBuildAndWait(oc, "myphp")
br.AssertSuccess()
br, _ = exutil.StartBuildAndWait(oc, "myphp")
br.AssertSuccess()
br, _ = exutil.StartBuildAndWait(oc, "myphp")
br.AssertSuccess()
buildConfig, err := oc.Client().BuildConfigs(oc.Namespace()).Get("myphp", metav1.GetOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
builds, err := oc.Client().Builds(oc.Namespace()).List(metav1.ListOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
o.Expect(int32(len(builds.Items))).To(o.Equal(*buildConfig.Spec.SuccessfulBuildsHistoryLimit), "there should be %v completed builds left after pruning, but instead there were %v", *buildConfig.Spec.SuccessfulBuildsHistoryLimit, len(builds.Items))
})
g.It("should prune failed builds based on the failedBuildsHistoryLimit setting", func() {
g.By("creating test failed build config")
err := oc.Run("create").Args("-f", failedBuildConfig).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting three test builds")
br, _ := exutil.StartBuildAndWait(oc, "myphp")
br.AssertFailure()
br, _ = exutil.StartBuildAndWait(oc, "myphp")
br.AssertFailure()
br, _ = exutil.StartBuildAndWait(oc, "myphp")
br.AssertFailure()
buildConfig, err := oc.Client().BuildConfigs(oc.Namespace()).Get("myphp", metav1.GetOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
builds, err := oc.Client().Builds(oc.Namespace()).List(metav1.ListOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
o.Expect(int32(len(builds.Items))).To(o.Equal(*buildConfig.Spec.FailedBuildsHistoryLimit), "there should be %v failed builds left after pruning, but instead there were %v", *buildConfig.Spec.FailedBuildsHistoryLimit, len(builds.Items))
})
g.It("should prune canceled builds based on the failedBuildsHistoryLimit setting", func() {
g.By("creating test successful build config")
err := oc.Run("create").Args("-f", failedBuildConfig).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting and canceling three test builds")
_, _, _ = exutil.StartBuild(oc, "myphp")
err = oc.Run("cancel-build").Args("myphp-1").Execute()
_, _, _ = exutil.StartBuild(oc, "myphp")
err = oc.Run("cancel-build").Args("myphp-2").Execute()
_, _, _ = exutil.StartBuild(oc, "myphp")
err = oc.Run("cancel-build").Args("myphp-3").Execute()
buildConfig, err := oc.Client().BuildConfigs(oc.Namespace()).Get("myphp", metav1.GetOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
builds, err := oc.Client().Builds(oc.Namespace()).List(metav1.ListOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
o.Expect(int32(len(builds.Items))).To(o.Equal(*buildConfig.Spec.FailedBuildsHistoryLimit), "there should be %v canceled builds left after pruning, but instead there were %v", *buildConfig.Spec.FailedBuildsHistoryLimit, len(builds.Items))
})
g.It("should prune errored builds based on the failedBuildsHistoryLimit setting", func() {
g.By("creating test failed build config")
err := oc.Run("create").Args("-f", erroredBuildConfig).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting three test builds")
br, _ := exutil.StartBuildAndWait(oc, "myphp")
br.AssertFailure()
br, _ = exutil.StartBuildAndWait(oc, "myphp")
br.AssertFailure()
br, _ = exutil.StartBuildAndWait(oc, "myphp")
br.AssertFailure()
buildConfig, err := oc.Client().BuildConfigs(oc.Namespace()).Get("myphp", metav1.GetOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
builds, err := oc.Client().Builds(oc.Namespace()).List(metav1.ListOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
o.Expect(int32(len(builds.Items))).To(o.Equal(*buildConfig.Spec.FailedBuildsHistoryLimit), "there should be %v failed builds left after pruning, but instead there were %v", *buildConfig.Spec.FailedBuildsHistoryLimit, len(builds.Items))
})
g.It("[Conformance] buildconfigs should have a default history limit set when created via the group api", func() {
g.By("creating a build config with the group api")
err := oc.Run("create").Args("-f", groupBuildConfig).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
buildConfig, err := oc.Client().BuildConfigs(oc.Namespace()).Get("myphp", metav1.GetOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
o.Expect(buildConfig.Spec.SuccessfulBuildsHistoryLimit).NotTo(o.BeNil(), "the buildconfig should have the default successful history limit set")
o.Expect(buildConfig.Spec.FailedBuildsHistoryLimit).NotTo(o.BeNil(), "the buildconfig should have the default failed history limit set")
o.Expect(*buildConfig.Spec.SuccessfulBuildsHistoryLimit).To(o.Equal(buildapi.DefaultSuccessfulBuildsHistoryLimit), "the buildconfig should have the default successful history limit set")
o.Expect(*buildConfig.Spec.FailedBuildsHistoryLimit).To(o.Equal(buildapi.DefaultFailedBuildsHistoryLimit), "the buildconfig should have the default failed history limit set")
})
g.It("[Conformance] buildconfigs should not have a default history limit set when created via the legacy api", func() {
g.By("creating a build config with the legacy api")
err := oc.Run("create").Args("-f", legacyBuildConfig).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
buildConfig, err := oc.Client().BuildConfigs(oc.Namespace()).Get("myphp", metav1.GetOptions{})
if err != nil {
fmt.Fprintf(g.GinkgoWriter, "%v", err)
}
o.Expect(buildConfig.Spec.SuccessfulBuildsHistoryLimit).To(o.BeNil(), "the buildconfig should not have the default successful history limit set")
o.Expect(buildConfig.Spec.FailedBuildsHistoryLimit).To(o.BeNil(), "the buildconfig should not have the default failed history limit set")
})
})