injector

package
v0.0.0-...-010ac7f Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// the label means whether to enbale injection , "true" or "false".
	ActiveInjectorLabel = "swck-java-agent-injected"
	// SidecarInjectSucceedAnno represents injection succeed
	SidecarInjectSucceedAnno = "sidecar.skywalking.apache.org/succeed"
)
View Source
const (
	// CPU is in cores (100m = .1 cores)
	CPU string = "cpu"
	// Memory is in bytes (100Gi = 100GiB = 100 * 1024 * 1024 * 1024)
	Memory string = "memory"
	// EphemeralStorage is in bytes (100Gi = 100GiB = 100 * 1024 * 1024 * 1024)
	EphemeralStorage string = "ephemeral-storage"
	// HugePagesPrefix is huge pages prefix
	HugePagesPrefix string = "hugepages-"
)

Variables

View Source
var (
	//AnnotationValidateFuncs define all validate functions
	AnnotationValidateFuncs = []AnnotationValidateFunc{
		ValidateServiceName,
		ValidateBackendServices,
		ValidateIPv4OrHostname,
		ValidateResourceRequirements,
	}
)

Functions

func GetInjectedAgentConfig

func GetInjectedAgentConfig(annotation *map[string]string, configuration *map[string]string)

func PatchReq

func PatchReq(pod *corev1.Pod, req admission.Request) admission.Response

PatchReq is to fill the injected pod into the request and return the Response

func ValidateBackendServices

func ValidateBackendServices(annotation, value string) error

ValidateBackendServices validates an annotation's value is valid backend services

func ValidateIPv4OrHostname

func ValidateIPv4OrHostname(annotation, service string) error

ValidateIPv4OrHostname validates an annotation's value is valid ipv4 or hostname

func ValidateResourceRequirements

func ValidateResourceRequirements(annotation, value string) error

ValidateResourceRequirements validates the resource requirement

func ValidateServiceName

func ValidateServiceName(annotation, value string) error

ValidateServiceName validates the ServiceName is nil or not

Types

type Annotation

type Annotation struct {
	// Name defines the reference to configuration used in Pod's AnnotationOverlay.
	Name string `yaml:"name"`
	// DefaultValue defines the default value of configuration, if there
	// isn't a default value, it will be "nil".
	DefaultValue string `yaml:"defaultValue"`
	// ValidateFunc defines a Validate func to judge whether the value
	// is valid, if there isn't a validate func, it will be "nil".
	ValidateFunc string `yaml:"validateFunc"`
	// EnvName represent the environment variable , just like following
	// in agent.namespace=${SW_AGENT_NAMESPACE:} , the EnvName is SW_AGENT_NAMESPACE
	EnvName string `yaml:"envName"`
}

Annotation defines configuration that user can overlay, including sidecar configuration and java agent configuration.

type AnnotationOverlay

type AnnotationOverlay map[Annotation]string

AnnotationOverlay is used to set overlaied value

func NewAnnotationOverlay

func NewAnnotationOverlay() *AnnotationOverlay

NewAnnotationOverlay will create a new AnnotationOverlay

func (*AnnotationOverlay) GetFinalValue

func (as *AnnotationOverlay) GetFinalValue(a Annotation) string

GetFinalValue will get overlaied value first , then default

func (*AnnotationOverlay) GetOverlayValue

func (as *AnnotationOverlay) GetOverlayValue(a Annotation) string

GetOverlayValue will get overlaied value, if not then return ""

func (*AnnotationOverlay) SetOverlay

func (as *AnnotationOverlay) SetOverlay(AnnotationOverlay *map[string]string, a Annotation) error

SetOverlay will set overlaied value

type AnnotationValidateFunc

type AnnotationValidateFunc func(annotation, value string) error

AnnotationValidateFunc is the type of validate function

func FindValidateFunc

func FindValidateFunc(funcName string) AnnotationValidateFunc

FindValidateFunc is find the validate function for an annotation

type Annotations

type Annotations struct {
	Annotations []Annotation
}

Annotations are set of

func GetAnnotationsByPrefix

func GetAnnotationsByPrefix(a Annotations, prefixName string) *Annotations

GetAnnotationsByPrefix gets annotations from annotations.yaml

func NewAnnotations

func NewAnnotations() (*Annotations, error)

NewAnnotations will create a new AnnotationOverlay

type GetStrategy

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

GetStrategy is the first step of injection process

type InjectProcessData

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

InjectProcessData defines data that needs to be processed in the injection process Divide the entire injection process into 5 steps 1.Get injection strategy 2.Overlay the sidecar info 3.Overlay the agent by setting jvm string 4.Overlay the plugins by setting jvm string and set the optional plugins 5.Inject fields into Pod After all steps are completed, return fully injected Pod, Or there is an error in a certain step, inject error info into annotations and return incompletely injected Pod

func NewInjectProcess

func NewInjectProcess(ctx context.Context, injectFileds *SidecarInjectField, annotation *Annotations,
	annotationOverlay *AnnotationOverlay, swAgentL *v1alpha1.SwAgentList, pod *corev1.Pod, req admission.Request, log logr.Logger,
	kubeclient client.Client) *InjectProcessData

NewInjectProcess create a new InjectProcess

func (*InjectProcessData) Run

Run will connect the above six steps into a chain and start to execute the first step

type Injection

type Injection interface {
	// contains filtered or unexported methods
}

Injection is each step of the injection process

type JavaagentInjector

type JavaagentInjector struct {
	Client client.Client
	// contains filtered or unexported fields
}

JavaagentInjector injects java agent into Pods

func NewJavaagentInjector

func NewJavaagentInjector(client client.Client, schema *runtime.Scheme) *JavaagentInjector

func (*JavaagentInjector) Handle

Handle will process every coming pod under the specified namespace which labeled "swck-injection=enabled"

type OverlayAgent

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

OverlayAgent is the third step of injection process

type OverlayPlugins

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

OverlayPlugins is the fourth step of injection process

type OverlaySidecar

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

OverlaySidecar is the second step of injection process

type OverlaySwAgentCR

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

OverlaySwAgentCR is the cr config step of injection process

type PodInject

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

PodInject is the sixth step of injection process

type SidecarInjectField

type SidecarInjectField struct {
	// determine whether to inject , default is not to inject
	NeedInject bool
	// Initcontainer is a container that has the agent folder
	Initcontainer corev1.Container
	// sidecarVolume is a shared directory between App's container and initcontainer
	SidecarVolume corev1.Volume
	// sidecarVolumeMount is a path that specifies a shared directory
	SidecarVolumeMount corev1.VolumeMount
	// env is used to set java agent’s parameters
	Env corev1.EnvVar
	// envs is the envs pass to target containers
	Envs []corev1.EnvVar
	// the string is used to set jvm agent ,just like following
	// -javaagent: /sky/agent/skywalking-agent,jar=jvmAgentConfigStr
	JvmAgentConfigStr string
	// determine which container to inject , default is to inject all containers
	InjectContainer string
}

SidecarInjectField contains all info that will be injected

func NewSidecarInjectField

func NewSidecarInjectField() *SidecarInjectField

NewSidecarInjectField will create a new SidecarInjectField

func (*SidecarInjectField) AgentOverlayandGetValue

func (s *SidecarInjectField) AgentOverlayandGetValue(ao *AnnotationOverlay, annotation *map[string]string,
	a Annotation) bool

AgentOverlayandGetValue will do real annotation overlay

func (*SidecarInjectField) GetInjectStrategy

func (s *SidecarInjectField) GetInjectStrategy(labels, annotation *map[string]string)

GetInjectStrategy gets user's injection strategy

func (*SidecarInjectField) Inject

func (s *SidecarInjectField) Inject(pod *corev1.Pod)

Inject will do real injection

func (*SidecarInjectField) OverlayAgent

func (s *SidecarInjectField) OverlayAgent(a Annotations, ao *AnnotationOverlay, annotation *map[string]string) bool

OverlayAgent overlays agent

func (*SidecarInjectField) OverlayOptional

func (s *SidecarInjectField) OverlayOptional(swAgentL []v1alpha1.SwAgent, annotation *map[string]string)

OverlayOptional overlays optional plugins and move optional plugins to the directory(/plugins) user must ensure that the optional plugins are in the injected container's image Notice , user must specify the correctness of the regular value such as optional.skywalking.apache.org: "trace|webflux|cloud-gateway-2.1.x" or optional-reporter.skywalking.apache.org: "kafka" the final command will be "cd /optional-plugins && ls | grep -E "trace|webflux|cloud-gateway-2.1.x" | xargs -i cp {} /plugins or "cd /optional-reporter-plugins && ls | grep -E "kafka" | xargs -i cp {} /plugins"

func (*SidecarInjectField) OverlayPlugins

func (s *SidecarInjectField) OverlayPlugins(annotation *map[string]string)

OverlayPlugins will add Plugins' config to JvmAgentStr without verification Notice, if a config is not in agent.config, it will be seen as a plugin config user must ensure the accuracy of configuration. Otherwides,If a separator(, or =) in the option or value, it should be wrapped in quotes.

func (*SidecarInjectField) OverlaySidecar

func (s *SidecarInjectField) OverlaySidecar(a Annotations, ao *AnnotationOverlay, annotation *map[string]string) bool

OverlaySidecar overlays default config

func (*SidecarInjectField) OverlaySwAgentCR

func (s *SidecarInjectField) OverlaySwAgentCR(swAgentL *v1alpha1.SwAgentList) bool

func (*SidecarInjectField) SidecarOverlayandGetValue

func (s *SidecarInjectField) SidecarOverlayandGetValue(ao *AnnotationOverlay, annotation *map[string]string,
	a Annotation) (string, bool)

SidecarOverlayandGetValue get final value of sidecar

Jump to

Keyboard shortcuts

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