1 // Copyright 2020 The Kubernetes Authors. 2 // SPDX-License-Identifier: Apache-2.0 3 4 package engine 5 6 import ( 7 "context" 8 9 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 10 "k8s.io/apimachinery/pkg/labels" 11 "sigs.k8s.io/controller-runtime/pkg/client" 12 ) 13 14 // ClusterReader is the interface provided to the statusReaders to talk to the cluster. Implementations 15 // of this interface allows different caching strategies, for example by pre-fetching resources using 16 // LIST calls rather than letting each engine run multiple GET calls against the cluster. This can 17 // significantly reduce the number of requests. 18 type ClusterReader interface { 19 // Get looks up the resource identifier by the key and the GVK in the provided obj reference. If something 20 // goes wrong or the resource doesn't exist, an error is returned. 21 Get(ctx context.Context, key client.ObjectKey, obj *unstructured.Unstructured) error 22 // ListNamespaceScoped looks up the resources of the GVK given in the list and matches the namespace and 23 // selector provided. 24 ListNamespaceScoped(ctx context.Context, list *unstructured.UnstructuredList, 25 namespace string, selector labels.Selector) error 26 // ListClusterScoped looks up the resources of the GVK given in the list and that matches the selector 27 // provided. 28 ListClusterScoped(ctx context.Context, list *unstructured.UnstructuredList, selector labels.Selector) error 29 // Sync is called by the engine before every polling loop, which provides an opportunity for the Reader 30 // to sync caches. 31 Sync(ctx context.Context) error 32 } 33