Documentation
¶
Overview ¶
Package kubernetes provides Kubernetes environment detection and integration.
Package kubernetes provides Kubernetes environment detection and integration.
Package kubernetes provides Kubernetes environment detection and integration.
Index ¶
- Constants
- Variables
- func TokenReviewMiddleware(auth *TokenReviewAuthenticator) func(http.Handler) http.Handler
- type CRDController
- func (c *CRDController) Start(ctx context.Context) error
- func (c *CRDController) Stop()
- func (c *CRDController) UpdateData(ctx context.Context, data []DataEntry) error
- func (c *CRDController) UpdateMetadata(ctx context.Context, metadata map[string]string) error
- func (c *CRDController) UpdateSecretIndex(ctx context.Context, refs []SecretRef, secretData map[string][]byte) error
- type Config
- type DataEntry
- type DefaultDetector
- type EnvironmentDetector
- type HTTPTokenReviewClient
- type HookAffinity
- type HookCapabilities
- type HookContainer
- type HookEnvVar
- type HookJob
- type HookJobConfig
- type HookJobMetadata
- type HookJobOwnerReference
- type HookJobRunner
- type HookJobSpec
- type HookLister
- type HookNodeAffinity
- type HookNodeSelector
- type HookNodeSelectorRequirement
- type HookNodeSelectorTerm
- type HookPodMetadata
- type HookPodSpec
- type HookPodTemplate
- type HookSecurityContext
- type HookToleration
- type JobClient
- func (c *JobClient) CreateJob(ctx context.Context, namespace string, job *HookJob) error
- func (c *JobClient) DeleteJob(ctx context.Context, namespace, name string) error
- func (c *JobClient) GetJob(ctx context.Context, namespace, name string) (JobState, error)
- func (c *JobClient) GetPlexdHook(ctx context.Context, namespace, name string) (*PlexdHook, error)
- func (c *JobClient) ListJobPods(ctx context.Context, namespace, jobName string) ([]JobPod, error)
- func (c *JobClient) PodLog(ctx context.Context, namespace, pod string, limitBytes int64) (string, error)
- type JobPod
- type JobState
- type K8sAuditLogReader
- type KubeClient
- type KubeSecret
- type KubernetesEnvironment
- type PlexdHook
- type PlexdHookEvent
- type PlexdHookJobTemplate
- type PlexdHookParam
- type PlexdHookSpec
- type PlexdHookStatus
- type PlexdNodeState
- type PlexdNodeStateEvent
- type PlexdNodeStateSpec
- type PlexdNodeStateStatus
- type ReportNotifier
- type SecretRef
- type TokenReviewAuthenticator
- type TokenReviewClient
- type TokenReviewResult
Constants ¶
const DefaultAuditLogPath = "/var/log/kubernetes/audit/audit.log"
DefaultAuditLogPath is the default path to the Kubernetes audit log.
const DefaultCACertPath = ServiceAccountBasePath + "/ca.crt"
DefaultCACertPath is the default path to the Kubernetes cluster CA certificate.
const DefaultCRDSyncInterval = 10 * time.Second
DefaultCRDSyncInterval is the default interval for syncing CRD state.
const DefaultNamespacePath = ServiceAccountBasePath + "/namespace"
DefaultNamespacePath is the default path to the service account namespace file.
const DefaultTokenPath = ServiceAccountBasePath + "/token"
DefaultTokenPath is the default path to the service account token.
const ServiceAccountBasePath = "/var/run/secrets/kubernetes.io/serviceaccount"
ServiceAccountBasePath is the base path for Kubernetes service account secrets.
Variables ¶
var ( // ErrNotFound is returned when a requested resource does not exist. ErrNotFound = errors.New("kubernetes: resource not found") // ErrAlreadyExists is returned when creating a resource that already exists. ErrAlreadyExists = errors.New("kubernetes: resource already exists") ErrUnauthorized = errors.New("kubernetes: unauthorized") )
Sentinel errors for Kubernetes operations.
Functions ¶
func TokenReviewMiddleware ¶
func TokenReviewMiddleware(auth *TokenReviewAuthenticator) func(http.Handler) http.Handler
TokenReviewMiddleware returns an HTTP middleware that authenticates requests using the TokenReviewAuthenticator. It extracts the Bearer token from the Authorization header, validates it, and attaches the identity to the request context. Returns 401 Unauthorized on failure.
Types ¶
type CRDController ¶
type CRDController struct {
// contains filtered or unexported fields
}
CRDController manages the lifecycle of a PlexdNodeState CRD resource: creates on startup, updates spec on state changes, watches status for workload-written report entries, and manages associated Kubernetes Secrets.
func NewCRDController ¶
func NewCRDController(client KubeClient, cfg Config, nodeID, meshIP, namespace string, reportNotifier ReportNotifier, logger *slog.Logger) *CRDController
NewCRDController creates a new CRDController.
func (*CRDController) Start ¶
func (c *CRDController) Start(ctx context.Context) error
Start creates or updates the PlexdNodeState resource and starts the status watcher goroutine. It blocks until the context is cancelled.
func (*CRDController) Stop ¶
func (c *CRDController) Stop()
Stop cancels the status watch and returns.
func (*CRDController) UpdateData ¶
func (c *CRDController) UpdateData(ctx context.Context, data []DataEntry) error
UpdateData updates the PlexdNodeState .spec.data via the KubeClient.
func (*CRDController) UpdateMetadata ¶
UpdateMetadata updates the PlexdNodeState .spec.metadata via the KubeClient.
func (*CRDController) UpdateSecretIndex ¶
func (c *CRDController) UpdateSecretIndex(ctx context.Context, refs []SecretRef, secretData map[string][]byte) error
UpdateSecretIndex updates the PlexdNodeState .spec.secretRefs and manages associated Kubernetes Secrets with ownerReferences. New refs get Secrets created; removed refs get Secrets deleted.
type Config ¶
type Config struct {
// Enabled controls whether Kubernetes integration is active.
// Default: false (must be explicitly enabled).
Enabled bool
// CRDEnabled controls whether CRD management is active.
// Default: true when Enabled is true.
CRDEnabled bool
// Namespace overrides the auto-detected namespace. If empty, the
// namespace is read from the service account metadata at runtime.
Namespace string
// AuditLogPath is the filesystem path to the Kubernetes audit log.
// Default: /var/log/kubernetes/audit/audit.log.
AuditLogPath string
// CRDSyncInterval controls how often CRD state is reconciled.
// Must be at least 1s. Default: 10s.
CRDSyncInterval time.Duration
// TokenPath is the filesystem path to the service account token.
// Default: /var/run/secrets/kubernetes.io/serviceaccount/token.
TokenPath string
}
Config holds the configuration for the Kubernetes integration.
func (*Config) ApplyDefaults ¶
func (c *Config) ApplyDefaults(env *KubernetesEnvironment)
ApplyDefaults sets default values for zero-valued fields. If env is non-nil and InCluster is true, auto-detected values are used for unset fields.
type DataEntry ¶
type DataEntry struct {
Key string `json:"key"`
ContentType string `json:"contentType,omitempty"`
Payload any `json:"payload,omitempty"`
Version int `json:"version,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
}
DataEntry represents a single data item in the PlexdNodeState spec or status report.
type DefaultDetector ¶
DefaultDetector implements EnvironmentDetector using real environment variables and filesystem paths.
func (*DefaultDetector) Detect ¶
func (d *DefaultDetector) Detect() *KubernetesEnvironment
Detect checks environment variables and filesystem paths to determine whether the process is running inside a Kubernetes pod. Returns a KubernetesEnvironment with InCluster=false if KUBERNETES_SERVICE_HOST is not set, or if the service account token file does not exist.
type EnvironmentDetector ¶
type EnvironmentDetector interface {
// Detect returns information about the Kubernetes environment.
// Returns nil if the process is not running inside a Kubernetes pod.
Detect() *KubernetesEnvironment
}
EnvironmentDetector detects whether the process is running inside a Kubernetes cluster and returns environment metadata.
type HTTPTokenReviewClient ¶
type HTTPTokenReviewClient struct {
// contains filtered or unexported fields
}
HTTPTokenReviewClient implements TokenReviewClient using the Kubernetes API server.
func NewHTTPTokenReviewClient ¶
func NewHTTPTokenReviewClient(apiServer, saTokenPath string) *HTTPTokenReviewClient
NewHTTPTokenReviewClient creates a new client that calls the TokenReview API on the given apiServer. The saTokenPath is the filesystem path to the service account token used to authenticate with the API server.
func (*HTTPTokenReviewClient) Review ¶
func (c *HTTPTokenReviewClient) Review(ctx context.Context, token string) (*TokenReviewResult, error)
Review validates a bearer token by calling the Kubernetes TokenReview API.
type HookAffinity ¶ added in v0.32.0
type HookAffinity struct {
NodeAffinity HookNodeAffinity `json:"nodeAffinity"`
}
HookAffinity is the affinity of the Job's pod.
type HookCapabilities ¶ added in v0.32.0
type HookCapabilities struct {
Drop []string `json:"drop"`
}
HookCapabilities lists the capabilities the hook container drops.
type HookContainer ¶ added in v0.32.0
type HookContainer struct {
Name string `json:"name"`
Image string `json:"image"`
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env []HookEnvVar `json:"env"`
SecurityContext HookSecurityContext `json:"securityContext"`
}
HookContainer is the one container of the Job's pod. Command and Args are left out when empty, so the image's entrypoint and arguments apply.
type HookEnvVar ¶ added in v0.32.0
HookEnvVar is one environment variable of the hook container.
type HookJob ¶ added in v0.32.0
type HookJob struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Metadata HookJobMetadata `json:"metadata"`
Spec HookJobSpec `json:"spec"`
}
HookJob is a batch/v1 Job as HookJobRunner creates it for one run of a PlexdHook. It holds only the fields that Job sets, with the JSON names of the batch/v1 API.
type HookJobConfig ¶ added in v0.32.0
type HookJobConfig struct {
// Namespace is the ServiceAccount's namespace. The runner reads PlexdHooks
// and creates Jobs there.
Namespace string
// NodeName is the Kubernetes node the agent runs on, from MY_NODE_NAME.
// Every Job is pinned to it.
NodeName string
// NodeID is plexd's node id.
NodeID string
// OutputLimit is actions.max_output_bytes.
OutputLimit int64
}
HookJobConfig is what a HookJobRunner needs to know of the agent it runs in.
type HookJobMetadata ¶ added in v0.32.0
type HookJobMetadata struct {
Name string `json:"name"`
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
OwnerReferences []HookJobOwnerReference `json:"ownerReferences"`
}
HookJobMetadata is the Job's object metadata.
type HookJobOwnerReference ¶ added in v0.32.0
type HookJobOwnerReference struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Name string `json:"name"`
UID string `json:"uid"`
Controller bool `json:"controller"`
BlockOwnerDeletion bool `json:"blockOwnerDeletion"`
}
HookJobOwnerReference names the PlexdHook that owns the Job. Both flags are always written, so the API server never fills in a default for blockOwnerDeletion.
type HookJobRunner ¶ added in v0.32.0
type HookJobRunner struct {
// contains filtered or unexported fields
}
HookJobRunner runs a dispatched PlexdHook as one Kubernetes Job per execution, on the agent's own node, and follows the Job to its end. It implements actions.PlexdHookRunner.
The Job is named after the node id and the execution id together, so Start, Wait and Stop find the same Job from the execution id alone, in this agent process or the next one, and two agents that receive the same execution id for a cohort dispatch create two Jobs.
func NewHookJobRunner ¶ added in v0.32.0
func NewHookJobRunner(client hookJobAPI, cfg HookJobConfig, logger *slog.Logger) *HookJobRunner
NewHookJobRunner returns a HookJobRunner that reaches the API server through client.
func (*HookJobRunner) Start ¶ added in v0.32.0
func (r *HookJobRunner) Start(ctx context.Context, run actions.PlexdHookRun) error
Start reads the PlexdHook run.Hook names and creates the run's Job from it. A Job that already exists is not an error: it is this run's, created by an earlier attempt.
A hook that does not exist returns actions.ErrPlexdHookNotFound. A hook whose image is not pinned by a sha256 digest is refused without a Job, as the capability manifest leaves it out; so is a parameter with a NUL in its name or value, which no process environment can carry.
func (*HookJobRunner) Stop ¶ added in v0.32.0
Stop reads the log of the run's Job so far and deletes the Job. A Job without a pod gives an empty log. A failed delete is returned with the log that was read.
The log read gets at most half of what is left of ctx, so an API server that is slow to answer it cannot spend the time the delete needs: a Stop that does not delete leaves the hook running until the Job's backstop.
func (*HookJobRunner) Wait ¶ added in v0.32.0
func (r *HookJobRunner) Wait(ctx context.Context, executionID string, bound time.Duration) (actions.PlexdHookResult, error)
Wait follows the run's Job until it is over and returns its outcome. It reads the Job's status at once and then every poll interval:
- Complete: the run succeeded, with the hook container's exit code and log.
- Failed with reason DeadlineExceeded: the backstop ended the Job, which deleted its pods with their log, so the run timed out with neither.
- Failed otherwise: the run failed, with the exit code and log when the container terminated, or the Job's reason and message when it did not.
- Gone: actions.ErrPlexdHookJobNotFound.
- Unreadable: logged once per streak of failed reads, and read again.
When bound has passed since Wait began, it reads the Job's status once more, so a Job that ended since the last read is reported as it ended, and then reads what log there is, deletes the Job and returns a timed-out run, saying so when the hook container never started. When ctx ends first it returns ctx.Err() and leaves the Job alone: the agent is going away or the run was cancelled, and either way the caller decides what becomes of the Job.
The same holds when ctx ends while Wait reads the outcome of a Job it found over, or deletes one whose bound passed: a read or a delete that ctx cut short returns ctx.Err() rather than a result missing its exit code or its log, and the caller stops the Job or leaves it for the next agent.
type HookJobSpec ¶ added in v0.32.0
type HookJobSpec struct {
BackoffLimit int32 `json:"backoffLimit"`
ActiveDeadlineSeconds int64 `json:"activeDeadlineSeconds"`
TTLSecondsAfterFinished int32 `json:"ttlSecondsAfterFinished"`
Template HookPodTemplate `json:"template"`
}
HookJobSpec is the Job's spec.
type HookLister ¶ added in v0.8.0
type HookLister struct {
// contains filtered or unexported fields
}
HookLister reads PlexdHook resources through the Kubernetes API server with the pod's ServiceAccount credentials. ListPlexdHooks is one GET, WatchPlexdHooks is one GET held open as a stream, and neither ever writes.
func NewInClusterHookLister ¶ added in v0.8.0
func NewInClusterHookLister(env *KubernetesEnvironment) (*HookLister, error)
NewInClusterHookLister builds a HookLister for the API server a pod reaches through the KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT variables, trusting the cluster CA at DefaultCACertPath and authenticating with the ServiceAccount token at env.ServiceAccountToken. The client carries no overall timeout, because a watch response lasts as long as its stream: the context passed to ListPlexdHooks or WatchPlexdHooks bounds each call, and the transport bounds only how long an API server may take to start answering.
func (*HookLister) ListPlexdHooks ¶ added in v0.8.0
ListPlexdHooks returns the PlexdHook resources in namespace, or an empty slice when there are none.
The ServiceAccount token is read from disk on every call, because the kubelet rotates it. A 401 or 403 wraps ErrUnauthorized (the ServiceAccount lacks the read grant), a 404 wraps ErrNotFound (the CRD is not installed), and any other status is an error naming it. A context that runs out surfaces as an error wrapping the context's own error.
func (*HookLister) WatchPlexdHooks ¶ added in v0.25.0
func (l *HookLister) WatchPlexdHooks(ctx context.Context, namespace string) (<-chan PlexdHookEvent, error)
WatchPlexdHooks opens a watch on the PlexdHook resources in namespace and returns a channel of their changes. The request carries no resourceVersion, so the API server starts by replaying every existing resource as ADDED, and a version that has gone stale (410 Gone) cannot occur.
An open fails the way ListPlexdHooks does, with the same token handling and the same mapping of a 401 or 403 to ErrUnauthorized and a 404 to ErrNotFound, and it returns no channel.
The channel closes when the stream ends, a frame does not decode, a frame has type ERROR, or ctx ends. It carries no reason, because the answer to each of these is the same: open a new watch. A caller that stops receiving must cancel ctx, which is what releases the goroutine feeding the channel.
type HookNodeAffinity ¶ added in v0.32.0
type HookNodeAffinity struct {
RequiredDuringSchedulingIgnoredDuringExecution HookNodeSelector `json:"requiredDuringSchedulingIgnoredDuringExecution"`
}
HookNodeAffinity holds the node selector the Job's pod must match.
type HookNodeSelector ¶ added in v0.32.0
type HookNodeSelector struct {
NodeSelectorTerms []HookNodeSelectorTerm `json:"nodeSelectorTerms"`
}
HookNodeSelector is a node selector, met when any of its terms is.
type HookNodeSelectorRequirement ¶ added in v0.32.0
type HookNodeSelectorRequirement struct {
Key string `json:"key"`
Operator string `json:"operator"`
Values []string `json:"values"`
}
HookNodeSelectorRequirement is one requirement on a field of a Node.
type HookNodeSelectorTerm ¶ added in v0.32.0
type HookNodeSelectorTerm struct {
MatchFields []HookNodeSelectorRequirement `json:"matchFields"`
}
HookNodeSelectorTerm is one node selector term, met when all of its field requirements are.
type HookPodMetadata ¶ added in v0.32.0
HookPodMetadata is the object metadata of the Job's pod.
type HookPodSpec ¶ added in v0.32.0
type HookPodSpec struct {
RestartPolicy string `json:"restartPolicy"`
AutomountServiceAccountToken bool `json:"automountServiceAccountToken"`
Tolerations []HookToleration `json:"tolerations"`
Affinity HookAffinity `json:"affinity"`
Containers []HookContainer `json:"containers"`
}
HookPodSpec is the spec of the Job's pod. automountServiceAccountToken is always written, because false is the value that matters.
type HookPodTemplate ¶ added in v0.32.0
type HookPodTemplate struct {
Metadata HookPodMetadata `json:"metadata"`
Spec HookPodSpec `json:"spec"`
}
HookPodTemplate is the template of the Job's pod.
type HookSecurityContext ¶ added in v0.32.0
type HookSecurityContext struct {
Privileged bool `json:"privileged,omitempty"`
ReadOnlyRootFilesystem bool `json:"readOnlyRootFilesystem,omitempty"`
Capabilities *HookCapabilities `json:"capabilities,omitempty"`
}
HookSecurityContext is the hook container's security context: privileged, or a read-only root filesystem with every capability dropped. A field that is not set is left out, so each of the two shapes carries only its own keys.
type HookToleration ¶ added in v0.32.0
type HookToleration struct {
Operator string `json:"operator"`
}
HookToleration is one toleration of the Job's pod.
type JobClient ¶ added in v0.32.0
type JobClient struct {
// contains filtered or unexported fields
}
JobClient runs the Jobs of dispatched PlexdHooks through the Kubernetes API server with the pod's ServiceAccount credentials: it reads a PlexdHook, creates, reads and deletes a Job, lists the Job's pods and reads a pod's log. HookJobRunner is its one user.
func NewInClusterJobClient ¶ added in v0.32.0
func NewInClusterJobClient(env *KubernetesEnvironment) (*JobClient, error)
NewInClusterJobClient builds a JobClient for the API server a pod reaches through the KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT variables, trusting the cluster CA at DefaultCACertPath and authenticating with the ServiceAccount token at env.ServiceAccountToken, as NewInClusterHookLister does. The client carries no overall timeout: the context passed to each method bounds the call.
func (*JobClient) CreateJob ¶ added in v0.32.0
CreateJob creates job in namespace. A Job of the same name that already exists wraps ErrAlreadyExists.
func (*JobClient) DeleteJob ¶ added in v0.32.0
DeleteJob deletes the Job name in namespace and, through background propagation, its pods. A Job that is already gone is not an error.
func (*JobClient) GetJob ¶ added in v0.32.0
GetJob returns the state of the Job name in namespace. A Job that does not exist wraps ErrNotFound.
Only the Complete and Failed conditions with status True count. The FailureTarget condition the Job controller sets ahead of Failed is ignored: the Job's pods may still be terminating then, and Failed follows once they are gone.
func (*JobClient) GetPlexdHook ¶ added in v0.32.0
GetPlexdHook returns the PlexdHook name in namespace. A hook that does not exist wraps ErrNotFound.
func (*JobClient) ListJobPods ¶ added in v0.32.0
ListJobPods returns the pods of the Job jobName in namespace, selected by the job-name label the Job controller sets on them, or an empty slice when there are none.
func (*JobClient) PodLog ¶ added in v0.32.0
func (c *JobClient) PodLog(ctx context.Context, namespace, pod string, limitBytes int64) (string, error)
PodLog returns the log of the hook container of pod in namespace, at most its first limitBytes bytes. The API server cuts the log there already; the read is bounded the same way so a server that ignores the limit cannot hand over more.
type JobPod ¶ added in v0.32.0
type JobPod struct {
Name string
CreatedAt time.Time
// ExitCode is the hook container's exit code; nil until it terminated.
ExitCode *int
// WaitingReason is why the hook container waits to start, such as
// ErrImagePull; empty when it is not waiting.
WaitingReason string
}
JobPod is what the runner needs of one pod of a Job.
type JobState ¶ added in v0.32.0
type JobState struct {
// Complete is set by a Complete condition with status True.
Complete bool
// Failed is set by a Failed condition with status True.
Failed bool
// Reason and Message are those of the condition that set a flag, such as
// BackoffLimitExceeded or DeadlineExceeded for a failed Job.
Reason string
Message string
}
JobState is what the conditions of a Job say about its end. Both flags are false while the Job runs.
type K8sAuditLogReader ¶
type K8sAuditLogReader struct {
// contains filtered or unexported fields
}
K8sAuditLogReader implements auditfwd.K8sAuditReader by reading Kubernetes audit log files in JSON-lines format. It tracks the file position between reads so only new entries are returned on each call.
func NewK8sAuditLogReader ¶
func NewK8sAuditLogReader(path string, logger *slog.Logger) *K8sAuditLogReader
NewK8sAuditLogReader creates a new reader for the audit log at the given path.
func (*K8sAuditLogReader) ReadEvents ¶
func (r *K8sAuditLogReader) ReadEvents(_ context.Context) ([]auditfwd.K8sAuditEntry, error)
ReadEvents reads new audit log entries since the last call. It returns only entries appended after the previously recorded offset. If the file does not exist, it returns nil, nil. If the file has been truncated (current size is smaller than the stored offset), it resets to the beginning.
type KubeClient ¶
type KubeClient interface {
// GetNodeState retrieves the PlexdNodeState CRD for the given name and namespace.
// Returns ErrNotFound if the resource does not exist.
GetNodeState(ctx context.Context, namespace, name string) (*PlexdNodeState, error)
// CreateNodeState creates a new PlexdNodeState CRD resource.
// Returns ErrAlreadyExists if the resource already exists.
CreateNodeState(ctx context.Context, state *PlexdNodeState) error
// UpdateNodeState updates an existing PlexdNodeState CRD resource spec.
// Returns ErrNotFound if the resource does not exist.
UpdateNodeState(ctx context.Context, state *PlexdNodeState) error
// DeleteNodeState deletes a PlexdNodeState CRD resource.
// Returns nil if the resource does not exist (idempotent).
DeleteNodeState(ctx context.Context, namespace, name string) error
// WatchNodeState starts a watch on a specific PlexdNodeState resource.
// Returns a channel that receives events until the context is cancelled.
WatchNodeState(ctx context.Context, namespace, name string) (<-chan PlexdNodeStateEvent, error)
// CreateSecret creates a Kubernetes Secret.
// Returns ErrAlreadyExists if the secret already exists.
CreateSecret(ctx context.Context, secret *KubeSecret) error
// UpdateSecret updates an existing Kubernetes Secret.
// Returns ErrNotFound if the secret does not exist.
UpdateSecret(ctx context.Context, secret *KubeSecret) error
// DeleteSecret deletes a Kubernetes Secret.
// Returns nil if the secret does not exist (idempotent).
DeleteSecret(ctx context.Context, namespace, name string) error
}
KubeClient abstracts Kubernetes API interactions for testability. All methods that modify state must be idempotent: repeating an operation that is already applied returns nil.
type KubeSecret ¶
type KubeSecret struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Labels map[string]string `json:"labels,omitempty"`
Data map[string][]byte `json:"data,omitempty"`
OwnerRefName string `json:"ownerRefName,omitempty"`
OwnerRefUID string `json:"ownerRefUID,omitempty"`
}
KubeSecret represents a Kubernetes Secret managed by plexd.
type KubernetesEnvironment ¶
type KubernetesEnvironment struct {
// InCluster is true when plexd is running inside a Kubernetes pod.
InCluster bool
// Namespace is the Kubernetes namespace of the pod.
Namespace string
// PodName is the name of the pod, typically sourced from the HOSTNAME env var.
PodName string
// NodeName is the Kubernetes node name, sourced from the MY_NODE_NAME env var
// (set via the downward API).
NodeName string
// ServiceAccountToken is the filesystem path to the service account token.
ServiceAccountToken string
}
KubernetesEnvironment holds information about the Kubernetes environment in which plexd is running. A nil value indicates that the process is not running inside a Kubernetes pod.
type PlexdHook ¶
type PlexdHook struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
UID string `json:"uid,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Spec PlexdHookSpec `json:"spec"`
Status PlexdHookStatus `json:"status,omitempty"`
}
PlexdHook represents the CRD resource for a hook execution request.
type PlexdHookEvent ¶
PlexdHookEvent represents a watch event for a PlexdHook resource.
type PlexdHookJobTemplate ¶
type PlexdHookJobTemplate struct {
Image string `json:"image"`
Command []string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
}
PlexdHookJobTemplate holds the job template for a PlexdHook.
type PlexdHookParam ¶
PlexdHookParam represents a name/value parameter for a PlexdHook.
type PlexdHookSpec ¶
type PlexdHookSpec struct {
HookName string `json:"hookName"`
JobTemplate *PlexdHookJobTemplate `json:"jobTemplate,omitempty"`
Parameters []PlexdHookParam `json:"parameters,omitempty"`
Privileged bool `json:"privileged,omitempty"`
}
PlexdHookSpec holds the spec fields of a PlexdHook CRD resource.
func (PlexdHookSpec) Image ¶ added in v0.8.0
func (s PlexdHookSpec) Image() string
Image returns the container image a hook with this spec runs: the job template's image, or defaultHookImage when the template or its image is absent.
func (PlexdHookSpec) ImageDigest ¶ added in v0.32.0
func (s PlexdHookSpec) ImageDigest() (string, bool)
ImageDigest returns the digest after the last `@` of Image, and whether it is a canonical sha256 digest. plexd has no registry access to resolve a tag, so only a hook whose image is pinned this way is reported in the capability manifest and run. Both ask this method, so the manifest cannot report a hook the runner refuses, or the other way round.
type PlexdHookStatus ¶
type PlexdHookStatus struct {
JobName string `json:"jobName,omitempty"`
Phase string `json:"phase,omitempty"`
Message string `json:"message,omitempty"`
StartedAt *time.Time `json:"startedAt,omitempty"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
}
PlexdHookStatus holds the status fields of a PlexdHook CRD resource.
type PlexdNodeState ¶
type PlexdNodeState struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
UID string `json:"uid,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Spec PlexdNodeStateSpec `json:"spec"`
Status PlexdNodeStateStatus `json:"status,omitempty"`
LastUpdate time.Time `json:"lastUpdate"`
}
PlexdNodeState represents the CRD resource for a node's state.
type PlexdNodeStateEvent ¶
type PlexdNodeStateEvent struct {
Type string `json:"type"` // ADDED, MODIFIED, DELETED
State *PlexdNodeState `json:"state"`
}
PlexdNodeStateEvent represents a watch event for a PlexdNodeState resource.
type PlexdNodeStateSpec ¶
type PlexdNodeStateSpec struct {
NodeID string `json:"nodeId"`
MeshIP string `json:"meshIp,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Data []DataEntry `json:"data,omitempty"`
SecretRefs []SecretRef `json:"secretRefs,omitempty"`
}
PlexdNodeStateSpec holds the spec fields of a PlexdNodeState CRD resource.
type PlexdNodeStateStatus ¶
type PlexdNodeStateStatus struct {
Report []DataEntry `json:"report,omitempty"`
}
PlexdNodeStateStatus holds the status fields of a PlexdNodeState CRD resource.
type ReportNotifier ¶
type ReportNotifier interface {
NotifyChange()
}
ReportNotifier is called when the CRDController detects new or changed report entries in the status subresource.
type SecretRef ¶
type SecretRef struct {
Key string `json:"key"`
SecretName string `json:"secretName"`
Version int `json:"version,omitempty"`
}
SecretRef represents a reference to a Kubernetes Secret holding encrypted data.
type TokenReviewAuthenticator ¶
type TokenReviewAuthenticator struct {
// contains filtered or unexported fields
}
TokenReviewAuthenticator validates bearer tokens using the Kubernetes TokenReview API.
func NewTokenReviewAuthenticator ¶
func NewTokenReviewAuthenticator(client TokenReviewClient, logger *slog.Logger, audiences []string) *TokenReviewAuthenticator
NewTokenReviewAuthenticator creates a new authenticator that validates tokens via the provided TokenReviewClient. If audiences is non-empty, the result must contain at least one matching audience for authentication to succeed.
func (*TokenReviewAuthenticator) Authenticate ¶
func (a *TokenReviewAuthenticator) Authenticate(ctx context.Context, token string) (*TokenReviewResult, error)
Authenticate validates the given bearer token. Returns the review result if the token is valid, or an error if authentication fails. If audiences are configured, the result must contain at least one matching audience.
type TokenReviewClient ¶
type TokenReviewClient interface {
// Review validates a bearer token via the Kubernetes TokenReview API.
// Returns the authenticated identity if valid, or an error if invalid or unreachable.
Review(ctx context.Context, token string) (*TokenReviewResult, error)
}
TokenReviewClient abstracts Kubernetes TokenReview API access for testability.
type TokenReviewResult ¶
type TokenReviewResult struct {
Authenticated bool
Username string
UID string
Groups []string
Audiences []string
}
TokenReviewResult contains the result of a TokenReview API call.
func IdentityFromContext ¶
func IdentityFromContext(ctx context.Context) *TokenReviewResult
IdentityFromContext retrieves the TokenReviewResult from the request context. Returns nil if no identity is present.