@@ -12,13 +12,21 @@ import (
12
12
13
13
admissionv1 "k8s.io/api/admission/v1"
14
14
appsv1 "k8s.io/api/apps/v1"
15
+ "k8s.io/apimachinery/pkg/types"
16
+ "k8s.io/klog/v2"
15
17
"sigs.k8s.io/controller-runtime/pkg/manager"
16
18
"sigs.k8s.io/controller-runtime/pkg/webhook"
17
19
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
18
20
19
21
"go.goms.io/fleet/pkg/utils"
20
22
)
21
23
24
+ const (
25
+ deniedReplicaSetResource = "ReplicaSet creation is disallowed in the fleet hub cluster"
26
+ allowedReplicaSetResource = "ReplicaSet creation is allowed in the fleet hub cluster"
27
+ replicaSetDeniedFormat = "ReplicaSet %s/%s creation is disallowed in the fleet hub cluster."
28
+ )
29
+
22
30
var (
23
31
// ValidationPath is the webhook service path which admission requests are routed to for validating ReplicaSet resources.
24
32
ValidationPath = fmt .Sprintf (utils .ValidationPathFmt , appsv1 .SchemeGroupVersion .Group , appsv1 .SchemeGroupVersion .Version , "replicaset" )
@@ -37,14 +45,18 @@ func Add(mgr manager.Manager) error {
37
45
38
46
// Handle replicaSetValidator denies all creation requests.
39
47
func (v * replicaSetValidator ) Handle (_ context.Context , req admission.Request ) admission.Response {
48
+ namespacedName := types.NamespacedName {Name : req .Name , Namespace : req .Namespace }
40
49
if req .Operation == admissionv1 .Create {
50
+ klog .V (2 ).InfoS ("handling replicaSet resource" , "operation" , req .Operation , "subResource" , req .SubResource , "namespacedName" , namespacedName )
41
51
rs := & appsv1.ReplicaSet {}
42
52
if err := v .decoder .Decode (req , rs ); err != nil {
43
53
return admission .Errored (http .StatusBadRequest , err )
44
54
}
45
55
if ! utils .IsReservedNamespace (rs .Namespace ) {
46
- return admission .Denied (fmt .Sprintf ("ReplicaSet %s/%s creation is disallowed in the fleet hub cluster." , rs .Namespace , rs .Name ))
56
+ klog .V (2 ).InfoS (deniedReplicaSetResource , "user" , req .UserInfo .Username , "groups" , req .UserInfo .Groups , "operation" , req .Operation , "GVK" , req .RequestKind , "subResource" , req .SubResource , "namespacedName" , namespacedName )
57
+ return admission .Denied (fmt .Sprintf (replicaSetDeniedFormat , rs .Namespace , rs .Name ))
47
58
}
48
59
}
60
+ klog .V (3 ).InfoS (allowedReplicaSetResource , "user" , req .UserInfo .Username , "groups" , req .UserInfo .Groups , "operation" , req .Operation , "GVK" , req .RequestKind , "subResource" , req .SubResource , "namespacedName" , namespacedName )
49
61
return admission .Allowed ("" )
50
62
}
0 commit comments