Documentation
¶
Overview ¶
Package kube wraps client-go and provides Fleetsweeper's connection helpers for multi-cluster scans, including QPS/burst tuning, a user agent for apiserver audit trails, and concurrent ConnectAll fan-out.
Index ¶
- Constants
- Variables
- func AvailableContexts(kubeconfigPath string) ([]string, error)
- func InCluster() bool
- func LoadConfig(kubeconfigPath, contextName string) (*rest.Config, error)
- func ResolveContexts(kubeconfigPath string, names []string) ([]string, error)
- type Client
- func ConnectAll(ctx context.Context, kubeconfigPath string, contexts []string, workers int) []*Client
- func NewClient(_ context.Context, kubeconfigPath, contextName string) (*Client, error)
- func NewTestClient(contextName string, vi *TestVersionInfo) *Client
- func NewTestClientWithClientset(contextName string, cs kubernetes.Interface) *Client
- func NewTestClientWithDynamic(contextName string, cs kubernetes.Interface, dyn dynamic.Interface) *Client
- type TestVersionInfo
Constants ¶
const InClusterContext = "in-cluster"
InClusterContext is the context name of the cluster a pod runs in, reached through its ServiceAccount when no kubeconfig is given. LoadConfig resolves it to the in-cluster config.
Variables ¶
var ( // ErrLoadConfig indicates a failure loading or parsing the kubeconfig file. ErrLoadConfig = errors.New("load kubeconfig") // ErrConnect indicates a failure connecting to a cluster. ErrConnect = errors.New("connect to cluster") // ErrNoContexts indicates the kubeconfig defines no contexts to scan. ErrNoContexts = errors.New("no contexts in kubeconfig") )
Functions ¶
func AvailableContexts ¶
AvailableContexts returns all context names defined in the kubeconfig file. A pod given no kubeconfig gets InClusterContext alone, so it scans the cluster it runs in.
func InCluster ¶ added in v0.13.0
func InCluster() bool
InCluster reports whether the process appears to be running inside a Kubernetes pod.
func LoadConfig ¶ added in v0.13.0
LoadConfig returns a rest.Config for the named context. When kubeconfigPath is empty and an in-cluster ServiceAccount token is present the in-cluster configuration is preferred so the tool can run as a Deployment.
func ResolveContexts ¶ added in v0.16.0
ResolveContexts returns the contexts to scan: names when any are given, else every context in the kubeconfig. Scanning the whole fleet needs no selection, so an empty selection is never an error unless the kubeconfig itself holds no contexts.
Types ¶
type Client ¶
type Client struct {
// Context is the kubeconfig context name this client is connected to.
Context string
// contains filtered or unexported fields
}
Client wraps a Kubernetes client connection to a single cluster.
func ConnectAll ¶
func ConnectAll(ctx context.Context, kubeconfigPath string, contexts []string, workers int) []*Client
ConnectAll connects to the given kubeconfig contexts concurrently. Unreachable clusters are logged as warnings and excluded from the result.
func NewClient ¶
NewClient creates a Client connected to the named kubeconfig context. When kubeconfigPath is empty and the process is running inside a Kubernetes pod the in-cluster service account configuration is used instead. Context is set to contextName as given.
func NewTestClient ¶
func NewTestClient(contextName string, vi *TestVersionInfo) *Client
NewTestClient creates a Client backed by a fake clientset for testing.
func NewTestClientWithClientset ¶
func NewTestClientWithClientset(contextName string, cs kubernetes.Interface) *Client
NewTestClientWithClientset creates a Client using the provided fake clientset.
func NewTestClientWithDynamic ¶ added in v0.1.1
func NewTestClientWithDynamic(contextName string, cs kubernetes.Interface, dyn dynamic.Interface) *Client
NewTestClientWithDynamic creates a Client backed by both a typed clientset and a dynamic client, for scanners that consult discovery and the dynamic API. Either interface may be nil when a test does not exercise it.
func (*Client) Clientset ¶
func (c *Client) Clientset() kubernetes.Interface
Clientset returns the typed Kubernetes client interface.
type TestVersionInfo ¶
type TestVersionInfo struct {
// Major is the major version number.
Major string
// Minor is the minor version number.
Minor string
// GitVersion is the full version string.
GitVersion string
// Platform is the server platform string.
Platform string
}
TestVersionInfo holds version data for constructing test clients.