diff --git a/.github/workflows/container-registry-ghcr.yaml b/.github/workflows/container-registry-ghcr.yaml new file mode 100644 index 0000000..5e9d423 --- /dev/null +++ b/.github/workflows/container-registry-ghcr.yaml @@ -0,0 +1,56 @@ +################################################################################ +# This file is AUTOGENERATED with # +# Edit Makefile.maker.yaml instead. # +################################################################################ + +# Copyright 2024 SAP SE +# SPDX-License-Identifier: Apache-2.0 + +name: Container Registry GHCR +"on": + push: + branches: + - master + workflow_dispatch: {} +permissions: + contents: read + packages: write +jobs: + build-and-push-image: + name: Push container to ghcr.io + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + username: ${{ github.actor }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + # https://github.com/docker/metadata-action#typeedge + type=edge + # https://github.com/docker/metadata-action#latest-tag + type=raw,value=latest,enable={{is_default_branch}} + # https://github.com/docker/metadata-action#typesemver + type=semver,pattern={{raw}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} diff --git a/Makefile b/Makefile index 552a071..ec9ec5f 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ install-addlicense: FORCE prepare-static-check: FORCE install-golangci-lint install-go-licence-detector install-addlicense GO_BUILDFLAGS = -mod vendor -GO_LDFLAGS = +GO_LDFLAGS = -X main.Version=$(shell git describe --tags --abbrev=0) GO_TESTENV = GO_BUILDENV = diff --git a/Makefile.maker.yaml b/Makefile.maker.yaml index 81ee7d5..c5860d1 100644 --- a/Makefile.maker.yaml +++ b/Makefile.maker.yaml @@ -11,6 +11,8 @@ dockerfile: golang: setGoModVersion: true enableVendoring: true +variables: + GO_LDFLAGS: "-X main.Version=$(shell git describe --tags --abbrev=0)" golangciLint: createConfig: true githubWorkflow: @@ -18,6 +20,13 @@ githubWorkflow: enabled: true global: defaultBranch: master + pushContainerToGhcr: + enabled: true + platforms: "linux/amd64" + tagStrategy: + - edge + - latest + - semver renovate: enabled: true assignees: diff --git a/REUSE.toml b/REUSE.toml new file mode 100644 index 0000000..552d440 --- /dev/null +++ b/REUSE.toml @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: SAP SE +# SPDX-License-Identifier: Apache-2.0 + +version = 1 + +[[annotations]] +path = [ + ".github/CODEOWNERS", + ".github/renovate.json", + ".gitignore", + ".license-scan-overrides.jsonl", + ".license-scan-rules.json", + "go.mod", + "go.sum", + "Makefile.maker.yaml", +] +SPDX-FileCopyrightText = "SAP SE" +SPDX-License-Identifier = "Apache-2.0" diff --git a/go.mod b/go.mod index 688d2f6..93a43ed 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/sapcc/kubernetes-oomkill-exporter -go 1.23.1 +go 1.23 require ( github.com/containerd/containerd v1.7.24 diff --git a/main.go b/main.go index 3272ee7..762d9ea 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,9 @@ package main import ( "flag" + "fmt" "net/http" + "os" "regexp" "strings" "time" @@ -32,11 +34,8 @@ import ( ) var ( - defaultPattern = `^oom-kill.+,task_memcg=\/kubepods(?:\.slice)?\/.+\/(?:kubepods-burstable-)?pod(\w+[-_]\w+[-_]\w+[-_]\w+[-_]\w+)(?:\.slice)?\/(?:cri-containerd-)?([a-f0-9]+)` - kmesgRE = regexp.MustCompile(defaultPattern) -) - -var ( + defaultPattern = `^oom-kill.+,task_memcg=\/kubepods(?:\.slice)?\/.+\/(?:kubepods-burstable-)?pod(\w+[-_]\w+[-_]\w+[-_]\w+[-_]\w+)(?:\.slice)?\/(?:cri-containerd-)?([a-f0-9]+)` + kmesgRE = regexp.MustCompile(defaultPattern) kubernetesCounterVec *prometheus.CounterVec prometheusContainerLabels = map[string]string{ "io.kubernetes.container.name": "container_name", @@ -45,6 +44,8 @@ var ( "io.kubernetes.pod.name": "pod_name", } metricsAddr string + versionFlag bool + Version = "dev" // set on compile time ) func init() { @@ -52,6 +53,13 @@ func init() { flag.StringVar(&metricsAddr, "listen-address", ":9102", "The address to listen on for HTTP requests.") flag.StringVar(&newPattern, "regexp-pattern", defaultPattern, "Overwrites the default regexp pattern to match and extract Pod UID and Container ID.") + flag.BoolVar(&versionFlag, "version", false, "Print version info") + flag.Parse() + + if versionFlag { + fmt.Printf("Version: %s\n", Version) + os.Exit(0) + } if newPattern != "" { kmesgRE = regexp.MustCompile(newPattern) @@ -59,8 +67,6 @@ func init() { } func main() { - flag.Parse() - containerdClient, err := containerd.New("/run/containerd/containerd.sock") if err != nil { glog.Fatal(err)