Documentation ¶
Overview ¶
Package patcher contains utilities to patch a Pod to inject the Dapr sidecar container.
Index ¶
- Constants
- Variables
- func GetEnvPatchOperations(envs []corev1.EnvVar, addEnv []corev1.EnvVar, containerIdx int) jsonpatch.Patch
- func GetVolumeMountPatchOperations(volumeMounts []corev1.VolumeMount, addMounts []corev1.VolumeMount, ...) jsonpatch.Patch
- func Injectable(appID string, components []componentsapi.Component) []corev1.Container
- func NewPatchOperation(op string, path string, value any) jsonpatch.Operation
- func PatchPod(pod *corev1.Pod, patch jsonpatch.Patch) (*corev1.Pod, error)
- type GetInjectedComponentContainersFn
- type Service
- type SidecarConfig
- func (c *SidecarConfig) GetAppID() string
- func (c *SidecarConfig) GetAppProtocol() string
- func (c *SidecarConfig) GetPatch() (patchOps jsonpatch.Patch, err error)
- func (c *SidecarConfig) NeedsPatching() bool
- func (c *SidecarConfig) SetFromPodAnnotations()
- func (c *SidecarConfig) String() string
- func (c *SidecarConfig) StringAll() string
Constants ¶
const ( // Path for patching containers. PatchPathContainers = "/spec/containers" // Path for patching volumes. PatchPathVolumes = "/spec/volumes" // Path for patching labels. PatchPathLabels = "/metadata/labels" )
Variables ¶
var ( // Dapr API service. ServiceAPI = Service{"dapr-api", 443} // Dapr placement service. ServicePlacement = Service{"dapr-placement-server", 50005} // Dapr placement service. ServiceScheduler = Service{"dapr-scheduler-server", 50006} // Dapr Sentry service. ServiceSentry = Service{"dapr-sentry", 443} )
Predefined services
Functions ¶
func GetEnvPatchOperations ¶
func GetEnvPatchOperations(envs []corev1.EnvVar, addEnv []corev1.EnvVar, containerIdx int) jsonpatch.Patch
GetEnvPatchOperations adds new environment variables only if they do not exist. It does not override existing values for those variables if they have been defined already.
func GetVolumeMountPatchOperations ¶
func GetVolumeMountPatchOperations(volumeMounts []corev1.VolumeMount, addMounts []corev1.VolumeMount, containerIdx int) jsonpatch.Patch
GetVolumeMountPatchOperations gets the patch operations for volume mounts
func Injectable ¶
func Injectable(appID string, components []componentsapi.Component) []corev1.Container
Injectable parses the container definition from components annotations returning them as a list. Uses the appID to filter only the eligble components for such apps avoiding injecting containers that will not be used.
func NewPatchOperation ¶
NewPatchOperation returns a jsonpatch.Operation with the provided properties. This patch represents a discrete change to be applied to a Kubernetes resource.
Types ¶
type GetInjectedComponentContainersFn ¶
type GetInjectedComponentContainersFn = func(appID string, namespace string) ([]corev1.Container, error)
GetInjectedComponentContainersFn is a function that returns the list of component containers for a given appID and namespace.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents a Dapr control plane service's information.
func NewService ¶
NewService returns a Service with values from a string in the format "<name>:<port>"
type SidecarConfig ¶
type SidecarConfig struct { GetInjectedComponentContainers GetInjectedComponentContainersFn Mode injectorConsts.DaprMode `default:"kubernetes"` Namespace string MTLSEnabled bool Identity string IgnoreEntrypointTolerations []corev1.Toleration ImagePullPolicy corev1.PullPolicy OperatorAddress string SentryAddress string RunAsNonRoot bool RunAsUser *int64 RunAsGroup *int64 EnableK8sDownwardAPIs bool ReadOnlyRootFilesystem bool SidecarDropALLCapabilities bool DisableTokenVolume bool CurrentTrustAnchors []byte ControlPlaneNamespace string ControlPlaneTrustDomain string ActorsService string RemindersService string SentrySPIFFEID string SidecarHTTPPort int32 `default:"3500"` SidecarPublicPort int32 `default:"3501"` Enabled bool `annotation:"dapr.io/enabled"` AppPort int32 `annotation:"dapr.io/app-port"` Config string `annotation:"dapr.io/config"` AppProtocol string `annotation:"dapr.io/app-protocol" default:"http"` AppSSL bool `annotation:"dapr.io/app-ssl"` // TODO: Deprecated in Dapr 1.11; remove in a future Dapr version AppID string `annotation:"dapr.io/app-id"` EnableProfiling bool `annotation:"dapr.io/enable-profiling"` LogLevel string `annotation:"dapr.io/log-level" default:"info"` APITokenSecret string `annotation:"dapr.io/api-token-secret"` AppTokenSecret string `annotation:"dapr.io/app-token-secret"` LogAsJSON bool `annotation:"dapr.io/log-as-json"` AppMaxConcurrency *int `annotation:"dapr.io/app-max-concurrency"` EnableMetrics bool `annotation:"dapr.io/enable-metrics" default:"true"` SidecarMetricsPort int32 `annotation:"dapr.io/metrics-port" default:"9090"` EnableDebug bool `annotation:"dapr.io/enable-debug" default:"false"` SidecarDebugPort int32 `annotation:"dapr.io/debug-port" default:"40000"` Env string `annotation:"dapr.io/env"` SidecarAPIGRPCPort int32 `annotation:"dapr.io/grpc-port" default:"50001"` SidecarInternalGRPCPort int32 `annotation:"dapr.io/internal-grpc-port" default:"50002"` SidecarCPURequest string `annotation:"dapr.io/sidecar-cpu-request"` SidecarCPULimit string `annotation:"dapr.io/sidecar-cpu-limit"` SidecarMemoryRequest string `annotation:"dapr.io/sidecar-memory-request"` SidecarMemoryLimit string `annotation:"dapr.io/sidecar-memory-limit"` SidecarListenAddresses string `annotation:"dapr.io/sidecar-listen-addresses" default:"[::1],127.0.0.1"` SidecarLivenessProbeDelaySeconds int32 `annotation:"dapr.io/sidecar-liveness-probe-delay-seconds" default:"3"` SidecarLivenessProbeTimeoutSeconds int32 `annotation:"dapr.io/sidecar-liveness-probe-timeout-seconds" default:"3"` SidecarLivenessProbePeriodSeconds int32 `annotation:"dapr.io/sidecar-liveness-probe-period-seconds" default:"6"` SidecarLivenessProbeThreshold int32 `annotation:"dapr.io/sidecar-liveness-probe-threshold" default:"3"` SidecarReadinessProbeDelaySeconds int32 `annotation:"dapr.io/sidecar-readiness-probe-delay-seconds" default:"3"` SidecarReadinessProbeTimeoutSeconds int32 `annotation:"dapr.io/sidecar-readiness-probe-timeout-seconds" default:"3"` SidecarReadinessProbePeriodSeconds int32 `annotation:"dapr.io/sidecar-readiness-probe-period-seconds" default:"6"` SidecarReadinessProbeThreshold int32 `annotation:"dapr.io/sidecar-readiness-probe-threshold" default:"3"` SidecarImage string `annotation:"dapr.io/sidecar-image"` SidecarSeccompProfileType string `annotation:"dapr.io/sidecar-seccomp-profile-type"` HTTPMaxRequestSize *int `annotation:"dapr.io/http-max-request-size"` // Legacy flag MaxBodySize string `annotation:"dapr.io/max-body-size"` HTTPReadBufferSize *int `annotation:"dapr.io/http-read-buffer-size"` // Legacy flag ReadBufferSize string `annotation:"dapr.io/read-buffer-size"` GracefulShutdownSeconds int `annotation:"dapr.io/graceful-shutdown-seconds" default:"-1"` BlockShutdownDuration *string `annotation:"dapr.io/block-shutdown-duration"` EnableAPILogging *bool `annotation:"dapr.io/enable-api-logging"` UnixDomainSocketPath string `annotation:"dapr.io/unix-domain-socket-path"` VolumeMounts string `annotation:"dapr.io/volume-mounts"` VolumeMountsRW string `annotation:"dapr.io/volume-mounts-rw"` DisableBuiltinK8sSecretStore bool `annotation:"dapr.io/disable-builtin-k8s-secret-store"` EnableAppHealthCheck bool `annotation:"dapr.io/enable-app-health-check"` AppHealthCheckPath string `annotation:"dapr.io/app-health-check-path" default:"/healthz"` AppHealthProbeInterval int32 `annotation:"dapr.io/app-health-probe-interval" default:"5"` // In seconds AppHealthProbeTimeout int32 `annotation:"dapr.io/app-health-probe-timeout" default:"500"` // In milliseconds AppHealthThreshold int32 `annotation:"dapr.io/app-health-threshold" default:"3"` PlacementAddress string `annotation:"dapr.io/placement-host-address"` SchedulerAddress string `annotation:"dapr.io/scheduler-host-address"` PluggableComponents string `annotation:"dapr.io/pluggable-components"` PluggableComponentsSocketsFolder string `annotation:"dapr.io/pluggable-components-sockets-folder"` ComponentContainer string `annotation:"dapr.io/component-container"` InjectPluggableComponents bool `annotation:"dapr.io/inject-pluggable-components"` AppChannelAddress string `annotation:"dapr.io/app-channel-address"` // contains filtered or unexported fields }
SidecarConfig contains the configuration for the sidecar container. Its parameters can be read from annotations on a pod. Note: make sure that the annotations defined here are in-sync with the constants in the pkg/injector/annotations package.
func NewSidecarConfig ¶
func NewSidecarConfig(pod *corev1.Pod) *SidecarConfig
NewSidecarConfig returns a ContainerConfig object for a pod.
func (*SidecarConfig) GetAppID ¶
func (c *SidecarConfig) GetAppID() string
GetAppID returns the AppID property, fallinb back to the name of the pod.
func (*SidecarConfig) GetAppProtocol ¶
func (c *SidecarConfig) GetAppProtocol() string
func (*SidecarConfig) GetPatch ¶
func (c *SidecarConfig) GetPatch() (patchOps jsonpatch.Patch, err error)
GetPatch returns the patch to apply to a Pod to inject the Dapr sidecar
func (*SidecarConfig) NeedsPatching ¶
func (c *SidecarConfig) NeedsPatching() bool
NeedsPatching returns true if patching is needed.
func (*SidecarConfig) SetFromPodAnnotations ¶
func (c *SidecarConfig) SetFromPodAnnotations()
func (*SidecarConfig) String ¶
func (c *SidecarConfig) String() string
String implements fmt.Stringer and is used to print the state of the object, primarily for debugging purposes.
func (*SidecarConfig) StringAll ¶
func (c *SidecarConfig) StringAll() string
StringAll returns the list of all annotations (including empty ones), primarily for debugging purposes.