Documentation
¶
Overview ¶
Package steve provides a Kubernetes dynamic client for accessing clusters via Rancher's Steve API.
Index ¶
- Variables
- func GetGVR(kind string) (schema.GroupVersionResource, bool)
- type APIResourceInfo
- type AllResourceItem
- type AllResourcesResult
- type Client
- func (c *Client) CreateResource(ctx context.Context, clusterID string, resource *unstructured.Unstructured) (*unstructured.Unstructured, error)
- func (c *Client) DeleteResource(ctx context.Context, clusterID, kind, namespace, name string) error
- func (c *Client) DescribeResource(ctx context.Context, clusterID, kind, namespace, name string) (*DescribeResult, error)
- func (c *Client) GetAllContainerLogs(ctx context.Context, clusterID, namespace, podName string, opts *PodLogOptions) (map[string]string, error)
- func (c *Client) GetAllResources(ctx context.Context, clusterID string, opts *GetAllOptions) (*AllResourcesResult, error)
- func (c *Client) GetEvents(ctx context.Context, clusterID, namespace, name, kind string) ([]corev1.Event, error)
- func (c *Client) GetMultiPodLogs(ctx context.Context, clusterID, namespace string, labelSelector string, ...) ([]MultiPodLogResult, error)
- func (c *Client) GetPodLogs(ctx context.Context, clusterID, namespace, podName string, opts *PodLogOptions) (string, error)
- func (c *Client) GetResource(ctx context.Context, clusterID, kind, namespace, name string) (*unstructured.Unstructured, error)
- func (c *Client) InspectPod(ctx context.Context, clusterID, namespace, podName string) (*InspectPodResult, error)
- func (c *Client) ListAPIResources(ctx context.Context, clusterID string) ([]APIResourceInfo, error)
- func (c *Client) ListResources(ctx context.Context, clusterID, kind, namespace string, opts *ListOptions) (*unstructured.UnstructuredList, error)
- func (c *Client) PatchResource(ctx context.Context, clusterID, kind, namespace, name string, patch []byte) (*unstructured.Unstructured, error)
- func (c *Client) WatchResources(ctx context.Context, clusterID, kind, namespace string, opts *WatchOptions) (watch.Interface, error)
- type DescribeResult
- type GetAllOptions
- type InspectPodResult
- type ListOptions
- type MultiPodLogResult
- type PodLogOptions
- type WatchOptions
Constants ¶
This section is empty.
Variables ¶
var K8sKindsToGVRs = map[string]schema.GroupVersionResource{
"pod": {Group: "", Version: "v1", Resource: "pods"},
"service": {Group: "", Version: "v1", Resource: "services"},
"svc": {Group: "", Version: "v1", Resource: "services"},
"configmap": {Group: "", Version: "v1", Resource: "configmaps"},
"cm": {Group: "", Version: "v1", Resource: "configmaps"},
"secret": {Group: "", Version: "v1", Resource: "secrets"},
"event": {Group: "", Version: "v1", Resource: "events"},
"ev": {Group: "", Version: "v1", Resource: "events"},
"namespace": {Group: "", Version: "v1", Resource: "namespaces"},
"ns": {Group: "", Version: "v1", Resource: "namespaces"},
"node": {Group: "", Version: "v1", Resource: "nodes"},
"no": {Group: "", Version: "v1", Resource: "nodes"},
"serviceaccount": {Group: "", Version: "v1", Resource: "serviceaccounts"},
"sa": {Group: "", Version: "v1", Resource: "serviceaccounts"},
"persistentvolume": {Group: "", Version: "v1", Resource: "persistentvolumes"},
"pv": {Group: "", Version: "v1", Resource: "persistentvolumes"},
"persistentvolumeclaim": {Group: "", Version: "v1", Resource: "persistentvolumeclaims"},
"pvc": {Group: "", Version: "v1", Resource: "persistentvolumeclaims"},
"resourcequota": {Group: "", Version: "v1", Resource: "resourcequotas"},
"quota": {Group: "", Version: "v1", Resource: "resourcequotas"},
"limitrange": {Group: "", Version: "v1", Resource: "limitranges"},
"limits": {Group: "", Version: "v1", Resource: "limitranges"},
"endpoints": {Group: "", Version: "v1", Resource: "endpoints"},
"ep": {Group: "", Version: "v1", Resource: "endpoints"},
"deployment": {Group: "apps", Version: "v1", Resource: "deployments"},
"deploy": {Group: "apps", Version: "v1", Resource: "deployments"},
"statefulset": {Group: "apps", Version: "v1", Resource: "statefulsets"},
"sts": {Group: "apps", Version: "v1", Resource: "statefulsets"},
"daemonset": {Group: "apps", Version: "v1", Resource: "daemonsets"},
"ds": {Group: "apps", Version: "v1", Resource: "daemonsets"},
"replicaset": {Group: "apps", Version: "v1", Resource: "replicasets"},
"rs": {Group: "apps", Version: "v1", Resource: "replicasets"},
"job": {Group: "batch", Version: "v1", Resource: "jobs"},
"cronjob": {Group: "batch", Version: "v1", Resource: "cronjobs"},
"cj": {Group: "batch", Version: "v1", Resource: "cronjobs"},
"ingress": {Group: "networking.k8s.io", Version: "v1", Resource: "ingresses"},
"ing": {Group: "networking.k8s.io", Version: "v1", Resource: "ingresses"},
"networkpolicy": {Group: "networking.k8s.io", Version: "v1", Resource: "networkpolicies"},
"netpol": {Group: "networking.k8s.io", Version: "v1", Resource: "networkpolicies"},
"ingressclass": {Group: "networking.k8s.io", Version: "v1", Resource: "ingressclasses"},
"horizontalpodautoscaler": {Group: "autoscaling", Version: "v2", Resource: "horizontalpodautoscalers"},
"hpa": {Group: "autoscaling", Version: "v2", Resource: "horizontalpodautoscalers"},
"vpa": {Group: "autoscaling.k8s.io", Version: "v1", Resource: "verticalpodautoscalers"},
"role": {Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "roles"},
"rolebinding": {Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "rolebindings"},
"clusterrole": {Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterroles"},
"clusterrolebinding": {Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterrolebindings"},
"storageclass": {Group: "storage.k8s.io", Version: "v1", Resource: "storageclasses"},
"sc": {Group: "storage.k8s.io", Version: "v1", Resource: "storageclasses"},
"volumeattachment": {Group: "storage.k8s.io", Version: "v1", Resource: "volumeattachments"},
"crd": {Group: "apiextensions.k8s.io", Version: "v1", Resource: "customresourcedefinitions"},
"customresourcedefinition": {Group: "apiextensions.k8s.io", Version: "v1", Resource: "customresourcedefinitions"},
"customresourcedefinitions": {Group: "apiextensions.k8s.io", Version: "v1", Resource: "customresourcedefinitions"},
"endpointslice": {Group: "discovery.k8s.io", Version: "v1", Resource: "endpointslices"},
"endpointslices": {Group: "discovery.k8s.io", Version: "v1", Resource: "endpointslices"},
"poddisruptionbudget": {Group: "policy", Version: "v1", Resource: "poddisruptionbudgets"},
"pdb": {Group: "policy", Version: "v1", Resource: "poddisruptionbudgets"},
"node.metrics.k8s.io": {Group: "metrics.k8s.io", Version: "v1beta1", Resource: "nodes"},
"pod.metrics.k8s.io": {Group: "metrics.k8s.io", Version: "v1beta1", Resource: "pods"},
"nodemetrics": {Group: "metrics.k8s.io", Version: "v1beta1", Resource: "nodes"},
"podmetrics": {Group: "metrics.k8s.io", Version: "v1beta1", Resource: "pods"},
"cluster": {Group: "management.cattle.io", Version: "v3", Resource: "clusters"},
"project": {Group: "management.cattle.io", Version: "v3", Resource: "projects"},
"user": {Group: "management.cattle.io", Version: "v3", Resource: "users"},
"roletemplate": {Group: "management.cattle.io", Version: "v3", Resource: "roletemplates"},
"globalrole": {Group: "management.cattle.io", Version: "v3", Resource: "globalroles"},
"globalrolebinding": {Group: "management.cattle.io", Version: "v3", Resource: "globalrolebindings"},
"clusterroletemplatebinding": {Group: "management.cattle.io", Version: "v3", Resource: "clusterroletemplatebindings"},
"projectroletemplatebinding": {Group: "management.cattle.io", Version: "v3", Resource: "projectroletemplatebindings"},
"nodetemplate": {Group: "management.cattle.io", Version: "v3", Resource: "nodetemplates"},
"nodedriver": {Group: "management.cattle.io", Version: "v3", Resource: "nodedrivers"},
"setting": {Group: "management.cattle.io", Version: "v3", Resource: "settings"},
"bundle": {Group: "fleet.cattle.io", Version: "v1alpha1", Resource: "bundles"},
"gitrepo": {Group: "fleet.cattle.io", Version: "v1alpha1", Resource: "gitrepos"},
"bundledeployment": {Group: "fleet.cattle.io", Version: "v1alpha1", Resource: "bundledeployments"},
"clustergroup": {Group: "fleet.cattle.io", Version: "v1alpha1", Resource: "clustergroups"},
"fleetcluster": {Group: "fleet.cattle.io", Version: "v1alpha1", Resource: "clusters"},
"certificate": {Group: "cert-manager.io", Version: "v1", Resource: "certificates"},
"issuer": {Group: "cert-manager.io", Version: "v1", Resource: "issuers"},
"clusterissuer": {Group: "cert-manager.io", Version: "v1", Resource: "clusterissuers"},
}
K8sKindsToGVRs maps lowercase Kubernetes resource kind names to their corresponding GroupVersionResource (GVR) identifiers. This mapping is used for dynamic client operations to resolve resource types across different API groups and versions.
Functions ¶
Types ¶
type APIResourceInfo ¶ added in v0.5.1
type APIResourceInfo struct {
Name string
SingularName string
Namespaced bool
Kind string
Group string
Version string
Verbs []string
}
APIResourceInfo contains information about a Kubernetes API resource type.
func (*APIResourceInfo) GVR ¶ added in v0.5.1
func (r *APIResourceInfo) GVR() schema.GroupVersionResource
GVR returns the GroupVersionResource for this API resource.
type AllResourceItem ¶ added in v0.5.1
type AllResourceItem struct {
Name string
Namespace string
Kind string
APIVersion string
Resource *unstructured.Unstructured
}
AllResourceItem represents a single resource found by GetAllResources.
type AllResourcesResult ¶ added in v0.5.1
type AllResourcesResult struct {
Items []AllResourceItem
}
AllResourcesResult contains all resources retrieved by GetAllResources.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides methods for interacting with Kubernetes clusters via Rancher's Steve API.
func (*Client) CreateResource ¶
func (c *Client) CreateResource(ctx context.Context, clusterID string, resource *unstructured.Unstructured) (*unstructured.Unstructured, error)
CreateResource creates a new Kubernetes resource.
func (*Client) DeleteResource ¶
DeleteResource deletes a Kubernetes resource.
func (*Client) DescribeResource ¶ added in v0.4.1
func (c *Client) DescribeResource(ctx context.Context, clusterID, kind, namespace, name string) (*DescribeResult, error)
DescribeResource retrieves a Kubernetes resource along with its related events.
func (*Client) GetAllContainerLogs ¶
func (c *Client) GetAllContainerLogs(ctx context.Context, clusterID, namespace, podName string, opts *PodLogOptions) (map[string]string, error)
GetAllContainerLogs retrieves logs from all containers in a pod.
func (*Client) GetAllResources ¶ added in v0.5.1
func (c *Client) GetAllResources(ctx context.Context, clusterID string, opts *GetAllOptions) (*AllResourcesResult, error)
GetAllResources retrieves all resources across all (or specified) resource types. Similar to ketall, it fetches resources that "kubectl get all" doesn't show.
func (*Client) GetEvents ¶ added in v0.4.1
func (c *Client) GetEvents(ctx context.Context, clusterID, namespace, name, kind string) ([]corev1.Event, error)
GetEvents retrieves Kubernetes events related to a specific resource. Filters by involvedObject fields: name, namespace, and optionally kind.
func (*Client) GetMultiPodLogs ¶ added in v0.5.1
func (c *Client) GetMultiPodLogs(ctx context.Context, clusterID, namespace string, labelSelector string, opts *PodLogOptions) ([]MultiPodLogResult, error)
GetMultiPodLogs retrieves logs from multiple pods using label selector and merges them. Returns logs organized by pod name, with each pod's logs organized by container name.
func (*Client) GetPodLogs ¶
func (c *Client) GetPodLogs(ctx context.Context, clusterID, namespace, podName string, opts *PodLogOptions) (string, error)
GetPodLogs retrieves logs from a specific pod and container.
func (*Client) GetResource ¶
func (c *Client) GetResource(ctx context.Context, clusterID, kind, namespace, name string) (*unstructured.Unstructured, error)
GetResource retrieves a single Kubernetes resource by name.
func (*Client) InspectPod ¶
func (c *Client) InspectPod(ctx context.Context, clusterID, namespace, podName string) (*InspectPodResult, error)
InspectPod retrieves comprehensive information about a pod including its parent, metrics, and logs.
func (*Client) ListAPIResources ¶ added in v0.5.1
ListAPIResources discovers all API resources available in the cluster. It returns a list of resource types that can be used to fetch all resources.
func (*Client) ListResources ¶
func (c *Client) ListResources(ctx context.Context, clusterID, kind, namespace string, opts *ListOptions) (*unstructured.UnstructuredList, error)
ListResources lists Kubernetes resources matching the provided parameters.
func (*Client) PatchResource ¶
func (c *Client) PatchResource(ctx context.Context, clusterID, kind, namespace, name string, patch []byte) (*unstructured.Unstructured, error)
PatchResource patches an existing Kubernetes resource using JSON patch.
func (*Client) WatchResources ¶ added in v0.5.1
func (c *Client) WatchResources(ctx context.Context, clusterID, kind, namespace string, opts *WatchOptions) (watch.Interface, error)
WatchResources watches Kubernetes resources matching the provided parameters and returns a watch.Interface for consuming events.
type DescribeResult ¶ added in v0.4.1
type DescribeResult struct {
Resource *unstructured.Unstructured `json:"resource"`
Events []corev1.Event `json:"events,omitempty"`
}
DescribeResult contains the results of describing a resource.
func (*DescribeResult) ToJSON ¶ added in v0.4.1
func (r *DescribeResult) ToJSON() (string, error)
ToJSON converts the DescribeResult to a JSON string.
type GetAllOptions ¶ added in v0.5.1
type GetAllOptions struct {
Namespace string
ExcludeEvents bool
Scope string // "namespaced", "cluster", or "" (all)
Limit int64
}
GetAllOptions contains options for GetAllResources.
type InspectPodResult ¶
type InspectPodResult struct {
Pod *unstructured.Unstructured `json:"pod"`
Parent *unstructured.Unstructured `json:"parent,omitempty"`
Metrics *unstructured.Unstructured `json:"metrics,omitempty"`
Logs map[string]string `json:"logs"`
}
InspectPodResult contains the results of inspecting a pod.
func (*InspectPodResult) ToJSON ¶
func (r *InspectPodResult) ToJSON() (string, error)
ToJSON converts the InspectPodResult to a JSON string.
type ListOptions ¶
ListOptions contains options for listing resources.
type MultiPodLogResult ¶ added in v0.5.1
type MultiPodLogResult struct {
Pod string `json:"pod"`
Namespace string `json:"namespace,omitempty"`
Logs map[string]string `json:"logs,omitempty"`
Error string `json:"error,omitempty"`
}
MultiPodLogResult contains the log result for a single pod
type PodLogOptions ¶
type PodLogOptions struct {
Container string
TailLines *int64
SinceSeconds *int64
Timestamps bool
Previous bool
}
PodLogOptions contains options for fetching pod logs.
type WatchOptions ¶ added in v0.5.1
WatchOptions contains options for watching resources.