Skip to content

Commit 4855ca3

Browse files
authored
Fix Webhook proxy BC recreation issue (#1324)
1 parent dee143c commit 4855ca3

3 files changed

Lines changed: 55 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
### Fixed
1313

14+
- Webhook proxy BC recretion issue ([#1265](https://github.com/opendevstack/ods-core/issues/1265))
15+
1416
## [4.7.0] - 2025-1-27
1517

1618
### Changed

jenkins/webhook-proxy/Dockerfile

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
# Ideally we would us a very small image like plain alpine and just copy the
2-
# pre-built binary into it, but due to e.g. multistage builds not available in
3-
# OpenShift yet, for now the easiest is to build the binary in this image.
4-
FROM golang:1.23-alpine
1+
# Build stage
2+
FROM public.ecr.aws/docker/library/golang:1.23-alpine AS builder
3+
4+
RUN apk update && \
5+
apk -i upgrade && \
6+
apk cache clean && \
7+
mkdir -p /home/webhook-proxy
8+
9+
COPY main.go /home/webhook-proxy/main.go
10+
COPY go.mod /home/webhook-proxy/go.mod
11+
12+
WORKDIR /home/webhook-proxy
13+
14+
RUN CGO_ENABLED=0 go build -o webhook-proxy
15+
16+
# Final stage
17+
FROM registry.access.redhat.com/ubi9/ubi-micro:latest
518

619
# Set default ALLOWED_EXTERNAL_PROJECTS env var
720
ARG allowedExternalProjects=opendevstack
821
ENV ALLOWED_EXTERNAL_PROJECTS=$allowedExternalProjects
922

10-
RUN apk add -i ca-certificates && \
11-
apk update && \
12-
apk -i upgrade && \
13-
apk cache clean && \
14-
mkdir -p /home/webhook-proxy && \
23+
RUN mkdir -p /home/webhook-proxy && \
1524
chgrp -R 0 /home/webhook-proxy && \
1625
chmod g+w /home/webhook-proxy
1726

18-
COPY main.go /home/webhook-proxy/main.go
19-
COPY go.mod /home/webhook-proxy/go.mod
27+
COPY --from=builder /home/webhook-proxy/webhook-proxy /home/webhook-proxy/webhook-proxy
2028
COPY pipeline.json.tmpl /home/webhook-proxy/pipeline.json.tmpl
2129

2230
WORKDIR /home/webhook-proxy
2331

24-
RUN CGO_ENABLED=0 go build -o webhook-proxy
25-
2632
EXPOSE 8080
2733

2834
CMD ./webhook-proxy

jenkins/webhook-proxy/main.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,28 @@ type BuildConfigData struct {
7777
// buildConfig represents the relevant fields of an OpenShift BuildConfig, see
7878
// https://docs.openshift.com/container-platform/3.11/rest_api/apis-build.openshift.io/v1.BuildConfig.html#object-schema.
7979
type buildConfig struct {
80-
Metadata struct {
81-
ResourceVersion string `json:"resourceVersion"`
82-
} `json:"metadata"`
83-
Spec struct {
84-
Source struct {
85-
Git struct {
86-
Ref string `json:"ref"`
87-
} `json:"git"`
88-
} `json:"source"`
89-
Strategy struct {
90-
JenkinsPipelineStrategy struct {
91-
JenkinsfilePath string `json:"jenkinsfilePath"`
92-
} `json:"jenkinsPipelineStrategy"`
93-
} `json:"strategy"`
94-
} `json:"spec"`
80+
Metadata struct {
81+
ResourceVersion string `json:"resourceVersion"`
82+
} `json:"metadata"`
83+
Spec struct {
84+
Source struct {
85+
Git struct {
86+
Ref string `json:"ref"`
87+
} `json:"git"`
88+
} `json:"source"`
89+
Strategy struct {
90+
JenkinsPipelineStrategy struct {
91+
JenkinsfilePath string `json:"jenkinsfilePath"`
92+
} `json:"jenkinsPipelineStrategy"`
93+
} `json:"strategy"`
94+
Triggers []struct {
95+
Type string `json:"type"`
96+
// Generic struct {
97+
// Secret string `json:"secret"`
98+
// AllowEnv bool `json:"allowEnv"`
99+
// } `json:"generic"`
100+
} `json:"triggers"`
101+
} `json:"spec"`
95102
}
96103

97104
// Client makes requests, e.g. to create and delete pipelines, or to forward
@@ -509,6 +516,18 @@ func (s *Server) HandleRoot() http.HandlerFunc {
509516
updatePipeline = true
510517
resourceVersion = bc.Metadata.ResourceVersion
511518
}
519+
triggerExists := false
520+
for _, trigger := range bc.Spec.Triggers {
521+
if trigger.Type != "" {
522+
triggerExists = true
523+
break
524+
}
525+
}
526+
if !triggerExists {
527+
log.Println(requestID, "Trigger secret does not exist, updating pipeline")
528+
updatePipeline = true
529+
resourceVersion = bc.Metadata.ResourceVersion
530+
}
512531
}
513532

514533
buildConfigData := BuildConfigData{

0 commit comments

Comments
 (0)