github.com/grafana/tanka@v0.26.1-0.20240506093700-c22cfc35c21a/pkg/kubernetes/client/client.go (about)

     1  package client
     2  
     3  import (
     4  	"github.com/grafana/tanka/pkg/kubernetes/manifest"
     5  )
     6  
     7  // Client for working with Kubernetes
     8  type Client interface {
     9  	// Get the specified object(s) from the cluster
    10  	Get(namespace, kind, name string) (manifest.Manifest, error)
    11  	GetByLabels(namespace, kind string, labels map[string]string) (manifest.List, error)
    12  	GetByState(data manifest.List, opts GetByStateOpts) (manifest.List, error)
    13  
    14  	// Apply the configuration to the cluster. `data` must contain a plaintext
    15  	// format that is `kubectl-apply(1)` compatible
    16  	Apply(data manifest.List, opts ApplyOpts) error
    17  
    18  	// DiffServerSide runs the diff operation on the server and returns the
    19  	// result in `diff(1)` format
    20  	DiffServerSide(data manifest.List) (*string, error)
    21  
    22  	// Delete the specified object(s) from the cluster
    23  	Delete(namespace, kind, name string, opts DeleteOpts) error
    24  
    25  	// Namespaces the cluster currently has
    26  	Namespaces() (map[string]bool, error)
    27  
    28  	// Namespace retrieves a namespace from the cluster
    29  	Namespace(namespace string) (manifest.Manifest, error)
    30  
    31  	// Resources returns all known api-resources of the cluster
    32  	Resources() (Resources, error)
    33  
    34  	// Info returns known informational data about the client. Best effort based,
    35  	// fields of `Info` that cannot be stocked with valuable data, e.g.
    36  	// due to an error, shall be left nil.
    37  	Info() Info
    38  
    39  	// Close may run tasks once the client is no longer needed.
    40  	Close() error
    41  }
    42  
    43  // ApplyOpts allow to specify additional parameter for apply operations
    44  type ApplyOpts struct {
    45  	// force allows to ignore checks and force the operation
    46  	Force bool
    47  
    48  	// validate allows to enable/disable kubectl validation
    49  	Validate bool
    50  
    51  	// autoApprove allows to skip the interactive approval
    52  	AutoApprove bool
    53  
    54  	// DryRun string passed to kubectl as --dry-run=<DryRun>
    55  	DryRun string
    56  
    57  	// ApplyStrategy to pick a final method for deploying generated objects
    58  	ApplyStrategy string
    59  }
    60  
    61  // DeleteOpts allow to specify additional parameters for delete operations
    62  // Currently not different from ApplyOpts, but may be required in the future
    63  type DeleteOpts ApplyOpts
    64  
    65  // GetByStateOpts allow to specify additional parameters for GetByState function
    66  // Currently there is just ignoreNotFound parameter which is only useful for
    67  // GetByState() so we only have GetByStateOpts instead of more generic GetOpts
    68  // for all get operations
    69  type GetByStateOpts struct {
    70  	// ignoreNotFound allows to ignore errors caused by missing objects
    71  	IgnoreNotFound bool
    72  }