Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: enable remote debug in helm #757

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Dockerfile.debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) 2015 The Gravitee team (http://gravitee.io)
#
# 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.
# Build the manager binary
FROM golang:1.22 AS builder
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY internal/ internal/
COPY controllers/ controllers/
COPY pkg/ pkg/
# Copy the CRD manifests
COPY helm/gko/crds/ helm/gko/crds/
# Build
RUN CGO_ENABLED=0 go install github.com/go-delve/delve/cmd/dlv@latest
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags "all=-N -l" -o manager main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM alpine
WORKDIR /
COPY --from=builder /workspace/helm/gko/crds/ helm/gko/crds/
COPY --from=builder /go/bin/dlv dlv
COPY --from=builder /workspace/manager .
ENTRYPOINT [ "/dlv" , "--listen=:32767", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "/manager"]
39 changes: 39 additions & 0 deletions helm/gko/templates/debug/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2015 The Gravitee team (http://gravitee.io)
#
# 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.
{{- if .Values.dev.debug.enabled }}
---
apiVersion: v1
kind: Service
metadata:
name: gko-controller-manager-debug-service
namespace: '{{ .Release.Namespace }}'
labels:
control-plane: controller-manager
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/name: {{ template "helm.name" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
annotations:
meta.helm.sh/release-name: {{ .Release.Name }}
meta.helm.sh/release-namespace: {{ .Release.Namespace }}
spec:
type: NodePort
ports:
- name: debug
port: {{ .Values.dev.debug.port }}
targetPort: {{ .Values.dev.debug.port }}
nodePort: {{ .Values.dev.debug.port }}
selector:
control-plane: controller-manager
{{- end }}
8 changes: 8 additions & 0 deletions helm/gko/templates/manager/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ spec:
- --leader-elect
command:
- /manager
{{- if .Values.dev.debug.enabled }}
ports:
- containerPort: {{ .Values.dev.debug.port }}
name: debugger
protocol: TCP
{{- end }}
envFrom:
- configMapRef:
name: '{{ .Values.manager.configMap.name }}'
Expand Down Expand Up @@ -103,8 +109,10 @@ spec:
name: webhook-cert
readOnly: true
{{- end }}
{{- if not .Values.dev.debug.enabled }}
securityContext:
runAsNonRoot: true
{{- end }}
serviceAccountName: {{ template "rbac.serviceAccountName" . }}
{{- if .Values.manager.webhook.enabled }}
volumes:
Expand Down
6 changes: 6 additions & 0 deletions helm/gko/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,9 @@ ingress:
httpClient:
## @param httpClient.insecureSkipCertVerify see manager.httpClient.insecureSkipCertVerify
insecureSkipCertVerify: false

dev:
## @skip dev.debug This is used by dev for debug only.
debug:
enabled: false
port: 32767
3 changes: 3 additions & 0 deletions kind/kind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ nodes:
# gravitee-apim-gateway
- containerPort: 30083
hostPort: 30083
# gko-controller debug port
- containerPort: 32767
hostPort: 32767
3 changes: 2 additions & 1 deletion make/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ docker-build: ## Build docker image with the manager.
docker-push: ## Push docker image with the manager.
docker push ${IMG}:${TAG}


docker-build-debug: ## Build docker image with remote debug enabled
docker build -f Dockerfile.debug -t ${IMG}:${TAG} .