@@ -27,6 +27,7 @@ import (
2727 "k8s.io/apimachinery/pkg/runtime"
2828 "k8s.io/apimachinery/pkg/types"
2929 "k8s.io/utils/ptr"
30+ utilmaps "sigs.k8s.io/kueue/pkg/util/maps"
3031)
3132
3233var _ = Describe ("AppWrapper Webhook Tests" , func () {
@@ -39,6 +40,16 @@ var _ = Describe("AppWrapper Webhook Tests", func() {
3940 Expect (aw .Spec .Suspend ).Should (BeTrue (), "aw.Spec.Suspend should have been changed to true" )
4041 Expect (k8sClient .Delete (ctx , aw )).To (Succeed ())
4142 })
43+
44+ It ("User name and ID are set" , func () {
45+ aw := toAppWrapper (pod (100 ))
46+ aw .Labels = utilmaps .MergeKeepFirst (map [string ]string {AppWrapperUsernameLabel : "bad" , AppWrapperUserIDLabel : "bad" }, aw .Labels )
47+
48+ Expect (k8sLimitedClient .Create (ctx , aw )).To (Succeed ())
49+ Expect (aw .Labels [AppWrapperUsernameLabel ]).Should (BeIdenticalTo (limitedUserName ))
50+ Expect (aw .Labels [AppWrapperUserIDLabel ]).Should (BeIdenticalTo (limitedUserID ))
51+ Expect (k8sLimitedClient .Delete (ctx , aw )).To (Succeed ())
52+ })
4253 })
4354
4455 Context ("Validating Webhook" , func () {
@@ -128,6 +139,36 @@ var _ = Describe("AppWrapper Webhook Tests", func() {
128139 Expect (k8sClient .Create (ctx , aw )).ShouldNot (Succeed ())
129140 })
130141
142+ It ("User name and ID are immutable" , func () {
143+ aw := toAppWrapper (pod (100 ))
144+ awName := types.NamespacedName {Name : aw .Name , Namespace : aw .Namespace }
145+ Expect (k8sClient .Create (ctx , aw )).Should (Succeed ())
146+
147+ aw = getAppWrapper (awName )
148+ aw .Labels [AppWrapperUsernameLabel ] = "bad"
149+ Expect (k8sClient .Update (ctx , aw )).ShouldNot (Succeed ())
150+
151+ aw = getAppWrapper (awName )
152+ aw .Labels [AppWrapperUserIDLabel ] = "bad"
153+ Expect (k8sClient .Update (ctx , aw )).ShouldNot (Succeed ())
154+
155+ Expect (k8sClient .Delete (ctx , aw )).To (Succeed ())
156+ })
157+
158+ It ("User name and ID should be preserved on updates" , func () {
159+ aw := toAppWrapper (pod (100 ))
160+ awName := types.NamespacedName {Name : aw .Name , Namespace : aw .Namespace }
161+ Expect (k8sLimitedClient .Create (ctx , aw )).Should (Succeed ())
162+
163+ aw = getAppWrapper (awName )
164+ Expect (k8sClient .Update (ctx , aw )).Should (Succeed ())
165+
166+ aw = getAppWrapper (awName )
167+ Expect (aw .Labels [AppWrapperUsernameLabel ]).Should (BeIdenticalTo (limitedUserName ))
168+ Expect (aw .Labels [AppWrapperUserIDLabel ]).Should (BeIdenticalTo (limitedUserID ))
169+ Expect (k8sLimitedClient .Delete (ctx , aw )).To (Succeed ())
170+ })
171+
131172 Context ("aw.Spec.Components is immutable" , func () {
132173 It ("Updates to non-sensitive fields are allowed" , func () {
133174 aw := toAppWrapper (pod (100 ), deployment (4 , 100 ))
0 commit comments