kubernetes

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MPL-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAndLoadKubeConfig

func DecodeAndLoadKubeConfig(encodedKubeConfig string) (*clientcmdapi.Config, error)

DecodeAndLoadKubeConfig decodes a base64 encoded kubeconfig and attempts to load the Config.

func GetKubeConfigPath

func GetKubeConfigPath(kubeConfigPath string) (string, error)

GetKubeConfigPath given a kubeConfigPath that might be empty gets a kubeconfig path, by returning the provided value if is not empty, or the value of the kubeConfigEnv if set, or the default kubeconfig path in the users' home dir (~/.kube/config).

func NewMockGetLogsFunc

func NewMockGetLogsFunc(logs []byte) func(ctx context.Context, req GetPodLogsRequest) (*GetPodLogsResponse, error)

NewMockGetLogsFunc creates a GetLogsFunc that returns the provided logs when called.

Types

type Client

type Client interface {
	// NewExecRequest creates a new exec request for the given opts
	NewExecRequest(opts ExecRequestOpts) it.ExecRequest
	// QueryPodInfos gets a slice of all the pods that match the QueryPodInfosRequest. If the namespace
	// is not provided in the request it will be defaulted to 'default'.
	QueryPodInfos(ctx context.Context, req QueryPodInfosRequest) ([]PodInfo, error)
	// GetPodInfo get pod info for the pod that matches the request. If the namespace is not provided
	// in the request it will be defaulted to 'default'.
	GetPodInfo(ctx context.Context, req GetPodInfoRequest) (*PodInfo, error)
	// GetLogs gets the logs for the provided QueryPodInfosRequest
	GetLogs(ctx context.Context, req GetPodLogsRequest) (*GetPodLogsResponse, error)
	// ListPods returns all pods matching the given request
	ListPods(ctx context.Context, req *ListPodsRequest) (*ListPodsResponse, error)
}

Client A wrapper around the k8s clientset that provides an api that the provider can use.

func NewClient

func NewClient(cfg ClientCfg) (Client, error)

NewClient creates a new Kubernetes Client.

type ClientCfg

type ClientCfg struct {
	KubeConfigBase64 string
	ContextName      string
}

type ExecRequestOpts

type ExecRequestOpts struct {
	Command   string
	StdIn     bool
	Namespace string
	Pod       string
	Container string
}

type GetPodInfoRequest

type GetPodInfoRequest struct {
	// Namespace the namespace that the pod is in
	Namespace string
	// Name the name of the pod
	Name string
}

GetPodInfoRequest a request for getting pod info.

type GetPodLogsRequest

type GetPodLogsRequest struct {
	ContextName string
	Namespace   string
	Pod         string
	Container   string
}

type GetPodLogsResponse

type GetPodLogsResponse struct {
	ContextName string
	Namespace   string
	Pod         string
	Container   string
	Logs        []byte
}

func (GetPodLogsResponse) GetAppName

func (p GetPodLogsResponse) GetAppName() string

GetAppName implements remoteflight.GetLogsResponse.GetAppName.

func (GetPodLogsResponse) GetLogFileName

func (p GetPodLogsResponse) GetLogFileName() string

func (GetPodLogsResponse) GetLogs

func (p GetPodLogsResponse) GetLogs() []byte

type ListPodsRequest

type ListPodsRequest struct {
	// The kubernetes namespace to query
	Namespace string
	// Label selectors to filter by
	LabelSelectors []string
	// Field selectors to filter by
	FieldSelectors []string
	// How we'll retry the request
	*retry.Retrier
	// Options we'll apply to the retrier
	RetryOpts []retry.RetrierOpt
}

ListPodsRequest is a request to list the pods matching the search criteria.

func NewListPodsRequest

func NewListPodsRequest(opts ...ListPodsRequestOpt) *ListPodsRequest

NewListPodsRequest takes NewListPodsRequestOpt's and returns a new instance of ListPodsRequest.

type ListPodsRequestOpt

type ListPodsRequestOpt func(*ListPodsRequest)

ListPodsRequestOpt is a functional option for NewListPodsRequest.

func WithListPodsRequestFieldSelectors

func WithListPodsRequestFieldSelectors(selectors []string) ListPodsRequestOpt

WithListPodsRequestFieldSelectors allows the caller to define field selectors for the ListPods request.

func WithListPodsRequestLabelSelectors

func WithListPodsRequestLabelSelectors(selectors []string) ListPodsRequestOpt

WithListPodsRequestLabelSelectors allows the caller to define label selectors for the ListPods request.

func WithListPodsRequestNamespace

func WithListPodsRequestNamespace(name string) ListPodsRequestOpt

WithListPodsRequestNamespace allows the caller to define namespace for the ListPods request.

func WithListPodsRequestRetryOpts

func WithListPodsRequestRetryOpts(opts ...retry.RetrierOpt) ListPodsRequestOpt

WithListPodsRequestRetryOpts allows the caller to define retry options for the ListPods request.

type ListPodsResponse

type ListPodsResponse struct {
	Pods *Pods
}

ListPodsResponse is ListPods response.

func (*ListPodsResponse) String

func (r *ListPodsResponse) String() string

String returns the list of pods as a string.

type MockClient

type MockClient struct {
	NewExecRequestFunc func(opts ExecRequestOpts) it.ExecRequest
	QueryPodInfosFunc  func(ctx context.Context, req QueryPodInfosRequest) ([]PodInfo, error)
	GetPodInfoFunc     func(ctx context.Context, req GetPodInfoRequest) (*PodInfo, error)
	GetLogsFunc        func(ctx context.Context, req GetPodLogsRequest) (*GetPodLogsResponse, error)
	ListPodsFunc       func(ctx context.Context, req *ListPodsRequest) (*ListPodsResponse, error)
}

MockClient a mock Kubernetes Client.

func (*MockClient) GetLogs

func (*MockClient) GetPodInfo

func (m *MockClient) GetPodInfo(ctx context.Context, req GetPodInfoRequest) (*PodInfo, error)

func (*MockClient) ListPods

func (m *MockClient) ListPods(ctx context.Context, req *ListPodsRequest) (*ListPodsResponse, error)

func (*MockClient) NewExecRequest

func (m *MockClient) NewExecRequest(opts ExecRequestOpts) it.ExecRequest

func (*MockClient) QueryPodInfos

func (m *MockClient) QueryPodInfos(ctx context.Context, req QueryPodInfosRequest) ([]PodInfo, error)

type PodInfo

type PodInfo struct {
	Name       string
	Namespace  string
	Containers []string
	Pod        *v1.Pod
}

type Pods

type Pods v1.PodList

Pods is an alias for a v1.PodList so we can attach methods to it.

func (*Pods) String

func (p *Pods) String() string

String returns the pods list as a human readable string.

type QueryPodInfosRequest

type QueryPodInfosRequest struct {
	Namespace     string
	LabelSelector string
	FieldSelector string
	// ExpectedPodCount the expected number of pods that should be returned from the query
	ExpectedPodCount int
	// WaitTimeout the amount of time to wait for the pods to be in the 'RUNNING' state
	WaitTimeout time.Duration
}

Jump to

Keyboard shortcuts

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