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

Add version flag, build ghcr image #37

Merged
merged 1 commit into from
Dec 11, 2024
Merged
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
56 changes: 56 additions & 0 deletions .github/workflows/container-registry-ghcr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
################################################################################
# This file is AUTOGENERATED with <https://github.com/sapcc/go-makefile-maker> #
# 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 }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 =

Expand Down
9 changes: 9 additions & 0 deletions Makefile.maker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ dockerfile:
golang:
setGoModVersion: true
enableVendoring: true
variables:
GO_LDFLAGS: "-X main.Version=$(shell git describe --tags --abbrev=0)"
golangciLint:
createConfig: true
githubWorkflow:
ci:
enabled: true
global:
defaultBranch: master
pushContainerToGhcr:
enabled: true
platforms: "linux/amd64"
tagStrategy:
- edge
- latest
- semver
renovate:
enabled: true
assignees:
Expand Down
18 changes: 18 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 13 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package main

import (
"flag"
"fmt"
"net/http"
"os"
"regexp"
"strings"
"time"
Expand All @@ -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",
Expand All @@ -45,22 +44,29 @@ var (
"io.kubernetes.pod.name": "pod_name",
}
metricsAddr string
versionFlag bool
Version = "dev" // set on compile time
)

func init() {
var newPattern string

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)
}
}

func main() {
flag.Parse()

containerdClient, err := containerd.New("/run/containerd/containerd.sock")
if err != nil {
glog.Fatal(err)
Expand Down
Loading