...

Source file src/sigs.k8s.io/controller-runtime/pkg/builder/example_webhook_test.go

Documentation: sigs.k8s.io/controller-runtime/pkg/builder

     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 builder_test
    18  
    19  import (
    20  	"os"
    21  
    22  	"sigs.k8s.io/controller-runtime/pkg/builder"
    23  	"sigs.k8s.io/controller-runtime/pkg/client/config"
    24  	logf "sigs.k8s.io/controller-runtime/pkg/log"
    25  	"sigs.k8s.io/controller-runtime/pkg/manager"
    26  	"sigs.k8s.io/controller-runtime/pkg/manager/signals"
    27  
    28  	examplegroup "sigs.k8s.io/controller-runtime/examples/crd/pkg"
    29  )
    30  
    31  // This example use webhook builder to create a simple webhook that is managed
    32  // by a manager for CRD ChaosPod. And then start the manager.
    33  func ExampleWebhookBuilder() {
    34  	var log = logf.Log.WithName("webhookbuilder-example")
    35  
    36  	mgr, err := manager.New(config.GetConfigOrDie(), manager.Options{})
    37  	if err != nil {
    38  		log.Error(err, "could not create manager")
    39  		os.Exit(1)
    40  	}
    41  
    42  	err = builder.
    43  		WebhookManagedBy(mgr).         // Create the WebhookManagedBy
    44  		For(&examplegroup.ChaosPod{}). // ChaosPod is a CRD.
    45  		Complete()
    46  	if err != nil {
    47  		log.Error(err, "could not create webhook")
    48  		os.Exit(1)
    49  	}
    50  
    51  	if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
    52  		log.Error(err, "could not start manager")
    53  		os.Exit(1)
    54  	}
    55  }
    56  

View as plain text