Documentation ¶
Overview ¶
Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func GetBackendService(configuration *map[string]string) string
- func GetConfigmapConfiguration(configmap *corev1.ConfigMap) (map[string]string, error)
- func GetInjectedAgentConfig(annotation *map[string]string, configuration *map[string]string)
- func GetServiceName(configuration *map[string]string) string
- func GetTmplFunc() map[string]interface{}
- func PatchReq(pod *corev1.Pod, req admission.Request) admission.Response
- func ValidateConfigmap(configmap *corev1.ConfigMap) (bool, error)
- func ValidateIpandPort(annotation, value string) error
- func ValidateServiceName(annotation, value string) error
- type Annotation
- type AnnotationOverlay
- type AnnotationValidateFunc
- type Annotations
- type GetConfigmap
- type GetStrategy
- type InjectProcessData
- type Injection
- type OverlayAgent
- type OverlayPlugins
- type OverlaySidecar
- type PodInject
- type SidecarInjectField
- func (s *SidecarInjectField) AgentOverlayandGetValue(ao *AnnotationOverlay, annotation *map[string]string, a Annotation) bool
- func (s *SidecarInjectField) CreateConfigmap(ctx context.Context, kubeclient client.Client, namespace string, ...) bool
- func (s *SidecarInjectField) GetInjectStrategy(a Annotations, labels, annotation *map[string]string)
- func (s *SidecarInjectField) Inject(pod *corev1.Pod)
- func (s *SidecarInjectField) OverlayAgent(a Annotations, ao *AnnotationOverlay, annotation *map[string]string) bool
- func (s *SidecarInjectField) OverlayOptional(annotation *map[string]string)
- func (s *SidecarInjectField) OverlayPlugins(annotation *map[string]string)
- func (s *SidecarInjectField) OverlaySidecar(a Annotations, ao *AnnotationOverlay, annotation *map[string]string) bool
- func (s *SidecarInjectField) SidecarOverlayandGetValue(ao *AnnotationOverlay, annotation *map[string]string, a Annotation) (string, bool)
Constants ¶
const ( // DefaultConfigmapNamespace is the system namespace DefaultConfigmapNamespace = "skywalking-swck-system" // DefaultConfigmapName is the default configmap's name DefaultConfigmapName = "skywalking-swck-java-agent-configmap" // DefaultConfigmapKey is the key of default configmap DefaultConfigmapKey = "agent.config" )
const ( // the label means whether to enbale injection , "true" of "false" ActiveInjectorLabel = "swck-java-agent-injected" // SidecarInjectSucceedAnno represents injection succeed SidecarInjectSucceedAnno = "sidecar.skywalking.apache.org/succeed" // the ServiceName and BackendService are important information that need to be printed ServiceName = "agent.service_name" BackendService = "collector.backend_service" )
Variables ¶
var ( //AnnotationValidateFuncs define all validate functions AnnotationValidateFuncs = []AnnotationValidateFunc{ ValidateServiceName, ValidateIpandPort, } )
Functions ¶
func GetBackendService ¶
func GetConfigmapConfiguration ¶
GetConfigmapConfiguration will get the value of agent.config
func GetInjectedAgentConfig ¶
func GetServiceName ¶
func GetTmplFunc ¶
func GetTmplFunc() map[string]interface{}
GetTmplFunc will create template func used in configmap.yaml
func ValidateConfigmap ¶
ValidateConfigmap will verify the value of configmap
func ValidateIpandPort ¶
ValidateIpandPort validates an annotation's value is valid ip and port
func ValidateServiceName ¶
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 ¶
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 GetConfigmap ¶
type GetConfigmap struct {
// contains filtered or unexported fields
}
GetConfigmap is the fifth step of injection process
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 6 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.Get the ConfigMap 6.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, pod *corev1.Pod, req admission.Request, log logr.Logger, kubeclient client.Client) *InjectProcessData
NewInjectProcess create a new InjectProcess
func (*InjectProcessData) Run ¶
func (ipd *InjectProcessData) Run() admission.Response
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 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 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 // determine whether to use annotation to overlay agent config , // default is not to overlay,which means only use configmap to set agent config // Otherwise, the way to overlay is set jvm agent ,just like following // -javaagent: /sky/agent/skywalking-agent,jar={config1}={value1},{config2}={value2} AgentOverlay 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 // configmapVolume is volume that provide user with configmap ConfigmapVolume corev1.Volume // configmapVolumeMount is the configmap's mountpath for user // Notice : the mount path will overwrite the original agent/config/agent.config // So the mount path must match the path of agent.config in the image ConfigmapVolumeMount corev1.VolumeMount // env is used to set java agent’s parameters Env 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) CreateConfigmap ¶
func (s *SidecarInjectField) CreateConfigmap(ctx context.Context, kubeclient client.Client, namespace string, annotation *map[string]string) bool
CreateConfigmap will create a configmap to set java agent config.
func (*SidecarInjectField) GetInjectStrategy ¶
func (s *SidecarInjectField) GetInjectStrategy(a Annotations, 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(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) SidecarOverlayandGetValue ¶
func (s *SidecarInjectField) SidecarOverlayandGetValue(ao *AnnotationOverlay, annotation *map[string]string, a Annotation) (string, bool)
SidecarOverlayandGetValue get final value of sidecar