kubernetes

package
v0.0.55 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: Apache-2.0 Imports: 51 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)

DefaultTailLines is the 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 (
	ErrorKubeconfigInClusterNotAllowed = errors.New("kubeconfig manager cannot be used in in-cluster deployments")
	ErrorInClusterNotInCluster         = errors.New("in-cluster manager cannot be used outside of a cluster")
)
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 IsInCluster added in v0.0.54

func IsInCluster(cfg *config.StaticConfig) bool

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 {
	kubernetes.Interface
	// 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(staticConfig *config.StaticConfig, clientCmdConfig clientcmd.ClientConfig, restConfig *rest.Config) (*AccessControlClientset, error)

func (*AccessControlClientset) DiscoveryClient

func (*AccessControlClientset) DynamicClient added in v0.0.55

func (a *AccessControlClientset) DynamicClient() dynamic.Interface

func (*AccessControlClientset) MetricsV1beta1Client added in v0.0.55

func (a *AccessControlClientset) MetricsV1beta1Client() *metricsv1beta1.MetricsV1beta1Client

func (*AccessControlClientset) Nodes added in v0.0.54

Nodes returns NodeInterface Deprecated: use CoreV1().Nodes() directly

func (*AccessControlClientset) Pods

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

Pods returns PodInterface Deprecated: use CoreV1().Pods(namespace) directly

func (*AccessControlClientset) RESTMapper added in v0.0.55

func (*AccessControlClientset) SelfSubjectAccessReviews

SelfSubjectAccessReviews returns SelfSubjectAccessReviewInterface Deprecated: use AuthorizationV1().SelfSubjectAccessReviews() directly

func (*AccessControlClientset) Services

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

Services returns ServiceInterface Deprecated: use CoreV1().Services(namespace) directly

func (*AccessControlClientset) ToRawKubeConfigLoader added in v0.0.55

func (a *AccessControlClientset) ToRawKubeConfigLoader() clientcmd.ClientConfig

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

func (*AccessControlClientset) TokenReview

TokenReview returns TokenReviewInterface Deprecated: use AuthenticationV1().TokenReviews() directly

type AccessControlRoundTripper added in v0.0.55

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

func (*AccessControlRoundTripper) RoundTrip added in v0.0.55

func (rt *AccessControlRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

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.51

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) NewKiali added in v0.0.55

func (k *Kubernetes) NewKiali() *kiali.Kiali

NewKiali returns a Kiali client initialized with the same StaticConfig and bearer token as the underlying derived Kubernetes manager.

func (*Kubernetes) NodesLog added in v0.0.54

func (k *Kubernetes) NodesLog(ctx context.Context, name string, query string, tailLines int64) (string, error)

func (*Kubernetes) NodesStatsSummary added in v0.0.54

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

func (*Kubernetes) NodesTop added in v0.0.54

func (k *Kubernetes) NodesTop(ctx context.Context, options NodesTopOptions) (*metrics.NodeMetricsList, error)

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)

func (*Kubernetes) ResourcesScale added in v0.0.55

func (k *Kubernetes) ResourcesScale(
	ctx context.Context,
	gvk *schema.GroupVersionKind,
	namespace, name string,
	desiredScale int64,
	shouldScale bool,
) (*unstructured.Unstructured, error)

func (*Kubernetes) ToDiscoveryClient added in v0.0.55

func (k *Kubernetes) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, error)

func (*Kubernetes) ToRESTConfig added in v0.0.55

func (k *Kubernetes) ToRESTConfig() (*rest.Config, error)

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

func (*Kubernetes) ToRESTMapper added in v0.0.55

func (k *Kubernetes) ToRESTMapper() (meta.RESTMapper, error)

func (*Kubernetes) ToRawKubeConfigLoader added in v0.0.55

func (k *Kubernetes) ToRawKubeConfigLoader() clientcmd.ClientConfig

type Manager

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

func NewInClusterManager added in v0.0.54

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

func NewKubeconfigManager added in v0.0.54

func NewKubeconfigManager(config *config.StaticConfig, kubeconfigContext string) (*Manager, error)

func NewManager

func NewManager(config *config.StaticConfig, restConfig *rest.Config, clientCmdConfig clientcmd.ClientConfig) (*Manager, error)

func (*Manager) Derived

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

func (*Manager) Invalidate added in v0.0.55

func (m *Manager) Invalidate()

Invalidate invalidates the cached discovery information.

func (*Manager) IsOpenShift

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

func (*Manager) VerifyToken

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

type McpReload added in v0.0.55

type McpReload func() error

McpReload is a function type that defines a callback for reloading MCP toolsets (including tools, prompts, or other configurations)

type NodesTopOptions added in v0.0.54

type NodesTopOptions struct {
	metav1.ListOptions
	Name string
}

type Openshift added in v0.0.51

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

type PodsTopOptions

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

type Provider added in v0.0.54

type Provider interface {
	// Openshift extends the Openshift interface to provide OpenShift specific functionality to toolset providers
	// TODO: with the configurable toolset implementation and especially the multi-cluster approach
	// extending this interface might not be a good idea anymore.
	// For the kubecontext case, a user might be targeting both an OpenShift flavored cluster and a vanilla Kubernetes cluster.
	// See: https://github.com/containers/kubernetes-mcp-server/pull/372#discussion_r2421592315
	Openshift
	TokenVerifier
	GetTargets(ctx context.Context) ([]string, error)
	GetDerivedKubernetes(ctx context.Context, target string) (*Kubernetes, error)
	GetDefaultTarget() string
	GetTargetParameterName() string
	// WatchTargets sets up a watcher for changes in the cluster targets and calls the provided McpReload function when changes are detected
	WatchTargets(reload McpReload)
	Close()
}

func NewProvider added in v0.0.54

func NewProvider(cfg *config.StaticConfig) (Provider, error)

type ProviderFactory added in v0.0.53

type ProviderFactory func(cfg *config.StaticConfig) (Provider, error)

ProviderFactory creates a new Provider 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
}

type TokenVerifier added in v0.0.54

type TokenVerifier interface {
	VerifyToken(ctx context.Context, cluster, token, audience string) (*authenticationv1api.UserInfo, []string, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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