diff --git a/helm/tailing-sidecar-operator/conf/operator.yaml b/helm/tailing-sidecar-operator/conf/operator.yaml new file mode 100644 index 00000000..773049f6 --- /dev/null +++ b/helm/tailing-sidecar-operator/conf/operator.yaml @@ -0,0 +1,2 @@ +sidecar: + image: {{ .Values.sidecar.image.repository }}:{{ .Values.sidecar.image.tag | default .Chart.AppVersion }} diff --git a/helm/tailing-sidecar-operator/templates/_helpers.tpl b/helm/tailing-sidecar-operator/templates/_helpers.tpl index 71369825..70d6e74b 100644 --- a/helm/tailing-sidecar-operator/templates/_helpers.tpl +++ b/helm/tailing-sidecar-operator/templates/_helpers.tpl @@ -49,3 +49,10 @@ Selector labels app.kubernetes.io/name: {{ include "tailing-sidecar-operator.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} + +{{/* +Configmap name +*/}} +{{- define "tailing-sidecar-operator.configMap.name" -}} +{{- printf "%s-%s" .Release.Name "operator-config" | trunc 63 | trimSuffix "-" }} +{{- end }} diff --git a/helm/tailing-sidecar-operator/templates/configmap.yaml b/helm/tailing-sidecar-operator/templates/configmap.yaml new file mode 100644 index 00000000..dd67d3a9 --- /dev/null +++ b/helm/tailing-sidecar-operator/templates/configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "tailing-sidecar-operator.configMap.name" . }} + labels: + {{- include "tailing-sidecar-operator.labels" . | nindent 4 }} +data: + config.yaml: | + {{- (tpl (.Files.Get "conf/operator.yaml") .) | nindent 4 }} diff --git a/helm/tailing-sidecar-operator/templates/resources.yaml b/helm/tailing-sidecar-operator/templates/resources.yaml index 8757e458..265aeaed 100644 --- a/helm/tailing-sidecar-operator/templates/resources.yaml +++ b/helm/tailing-sidecar-operator/templates/resources.yaml @@ -368,6 +368,8 @@ spec: metadata: labels: {{- include "tailing-sidecar-operator.selectorLabels" . | nindent 8 }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} spec: containers: - args: @@ -384,7 +386,7 @@ spec: - args: - --metrics-addr=127.0.0.1:8080 - --enable-leader-election - - --tailing-sidecar-image={{ .Values.sidecar.image.repository }}:{{ .Values.sidecar.image.tag | default .Chart.AppVersion }} + - --config=/tailing-sidecar/config/config.yaml command: - /manager image: {{ .Values.operator.image.repository }}:{{ .Values.operator.image.tag | default .Chart.AppVersion }} @@ -431,6 +433,9 @@ spec: - mountPath: /tmp/k8s-webhook-server/serving-certs name: cert readOnly: true + - mountPath: /tailing-sidecar/config + name: config + readOnly: true serviceAccountName: tailing-sidecar-service-account terminationGracePeriodSeconds: 10 volumes: @@ -438,3 +443,6 @@ spec: secret: defaultMode: 420 secretName: webhook-server-cert + - name: config + configMap: + name: {{ template "tailing-sidecar-operator.configMap.name" . }} diff --git a/helm/tailing-sidecar-operator/values.yaml b/helm/tailing-sidecar-operator/values.yaml index 0a651baf..9fade9b1 100644 --- a/helm/tailing-sidecar-operator/values.yaml +++ b/helm/tailing-sidecar-operator/values.yaml @@ -4,9 +4,9 @@ nameOverride: "" operator: image: pullPolicy: IfNotPresent - repository: public.ecr.aws/sumologic/tailing-sidecar-operator + repository: localhost:32000/sumologic/tailing-sidecar-operator # Overrides the image tag whose default is the Helm Chart appVersion. - tag: "" + tag: "latest" resources: limits: cpu: 100m @@ -22,9 +22,9 @@ operator: sidecar: image: - repository: public.ecr.aws/sumologic/tailing-sidecar + repository: localhost:32000/sumologic/tailing-sidecar # Overrides the image tag whose default is the Helm Chart appVersion. - tag: "" + tag: "latest" kubeRbacProxy: image: diff --git a/operator/Dockerfile b/operator/Dockerfile index ed8a8496..4e9dc3cd 100644 --- a/operator/Dockerfile +++ b/operator/Dockerfile @@ -11,7 +11,7 @@ COPY . . RUN go mod download # Build -RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager main.go config.go +RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -a -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/operator/Makefile b/operator/Makefile index 16f14ab4..1aa9dce6 100755 --- a/operator/Makefile +++ b/operator/Makefile @@ -46,11 +46,11 @@ clean: # Build manager binary manager: generate fmt vet - go build -o bin/manager main.go ./config.go + go build -o bin/manager main.go # Run against the configured Kubernetes cluster in ~/.kube/config run: generate fmt vet manifests - go run ./main.go ./config.go + go run ./main.go # Install CRDs into a cluster install: manifests kustomize diff --git a/operator/main.go b/operator/main.go index 568de469..b6920985 100644 --- a/operator/main.go +++ b/operator/main.go @@ -50,40 +50,15 @@ func main() { var metricsAddr string var enableLeaderElection bool var tailingSidecarImage string - var configPath string - var config Config - var err error - flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") flag.BoolVar(&enableLeaderElection, "enable-leader-election", false, "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") - flag.StringVar(&tailingSidecarImage, "tailing-sidecar-image", "", "tailing sidecar image") - flag.StringVar(&configPath, "config", "", "Path to the configuration file") + flag.StringVar(&tailingSidecarImage, "tailing-sidecar-image", "sumologic/tailing-sidecar:latest", "tailing sidecar image") flag.Parse() ctrl.SetLogger(zap.New(zap.UseDevMode(true))) - if configPath != "" { - config, err = ReadConfig(configPath) - - if err != nil { - setupLog.Error(err, "unable to read configuration", "configPath", configPath) - os.Exit(1) - } - } else { - config = Config{} - } - - if err := config.Validate(); err != nil { - setupLog.Error(err, "configuration error", "configPath", configPath) - os.Exit(1) - } - - if tailingSidecarImage != "" { - config.Sidecar.Image = tailingSidecarImage - } - mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsAddr, @@ -109,7 +84,7 @@ func main() { mgr.GetWebhookServer().Register("/add-tailing-sidecars-v1-pod", &webhook.Admission{ Handler: &handler.PodExtender{ Client: mgr.GetClient(), - TailingSidecarImage: config.Sidecar.Image, + TailingSidecarImage: tailingSidecarImage, }, })