Skip to content

Commit 4aaa04d

Browse files
feat: allow collaset to create privileged container (#328)
* feat: support allow privileged * add e2e * move parameter to webhook * add * add * add * add * fix e2e * fix e2e * fix e2e
1 parent 120f377 commit 4aaa04d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pkg/webhook/server/generic/collaset/collaset_validating_handler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"k8s.io/apimachinery/pkg/util/sets"
2525
"k8s.io/kubernetes/pkg/apis/core"
26+
"k8s.io/kubernetes/pkg/capabilities"
2627

2728
admissionv1 "k8s.io/api/admission/v1"
2829
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -48,6 +49,11 @@ type ValidatingHandler struct {
4849
}
4950

5051
func NewValidatingHandler() *ValidatingHandler {
52+
// Validating webhook allows to create privileged containers, this will only work if api-server is started with --allow-privileged=true.
53+
capabilities.Initialize(capabilities.Capabilities{
54+
AllowPrivileged: true,
55+
})
56+
5157
return &ValidatingHandler{
5258
WebhookHandlerMixin: mixin.NewWebhookHandlerMixin(),
5359
}

test/e2e/apps/collaset.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,29 @@ var _ = SIGDescribe("CollaSet", func() {
6262
randStr = rand.String(10)
6363
})
6464

65+
framework.KusionstackDescribe("CollaSet Basics", func() {
66+
framework.ConformanceIt("create privileged container", func() {
67+
cls := tester.NewCollaSet("collaset-"+randStr, 3, appsv1alpha1.UpdateStrategy{})
68+
// create container with privileged
69+
privileged := true
70+
cls.Spec.Template.Spec.Containers[0].SecurityContext = &v1.SecurityContext{
71+
Privileged: &privileged,
72+
}
73+
Expect(tester.CreateCollaSet(cls)).NotTo(HaveOccurred())
74+
75+
By("Wait for status replicas satisfied")
76+
Eventually(func() error { return tester.ExpectedStatusReplicas(cls, 3, 3, 3, 3, 3) }, 30*time.Second, 3*time.Second).ShouldNot(HaveOccurred())
77+
78+
By("Check container[0].securityContext.privileged")
79+
pods, err := tester.ListPodsForCollaSet(cls)
80+
Expect(err).NotTo(HaveOccurred())
81+
for i := range pods {
82+
privileged := pods[i].Spec.Containers[0].SecurityContext.Privileged
83+
Expect(*privileged).Should(BeTrue())
84+
}
85+
})
86+
})
87+
6588
framework.KusionstackDescribe("CollaSet Scaling", func() {
6689

6790
framework.ConformanceIt("scales in normal cases", func() {

0 commit comments

Comments
 (0)