alwaysallow.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package main
  14. import (
  15. "time"
  16. "k8s.io/api/admission/v1beta1"
  17. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  18. "k8s.io/klog"
  19. )
  20. // alwaysAllowDelayFiveSeconds sleeps for five seconds and allows all requests made to this function.
  21. func alwaysAllowDelayFiveSeconds(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
  22. klog.V(2).Info("always-allow-with-delay sleeping for 5 seconds")
  23. time.Sleep(5 * time.Second)
  24. klog.V(2).Info("calling always-allow")
  25. reviewResponse := v1beta1.AdmissionResponse{}
  26. reviewResponse.Allowed = true
  27. reviewResponse.Result = &metav1.Status{Message: "this webhook allows all requests"}
  28. return &reviewResponse
  29. }