Skip to content

Commit 6d790ad

Browse files
committed
add TLS, deployment, and helm chart
1 parent 9310376 commit 6d790ad

18 files changed

Lines changed: 758 additions & 77 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
name: build-ironic-hardware-exporter-images
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
tags:
8+
- ironic-hardware-exporter-v*
9+
paths:
10+
- "go/ironic-hardware-exporter/**"
11+
12+
jobs:
13+
build-ironic-hardware-exporter:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
packages: write
17+
contents: write
18+
id-token: write
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Install Go
26+
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6
27+
with:
28+
go-version: '1.25'
29+
cache: true
30+
cache-dependency-path: 'go/ironic-hardware-exporter/go.sum'
31+
32+
- name: Install syft
33+
uses: anchore/sbom-action/download-syft@57aae528053a48a3f6235f2d9461b05fbcb7366d # v0.23.1
34+
35+
- name: Install Cosign
36+
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
37+
38+
- name: Set up QEMU
39+
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4
40+
41+
- name: Set up Docker Buildx
42+
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
43+
44+
- name: Login to ghcr.io
45+
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4
46+
with:
47+
registry: "ghcr.io"
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- name: Extract tag name
52+
id: extract_tag
53+
run: echo "tag=${GITHUB_REF#refs/tags/ironic-hardware-exporter-v}" >> $GITHUB_OUTPUT
54+
55+
- name: Run GoReleaser
56+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6
57+
with:
58+
distribution: goreleaser
59+
version: "~> v2"
60+
args: release --clean --skip=validate
61+
workdir: go/ironic-hardware-exporter
62+
env:
63+
GIT_REPO: ${{ github.repository }}
64+
CUSTOM_TAG: ${{ steps.extract_tag.outputs.tag }}
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
67+
chart:
68+
runs-on: ubuntu-latest
69+
needs:
70+
- build-ironic-hardware-exporter
71+
steps:
72+
- name: Checkout repository
73+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
74+
- name: Log in to ghcr.io
75+
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4
76+
with:
77+
registry: ghcr.io
78+
username: '${{ github.actor }}'
79+
password: '${{ secrets.GITHUB_TOKEN }}'
80+
- name: Package and push Helm chart
81+
working-directory: go/ironic-hardware-exporter
82+
env:
83+
PKG_VER: '${{ github.ref_name }}'
84+
run: |
85+
PKG_VER=${PKG_VER#ironic-hardware-exporter-v}
86+
yq -i ".version = \"${PKG_VER}\"" helm/Chart.yaml
87+
yq -i ".appVersion = \"${PKG_VER}\"" helm/Chart.yaml
88+
yq helm/Chart.yaml
89+
helm package -u -d ${{ github.workspace }} helm
90+
helm push ${{ github.workspace }}/ironic-hardware-exporter-${PKG_VER}.tgz \
91+
oci://ghcr.io/${GITHUB_REPOSITORY_OWNER}/charts
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM gcr.io/distroless/base-debian12:nonroot
2+
COPY --chmod=555 ironic-hardware-exporter /usr/local/bin/ironic-hardware-exporter
3+
USER 65532:65532
4+
ENTRYPOINT ["/usr/local/bin/ironic-hardware-exporter"]
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
project_name: "ironic-hardware-exporter"
2+
version: 2
3+
4+
before:
5+
hooks:
6+
- go mod tidy
7+
8+
env:
9+
- CUSTOM_TAG={{ .Env.CUSTOM_TAG }}
10+
- GIT_REPO={{ .Env.GIT_REPO }}
11+
12+
builds:
13+
- main: main.go
14+
dir: ./cmd/ironic-hardware-exporter
15+
binary: ironic-hardware-exporter
16+
goos: ["linux"]
17+
goarch: ["amd64", "arm64"]
18+
flags:
19+
- -trimpath
20+
ldflags:
21+
- -s
22+
- -w
23+
- -X main.version={{.Version}}
24+
- -X main.commit={{.ShortCommit}}
25+
env:
26+
- CGO_ENABLED=0
27+
28+
changelog:
29+
disable: true
30+
31+
dockers:
32+
- skip_push: false
33+
use: buildx
34+
dockerfile: .goreleaser.Dockerfile
35+
image_templates:
36+
- ghcr.io/{{ .Env.GIT_REPO }}/{{ .ProjectName }}:{{ .Env.CUSTOM_TAG }}-amd64
37+
build_flag_templates:
38+
- --platform=linux/amd64
39+
- --label=org.opencontainers.image.version={{ .Env.CUSTOM_TAG }}
40+
- --label=org.opencontainers.image.revision={{ .Commit }}
41+
- --label=org.opencontainers.image.title={{ .ProjectName }}
42+
- --label=org.opencontainers.image.created={{ .Date }}
43+
- --label=org.opencontainers.image.description=Prometheus exporter for Ironic bare-metal hardware metrics
44+
- --label=org.opencontainers.image.vendor=rackspace
45+
- --label=org.opencontainers.image.licenses=Apache License 2.0
46+
- --label=org.opencontainers.image.source=https://rackspace.com/
47+
- --label=org.opencontainers.image.authors=Rackspace
48+
- skip_push: false
49+
goarch: arm64
50+
use: buildx
51+
dockerfile: .goreleaser.Dockerfile
52+
image_templates:
53+
- ghcr.io/{{ .Env.GIT_REPO }}/{{ .ProjectName }}:{{ .Env.CUSTOM_TAG }}-arm64
54+
build_flag_templates:
55+
- --platform=linux/arm64
56+
- --label=org.opencontainers.image.version={{ .Env.CUSTOM_TAG }}
57+
- --label=org.opencontainers.image.revision={{ .Commit }}
58+
- --label=org.opencontainers.image.title={{ .ProjectName }}
59+
- --label=org.opencontainers.image.created={{ .Date }}
60+
- --label=org.opencontainers.image.description=Prometheus exporter for Ironic bare-metal hardware metrics
61+
- --label=org.opencontainers.image.vendor=rackspace
62+
- --label=org.opencontainers.image.licenses=Apache License 2.0
63+
- --label=org.opencontainers.image.source=https://rackspace.com/
64+
- --label=org.opencontainers.image.authors=Rackspace
65+
66+
docker_manifests:
67+
- name_template: ghcr.io/{{ .Env.GIT_REPO }}/{{ .ProjectName }}:{{ .Env.CUSTOM_TAG }}
68+
image_templates:
69+
- ghcr.io/{{ .Env.GIT_REPO }}/{{ .ProjectName }}:{{ .Env.CUSTOM_TAG }}-amd64
70+
- ghcr.io/{{ .Env.GIT_REPO }}/{{ .ProjectName }}:{{ .Env.CUSTOM_TAG }}-arm64
71+
- name_template: ghcr.io/{{ .Env.GIT_REPO }}/{{ .ProjectName }}:latest
72+
image_templates:
73+
- ghcr.io/{{ .Env.GIT_REPO }}/{{ .ProjectName }}:{{ .Env.CUSTOM_TAG }}-amd64
74+
- ghcr.io/{{ .Env.GIT_REPO }}/{{ .ProjectName }}:{{ .Env.CUSTOM_TAG }}-arm64
75+
76+
signs:
77+
- cmd: cosign
78+
signature: "${artifact}.sigstore.json"
79+
output: true
80+
artifacts: checksum
81+
args:
82+
- sign-blob
83+
- "--bundle=${signature}"
84+
- "${artifact}"
85+
- --yes
86+
87+
docker_signs:
88+
- cmd: cosign
89+
artifacts: manifests
90+
output: true
91+
args:
92+
- "sign"
93+
- "--oidc-provider=github-actions"
94+
- "${artifact}@${digest}"
95+
- --yes
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM golang:1.25 AS builder
2+
ARG TARGETOS
3+
ARG TARGETARCH
4+
5+
WORKDIR /workspace
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
RUN go mod download
9+
10+
COPY cmd/ cmd/
11+
COPY internal/ internal/
12+
13+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
14+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
15+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
16+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
17+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ironic-hardware-exporter cmd/ironic-hardware-exporter/main.go
18+
19+
FROM gcr.io/distroless/static:nonroot
20+
WORKDIR /
21+
COPY --from=builder /workspace/ironic-hardware-exporter .
22+
USER 65532:65532
23+
24+
ENTRYPOINT ["/ironic-hardware-exporter"]

go/ironic-hardware-exporter/cmd/ironic-hardware-exporter/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ func main() {
3636
}
3737
defer statesConsumer.Close()
3838

39-
srv := server.New(store, cfg.Server.Port, sensorConsumer.IsReady)
39+
// both consumers must be up for the pod to be considered ready
40+
bothReady := func() bool {
41+
return sensorConsumer.IsReady() && statesConsumer.IsReady()
42+
}
43+
srv := server.New(store, cfg.Server.Port, bothReady)
4044
go func() {
4145
if err := srv.Start(); err != nil {
4246
log.Fatalf("HTTP server failed: %v", err)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: ironic-hardware-exporter
3+
description: Prometheus exporter for Ironic bare-metal hardware metrics via RabbitMQ
4+
type: application
5+
version: 0.1.0
6+
appVersion: 0.1.0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ironic-hardware-exporter has been deployed.
2+
3+
Prometheus metrics:
4+
kubectl port-forward svc/{{ include "ironic-hardware-exporter.fullname" . }} {{ .Values.service.port }}:{{ .Values.service.port }}
5+
curl http://localhost:{{ .Values.service.port }}/metrics
6+
7+
Health check:
8+
curl http://localhost:{{ .Values.service.port }}/health
9+
10+
Readiness check (503 if RabbitMQ connection is lost):
11+
curl http://localhost:{{ .Values.service.port }}/ready
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "ironic-hardware-exporter.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "ironic-hardware-exporter.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "ironic-hardware-exporter.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "ironic-hardware-exporter.labels" -}}
37+
helm.sh/chart: {{ include "ironic-hardware-exporter.chart" . }}
38+
{{ include "ironic-hardware-exporter.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "ironic-hardware-exporter.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "ironic-hardware-exporter.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}

0 commit comments

Comments
 (0)