kubernetes

package
v0.0.53 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CustomAuthorizationHeader = HeaderKey("kubernetes-authorization")
	OAuthAuthorizationHeader  = HeaderKey("Authorization")

	CustomUserAgent = "kubernetes-mcp-server/bearer-token-auth"
)
View Source
const (
	AppKubernetesComponent = "app.kubernetes.io/component"
	AppKubernetesManagedBy = "app.kubernetes.io/managed-by"
	AppKubernetesName      = "app.kubernetes.io/name"
	AppKubernetesPartOf    = "app.kubernetes.io/part-of"
)
View Source
const DefaultTailLines = int64(100)

Default number of lines to retrieve from the end of the logs

View Source
const KubeConfigTargetParameterName = "context"

KubeConfigTargetParameterName is the parameter name used to specify the kubeconfig context when using the kubeconfig cluster provider strategy.

Variables

View Source
var InClusterConfig = func() (*rest.Config, error) {

	inClusterConfig, err := rest.InClusterConfig()
	if inClusterConfig != nil {
		inClusterConfig.Host = "https://kubernetes.default.svc"
	}
	return inClusterConfig, err
}

InClusterConfig is a variable that holds the function to get the in-cluster config Exposed for testing

View Source
var Scheme = scheme.Scheme

Functions

func GetRegisteredStrategies added in v0.0.53

func GetRegisteredStrategies() []string

GetRegisteredStrategies returns a sorted list of all registered strategy names. This is useful for error messages and debugging.

func RegisterProvider added in v0.0.53

func RegisterProvider(strategy string, factory ProviderFactory)

RegisterProvider registers a provider factory for a given strategy name. This should be called from init() functions in provider implementation files. Panics if a provider is already registered for the given strategy.

Types

type AccessControlClientset

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

AccessControlClientset is a limited clientset delegating interface to the standard kubernetes.Clientset Only a limited set of functions are implemented with a single point of access to the kubernetes API where apiVersion and kinds are checked for allowed access

func NewAccessControlClientset

func NewAccessControlClientset(cfg *rest.Config, staticConfig *config.StaticConfig) (*AccessControlClientset, error)

func (*AccessControlClientset) DiscoveryClient

func (*AccessControlClientset) Pods

func (a *AccessControlClientset) Pods(namespace string) (corev1.PodInterface, error)

func (*AccessControlClientset) PodsExec

func (a *AccessControlClientset) PodsExec(namespace, name string, podExecOptions *v1.PodExecOptions) (remotecommand.Executor, error)

func (*AccessControlClientset) PodsMetricses

func (a *AccessControlClientset) PodsMetricses(ctx context.Context, namespace, name string, listOptions metav1.ListOptions) (*metrics.PodMetricsList, error)

func (*AccessControlClientset) SelfSubjectAccessReviews

func (*AccessControlClientset) Services

func (a *AccessControlClientset) Services(namespace string) (corev1.ServiceInterface, error)

func (*AccessControlClientset) TokenReview

TokenReview returns TokenReviewInterface

type AccessControlRESTMapper

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

func NewAccessControlRESTMapper

func NewAccessControlRESTMapper(delegate *restmapper.DeferredDiscoveryRESTMapper, staticConfig *config.StaticConfig) *AccessControlRESTMapper

func (AccessControlRESTMapper) KindFor

func (AccessControlRESTMapper) KindsFor

func (AccessControlRESTMapper) RESTMapping

func (a AccessControlRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error)

func (AccessControlRESTMapper) RESTMappings

func (a AccessControlRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error)

func (AccessControlRESTMapper) Reset

func (a AccessControlRESTMapper) Reset()

func (AccessControlRESTMapper) ResourceFor

func (AccessControlRESTMapper) ResourceSingularizer

func (a AccessControlRESTMapper) ResourceSingularizer(resource string) (singular string, err error)

func (AccessControlRESTMapper) ResourcesFor

type CloseWatchKubeConfig

type CloseWatchKubeConfig func() error

type HeaderKey

type HeaderKey string

type Kubernetes

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

func (*Kubernetes) AccessControlClientset added in v0.0.53

func (k *Kubernetes) AccessControlClientset() *AccessControlClientset

AccessControlClientset returns the access-controlled clientset This ensures that any denied resources configured in the system are properly enforced

func (*Kubernetes) ConfigurationContextsDefault added in v0.0.53

func (k *Kubernetes) ConfigurationContextsDefault() (string, error)

ConfigurationContextsDefault returns the current context name TODO: Should be moved to the Provider level ?

func (*Kubernetes) ConfigurationContextsList added in v0.0.53

func (k *Kubernetes) ConfigurationContextsList() (map[string]string, error)

ConfigurationContextsList returns the list of available context names TODO: Should be moved to the Provider level ?

func (*Kubernetes) ConfigurationView added in v0.0.52

func (k *Kubernetes) ConfigurationView(minify bool) (runtime.Object, error)

ConfigurationView returns the current kubeconfig content as a kubeconfig YAML If minify is true, keeps only the current-context and the relevant pieces of the configuration for that context. If minify is false, all contexts, clusters, auth-infos, and users are returned in the configuration. TODO: Should be moved to the Provider level ?

func (*Kubernetes) EventsList

func (k *Kubernetes) EventsList(ctx context.Context, namespace string) ([]map[string]any, error)

func (*Kubernetes) NamespaceOrDefault

func (k *Kubernetes) NamespaceOrDefault(namespace string) string

func (*Kubernetes) NamespacesList

func (k *Kubernetes) NamespacesList(ctx context.Context, options ResourceListOptions) (runtime.Unstructured, error)

func (*Kubernetes) NewHelm

func (k *Kubernetes) NewHelm() *helm.Helm

func (*Kubernetes) PodsDelete

func (k *Kubernetes) PodsDelete(ctx context.Context, namespace, name string) (string, error)

func (*Kubernetes) PodsExec

func (k *Kubernetes) PodsExec(ctx context.Context, namespace, name, container string, command []string) (string, error)

func (*Kubernetes) PodsGet

func (k *Kubernetes) PodsGet(ctx context.Context, namespace, name string) (*unstructured.Unstructured, error)

func (*Kubernetes) PodsListInAllNamespaces

func (k *Kubernetes) PodsListInAllNamespaces(ctx context.Context, options ResourceListOptions) (runtime.Unstructured, error)

func (*Kubernetes) PodsListInNamespace

func (k *Kubernetes) PodsListInNamespace(ctx context.Context, namespace string, options ResourceListOptions) (runtime.Unstructured, error)

func (*Kubernetes) PodsLog

func (k *Kubernetes) PodsLog(ctx context.Context, namespace, name, container string, previous bool, tail int64) (string, error)

func (*Kubernetes) PodsRun

func (k *Kubernetes) PodsRun(ctx context.Context, namespace, name, image string, port int32) ([]*unstructured.Unstructured, error)

func (*Kubernetes) PodsTop

func (k *Kubernetes) PodsTop(ctx context.Context, options PodsTopOptions) (*metrics.PodMetricsList, error)

func (*Kubernetes) ProjectsList

func (k *Kubernetes) ProjectsList(ctx context.Context, options ResourceListOptions) (runtime.Unstructured, error)

func (*Kubernetes) ResourcesCreateOrUpdate

func (k *Kubernetes) ResourcesCreateOrUpdate(ctx context.Context, resource string) ([]*unstructured.Unstructured, error)

func (*Kubernetes) ResourcesDelete

func (k *Kubernetes) ResourcesDelete(ctx context.Context, gvk *schema.GroupVersionKind, namespace, name string) error

func (*Kubernetes) ResourcesGet

func (k *Kubernetes) ResourcesGet(ctx context.Context, gvk *schema.GroupVersionKind, namespace, name string) (*unstructured.Unstructured, error)

func (*Kubernetes) ResourcesList

func (k *Kubernetes) ResourcesList(ctx context.Context, gvk *schema.GroupVersionKind, namespace string, options ResourceListOptions) (runtime.Unstructured, error)

type Manager

type Manager struct {
	CloseWatchKubeConfig CloseWatchKubeConfig
	// contains filtered or unexported fields
}

func NewManager

func NewManager(config *config.StaticConfig) (*Manager, error)

func (*Manager) Close

func (m *Manager) Close()

func (*Manager) Derived

func (m *Manager) Derived(ctx context.Context) (*Kubernetes, error)

func (*Manager) GetAPIServerHost

func (m *Manager) GetAPIServerHost() string

func (*Manager) IsInCluster

func (m *Manager) IsInCluster() bool

func (*Manager) IsOpenShift

func (m *Manager) IsOpenShift(_ context.Context) bool

func (*Manager) NamespaceOrDefault

func (m *Manager) NamespaceOrDefault(namespace string) string

func (*Manager) ToDiscoveryClient

func (m *Manager) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

func (*Manager) ToRESTConfig

func (m *Manager) ToRESTConfig() (*rest.Config, error)

ToRESTConfig returns the rest.Config object (genericclioptions.RESTClientGetter)

func (*Manager) ToRESTMapper

func (m *Manager) ToRESTMapper() (meta.RESTMapper, error)

func (*Manager) ToRawKubeConfigLoader

func (m *Manager) ToRawKubeConfigLoader() clientcmd.ClientConfig

ToRawKubeConfigLoader returns the clientcmd.ClientConfig object (genericclioptions.RESTClientGetter)

func (*Manager) VerifyToken

func (m *Manager) VerifyToken(ctx context.Context, token, audience string) (*authenticationv1api.UserInfo, []string, error)

func (*Manager) WatchKubeConfig

func (m *Manager) WatchKubeConfig(onKubeConfigChange func() error)

type ManagerProvider added in v0.0.53

type ManagerProvider interface {
	GetTargets(ctx context.Context) ([]string, error)
	GetManagerFor(ctx context.Context, target string) (*Manager, error)
	GetDefaultTarget() string
	GetTargetParameterName() string
	WatchTargets(func() error)
	Close()
}

func NewManagerProvider added in v0.0.53

func NewManagerProvider(cfg *config.StaticConfig) (ManagerProvider, error)

type Openshift added in v0.0.52

type Openshift interface {
	IsOpenShift(context.Context) bool
}

type PodsTopOptions

type PodsTopOptions struct {
	metav1.ListOptions
	AllNamespaces bool
	Namespace     string
	Name          string
}

type ProviderFactory added in v0.0.53

type ProviderFactory func(m *Manager, cfg *config.StaticConfig) (ManagerProvider, error)

ProviderFactory creates a new ManagerProvider instance for a given strategy. Implementations should validate that the Manager is compatible with their strategy (e.g., kubeconfig provider should reject in-cluster managers).

type ResourceListOptions

type ResourceListOptions struct {
	metav1.ListOptions
	AsTable bool
}

Jump to

Keyboard shortcuts

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