...

Source file src/sigs.k8s.io/controller-runtime/pkg/recorder/example_test.go

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

     1  /*
     2  Copyright 2018 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 recorder_test
    18  
    19  import (
    20  	corev1 "k8s.io/api/core/v1"
    21  
    22  	_ "github.com/onsi/ginkgo/v2"
    23  	"sigs.k8s.io/controller-runtime/pkg/recorder"
    24  )
    25  
    26  var (
    27  	recorderProvider recorder.Provider
    28  	somePod          *corev1.Pod // the object you're reconciling, for example
    29  )
    30  
    31  func Example_event() {
    32  	// recorderProvider is a recorder.Provider
    33  	recorder := recorderProvider.GetEventRecorderFor("my-controller")
    34  
    35  	// emit an event with a fixed message
    36  	recorder.Event(somePod, corev1.EventTypeWarning,
    37  		"WrongTrousers", "It's the wrong trousers, Gromit!")
    38  }
    39  
    40  func Example_eventf() {
    41  	// recorderProvider is a recorder.Provider
    42  	recorder := recorderProvider.GetEventRecorderFor("my-controller")
    43  
    44  	// emit an event with a variable message
    45  	mildCheese := "Wensleydale"
    46  	recorder.Eventf(somePod, corev1.EventTypeNormal,
    47  		"DislikesCheese", "Not even %s?", mildCheese)
    48  }
    49  

View as plain text