yangwwei commented on a change in pull request #81: [YUNIKORN-28] Support
validating yunikorn-configs before admitting it
URL:
https://github.com/apache/incubator-yunikorn-k8shim/pull/81#discussion_r390612743
##########
File path: pkg/plugin/admissioncontrollers/webhook/admission_controller.go
##########
@@ -167,6 +169,53 @@ func updateLabels(pod *v1.Pod, patch []patchOperation)
[]patchOperation {
return patch
}
+func (c *admissionController) validateConf(ar *v1beta1.AdmissionReview)
*v1beta1.AdmissionResponse {
+ req := ar.Request
+ log.Logger.Info("AdmissionReview",
+ zap.Any("Kind", req.Kind),
+ zap.String("Namespace", req.Namespace),
+ zap.String("UID", string(req.UID)),
+ zap.String("Operation", string(req.Operation)),
+ zap.Any("UserInfo", req.UserInfo))
+
+ if req.Kind.Kind == "ConfigMap" {
+ var configmap v1.ConfigMap
+ if err := json.Unmarshal(req.Object.Raw, &configmap); err !=
nil {
+ return &v1beta1.AdmissionResponse{
+ Result: &metav1.Status{
+ Message: err.Error(),
+ },
+ }
+ }
+ // validate new/updated config map
+ if err := c.validateConfigMap(&configmap); err != nil {
+ return &v1beta1.AdmissionResponse{
+ Result: &metav1.Status{
+ Message: err.Error(),
Review comment:
I think we should explicitly call the following while rejecting the request:
```
return &v1beta1.AdmissionResponse{
Allowed: false,
Result: &metav1.Status{
Reason: metav1.StatusReasonInvalid,
Message: err.Error(),
},
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]