Remove BPA from Makefile
[icn.git] / cmd / bpa-operator / vendor / sigs.k8s.io / controller-runtime / pkg / client / split.go
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 client
18
19 import (
20         "context"
21
22         "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
23         "k8s.io/apimachinery/pkg/runtime"
24 )
25
26 // DelegatingClient forms an interface Client by composing separate
27 // reader, writer and statusclient interfaces.  This way, you can have an Client that
28 // reads from a cache and writes to the API server.
29 type DelegatingClient struct {
30         Reader
31         Writer
32         StatusClient
33 }
34
35 // DelegatingReader forms a interface Reader that will cause Get and List
36 // requests for unstructured types to use the ClientReader while
37 // requests for any other type of object with use the CacheReader.
38 type DelegatingReader struct {
39         CacheReader  Reader
40         ClientReader Reader
41 }
42
43 // Get retrieves an obj for a given object key from the Kubernetes Cluster.
44 func (d *DelegatingReader) Get(ctx context.Context, key ObjectKey, obj runtime.Object) error {
45         _, isUnstructured := obj.(*unstructured.Unstructured)
46         if isUnstructured {
47                 return d.ClientReader.Get(ctx, key, obj)
48         }
49         return d.CacheReader.Get(ctx, key, obj)
50 }
51
52 // List retrieves list of objects for a given namespace and list options.
53 func (d *DelegatingReader) List(ctx context.Context, opts *ListOptions, list runtime.Object) error {
54         _, isUnstructured := list.(*unstructured.UnstructuredList)
55         if isUnstructured {
56                 return d.ClientReader.List(ctx, opts, list)
57         }
58         return d.CacheReader.List(ctx, opts, list)
59 }