Documentation ¶
Overview ¶
package sidecar contains helpers to build the Container object for Kubernetes to deploy the Dapr sidecar container.
Index ¶
- Constants
- Variables
- func AddDaprEnvVarsToContainers(containers map[int]corev1.Container) []patcher.PatchOperation
- func AddDaprSideCarAppIDLabel(appID string, labels map[string]string) patcher.PatchOperation
- func AddDaprSideCarInjectedLabel(labels map[string]string) patcher.PatchOperation
- func AddDaprSideCarMetricsEnabledLabel(metricsEnabled bool, labels map[string]string) patcher.PatchOperation
- func AddServiceAccountTokenVolume(containers []corev1.Container) []patcher.PatchOperation
- func AddSocketVolumeMountToContainers(containers map[int]corev1.Container, socketVolumeMount *corev1.VolumeMount) []patcher.PatchOperation
- func GetAppID(pod metaV1.ObjectMeta) string
- func GetMetricsEnabled(pod metaV1.ObjectMeta) bool
- func GetSidecarContainer(cfg ContainerConfig) (*corev1.Container, error)
- func GetTokenVolume() corev1.Volume
- func GetTrustAnchorsAndCertChain(ctx context.Context, kubeClient kubernetes.Interface, namespace string) (string, string, string)
- func GetUnixDomainSocketVolumeMount(pod *corev1.Pod) *corev1.VolumeMount
- func GetVolumeMounts(pod corev1.Pod) []corev1.VolumeMount
- func GetVolumesPatchOperations(volumes []corev1.Volume, addVolumes []corev1.Volume, path string) []patcher.PatchOperation
- func ParseEnvString(envStr string) []coreV1.EnvVar
- func ParseVolumeMountsString(volumeMountStr string, readOnly bool) []coreV1.VolumeMount
- func PodContainsSidecarContainer(pod *coreV1.Pod) bool
- func ServiceAddress(svc Service, namespace string, clusterDomain string) string
- type ContainerConfig
- type Service
Constants ¶
const ( SidecarContainerName = "daprd" // Name of the Dapr sidecar container SidecarHTTPPort = 3500 SidecarAPIGRPCPort = 50001 SidecarInternalGRPCPort = 50002 SidecarPublicPort = 3501 SidecarHTTPPortName = "dapr-http" SidecarGRPCPortName = "dapr-grpc" SidecarInternalGRPCPortName = "dapr-internal" SidecarMetricsPortName = "dapr-metrics" SidecarDebugPortName = "dapr-debug" SidecarHealthzPath = "healthz" SidecarInjectedLabel = "dapr.io/sidecar-injected" SidecarAppIDLabel = "dapr.io/app-id" SidecarMetricsEnabledLabel = "dapr.io/metrics-enabled" APIVersionV1 = "v1.0" UnixDomainSocketVolume = "dapr-unix-domain-socket" // Name of the Unix domain socket volume. UserContainerDaprHTTPPortName = "DAPR_HTTP_PORT" // Name of the variable exposed to the app containing the Dapr HTTP port. UserContainerDaprGRPCPortName = "DAPR_GRPC_PORT" // Name of the variable exposed to the app containing the Dapr gRPC port. PatchPathLabels = "/metadata/labels" TokenVolumeKubernetesMountPath = "/var/run/secrets/dapr.io/sentrytoken" /* #nosec */ // Mount path for the Kubernetes service account volume with the sentry token. TokenVolumeName = "dapr-identity-token" /* #nosec */ // Name of the volume with the service account token for daprd. )
Variables ¶
var ( // Dapr API service. ServiceAPI = Service{"dapr-api", 80} // Dapr placement service. ServicePlacement = Service{"dapr-placement-server", 50005} // Dapr sentry service. ServiceSentry = Service{"dapr-sentry", 80} )
var DaprPortEnv = []corev1.EnvVar{ { Name: UserContainerDaprHTTPPortName, Value: strconv.Itoa(SidecarHTTPPort), }, { Name: UserContainerDaprGRPCPortName, Value: strconv.Itoa(SidecarAPIGRPCPort), }, }
DaprPortEnv contains the env vars that are set in containers to pass the ports used by Dapr.
Functions ¶
func AddDaprEnvVarsToContainers ¶
func AddDaprEnvVarsToContainers(containers map[int]corev1.Container) []patcher.PatchOperation
AddDaprEnvVarsToContainers adds Dapr environment variables to all the containers in any Dapr-enabled pod. The containers can be injected or user-defined.
func AddDaprSideCarAppIDLabel ¶ added in v1.11.0
func AddDaprSideCarAppIDLabel(appID string, labels map[string]string) patcher.PatchOperation
AddDaprSideCarAppIDLabel adds Dapr app-id label which can be handy for metric labels
func AddDaprSideCarInjectedLabel ¶ added in v1.10.1
func AddDaprSideCarInjectedLabel(labels map[string]string) patcher.PatchOperation
AddDaprSideCarInjectedLabel adds Dapr label to patch pod so list of patched pods can be retrieved more efficiently
func AddDaprSideCarMetricsEnabledLabel ¶ added in v1.11.0
func AddDaprSideCarMetricsEnabledLabel(metricsEnabled bool, labels map[string]string) patcher.PatchOperation
AddDaprSideCarMetricsEnabledLabel adds Dapr metrics-enabled label which can be handy for scraping metrics
func AddServiceAccountTokenVolume ¶ added in v1.10.0
func AddServiceAccountTokenVolume(containers []corev1.Container) []patcher.PatchOperation
AddServiceAccountTokenVolume adds the projected volume for the service account token to the daprd The containers can be injected or user-defined.
func AddSocketVolumeMountToContainers ¶ added in v1.10.0
func AddSocketVolumeMountToContainers(containers map[int]corev1.Container, socketVolumeMount *corev1.VolumeMount) []patcher.PatchOperation
AddSocketVolumeMountToContainers adds the Dapr UNIX domain socket volume to all the containers in any Dapr-enabled pod.
func GetAppID ¶
func GetAppID(pod metaV1.ObjectMeta) string
GetAppID returns the app ID from the pod's annotation, or uses the pod's name as fallback.
func GetMetricsEnabled ¶ added in v1.11.0
func GetMetricsEnabled(pod metaV1.ObjectMeta) bool
GetMetricsEnabled returns true if metrics have been enabled, or false as fallback.
func GetSidecarContainer ¶
func GetSidecarContainer(cfg ContainerConfig) (*corev1.Container, error)
GetSidecarContainer returns the Container object for the sidecar.
func GetTokenVolume ¶ added in v1.10.0
GetTokenVolume returns the volume projection for the Kubernetes service account. Requests a new projected volume with a service account token for our specific audience.
func GetTrustAnchorsAndCertChain ¶
func GetTrustAnchorsAndCertChain(ctx context.Context, kubeClient kubernetes.Interface, namespace string) (string, string, string)
GetTrustAnchorsAndCertChain returns the trust anchor and certs.
func GetUnixDomainSocketVolumeMount ¶ added in v1.10.0
func GetUnixDomainSocketVolumeMount(pod *corev1.Pod) *corev1.VolumeMount
GetUnixDomainSocketVolumeMount returns a volume mount for the pod to append the UNIX domain socket.
func GetVolumeMounts ¶
func GetVolumeMounts(pod corev1.Pod) []corev1.VolumeMount
GetVolumeMounts returns the list of VolumeMount's for the sidecar container.
func GetVolumesPatchOperations ¶ added in v1.10.0
func ParseEnvString ¶
add env-vars from annotations.
func ParseVolumeMountsString ¶
func ParseVolumeMountsString(volumeMountStr string, readOnly bool) []coreV1.VolumeMount
ParseVolumeMountsString parses the annotation and returns volume mounts. The format of the annotation is: "mountPath1:hostPath1,mountPath2:hostPath2" The readOnly parameter applies to all mounts.
func PodContainsSidecarContainer ¶
PodContainsSidecarContainer returns true if the pod contains a sidecar container (i.e. a container named "daprd").
Types ¶
type ContainerConfig ¶
type ContainerConfig struct { AppID string Annotations annotations.Map CertChain string CertKey string ControlPlaneAddress string DaprSidecarImage string Identity string IgnoreEntrypointTolerations []corev1.Toleration ImagePullPolicy corev1.PullPolicy MTLSEnabled bool Namespace string PlacementServiceAddress string SentryAddress string Tolerations []corev1.Toleration TrustAnchors string VolumeMounts []corev1.VolumeMount ComponentsSocketsVolumeMount *corev1.VolumeMount SkipPlacement bool RunAsNonRoot bool ReadOnlyRootFilesystem bool SidecarDropALLCapabilities bool }
ContainerConfig contains the configuration for the sidecar container.