Documentation
¶
Overview ¶
Package kubernetes provides a client for the Kubernetes runtime including creating, starting, stopping, and retrieving container information.
Index ¶
- Constants
- func IsAvailable() bool
- type Client
- func (c *Client) AttachToWorkload(ctx context.Context, workloadName string) (io.WriteCloser, io.ReadCloser, error)
- func (c *Client) DeployWorkload(ctx context.Context, image string, containerName string, command []string, ...) (int, error)
- func (c *Client) GetWorkloadInfo(ctx context.Context, workloadName string) (runtime.ContainerInfo, error)
- func (c *Client) GetWorkloadLogs(ctx context.Context, workloadName string, follow bool) (string, error)
- func (c *Client) IsRunning(ctx context.Context) error
- func (c *Client) IsWorkloadRunning(ctx context.Context, workloadName string) (bool, error)
- func (c *Client) ListWorkloads(ctx context.Context) ([]runtime.ContainerInfo, error)
- func (c *Client) RemoveWorkload(ctx context.Context, workloadName string) error
- func (*Client) StopWorkload(_ context.Context, _ string) error
- type ConfigMapReader
- type DefaultPlatformDetector
- type Platform
- type PlatformDetector
- type RunConfigMapReader
- type SecurityContextBuilder
- func (b *SecurityContextBuilder) BuildContainerSecurityContext() *corev1.SecurityContext
- func (b *SecurityContextBuilder) BuildContainerSecurityContextApplyConfiguration() *corev1apply.SecurityContextApplyConfiguration
- func (b *SecurityContextBuilder) BuildPodSecurityContext() *corev1.PodSecurityContext
- func (b *SecurityContextBuilder) BuildPodSecurityContextApplyConfiguration() *corev1apply.PodSecurityContextApplyConfiguration
Constants ¶
const RuntimeName = "kubernetes"
RuntimeName is the name identifier for the Kubernetes runtime
const (
// UnknownStatus represents an unknown container status
UnknownStatus = "unknown"
)
Constants for container status
Variables ¶
This section is empty.
Functions ¶
func IsAvailable ¶ added in v0.2.12
func IsAvailable() bool
IsAvailable checks if kubernetes is available
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements the Deployer interface for container operations
func NewClientWithConfig ¶ added in v0.2.11
func NewClientWithConfig(clientset kubernetes.Interface, config *rest.Config) *Client
NewClientWithConfig creates a new container client with a provided config This is primarily used for testing with fake clients
func NewClientWithConfigAndPlatformDetector ¶ added in v0.2.11
func NewClientWithConfigAndPlatformDetector( clientset kubernetes.Interface, config *rest.Config, platformDetector PlatformDetector, ) *Client
NewClientWithConfigAndPlatformDetector creates a new container client with a provided config and platform detector This is primarily used for testing with fake clients and mock platform detectors
func (*Client) AttachToWorkload ¶ added in v0.0.37
func (c *Client) AttachToWorkload(ctx context.Context, workloadName string) (io.WriteCloser, io.ReadCloser, error)
AttachToWorkload implements runtime.Runtime. It establishes a kubectl attach connection to the MCP server pod.
Connection Failure Handling: If the connection fails permanently (after retries with exponential backoff), this function causes the process to exit with code 1. This triggers a Kubernetes restart, allowing the proxy to establish a fresh connection to the current pod. This is critical for handling StatefulSet pod restarts - when the MCP pod restarts, the old kubectl attach connection becomes stale and cannot be reused. Exiting allows Kubernetes to restart the proxy, which then attaches to the new pod.
The retry configuration (see attachRetryTimeout constant) accommodates typical pod restart times in both local and CI environments, while still failing fast enough for truly unavailable pods.
func (*Client) DeployWorkload ¶ added in v0.0.37
func (c *Client) DeployWorkload(ctx context.Context, image string, containerName string, command []string, envVars map[string]string, containerLabels map[string]string, _ *permissions.Profile, transportType string, options *runtime.DeployWorkloadOptions, _ bool, ) (int, error)
DeployWorkload implements runtime.Runtime.
func (*Client) GetWorkloadInfo ¶ added in v0.0.37
func (c *Client) GetWorkloadInfo(ctx context.Context, workloadName string) (runtime.ContainerInfo, error)
GetWorkloadInfo implements runtime.Runtime.
func (*Client) GetWorkloadLogs ¶ added in v0.0.37
func (c *Client) GetWorkloadLogs(ctx context.Context, workloadName string, follow bool) (string, error)
GetWorkloadLogs implements runtime.Runtime.
func (*Client) IsRunning ¶ added in v0.1.1
IsRunning checks the health of the container runtime. This is used to verify that the runtime is operational and can manage workloads.
func (*Client) IsWorkloadRunning ¶ added in v0.0.37
IsWorkloadRunning implements runtime.Runtime.
func (*Client) ListWorkloads ¶ added in v0.0.37
ListWorkloads implements runtime.Runtime.
func (*Client) RemoveWorkload ¶ added in v0.0.37
RemoveWorkload implements runtime.Runtime.
type ConfigMapReader ¶ added in v0.3.0
type ConfigMapReader struct {
// contains filtered or unexported fields
}
ConfigMapReader implements RunConfigMapReader using real Kubernetes API
func NewConfigMapReader ¶ added in v0.3.0
func NewConfigMapReader() (*ConfigMapReader, error)
NewConfigMapReader creates a new ConfigMapReader using in-cluster configuration This is the standard way to create a reader in production Note: This function is not unit tested as it requires a real Kubernetes cluster. The business logic is tested via NewConfigMapReaderWithClient with mock clients.
func NewConfigMapReaderWithClient ¶ added in v0.3.0
func NewConfigMapReaderWithClient(clientset kubernetes.Interface) *ConfigMapReader
NewConfigMapReaderWithClient creates a new ConfigMapReader with the provided clientset This is useful for testing with a mock clientset
func (*ConfigMapReader) GetRunConfigMap ¶ added in v0.3.0
GetRunConfigMap retrieves the runconfig.json from a ConfigMap
type DefaultPlatformDetector ¶ added in v0.2.8
type DefaultPlatformDetector struct {
// contains filtered or unexported fields
}
DefaultPlatformDetector implements PlatformDetector using the existing OpenShift detection logic
func (*DefaultPlatformDetector) DetectPlatform ¶ added in v0.2.8
func (d *DefaultPlatformDetector) DetectPlatform(config *rest.Config) (Platform, error)
DetectPlatform implements the PlatformDetector interface
type PlatformDetector ¶ added in v0.2.8
PlatformDetector defines the interface for detecting the Kubernetes platform type
func NewDefaultPlatformDetector ¶ added in v0.2.8
func NewDefaultPlatformDetector() PlatformDetector
NewDefaultPlatformDetector creates a new DefaultPlatformDetector
type RunConfigMapReader ¶ added in v0.3.0
type RunConfigMapReader interface {
// GetRunConfigMap retrieves the runconfig.json from a ConfigMap
// configMapRef should be in the format "namespace/configmap-name"
// Returns the runconfig.json content as a string
GetRunConfigMap(ctx context.Context, configMapRef string) (string, error)
}
RunConfigMapReader defines the interface for reading RunConfig from ConfigMaps This interface allows for easy mocking in tests
type SecurityContextBuilder ¶ added in v0.2.14
type SecurityContextBuilder struct {
// contains filtered or unexported fields
}
SecurityContextBuilder provides platform-aware security context configuration
func NewSecurityContextBuilder ¶ added in v0.2.14
func NewSecurityContextBuilder(platform Platform) *SecurityContextBuilder
NewSecurityContextBuilder creates a new SecurityContextBuilder for the given platform
func (*SecurityContextBuilder) BuildContainerSecurityContext ¶ added in v0.2.14
func (b *SecurityContextBuilder) BuildContainerSecurityContext() *corev1.SecurityContext
BuildContainerSecurityContext creates a platform-appropriate container security context
func (*SecurityContextBuilder) BuildContainerSecurityContextApplyConfiguration ¶ added in v0.2.14
func (b *SecurityContextBuilder) BuildContainerSecurityContextApplyConfiguration() *corev1apply.SecurityContextApplyConfiguration
BuildContainerSecurityContextApplyConfiguration creates a platform-appropriate container security context using the ApplyConfiguration types used by the client
func (*SecurityContextBuilder) BuildPodSecurityContext ¶ added in v0.2.14
func (b *SecurityContextBuilder) BuildPodSecurityContext() *corev1.PodSecurityContext
BuildPodSecurityContext creates a platform-appropriate pod security context
func (*SecurityContextBuilder) BuildPodSecurityContextApplyConfiguration ¶ added in v0.2.14
func (b *SecurityContextBuilder) BuildPodSecurityContextApplyConfiguration() *corev1apply.PodSecurityContextApplyConfiguration
BuildPodSecurityContextApplyConfiguration creates a platform-appropriate pod security context using the ApplyConfiguration types used by the client