Skip to content

Commit

Permalink
remove normal initcontainer in sidecarset's sidecar list (openkruise#…
Browse files Browse the repository at this point in the history
…1719)

Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>
  • Loading branch information
zmberg authored Aug 30, 2024
1 parent a6355b8 commit 68a3793
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
23 changes: 15 additions & 8 deletions pkg/control/sidecarcontrol/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,7 @@ func UpdatePodSidecarSetHash(pod *corev1.Pod, sidecarSet *appsv1alpha1.SidecarSe
// compatible done
}

sidecarList := sets.NewString()
for _, sidecar := range sidecarSet.Spec.Containers {
sidecarList.Insert(sidecar.Name)
}
for _, sidecar := range sidecarSet.Spec.InitContainers {
sidecarList.Insert(sidecar.Name)
}

sidecarList := listSidecarNameInSidecarSet(sidecarSet)
sidecarSetHash[sidecarSet.Name] = SidecarSetUpgradeSpec{
UpdateTimestamp: metav1.Now(),
SidecarSetHash: GetSidecarSetRevision(sidecarSet),
Expand Down Expand Up @@ -575,3 +568,17 @@ func IsSidecarContainer(container corev1.Container) bool {
}
return false
}

// listSidecarNameInSidecarSet list always init containers and sidecar containers
func listSidecarNameInSidecarSet(sidecarSet *appsv1alpha1.SidecarSet) sets.String {
sidecarList := sets.NewString()
for _, sidecar := range sidecarSet.Spec.InitContainers {
if IsSidecarContainer(sidecar.Container) {
sidecarList.Insert(sidecar.Name)
}
}
for _, sidecar := range sidecarSet.Spec.Containers {
sidecarList.Insert(sidecar.Name)
}
return sidecarList
}
5 changes: 4 additions & 1 deletion pkg/webhook/pod/mutating/sidecarset.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ func buildSidecars(isUpdated bool, pod *corev1.Pod, oldPod *corev1.Pod, matchedS
if !isUpdated {
for i := range sidecarSet.Spec.InitContainers {
initContainer := &sidecarSet.Spec.InitContainers[i]
sidecarList.Insert(initContainer.Name)
// only insert k8s native sidecar container for in-place update
if sidecarcontrol.IsSidecarContainer(initContainer.Container) {
sidecarList.Insert(initContainer.Name)
}
// volumeMounts that injected into sidecar container
// when volumeMounts SubPathExpr contains expansions, then need copy container EnvVars(injectEnvs)
injectedMounts, injectedEnvs := sidecarcontrol.GetInjectedVolumeMountsAndEnvs(control, initContainer, pod)
Expand Down

0 comments on commit 68a3793

Please sign in to comment.