Skip to content

Commit 926086e

Browse files
Merge pull request #18782 from coreydaley/bugzilla_1549832_cannot_delete_builds_in_namespace
Automatic merge from submit-queue. Fixes: cannot prune builds on buildConfig change
2 parents 1f02cb5 + 9e43bc5 commit 926086e

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

pkg/cmd/server/bootstrappolicy/controller_policy.go

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func init() {
120120
Rules: []rbac.PolicyRule{
121121
rbac.NewRule("get", "list", "watch").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs").RuleOrDie(),
122122
rbac.NewRule("create").Groups(buildGroup, legacyBuildGroup).Resources("buildconfigs/instantiate").RuleOrDie(),
123+
rbac.NewRule("delete").Groups(buildGroup, legacyBuildGroup).Resources("builds").RuleOrDie(),
123124
eventsRule(),
124125
},
125126
})

test/extended/builds/build_pruning.go

+51
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,57 @@ var _ = g.Describe("[Feature:Builds][pruning] prune builds based on settings in
240240

241241
})
242242

243+
g.It("should prune builds after a buildConfig change", func() {
244+
245+
g.By("creating test failed build config")
246+
err := oc.Run("create").Args("-f", failedBuildConfig).Execute()
247+
o.Expect(err).NotTo(o.HaveOccurred())
248+
249+
g.By("patching the build config to leave 5 builds")
250+
err = oc.Run("patch").Args("bc/myphp", "-p", `{"spec":{"failedBuildsHistoryLimit": 5}}`).Execute()
251+
252+
g.By("starting and canceling three test builds")
253+
for i := 1; i < 4; i++ {
254+
_, _, _ = exutil.StartBuild(oc, "myphp")
255+
err = oc.Run("cancel-build").Args(fmt.Sprintf("myphp-%d", i)).Execute()
256+
}
257+
258+
g.By("patching the build config to leave 1 build")
259+
err = oc.Run("patch").Args("bc/myphp", "-p", `{"spec":{"failedBuildsHistoryLimit": 1}}`).Execute()
260+
261+
buildConfig, err := oc.BuildClient().Build().BuildConfigs(oc.Namespace()).Get("myphp", metav1.GetOptions{})
262+
if err != nil {
263+
fmt.Fprintf(g.GinkgoWriter, "%v", err)
264+
}
265+
266+
var builds *buildapi.BuildList
267+
268+
g.By("waiting up to one minute for pruning to complete")
269+
err = wait.PollImmediate(pollingInterval, timeout, func() (bool, error) {
270+
builds, err = oc.BuildClient().Build().Builds(oc.Namespace()).List(metav1.ListOptions{})
271+
if err != nil {
272+
fmt.Fprintf(g.GinkgoWriter, "%v", err)
273+
return false, err
274+
}
275+
if int32(len(builds.Items)) == *buildConfig.Spec.FailedBuildsHistoryLimit {
276+
fmt.Fprintf(g.GinkgoWriter, "%v builds exist, retrying...", len(builds.Items))
277+
return true, nil
278+
}
279+
return false, nil
280+
})
281+
282+
if err != nil {
283+
fmt.Fprintf(g.GinkgoWriter, "%v", err)
284+
}
285+
286+
passed := false
287+
if int32(len(builds.Items)) == 1 || int32(len(builds.Items)) == 2 {
288+
passed = true
289+
}
290+
o.Expect(passed).To(o.BeTrue(), "there should be 1-2 completed builds left after pruning, but instead there were %v", len(builds.Items))
291+
292+
})
293+
243294
g.It("[Conformance] buildconfigs should have a default history limit set when created via the group api", func() {
244295

245296
g.By("creating a build config with the group api")

test/testdata/bootstrappolicy/bootstrap_cluster_roles.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -2710,6 +2710,13 @@ items:
27102710
- buildconfigs/instantiate
27112711
verbs:
27122712
- create
2713+
- apiGroups:
2714+
- ""
2715+
- build.openshift.io
2716+
resources:
2717+
- builds
2718+
verbs:
2719+
- delete
27132720
- apiGroups:
27142721
- ""
27152722
resources:

test/testdata/bootstrappolicy/bootstrap_policy_file.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -2962,6 +2962,14 @@ items:
29622962
- buildconfigs/instantiate
29632963
verbs:
29642964
- create
2965+
- apiGroups:
2966+
- ""
2967+
- build.openshift.io
2968+
attributeRestrictions: null
2969+
resources:
2970+
- builds
2971+
verbs:
2972+
- delete
29652973
- apiGroups:
29662974
- ""
29672975
attributeRestrictions: null

0 commit comments

Comments
 (0)