mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-21 18:11:22 +00:00
Plumb context to admission Admit/Validate
This commit is contained in:
@@ -177,7 +177,7 @@ func (r *RollbackREST) Create(ctx context.Context, name string, obj runtime.Obje
|
||||
}
|
||||
|
||||
if createValidation != nil {
|
||||
if err := createValidation(obj.DeepCopyObject()); err != nil {
|
||||
if err := createValidation(ctx, obj.DeepCopyObject()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -320,17 +320,17 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
|
||||
}
|
||||
|
||||
func toScaleCreateValidation(f rest.ValidateObjectFunc) rest.ValidateObjectFunc {
|
||||
return func(obj runtime.Object) error {
|
||||
return func(ctx context.Context, obj runtime.Object) error {
|
||||
scale, err := scaleFromDeployment(obj.(*apps.Deployment))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return f(scale)
|
||||
return f(ctx, scale)
|
||||
}
|
||||
}
|
||||
|
||||
func toScaleUpdateValidation(f rest.ValidateObjectUpdateFunc) rest.ValidateObjectUpdateFunc {
|
||||
return func(obj, old runtime.Object) error {
|
||||
return func(ctx context.Context, obj, old runtime.Object) error {
|
||||
newScale, err := scaleFromDeployment(obj.(*apps.Deployment))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -339,7 +339,7 @@ func toScaleUpdateValidation(f rest.ValidateObjectUpdateFunc) rest.ValidateObjec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return f(newScale, oldScale)
|
||||
return f(ctx, newScale, oldScale)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@@ -394,7 +395,7 @@ func TestCreateDeploymentRollbackValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
validationError := fmt.Errorf("admission deny")
|
||||
alwaysDenyValidationFunc := func(obj runtime.Object) error { return validationError }
|
||||
alwaysDenyValidationFunc := func(ctx context.Context, obj runtime.Object) error { return validationError }
|
||||
_, err := rollbackStorage.Create(ctx, rollback.Name, &rollback, alwaysDenyValidationFunc, &metav1.CreateOptions{})
|
||||
|
||||
if err == nil || validationError != err {
|
||||
|
@@ -225,17 +225,17 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
|
||||
}
|
||||
|
||||
func toScaleCreateValidation(f rest.ValidateObjectFunc) rest.ValidateObjectFunc {
|
||||
return func(obj runtime.Object) error {
|
||||
return func(ctx context.Context, obj runtime.Object) error {
|
||||
scale, err := scaleFromReplicaSet(obj.(*apps.ReplicaSet))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return f(scale)
|
||||
return f(ctx, scale)
|
||||
}
|
||||
}
|
||||
|
||||
func toScaleUpdateValidation(f rest.ValidateObjectUpdateFunc) rest.ValidateObjectUpdateFunc {
|
||||
return func(obj, old runtime.Object) error {
|
||||
return func(ctx context.Context, obj, old runtime.Object) error {
|
||||
newScale, err := scaleFromReplicaSet(obj.(*apps.ReplicaSet))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -244,7 +244,7 @@ func toScaleUpdateValidation(f rest.ValidateObjectUpdateFunc) rest.ValidateObjec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return f(newScale, oldScale)
|
||||
return f(ctx, newScale, oldScale)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -212,17 +212,17 @@ func (r *ScaleREST) Update(ctx context.Context, name string, objInfo rest.Update
|
||||
}
|
||||
|
||||
func toScaleCreateValidation(f rest.ValidateObjectFunc) rest.ValidateObjectFunc {
|
||||
return func(obj runtime.Object) error {
|
||||
return func(ctx context.Context, obj runtime.Object) error {
|
||||
scale, err := scaleFromStatefulSet(obj.(*apps.StatefulSet))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return f(scale)
|
||||
return f(ctx, scale)
|
||||
}
|
||||
}
|
||||
|
||||
func toScaleUpdateValidation(f rest.ValidateObjectUpdateFunc) rest.ValidateObjectUpdateFunc {
|
||||
return func(obj, old runtime.Object) error {
|
||||
return func(ctx context.Context, obj, old runtime.Object) error {
|
||||
newScale, err := scaleFromStatefulSet(obj.(*apps.StatefulSet))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -231,7 +231,7 @@ func toScaleUpdateValidation(f rest.ValidateObjectUpdateFunc) rest.ValidateObjec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return f(newScale, oldScale)
|
||||
return f(ctx, newScale, oldScale)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user