Skip to content

Commit a545ff3

Browse files
committed
[redis-operator] Build patched operator in-tree
This patch moves the build of the Redis operator into the Cozystack organization and patches it to prevent overwriting third-party labels on owned resources. ```release-note [redis-operator] Move operator into tree and patch it to retain third-party labels on owned resources, reducing noisy traffic to the API server. ``` Signed-off-by: Timofei Larkin <[email protected]>
1 parent 21de4f7 commit a545ff3

4 files changed

Lines changed: 67 additions & 1 deletion

File tree

‎packages/system/redis-operator/Makefile‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
REDIS_OPERATOR_TAG=$(shell grep -F 'ARG VERSION=' images/redis-operator/Dockerfile | cut -f2 -d=)
12
export NAME=redis-operator
23
export NAMESPACE=cozy-$(NAME)
34

5+
include ../../../scripts/common-envs.mk
46
include ../../../scripts/package.mk
57

68
update:
@@ -9,3 +11,16 @@ update:
911
helm repo update redis-operator
1012
helm pull redis-operator/redis-operator --untar --untardir charts
1113
sed -i '/{{/d' charts/redis-operator/crds/databases.spotahome.com_redisfailovers.yaml
14+
15+
image:
16+
docker buildx build images/redis-operator \
17+
--tag $(REGISTRY)/redis-operator:$(REDIS_OPERATOR_TAG) \
18+
--cache-from type=registry,ref=$(REGISTRY)/redis-operator:latest \
19+
--cache-to type=inline \
20+
--metadata-file images/redis-operator.json \
21+
$(BUILDX_ARGS)
22+
REPOSITORY="$(REGISTRY)/redis-operator" \
23+
yq -i '.redis-operator.image.repository = strenv(REPOSITORY)' values.yaml
24+
TAG=$(REDIS_OPERATOR_TAG)@$$(yq e '."containerimage.digest"' images/redis-operator.json -o json -r) \
25+
yq -i '.redis-operator.image.tag = strenv(TAG)' values.yaml
26+
rm -f images/redis-operator.json
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM golang:1.20 AS builder
2+
3+
ARG VERSION=v1.3.0-rc1
4+
5+
ARG TARGETOS
6+
ARG TARGETARCH
7+
8+
WORKDIR /workspace
9+
10+
RUN curl -sSL https://github.com/spotahome/redis-operator/archive/refs/tags/${VERSION}.tar.gz | tar -xzvf- --strip=1
11+
12+
COPY patches /patches
13+
RUN git apply /patches/*.diff
14+
15+
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH VERSION=$VERSION ./scripts/build.sh
16+
17+
FROM alpine:latest
18+
RUN apk --no-cache add \
19+
ca-certificates
20+
COPY --from=builder /workspace/bin/redis-operator /usr/local/bin
21+
RUN addgroup -g 1000 rf && \
22+
adduser -D -u 1000 -G rf rf && \
23+
chown rf:rf /usr/local/bin/redis-operator
24+
USER rf
25+
26+
ENTRYPOINT ["/usr/local/bin/redis-operator"]
27+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
diff --git a/service/k8s/service.go b/service/k8s/service.go
2+
index 712cc4c0..e84afc92 100644
3+
--- a/service/k8s/service.go
4+
+++ b/service/k8s/service.go
5+
@@ -10,6 +10,7 @@ import (
6+
7+
"github.com/spotahome/redis-operator/log"
8+
"github.com/spotahome/redis-operator/metrics"
9+
+ "github.com/spotahome/redis-operator/operator/redisfailover/util"
10+
)
11+
12+
// Service the ServiceAccount service that knows how to interact with k8s to manage them
13+
@@ -95,6 +96,10 @@ func (s *ServiceService) CreateOrUpdateService(namespace string, service *corev1
14+
// namespace is our spec(https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#concurrency-control-and-consistency),
15+
// we will replace the current namespace state.
16+
service.ResourceVersion = storedService.ResourceVersion
17+
+ newLabels := util.MergeLabels(storedService.GetLabels(), service.GetLabels())
18+
+ newAnnotations := util.MergeAnnotations(storedService.GetAnnotations(), service.GetAnnotations())
19+
+ service.SetLabels(newLabels)
20+
+ service.SetAnnotations(newAnnotations)
21+
return s.UpdateService(namespace, service)
22+
}
23+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
redis-operator:
22
image:
3-
tag: v1.3.0-rc1
3+
repository: ghcr.io/cozystack/cozystack/redis-operator
4+
tag: v1.3.0-rc1@sha256:a4012e6a1b5daaedb57cc27edfdbff52124de4164b5ec0ee53c5ce5710ef4c25

0 commit comments

Comments
 (0)