This is an automated email from the ASF dual-hosted git repository.
hanahmily pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-swck.git
The following commit(s) were added to refs/heads/master by this push:
new e62f9a8 Avoid duplicated injection while injecting java agent. (#98)
e62f9a8 is described below
commit e62f9a873e1c8a1675e0d386dbd49b60402df21c
Author: Ye Cao <[email protected]>
AuthorDate: Mon Oct 23 09:58:32 2023 +0800
Avoid duplicated injection while injecting java agent. (#98)
Signed-off-by: dashanji <[email protected]>
---
CHANGES.md | 7 +++++++
operator/pkg/operator/injector/injector.go | 8 +++++++-
test/e2e/oap-ui-agent/e2e.yaml | 4 ++++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/CHANGES.md b/CHANGES.md
index 7916439..0db04a1 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,6 +2,13 @@ Changes by Version
==================
Release Notes.
+0.9.0
+------------------
+
+#### Bugs
+
+- Fix the bug that the java agent is duplicated injected when update the pod.
+
0.8.0
------------------
diff --git a/operator/pkg/operator/injector/injector.go
b/operator/pkg/operator/injector/injector.go
index e2823cd..bf86a42 100644
--- a/operator/pkg/operator/injector/injector.go
+++ b/operator/pkg/operator/injector/injector.go
@@ -94,6 +94,7 @@ func NewSidecarInjectField() *SidecarInjectField {
// Inject will do real injection
func (s *SidecarInjectField) Inject(pod *corev1.Pod) {
log.Info(fmt.Sprintf("inject pod : %s", pod.GenerateName))
+
// add initcontrainers to spec
if pod.Spec.InitContainers != nil {
pod.Spec.InitContainers = append(pod.Spec.InitContainers,
s.Initcontainer)
@@ -150,11 +151,16 @@ func (s *SidecarInjectField) GetInjectStrategy(labels,
annotation *map[string]st
// set default value
s.NeedInject = false
- // set NeedInject's value , if the pod has the label
"swck-java-agent-injected=true", means need inject
+ // set NeedInject's value, if the pod has the label
"swck-java-agent-injected=true", means need inject
if *labels == nil {
return
}
+ // if the pod is injected, then return
+ if strings.EqualFold((*annotation)[SidecarInjectSucceedAnno], "true") {
+ return
+ }
+
if strings.EqualFold((*labels)[ActiveInjectorLabel], "true") {
s.NeedInject = true
}
diff --git a/test/e2e/oap-ui-agent/e2e.yaml b/test/e2e/oap-ui-agent/e2e.yaml
index 8eaee57..63ca84b 100644
--- a/test/e2e/oap-ui-agent/e2e.yaml
+++ b/test/e2e/oap-ui-agent/e2e.yaml
@@ -58,6 +58,10 @@ setup:
- namespace: skywalking-system
resource: deployment/demo
for: condition=Available
+ - name: patch test annotation
+ command: |
+ kubectl annotate pod $(kubectl get pod -lapp=demo -n skywalking-system
-oname | awk -F '/' '{print $2}') \
+ test-depulicate-injection=true -n skywalking-system
kind:
expose-ports:
- namespace: skywalking-system