...

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

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

     1  // Copyright 2020 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package fake
     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  type ClusterReader struct {
    15  	NoopClusterReader
    16  
    17  	GetResource *unstructured.Unstructured
    18  	GetErr      error
    19  
    20  	ListResources *unstructured.UnstructuredList
    21  	ListErr       error
    22  
    23  	SyncErr error
    24  }
    25  
    26  func (f *ClusterReader) Get(_ context.Context, _ client.ObjectKey, u *unstructured.Unstructured) error {
    27  	if f.GetResource != nil {
    28  		u.Object = f.GetResource.Object
    29  	}
    30  	return f.GetErr
    31  }
    32  
    33  func (f *ClusterReader) ListNamespaceScoped(_ context.Context, list *unstructured.UnstructuredList, _ string, _ labels.Selector) error {
    34  	if f.ListResources != nil {
    35  		list.Items = f.ListResources.Items
    36  	}
    37  	return f.ListErr
    38  }
    39  
    40  func (f *ClusterReader) Sync(_ context.Context) error {
    41  	return f.SyncErr
    42  }
    43  
    44  func NewNoopClusterReader() *NoopClusterReader {
    45  	return &NoopClusterReader{}
    46  }
    47  
    48  type NoopClusterReader struct{}
    49  
    50  func (n *NoopClusterReader) Get(_ context.Context, _ client.ObjectKey, _ *unstructured.Unstructured) error {
    51  	return nil
    52  }
    53  
    54  func (n *NoopClusterReader) ListNamespaceScoped(_ context.Context, _ *unstructured.UnstructuredList,
    55  	_ string, _ labels.Selector) error {
    56  	return nil
    57  }
    58  
    59  func (n *NoopClusterReader) ListClusterScoped(_ context.Context, _ *unstructured.UnstructuredList,
    60  	_ labels.Selector) error {
    61  	return nil
    62  }
    63  
    64  func (n *NoopClusterReader) Sync(_ context.Context) error {
    65  	return nil
    66  }
    67  

View as plain text