jimmidyson / configmap-reload

Simple binary to trigger a reload when a Kubernetes ConfigMap is updated
Apache License 2.0
983 stars 193 forks source link

Build with go 1.19, upgrade dependencies #78

Closed vvvirenyu closed 2 years ago

vvvirenyu commented 2 years ago

Build with minimum Go version 1.18 Upgrade fsnotify to v1.5.4

Build tests:

Build all configmap-reload binaries

$ make clean cross out/configmap-reload
rm -rf out
GOARCH=amd64 GOOS=linux \
go build --installsuffix cgo -ldflags="-s -w -extldflags '-static'" -a \
-o out/configmap-reload-linux-amd64 configmap-reload.go
GOARCH=arm GOOS=linux \
go build --installsuffix cgo -ldflags="-s -w -extldflags '-static'" -a \
-o out/configmap-reload-linux-arm configmap-reload.go
GOARCH=arm64 GOOS=linux \
go build --installsuffix cgo -ldflags="-s -w -extldflags '-static'" -a \
-o out/configmap-reload-linux-arm64 configmap-reload.go
GOARCH=ppc64le GOOS=linux \
go build --installsuffix cgo -ldflags="-s -w -extldflags '-static'" -a \
-o out/configmap-reload-linux-ppc64le configmap-reload.go
GOARCH=s390x GOOS=linux \
go build --installsuffix cgo -ldflags="-s -w -extldflags '-static'" -a \
-o out/configmap-reload-linux-s390x configmap-reload.go
GOARCH=amd64 GOOS=darwin \
go build --installsuffix cgo -ldflags="-s -w -extldflags '-static'" -a \
-o out/configmap-reload-darwin-amd64 configmap-reload.go
GOARCH=amd64 GOOS=windows \
go build --installsuffix cgo -ldflags="-s -w -extldflags '-static'" -a \
-o out/configmap-reload-windows-amd64.exe configmap-reload.go
cp out/configmap-reload-linux-amd64 out/configmap-reload

Check binary

$ ./out/configmap-reload
2022/10/06 22:27:12 Missing volume-dir
2022/10/06 22:27:12
Usage of ./out/configmap-reload:
-volume-dir value
the config map volume directory to watch for updates; may be used multiple times
-web.listen-address string
Address to listen on for web interface and telemetry. (default ":9533")
-web.telemetry-path string
Path under which to expose metrics. (default "/metrics")
-webhook-method string
the HTTP method url to use to send the webhook (default "POST")
-webhook-retries int
the amount of times to retry the webhook reload request (default 1)
-webhook-status-code int
the HTTP status code indicating successful triggering of reload (default 200)
-webhook-url value
the url to send a request to when the specified config map volume directory has been updated

Publish docker image

$ make docker GOOS=linux GOARCH=amd64 DOCKER_IMAGE_TAG=v0.7.1-go118
docker build --build-arg BASEIMAGE=amd64/busybox:stable --build-arg BINARY=configmap-reload-linux-amd64 -t jimmidyson/configmap-reload:v0.7.1-go118-amd64 .
Sending build context to Docker daemon  69.31MB
...
Successfully built 800f3b3854ad
Successfully tagged jimmidyson/configmap-reload:v0.7.1-go118-amd64

Functional tests

  1. Downloaded prometheus helm charts to deploy on a K8s cluster https://github.com/prometheus-community/helm-charts/blob/main/charts/prometheus/templates/server/cm.yaml

  2. Updated prometheus server config to point to the new configmap-reload docker image

  3. Successfully deployed prometheus server with new docker image

  4. Verified configmaps are updated inside the container when configmap is modified

  5. Verified Go version

    $ kubectl exec -it prometheus-server-0 -n my-namespace -- sh -c 'strings /configmap-reload | grep '^go1''
    Defaulted container "my-namespace-server-configmap-reload" out of: my-namespace-server-configmap-reload, my-namespace-server
    go1.18.6

Follow-up PR could include:

  1. Update golang used by circleci builds
  2. Upgrade client_golang library to v1.13.0 if needed