Skip to content

Commit e7a41e1

Browse files
authored
Merge pull request #7 from kloeckner-i/configurable_reconcile_period
improve pipeline speed
2 parents 7016795 + 40b2730 commit e7a41e1

9 files changed

Lines changed: 38 additions & 77 deletions

File tree

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ RUN apk update && apk upgrade && \
44
apk add --no-cache bash build-base
55

66
WORKDIR /opt/db-operator
7-
COPY . .
87

8+
# to reduce docker build time download dependency first before building
9+
COPY go.mod .
10+
COPY go.sum .
11+
RUN go mod download
12+
13+
# build
14+
COPY . .
915
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags build -o /usr/local/bin/db-operator ./cmd/manager
1016

1117
FROM alpine:3.11

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ build:
3232
operator-sdk build my-db-operator:local
3333

3434
helm: helm-init
35-
@helm upgrade --install --namespace default my-dboperator helm/db-operator -f helm/db-operator/values.yaml -f helm/db-operator/values-local.yaml
36-
@helm upgrade --install --namespace default my-dbins helm/db-instances --set operatorNamespace="default" -f helm/db-instances/values.yaml -f helm/db-instances/values-local.yaml
35+
@helm upgrade --install --namespace operator my-dboperator helm/db-operator -f helm/db-operator/values.yaml -f helm/db-operator/values-local.yaml
3736

3837
helm-init:
3938
@helm init --upgrade --wait

helm/db-instances/values-local.yaml

Lines changed: 0 additions & 67 deletions
This file was deleted.

helm/db-operator/templates/operator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ spec:
5151
value: "db-operator"
5252
- name: WATCH_NAMESPACE
5353
value: "" # it's necessary to set "" to watch cluster wide
54+
- name: RECONCILE_INTERVAL
55+
value: {{ .Values.reconcileInterval | quote }}
5456
- name: POD_NAME
5557
valueFrom:
5658
fieldRef:

helm/db-operator/values-local.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ image:
33
tag: "local"
44
pullPolicy: IfNotPresent
55

6+
7+
reconcileInterval: "10"

helm/db-operator/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ image:
88
# imagePullSecrets:
99
# - name: myRegistrySecret
1010

11+
reconcileInterval: "60"
1112

1213
rbac:
1314
create: true

integration/postgres/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ postgres:
22
serviceName: pg-test-db
33
adminUser: postgres
44
adminPassword: test1234
5-
image: postgres:10.4
5+
image: postgres:11

pkg/controller/database/controller.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package database
33
import (
44
"context"
55
"errors"
6+
"os"
7+
"strconv"
68
"time"
79

810
kciv1alpha1 "github.com/kloeckner-i/db-operator/pkg/apis/kci/v1alpha1"
@@ -34,7 +36,13 @@ func Add(mgr manager.Manager) error {
3436

3537
// newReconciler returns a new reconcile.Reconciler
3638
func newReconciler(mgr manager.Manager) reconcile.Reconciler {
37-
return &ReconcileDatabase{client: mgr.GetClient(), scheme: mgr.GetScheme(), recorder: mgr.GetEventRecorderFor("database-controller")}
39+
interval := os.Getenv("RECONCILE_INTERVAL")
40+
i, err := strconv.ParseInt(interval, 10, 64)
41+
if err != nil {
42+
i = 60
43+
logrus.Infof("Set default reconcile period to %d s for database-controller", i)
44+
}
45+
return &ReconcileDatabase{client: mgr.GetClient(), scheme: mgr.GetScheme(), recorder: mgr.GetEventRecorderFor("database-controller"), interval: time.Duration(i)}
3846
}
3947

4048
// add adds a new Controller to mgr with r as the reconcile.Reconciler
@@ -74,6 +82,7 @@ type ReconcileDatabase struct {
7482
client client.Client
7583
scheme *runtime.Scheme
7684
recorder record.EventRecorder
85+
interval time.Duration
7786
}
7887

7988
var (
@@ -100,7 +109,7 @@ func (r *ReconcileDatabase) Reconcile(request reconcile.Request) (reconcile.Resu
100109
// reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
101110
// reqLogger.Info("Reconciling Database")
102111

103-
reconcilePeriod := 60 * time.Second
112+
reconcilePeriod := r.interval * time.Second
104113
reconcileResult := reconcile.Result{RequeueAfter: reconcilePeriod}
105114

106115
ctx := context.TODO()

pkg/controller/dbinstance/controller.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package dbinstance
33
import (
44
"context"
55
"errors"
6+
"os"
7+
"strconv"
68
"time"
79

810
kciv1alpha1 "github.com/kloeckner-i/db-operator/pkg/apis/kci/v1alpha1"
@@ -28,7 +30,13 @@ func Add(mgr manager.Manager) error {
2830

2931
// newReconciler returns a new reconcile.Reconciler
3032
func newReconciler(mgr manager.Manager) reconcile.Reconciler {
31-
return &ReconcileDbInstance{client: mgr.GetClient(), scheme: mgr.GetScheme()}
33+
interval := os.Getenv("RECONCILE_INTERVAL")
34+
i, err := strconv.ParseInt(interval, 10, 64)
35+
if err != nil {
36+
i = 60
37+
logrus.Infof("Set default reconcile period to %d s for dbinstance-controller", i)
38+
}
39+
return &ReconcileDbInstance{client: mgr.GetClient(), scheme: mgr.GetScheme(), interval: time.Duration(i)}
3240
}
3341

3442
// add adds a new Controller to mgr with r as the reconcile.Reconciler
@@ -55,8 +63,9 @@ var _ reconcile.Reconciler = &ReconcileDbInstance{}
5563
type ReconcileDbInstance struct {
5664
// This client, initialized using mgr.Client() above, is a split client
5765
// that reads objects from the cache and writes to the apiserver
58-
client client.Client
59-
scheme *runtime.Scheme
66+
client client.Client
67+
scheme *runtime.Scheme
68+
interval time.Duration
6069
}
6170

6271
var (
@@ -75,7 +84,7 @@ var (
7584
func (r *ReconcileDbInstance) Reconcile(request reconcile.Request) (reconcile.Result, error) {
7685
// reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
7786
// reqLogger.Info("Reconciling DbInstance")
78-
reconcilePeriod := 60 * time.Second
87+
reconcilePeriod := r.interval * time.Second
7988
reconcileResult := reconcile.Result{RequeueAfter: reconcilePeriod}
8089

8190
ctx := context.TODO()

0 commit comments

Comments
 (0)