Skip to content

Commit

Permalink
Support specifying sidecar's image by "flomesh.io/sidecar-image" anno…
Browse files Browse the repository at this point in the history
…tation for pod and namespace. (#327)
  • Loading branch information
cybwan authored and reaver-flomesh committed Aug 16, 2024
1 parent 4f28448 commit 20b7a80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ const (
// SidecarInjectionAnnotation is the annotation used for sidecar injection
SidecarInjectionAnnotation = "flomesh.io/sidecar-injection"

// SidecarImageAnnotation is the annotation used for sidecar injection
SidecarImageAnnotation = "flomesh.io/sidecar-image"

// MetricsAnnotation is the annotation used for enabling/disabling metrics
MetricsAnnotation = "flomesh.io/metrics"

Expand Down
25 changes: 23 additions & 2 deletions pkg/sidecar/providers/pipy/driver/pipy_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,41 @@ import (
"github.com/flomesh-io/fsm/pkg/sidecar/providers/pipy/bootstrap"
)

func getPlatformSpecificSpecComponents(cfg configurator.Configurator, _ string) (podSecurityContext *corev1.SecurityContext, pipyContainer string) {
func getPlatformSpecificSpecComponents(injCtx *driver.InjectorContext, cfg configurator.Configurator, pod *corev1.Pod) (podSecurityContext *corev1.SecurityContext, pipyContainer string) {
podSecurityContext = &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.BoolPtr(false),
RunAsUser: func() *int64 {
uid := constants.SidecarUID
return &uid
}(),
}

if podAnnotations := pod.GetAnnotations(); len(podAnnotations) > 0 {
if podSidecarImage, exists := podAnnotations[constants.SidecarImageAnnotation]; exists {
if len(podSidecarImage) > 0 {
pipyContainer = podSidecarImage
return
}
}
}

if ns, err := injCtx.KubeClient.CoreV1().Namespaces().Get(context.Background(), injCtx.PodNamespace, metav1.GetOptions{}); err == nil {
if nsAnnotations := ns.GetAnnotations(); len(nsAnnotations) > 0 {
if nsSidecarImage, exists := nsAnnotations[constants.SidecarImageAnnotation]; exists {
if len(nsSidecarImage) > 0 {
pipyContainer = nsSidecarImage
return
}
}
}
}

pipyContainer = cfg.GetSidecarImage()
return
}

func getPipySidecarContainerSpec(injCtx *driver.InjectorContext, pod *corev1.Pod, cfg configurator.Configurator, cnPrefix string, originalHealthProbes models.HealthProbes, podOS string) corev1.Container {
securityContext, containerImage := getPlatformSpecificSpecComponents(cfg, podOS)
securityContext, containerImage := getPlatformSpecificSpecComponents(injCtx, cfg, pod)

podControllerKind := ""
podControllerName := ""
Expand Down

0 comments on commit 20b7a80

Please sign in to comment.