Skip to content

Commit

Permalink
feat(helm): use configmap to configure tailing-sidecar-operator
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Rosiek <[email protected]>
  • Loading branch information
Dominik Rosiek committed May 30, 2023
1 parent b894a24 commit 96cbc98
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 35 deletions.
2 changes: 2 additions & 0 deletions helm/tailing-sidecar-operator/conf/operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sidecar:
image: {{ .Values.sidecar.image.repository }}:{{ .Values.sidecar.image.tag | default .Chart.AppVersion }}
7 changes: 7 additions & 0 deletions helm/tailing-sidecar-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
9 changes: 9 additions & 0 deletions helm/tailing-sidecar-operator/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
10 changes: 9 additions & 1 deletion helm/tailing-sidecar-operator/templates/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down Expand Up @@ -431,10 +433,16 @@ 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:
- name: cert
secret:
defaultMode: 420
secretName: webhook-server-cert
- name: config
configMap:
name: {{ template "tailing-sidecar-operator.configMap.name" . }}
8 changes: 4 additions & 4 deletions helm/tailing-sidecar-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 2 additions & 27 deletions operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
})

Expand Down

0 comments on commit 96cbc98

Please sign in to comment.