From b56e44e3a225dba78d8fbef794922d8e8bc6d839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Pavl=C3=ADn?= Date: Wed, 11 Dec 2019 14:28:10 +0100 Subject: [PATCH] Initialize securityContext in injected metrics container --- pkg/webhook/v1alpha3/pod/inject_webhook.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/webhook/v1alpha3/pod/inject_webhook.go b/pkg/webhook/v1alpha3/pod/inject_webhook.go index 3b7cb4b6fce..286683059c0 100644 --- a/pkg/webhook/v1alpha3/pod/inject_webhook.go +++ b/pkg/webhook/v1alpha3/pod/inject_webhook.go @@ -137,7 +137,7 @@ func (s *sidecarInjector) Mutate(pod *v1.Pod, namespace string) (*v1.Pod, error) return nil, err } - injectContainer, err := s.getMetricsCollectorContainer(trial) + injectContainer, err := s.getMetricsCollectorContainer(trial, pod) if err != nil { return nil, err } @@ -162,7 +162,7 @@ func (s *sidecarInjector) Mutate(pod *v1.Pod, namespace string) (*v1.Pod, error) return mutatedPod, nil } -func (s *sidecarInjector) getMetricsCollectorContainer(trial *trialsv1alpha3.Trial) (*v1.Container, error) { +func (s *sidecarInjector) getMetricsCollectorContainer(trial *trialsv1alpha3.Trial, originalPod *v1.Pod) (*v1.Container, error) { mc := trial.Spec.MetricsCollector if mc.Collector.Kind == common.CustomCollector { return mc.Collector.CustomCollector, nil @@ -178,11 +178,13 @@ func (s *sidecarInjector) getMetricsCollectorContainer(trial *trialsv1alpha3.Tri } args := getMetricsCollectorArgs(trial.Name, metricName, mc) sidecarContainerName := getSidecarContainerName(trial.Spec.MetricsCollector.Collector.Kind) + securityContext := originalPod.Spec.Containers[0].SecurityContext.DeepCopy() injectContainer := v1.Container{ Name: sidecarContainerName, Image: image, Args: args, ImagePullPolicy: v1.PullIfNotPresent, + SecurityContext: securityContext, } return &injectContainer, nil }