sidecar

package
v1.9.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

package sidecar contains helpers to build the Container object for Kubernetes to deploy the Dapr sidecar container.

Index

Constants

View Source
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"
	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.
	ContainersPath                = "/spec/containers"
	KubernetesMountPath           = "/var/run/secrets/kubernetes.io/serviceaccount" // Mount path for the Kubernetes service account volume.
)

Variables

View Source
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}
)

DaprPortEnv contains the env vars that are set in containers to pass the ports used by Dapr.

Functions

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 GetSidecarContainer

func GetSidecarContainer(cfg ContainerConfig) (*corev1.Container, error)

GetSidecarContainer returns the Container object for the sidecar.

func GetTokenVolumeMount

func GetTokenVolumeMount(podSpec corev1.PodSpec) *corev1.VolumeMount

GetTokenVolumeMount returns the VolumeMount for the Kubernetes service account.

func GetTrustAnchorsAndCertChain

func GetTrustAnchorsAndCertChain(ctx context.Context, kubeClient kubernetes.Interface, namespace string) (string, string, string)

GetTrustAnchorsAndCertChain returns the trust anchor and certs.

func GetUnixDomainSocketVolume

func GetUnixDomainSocketVolume(pod *corev1.Pod) *corev1.VolumeMount

GetUnixDomainSocketVolume 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 ParseEnvString

func ParseEnvString(envStr string) []coreV1.EnvVar

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

func PodContainsSidecarContainer(pod *coreV1.Pod) bool

PodContainsSidecarContainer returns true if the pod contains a sidecar container (i.e. a container named "daprd").

func ServiceAddress

func ServiceAddress(svc Service, namespace string, clusterDomain string) string

ServiceAddress returns the address of a Dapr control plane service.

Types

type Annotations

type Annotations map[string]string

Annotations contains the annotations for the container.

func (Annotations) Exist

func (a Annotations) Exist(key string) bool

func (Annotations) GetBoolOrDefault

func (a Annotations) GetBoolOrDefault(key string, defaultValue bool) bool

func (Annotations) GetInt32

func (a Annotations) GetInt32(key string) (int32, error)

func (Annotations) GetInt32OrDefault

func (a Annotations) GetInt32OrDefault(key string, defaultValue int32) int32

func (Annotations) GetString

func (a Annotations) GetString(key string) string

func (Annotations) GetStringOrDefault

func (a Annotations) GetStringOrDefault(key, defaultValue string) string

type ContainerConfig

type ContainerConfig struct {
	AppID                       string
	Annotations                 Annotations
	CertChain                   string
	CertKey                     string
	ControlPlaneAddress         string
	DaprSidecarImage            string
	Identity                    string
	IgnoreEntrypointTolerations []corev1.Toleration
	ImagePullPolicy             corev1.PullPolicy
	MTLSEnabled                 bool
	Namespace                   string
	PlacementServiceAddress     string
	SentryAddress               string
	SocketVolumeMount           *corev1.VolumeMount
	TokenVolumeMount            *corev1.VolumeMount
	Tolerations                 []corev1.Toleration
	TrustAnchors                string
	VolumeMounts                []corev1.VolumeMount
}

ContainerConfig contains the configuration for the sidecar container.

type PatchOperation

type PatchOperation struct {
	Op    string      `json:"op"`
	Path  string      `json:"path"`
	Value interface{} `json:"value,omitempty"`
}

PatchOperation represents a discreet change to be applied to a Kubernetes resource.

func AddDaprEnvVarsToContainers

func AddDaprEnvVarsToContainers(containers []corev1.Container) []PatchOperation

AddDaprEnvVarsToContainers adds Dapr environment variables to all the containers in any Dapr-enabled pod. The containers can be injected or user-defined.

func AddSocketVolumeToContainers

func AddSocketVolumeToContainers(containers []corev1.Container, socketVolumeMount *corev1.VolumeMount) []PatchOperation

AddSocketVolumeToContainers adds the Dapr UNIX domain socket volume to all the containers in any Dapr-enabled pod.

type Service

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

Service represents a Dapr control plane service's information.

Jump to

Keyboard shortcuts

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