...

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

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

     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 reconcile_test
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"time"
    23  
    24  	"k8s.io/apimachinery/pkg/types"
    25  	"sigs.k8s.io/controller-runtime/pkg/reconcile"
    26  )
    27  
    28  // This example implements a simple no-op reconcile function that prints the object to be Reconciled.
    29  func ExampleFunc() {
    30  	r := reconcile.Func(func(_ context.Context, o reconcile.Request) (reconcile.Result, error) {
    31  		// Create your business logic to create, update, delete objects here.
    32  		fmt.Printf("Name: %s, Namespace: %s", o.Name, o.Namespace)
    33  		return reconcile.Result{}, nil
    34  	})
    35  
    36  	res, err := r.Reconcile(context.Background(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: "default", Name: "test"}})
    37  	if err != nil || res.Requeue || res.RequeueAfter != time.Duration(0) {
    38  		fmt.Printf("got requeue request: %v, %v\n", err, res)
    39  	}
    40  
    41  	// Output: Name: test, Namespace: default
    42  }
    43  

View as plain text