...

Source file src/sigs.k8s.io/cli-utils/pkg/kstatus/polling/clusterreader/direct_reader.go

Documentation: sigs.k8s.io/cli-utils/pkg/kstatus/polling/clusterreader

     1  // Copyright 2020 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package clusterreader
     5  
     6  import (
     7  	"context"
     8  
     9  	"k8s.io/apimachinery/pkg/api/meta"
    10  	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
    11  	"k8s.io/apimachinery/pkg/labels"
    12  	"sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine"
    13  	"sigs.k8s.io/cli-utils/pkg/object"
    14  	"sigs.k8s.io/controller-runtime/pkg/client"
    15  )
    16  
    17  // NewDirectClusterReader creates a new implementation of the engine.ClusterReader interface that makes
    18  // calls directly to the cluster without any caching.
    19  func NewDirectClusterReader(reader client.Reader, _ meta.RESTMapper, _ object.ObjMetadataSet) (engine.ClusterReader, error) {
    20  	return &DirectClusterReader{
    21  		Reader: reader,
    22  	}, nil
    23  }
    24  
    25  // DirectClusterReader is an implementation of the ClusterReader that just delegates all calls directly to
    26  // the underlying clusterreader. No caching.
    27  type DirectClusterReader struct {
    28  	Reader client.Reader
    29  }
    30  
    31  func (n *DirectClusterReader) Get(ctx context.Context, key client.ObjectKey, obj *unstructured.Unstructured) error {
    32  	return n.Reader.Get(ctx, key, obj)
    33  }
    34  
    35  func (n *DirectClusterReader) ListNamespaceScoped(ctx context.Context, list *unstructured.UnstructuredList, namespace string, selector labels.Selector) error {
    36  	return n.Reader.List(ctx, list, client.InNamespace(namespace), client.MatchingLabelsSelector{Selector: selector})
    37  }
    38  
    39  func (n *DirectClusterReader) ListClusterScoped(ctx context.Context, list *unstructured.UnstructuredList, selector labels.Selector) error {
    40  	return n.Reader.List(ctx, list, client.MatchingLabelsSelector{Selector: selector})
    41  }
    42  
    43  func (n *DirectClusterReader) Sync(_ context.Context) error {
    44  	return nil
    45  }
    46  

View as plain text