cluster

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Apply applies all of the configs at the given path.
	Apply(ctx context.Context, paths []string, serverSide bool) ([]byte, error)

	// ApplyStructured applies all of the configs at the given path and returns structured,
	// as opposed to raw, outputs
	ApplyStructured(ctx context.Context, paths []string, serverSide bool) ([]apply.Result, error)

	// Delete deletes the resources associated with one or more configs.
	Delete(ctx context.Context, ids []string) ([]byte, error)

	// Diff gets the diffs between the configs at the given path and the actual state of resources
	// in the cluster. It returns the raw output.
	Diff(ctx context.Context, paths []string, serverSide bool) ([]byte, error)

	// DiffStructured gets the diffs between the configs at the given path and the actual state of
	// resources in the cluster. It returns structured output.
	DiffStructured(ctx context.Context, paths []string, serverSide bool) ([]diff.Result, error)

	// Config returns the config for this cluster.
	Config() *Config

	// GetNamespaceUID returns the kubernetes identifier for a given namespace in this cluster.
	GetNamespaceUID(ctx context.Context, namespace string) (string, error)

	// Close cleans up this client.
	Close() error
}

Client is an interface that interacts with the API of a single Kubernetes cluster.

func NewFakeClient

func NewFakeClient(
	ctx context.Context,
	config *ClientConfig,
) (Client, error)

NewFakeClient returns a FakeClient that works without errors.

func NewFakeClientError

func NewFakeClientError(
	ctx context.Context,
	config *ClientConfig,
) (Client, error)

NewFakeClientError returns a FakeClient that simulates an error when running kubectl.

func NewKubeClient

func NewKubeClient(
	ctx context.Context,
	config *ClientConfig,
) (Client, error)

NewKubeClient creates a new Client instance for a real Kubernetes cluster.

type ClientConfig

type ClientConfig struct {
	// Config is the config for the cluster that we are communicating with.
	Config *Config

	// Debug indicates whether commands should be run with debug-level logging.
	Debug bool

	// KeepConfigs indicates whether kube client should keep around intermediate
	// yaml manifests. These are useful for debugging when there are apply errors.
	KeepConfigs bool

	// StreamingOutput indicates whether results should be streamed out to stdout and stderr.
	// Currently only applies to apply operations.
	StreamingOutput bool

	// Extra environment variables to add into kubectl calls.
	ExtraEnv []string
}

ClientConfig stores the configuration necessary to create a Client.

type Config

type Config struct {
	// Cluster is the name of the cluster.
	//
	// Required.
	Cluster string `json:"cluster"`

	// Region is the region for this cluster, e.g. us-west-2.
	//
	// Required.
	Region string `json:"region"`

	// Env is the environment for this cluster, e.g. production.
	//
	// Required.
	Environment string `json:"environment"`

	// AccountName is the name of the account where this cluster is running.
	//
	// Required.
	AccountName string `json:"accountName"`

	// AccountID is the ID of the account where this cluster is running.
	//
	// Required.
	AccountID string `json:"accountID"`

	// Version is the cluster version.
	//
	// Optional.
	Version string `json:"version"`

	// ConfigHash is a hash of the input configs and parameters for this cluster. It
	// can be used to compare the configuration states of various clusters.
	ConfigHash string `json:"configHash"`

	// ExpandedPath is the path to the results of expanding out all of the configs for this cluster.
	//
	// Optional, defaults to "expanded/[env]/[region]" if not set.
	ExpandedPath string `json:"expandedPath"`

	// Parameters are key/value pairs to be used for go templating.
	//
	// Optional.
	Parameters map[string]interface{} `json:"parameters"`

	// KubeConfigPath is the path to a kubeconfig that can be used with this cluster.
	//
	// Optional, defaults to value set on command-line (when running kubeapply manually) or
	// automatically generated via AWS API (when running in lambdas case).
	KubeConfigPath string `json:"kubeConfig"`

	// ServerSideApply sets whether we should be using server-side applies and diffs for this
	// cluster.
	ServerSideApply bool `json:"serverSideApply"`
}

Config represents the configuration for a single Kubernetes cluster in a single region and environment / account.

func (Config) ShortRegion

func (c Config) ShortRegion() string

ShortRegion converts the region in the cluster config to a short form that may be used in some templates.

type FakeClient

type FakeClient struct {
	NoDiffs bool
	Calls   []FakeClientCall
	// contains filtered or unexported fields
}

FakeClient is a fake implementation of a Client. For testing purposes only.

func (*FakeClient) Apply

func (cc *FakeClient) Apply(
	ctx context.Context,
	paths []string,
	serverSide bool,
) ([]byte, error)

Apply runs a fake apply using the configs in the argument path.

func (*FakeClient) ApplyStructured

func (cc *FakeClient) ApplyStructured(
	ctx context.Context,
	paths []string,
	serverSide bool,
) ([]apply.Result, error)

ApplyStructured runs a fake structured apply using the configs in the argument path.

func (*FakeClient) Close

func (cc *FakeClient) Close() error

Close closes the client.

func (*FakeClient) Config

func (cc *FakeClient) Config() *Config

Config returns this client's cluster config.

func (*FakeClient) Delete

func (cc *FakeClient) Delete(
	ctx context.Context,
	ids []string,
) ([]byte, error)

Delete deletes the resources associated with one or more configs.

func (*FakeClient) Diff

func (cc *FakeClient) Diff(
	ctx context.Context,
	paths []string,
	serverSide bool,
) ([]byte, error)

Diff gets the diffs between the configs at the given path and the actual state of resources in the cluster. It returns the raw output.

func (*FakeClient) DiffStructured

func (cc *FakeClient) DiffStructured(
	ctx context.Context,
	paths []string,
	serverSide bool,
) ([]diff.Result, error)

DiffStructured gets the diffs between the configs at the given path and the actual state of resources in the cluster. It returns structured output.

func (*FakeClient) GetNamespaceUID

func (cc *FakeClient) GetNamespaceUID(
	ctx context.Context,
	namespace string,
) (string, error)

GetNamespaceUID returns the kubernetes identifier for a given namespace in this cluster.

type FakeClientCall

type FakeClientCall struct {
	CallType string
	Paths    []string
}

FakeClientCall records a call that was made using the FakeClient.

type KubeClient

type KubeClient struct {
	// contains filtered or unexported fields
}

KubeClient is an implementation of a Client that hits an actual Kubernetes API. It's backed by a kube.OrderedClient which, in turn, wraps kubectl.

func (*KubeClient) Apply

func (cc *KubeClient) Apply(
	ctx context.Context,
	paths []string,
	serverSide bool,
) ([]byte, error)

Apply does a kubectl apply for the resources at the argument path.

func (*KubeClient) ApplyStructured

func (cc *KubeClient) ApplyStructured(
	ctx context.Context,
	paths []string,
	serverSide bool,
) ([]apply.Result, error)

ApplyStructured does a structured kubectl apply for the resources at the argument path.

func (*KubeClient) Close

func (cc *KubeClient) Close() error

Close closes the client and cleans up all of the associated resources.

func (*KubeClient) Config

func (cc *KubeClient) Config() *Config

Config returns this client's cluster config.

func (*KubeClient) Delete

func (cc *KubeClient) Delete(
	ctx context.Context,
	ids []string,
) ([]byte, error)

Delete deletes one or more resources associated with the argument paths.

func (*KubeClient) Diff

func (cc *KubeClient) Diff(
	ctx context.Context,
	paths []string,
	serverSide bool,
) ([]byte, error)

Diff gets the diffs between the configs at the given path and the actual state of resources in the cluster. It returns the raw output.

func (*KubeClient) DiffStructured

func (cc *KubeClient) DiffStructured(
	ctx context.Context,
	paths []string,
	serverSide bool,
) ([]diff.Result, error)

DiffStructured gets the diffs between the configs at the given path and the actual state of resources in the cluster. It returns structured output.

func (*KubeClient) GetNamespaceUID

func (cc *KubeClient) GetNamespaceUID(
	ctx context.Context,
	namespace string,
) (string, error)

GetNamespaceUID returns the kubernetes identifier for a given namespace in this cluster.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL