Repository navigation
Conversation
| // No error in parsing and the value is false, skip the pod. | ||
| if err == nil && !boolVal { | ||
| if err == nil && !enabled { | ||
| log.V(4).Info("pod has storageos.com/scheduler=false annotaion, skipping") |
There was a problem hiding this comment.
| log.V(4).Info("pod has storageos.com/scheduler=false annotaion, skipping") | |
| log.V(4).Infof("pod has %s=false annotaion, skipping", p.SchedulerAnnotationKey) |
Does it make sense to use the const you have defined already? I suppose there's not much chance of it changing. Really I'm just curious about whether you chose to not use the const.
There was a problem hiding this comment.
yeah, it probably does. With logr they recommend against vars in the message and encourage k=v pairs instead, but that doesn't work well here. Changed.
| namespace := req.AdmissionRequest.Namespace | ||
|
|
||
| // Create a copy of the pod to mutate. | ||
| copy := pod.DeepCopy() |
There was a problem hiding this comment.
Why do you have to create a copy of the pod as opposed to just modifying the pod object directly and sending that back?
There was a problem hiding this comment.
This code is based on https://github.com/storageos/cluster-operator/blob/v2.3.4/internal/pkg/admission/scheduler/handler.go#L64 where we used to pass the pod object to PatchResponse at the very end of the function to return a response. In the latest webhook package of controller runtime, PatchResponse is replaced with PatchResponseFromRaw which accepts the raw object in the request. So, we avoid doing a deep copy here.
There was a problem hiding this comment.
Removed the DeepCopy()
|
|
||
| ## Disabling | ||
|
|
||
| It is not possible to disable the Webhook server. Instead, disable thegla |
| Pods that have the annotation `storageos.com/scheduler=false` set are ignored. | ||
|
|
||
| The Pod's volumes are enumerated, and if at least one volume is backed by | ||
| StorageOS, the SchedulerName will be changed to use the StorageOS Pod scheduler. |
There was a problem hiding this comment.
SchedulerName should be highlighted
| The Pod Mutator is a mutating admission controller that modifies Pods during the | ||
| create process. | ||
|
|
||
| See [Namespace Delete Controller](controllers/pod-mutator/README.md) for |
There was a problem hiding this comment.
| See [Namespace Delete Controller](controllers/pod-mutator/README.md) for | |
| See [Pod Mutator Admission Controller](controllers/pod-mutator/README.md) for |
| namespace := req.AdmissionRequest.Namespace | ||
|
|
||
| // Create a copy of the pod to mutate. | ||
| copy := pod.DeepCopy() |
There was a problem hiding this comment.
This code is based on https://github.com/storageos/cluster-operator/blob/v2.3.4/internal/pkg/admission/scheduler/handler.go#L64 where we used to pass the pod object to PatchResponse at the very end of the function to return a response. In the latest webhook package of controller runtime, PatchResponse is replaced with PatchResponseFromRaw which accepts the raw object in the request. So, we avoid doing a deep copy here.
| `-scheduler-name` is the name of the scheduler extender to set in the Pod's | ||
| `SchedulerName` field. If set to an empty string, no updates will be made. When | ||
| set, the scheduler name must match the name of the scheduler extender configured | ||
| in the StorageOS cluster-operator. (default "storageos-scheduler)". |
There was a problem hiding this comment.
| in the StorageOS cluster-operator. (default "storageos-scheduler)". | |
| in the StorageOS cluster-operator. (default "storageos-scheduler"). |
| // MutatePod mutates a given pod with a configured scheduler name if the pod is | ||
| // associated with volumes managed by the configured provisioners. | ||
| // | ||
| // Errors returned here will block creation of the Pod. |
There was a problem hiding this comment.
May not be accurate. It depends on the webhook configuration if the failure is ignored or respected.
|
The implementation looks good to me. Left some inline comments about minor improvements. |
| @@ -0,0 +1,45 @@ | |||
| package controllers | |||
There was a problem hiding this comment.
In this way test related codebase looks like production code. I suggest to refactor the code to ensure test functions are only available in tests. If it is not possible a common solution to create a controllertest package for separation.
There was a problem hiding this comment.
Sorry, my bad, this package contains only tests :D
| obj.Annotations[m.key] = m.value | ||
| return nil | ||
| } | ||
| func (m testMutator) MutatePVC(ctx context.Context, obj *corev1.PersistentVolumeClaim, namespace string) error { |
a77bd31 to
1a13a94
Compare
This allows an admission controller to run multiple mutators for different tasks.
For Pod creation, this could be to add the StorageOS scheduler and to set a failure mode or failure mode label that should be applied to all of the Pod's PVCs.
This pattern will be used for PVC create where we will have separate mutators for encryption and labels.