Skip to content

Commit 2309b39

Browse files
zachallerCopilotcrenshaw-dev
authored
feat: webhook support and no timed reconcile (#130)
* add webhook and fast reconcile support Signed-off-by: Zach Aller <[email protected]> * change default to 5 minutes Signed-off-by: Zach Aller <[email protected]> * simulate webhook Signed-off-by: Zach Aller <[email protected]> * lint Signed-off-by: Zach Aller <[email protected]> * fix fake cs Signed-off-by: Zach Aller <[email protected]> * fix fake cs Signed-off-by: Zach Aller <[email protected]> * simplify fake commit Signed-off-by: Zach Aller <[email protected]> * lint Signed-off-by: Zach Aller <[email protected]> * fix test Signed-off-by: Zach Aller <[email protected]> * fix test Signed-off-by: Zach Aller <[email protected]> * add retry Signed-off-by: Zach Aller <[email protected]> * lint Signed-off-by: Zach Aller <[email protected]> * bump go Signed-off-by: Zach Aller <[email protected]> * use real k8s Signed-off-by: Zach Aller <[email protected]> * use real k8s Signed-off-by: Zach Aller <[email protected]> * drop parrelle Signed-off-by: Zach Aller <[email protected]> * remove kind Signed-off-by: Zach Aller <[email protected]> * add log Signed-off-by: Zach Aller <[email protected]> * add log Signed-off-by: Zach Aller <[email protected]> * reconcile end logs Signed-off-by: Zach Aller <[email protected]> * single test Signed-off-by: Zach Aller <[email protected]> * logs Signed-off-by: Zach Aller <[email protected]> * reconcile end logs Signed-off-by: Zach Aller <[email protected]> * turn all tests on Signed-off-by: Zach Aller <[email protected]> * cleanup Signed-off-by: Zach Aller <[email protected]> * cleanup Signed-off-by: Zach Aller <[email protected]> * logging Signed-off-by: Zach Aller <[email protected]> * review Signed-off-by: Zach Aller <[email protected]> * review - remove log Signed-off-by: Zach Aller <[email protected]> * fix server shutdown Signed-off-by: Zach Aller <[email protected]> * add todo Signed-off-by: Zach Aller <[email protected]> * Update internal/controller/changetransferpolicy_controller_test.go Co-authored-by: Copilot <[email protected]> * remove install Signed-off-by: Zach Aller <[email protected]> * bump go mod version to match Signed-off-by: Zach Aller <[email protected]> * bump go docker Signed-off-by: Zach Aller <[email protected]> * ignore install.yaml Signed-off-by: Zach Aller <[email protected]> * go 1.23 Signed-off-by: Zach Aller <[email protected]> * comments Signed-off-by: Zach Aller <[email protected]> * comments Signed-off-by: Zach Aller <[email protected]> * codedgen Signed-off-by: Zach Aller <[email protected]> * lint Signed-off-by: Zach Aller <[email protected]> * Update internal/utils/utils.go Co-authored-by: Michael Crenshaw <[email protected]> --------- Signed-off-by: Zach Aller <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: Michael Crenshaw <[email protected]>
1 parent 8571792 commit 2309b39

24 files changed

+566
-1272
lines changed

.github/workflows/ci-e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Set up Go
2424
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # pin@v5
2525
with:
26-
go-version: '1.22'
26+
go-version: '1.23'
2727
# see https://github.com/actions/setup-go?tab=readme-ov-file#caching-dependency-files-and-build-outputs
2828
cache-dependency-path: |
2929
go.sum

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Set up Go
1919
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # pin@v5
2020
with:
21-
go-version: "1.22"
21+
go-version: "1.23"
2222
- name: Get dependencies
2323
run: go mod download
2424
- name: Restore build output from cache
@@ -67,7 +67,7 @@ jobs:
6767
- name: Set up Go
6868
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # pin@v5
6969
with:
70-
go-version: "1.22"
70+
go-version: "1.23"
7171
- name: go mod tidy
7272
run: |
7373
go mod tidy

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Setup Go
2929
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
3030
with:
31-
go-version: 1.22
31+
go-version: "1.23"
3232

3333
- name: Docker Login in quay.io
3434
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ go.work
3030
# Github Certificates
3131
*.pem
3232
secret.yaml
33+
install.yaml
3334

3435
junit.xml
3536

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22 AS builder
2+
FROM golang:1.23 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -27,7 +27,7 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ma
2727
# Use distroless as minimal base image to package the manager binary
2828
# Refer to https://github.com/GoogleContainerTools/distroless for more details
2929
#FROM gcr.io/distroless/static:nonroot #TODO: figure out smallest/safest way to get git installed
30-
FROM golang:1.22
30+
FROM golang:1.23
3131
WORKDIR /
3232
RUN mkdir /git
3333
COPY --from=builder /workspace/manager .

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ test-deps: ginkgo manifests generate fmt vet envtest
9292

9393
.PHONY: test-parallel
9494
test-parallel: test-deps ## Run tests in parallel
95-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) -p -r -v -cover -coverprofile=cover.out --junit-report=junit.xml internal/
95+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) -p -procs=4 -r -v -cover -coverprofile=cover.out --junit-report=junit.xml internal/
9696

9797
.PHONY: test-parallel-repeat3
9898
test-parallel-repeat3: test-deps ## Run tests in parallel 3 times to check for flakiness --repeat does not count the first run
99-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) -p -r -v -cover -coverprofile=cover.out --junit-report=junit.xml --repeat=2 internal/
99+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) -p -procs=4 -r -v -cover -coverprofile=cover.out --junit-report=junit.xml --repeat=2 internal/
100100

101101
.PHONY: lint nilaway-no-test
102102
lint: golangci-lint ## Run golangci-lint linter & yamllint

api/v1alpha1/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ const ChangeTransferPolicyLabel = "promoter.argoproj.io/change-transfer-policy"
2929

3030
// PreviousEnvironmentCommitStatusKey the commit status key name used to indicate the previous environment health
3131
const PreviousEnvironmentCommitStatusKey = "promoter-previous-environment"
32+
33+
// ReconcileAtAnnotation is the annotation used to indicate when the webhook triggered a reconcile
34+
const ReconcileAtAnnotation = "promoter.argoproj.io/reconcile-at"

cmd/main.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ import (
2121
"flag"
2222
"os"
2323
"runtime/debug"
24+
"syscall"
2425
"time"
2526

27+
"github.com/argoproj-labs/gitops-promoter/internal/webhookreceiver"
28+
2629
"go.uber.org/zap/zapcore"
2730

2831
"github.com/argoproj-labs/gitops-promoter/internal/utils"
@@ -74,13 +77,13 @@ func main() {
7477
"If set the metrics endpoint is served securely")
7578
flag.BoolVar(&enableHTTP2, "enable-http2", false,
7679
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
77-
flag.StringVar(&promotionStrategyRequeue, "promotion-strategy-requeue-duration", "60s",
80+
flag.StringVar(&promotionStrategyRequeue, "promotion-strategy-requeue-duration", "300s",
7881
"How frequently to requeue promotion strategy resources for auto reconciliation")
79-
flag.StringVar(&changeTransferPolicyRequeue, "change-transfer-policy-requeue-duration", "60s",
82+
flag.StringVar(&changeTransferPolicyRequeue, "change-transfer-policy-requeue-duration", "300s",
8083
"How frequently to requeue proposed commit resources for auto reconciliation")
8184
opts := zap.Options{
8285
Development: true,
83-
TimeEncoder: zapcore.ISO8601TimeEncoder,
86+
TimeEncoder: zapcore.RFC3339NanoTimeEncoder,
8487
}
8588
opts.BindFlags(flag.CommandLine)
8689
flag.Parse()
@@ -143,10 +146,6 @@ func main() {
143146
panic("unable to start manager")
144147
}
145148

146-
// TODO: Create secret informer, and possibly ScmProvider Informer to pass into controllers
147-
// kubeClient, err := kubernetes.NewForConfig(mgr.GetConfig())
148-
// informerFactory := informers.NewSharedInformerFactory(kubeClient, 10*time.Minute)
149-
150149
pathLookup := utils.NewPathLookup()
151150

152151
if err = (&controller.PullRequestReconciler{
@@ -225,9 +224,17 @@ func main() {
225224

226225
processSignals := ctrl.SetupSignalHandler()
227226

228-
// setupLog.Info("starting informer factory")
229-
// informerFactory.Start(processSignals.Done())
230-
// informerFactory.WaitForCacheSync(processSignals.Done())
227+
whr := webhookreceiver.NewWebhookReceiver(mgr)
228+
go func() {
229+
err = whr.Start(processSignals, ":3333")
230+
if err != nil {
231+
setupLog.Error(err, "unable to start webhook receiver")
232+
err = syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
233+
if err != nil {
234+
setupLog.Error(err, "unable to kill process")
235+
}
236+
}
237+
}()
231238

232239
setupLog.Info("starting manager")
233240
if err := mgr.Start(processSignals); err != nil {

config/manager/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ kind: Kustomization
44
resources:
55
- namespace.yaml
66
- deployment.yaml
7+
- webhook_service.yaml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: webhook-receiver
5+
spec:
6+
selector:
7+
control-plane: controller-manager
8+
ports:
9+
- protocol: TCP
10+
port: 3333
11+
targetPort: 3333

0 commit comments

Comments
 (0)