k8s.io/kubernetes@v1.29.3/test/images/agnhost/webhook/alwaysallow.go (about)

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