From 7d0918b6d5ac8f64d44caa9ea133f7089dc2b243 Mon Sep 17 00:00:00 2001 From: Dimitar Date: Sat, 25 Feb 2023 05:18:29 +0000 Subject: [PATCH] Allow custom graceful termination and loadBalancerSourceRanges for the githubwebhook service (#2305) Co-authored-by: Dimitar Hristov --- Dockerfile | 4 ++- .../templates/githubwebhook.deployment.yaml | 8 ++++- .../templates/githubwebhook.service.yaml | 6 ++++ charts/actions-runner-controller/values.yaml | 3 ++ cmd/sleep/main.go | 33 +++++++++++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 cmd/sleep/main.go diff --git a/Dockerfile b/Dockerfile index 51a60255..4c5f8fbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,8 @@ RUN --mount=target=. \ go build -trimpath -ldflags="-s -w -X 'github.com/actions/actions-runner-controller/build.Version=${VERSION}'" -o /out/manager main.go && \ go build -trimpath -ldflags="-s -w" -o /out/github-runnerscaleset-listener ./cmd/githubrunnerscalesetlistener && \ go build -trimpath -ldflags="-s -w" -o /out/github-webhook-server ./cmd/githubwebhookserver && \ - go build -trimpath -ldflags="-s -w" -o /out/actions-metrics-server ./cmd/actionsmetricsserver + go build -trimpath -ldflags="-s -w" -o /out/actions-metrics-server ./cmd/actionsmetricsserver && \ + go build -trimpath -ldflags="-s -w" -o /out/sleep ./cmd/sleep # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details @@ -51,6 +52,7 @@ COPY --from=builder /out/manager . COPY --from=builder /out/github-webhook-server . COPY --from=builder /out/actions-metrics-server . COPY --from=builder /out/github-runnerscaleset-listener . +COPY --from=builder /out/sleep . USER 65532:65532 diff --git a/charts/actions-runner-controller/templates/githubwebhook.deployment.yaml b/charts/actions-runner-controller/templates/githubwebhook.deployment.yaml index 373ddb86..86a4aacd 100644 --- a/charts/actions-runner-controller/templates/githubwebhook.deployment.yaml +++ b/charts/actions-runner-controller/templates/githubwebhook.deployment.yaml @@ -56,6 +56,12 @@ spec: {{- end }} command: - "/github-webhook-server" + {{- if .Values.githubWebhookServer.lifecycle }} + {{- with .Values.githubWebhookServer.lifecycle }} + lifecycle: + {{- toYaml . | nindent 10 }} + {{- end }} + {{- end }} env: - name: GITHUB_WEBHOOK_SECRET_TOKEN valueFrom: @@ -148,7 +154,7 @@ spec: securityContext: {{- toYaml .Values.securityContext | nindent 12 }} {{- end }} - terminationGracePeriodSeconds: 10 + terminationGracePeriodSeconds: {{ .Values.githubWebhookServer.terminationGracePeriodSeconds }} {{- with .Values.githubWebhookServer.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/charts/actions-runner-controller/templates/githubwebhook.service.yaml b/charts/actions-runner-controller/templates/githubwebhook.service.yaml index daeb790b..99a7ea2c 100644 --- a/charts/actions-runner-controller/templates/githubwebhook.service.yaml +++ b/charts/actions-runner-controller/templates/githubwebhook.service.yaml @@ -23,4 +23,10 @@ spec: {{- end }} selector: {{- include "actions-runner-controller-github-webhook-server.selectorLabels" . | nindent 4 }} + {{- if .Values.githubWebhookServer.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{- range $ip := .Values.githubWebhookServer.service.loadBalancerSourceRanges }} + - {{ $ip -}} + {{- end }} + {{- end }} {{- end }} diff --git a/charts/actions-runner-controller/values.yaml b/charts/actions-runner-controller/values.yaml index 4d724051..91dec2be 100644 --- a/charts/actions-runner-controller/values.yaml +++ b/charts/actions-runner-controller/values.yaml @@ -240,6 +240,7 @@ githubWebhookServer: protocol: TCP name: http #nodePort: someFixedPortForUseWithTerraformCdkCfnEtc + loadBalancerSourceRanges: [] ingress: enabled: false ingressClassName: "" @@ -276,6 +277,8 @@ githubWebhookServer: # minAvailable: 1 # maxUnavailable: 3 # queueLimit: 100 + terminationGracePeriodSeconds: 10 + lifecycle: {} actionsMetrics: serviceAnnotations: {} diff --git a/cmd/sleep/main.go b/cmd/sleep/main.go new file mode 100644 index 00000000..b74f4503 --- /dev/null +++ b/cmd/sleep/main.go @@ -0,0 +1,33 @@ +/* +Copyright 2021 The actions-runner-controller authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "flag" + "fmt" + "time" +) + +var Seconds int + +func main() { + fmt.Printf("sleeping for %d seconds\n", Seconds) + time.Sleep(time.Duration(Seconds) * time.Second) + fmt.Println("done sleeping") +} + +func init() { + flag.IntVar(&Seconds, "seconds", 60, "Number of seconds to sleep") + flag.Parse() +}