Skip to content

Commit

Permalink
Add runtime flags on the dev image (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
voltbit authored Jan 27, 2021
1 parent 12b9708 commit a6667f7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ COPY --from=builder /bin/sh .
USER nonroot:nonroot
ENV PATH="./:${PATH}"

ARG NAMESPACE="default"
ARG METRICS_ADDR=":8080"
ARG ENABLE_LEADER_ELECTION="true"
ARG NAMESPACE_ARG="default"
ARG METRICS_ADDR_ARG=":8080"
ARG ENABLE_LEADER_ELECTION_ARG="true"

ENV NAMESPACE_ENV=${NAMESPACE}
ENV METRICS_ADDR_ENV=${METRICS_ADDR}
ENV ENABLE_LEADER_ELECTION_ENV=${ENABLE_LEADER_ELECTION}
ENV NAMESPACE_ENV=${NAMESPACE_ARG}
ENV METRICS_ADDR_ENV=${METRICS_ADDR_ARG}
ENV ENABLE_LEADER_ELECTION_ENV=${ENABLE_LEADER_ELECTION_ARG}

ENTRYPOINT ["/sh", "-c", "/manager -namespace=$NAMESPACE_ENV -metrics-addr=$METRICS_ADDR_ENV -enable-leader-election=$ENABLE_LEADER_ELECTION_ENV"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ To develop directly on a deployed operator without rebuilding and loading/deploy
2. Swap the dev image with the operator deploy using Telepresence

```
telepresence --mount /tmp/podtoken --context kind-redis-test --namespace default --swap-deployment redis-operator-manager --docker-run --rm -it -v $(pwd):/app -v=/tmp/podtoken/var/run/secrets:/var/run/secrets redis-operator:dev
telepresence --mount /tmp/podtoken --context kind-redis-test --namespace default --swap-deployment redis-operator-manager --docker-run --env NAMESPACE_ENV=default --rm -it -v $(pwd):/app -v=/tmp/podtoken/var/run/secrets:/var/run/secrets redis-operator:dev
```

**How it works**
Expand Down
10 changes: 9 additions & 1 deletion hack/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ RUN cd /tmp &&\
# This allows CompileDaemon to track the files we are changing in real time
WORKDIR /app

ARG NAMESPACE_ARG="default"
ARG METRICS_ADDR_ARG=":8080"
ARG ENABLE_LEADER_ELECTION_ARG="true"

ENV NAMESPACE_ENV=${NAMESPACE_ARG}
ENV METRICS_ADDR_ENV=${METRICS_ADDR_ARG}
ENV ENABLE_LEADER_ELECTION_ENV=${ENABLE_LEADER_ELECTION_ARG}

ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on

ENTRYPOINT CompileDaemon --build="go build -o manager main.go" --command="./manager"
ENTRYPOINT CompileDaemon --build="go build -o manager main.go" --command="./manager -namespace=$NAMESPACE_ENV -metrics-addr=$METRICS_ADDR_ENV -enable-leader-election=$ENABLE_LEADER_ELECTION_ENV"

8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ func init() {
func loggerOptions(*zap.Options) {}

func main() {
var metricsAddr string
var namespace string
var enableLeaderElection bool
var metricsAddr, namespace, enableLeaderElection string
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&namespace, "namespace", "default", "The namespace the operator will manage.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", true,
flag.StringVar(&enableLeaderElection, "enable-leader-election", "true",
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.Parse()
Expand All @@ -49,7 +47,7 @@ func main() {
Namespace: namespace,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElection: enableLeaderElection == "true",
LeaderElectionID: "1747e98e.payu.com",
})
if err != nil {
Expand Down

0 comments on commit a6667f7

Please sign in to comment.