Skip to content
Open
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
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2026 The Volcano 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.

name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
contents: read

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: "1.25"

- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.8.0

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: "1.25"

- name: Run tests
run: make test

build:
name: Build
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: "1.25"

- name: Build binary
run: make build
120 changes: 120 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Copyright 2026 The Volcano 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.

name: Release

on:
schedule:
# Daily build from master, tagged as "latest".
- cron: "0 0 * * *"
push:
tags:
- "v*.*.*"

permissions:
contents: read
packages: write

jobs:
check-changes:
name: Check for recent changes
runs-on: ubuntu-latest
if: github.event_name != 'schedule' || true
outputs:
has_changes: ${{ github.event_name == 'push' || steps.check.outputs.has_changes }}
steps:
- name: Checkout code
if: github.event_name == 'schedule'
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for commits in last 24h
if: github.event_name == 'schedule'
id: check
run: |
COMMITS=$(git log --oneline --since="24 hours ago" | wc -l)
if [[ "$COMMITS" -gt 0 ]]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi

release:
name: Build and Push Images
runs-on: ubuntu-latest
needs: check-changes
if: needs.check-changes.outputs.has_changes == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Determine image tag
id: meta
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
else
TAG="latest"
VERSION="latest"
fi
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "git_sha=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
echo "build_date=$(date -u +'%Y-%m-%d %H:%M:%S')" >> "$GITHUB_OUTPUT"
OWNER="${{ github.repository_owner }}"
echo "repo_owner=${OWNER,,}" >> "$GITHUB_OUTPUT"

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
volcanosh/numatopo:${{ steps.meta.outputs.tag }}
ghcr.io/${{ steps.meta.outputs.repo_owner }}/numatopo:${{ steps.meta.outputs.tag }}
build-args: |
VERSION=${{ steps.meta.outputs.version }}
GIT_SHA=${{ steps.meta.outputs.git_sha }}
BUILD_DATE=${{ steps.meta.outputs.build_date }}

- name: Logout from registries
if: always()
run: |
docker logout
docker logout ghcr.io
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "2"

run:
timeout: 5m

linters:
enable:
- errcheck
- govet
- ineffassign
- staticcheck
- unused
- revive

settings:
revive:
rules:
- name: exported
disabled: true

exclusions:
rules:
- linters: [revive]
text: "var-naming: avoid meaningless package names"
41 changes: 25 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
REL_OSARCH="linux/amd64"
BIN_DIR=_output/bin
REL_OSARCH = linux/amd64
BIN_DIR = _output/bin
IMAGE_REPO ?= volcanosh/numatopo

include Makefile.def

.EXPORT_ALL_VARIABLES:

.PHONY: init fmt lint test build image clean

init:
mkdir -p ${BIN_DIR}
@mkdir -p ${BIN_DIR}

fmt:
go fmt ./pkg/...
go fmt ./main.go

vet:
go vet ./pkg/...
go vet ./main.go
go fmt ./...

lint:
golint ./pkg/...
golint ./main.go

image: init fmt vet lint
golangci-lint run ./...

test:
go test -race ./...

build: init
CGO_ENABLED=0 go build -ldflags ${LD_FLAGS} -o ${BIN_DIR}/numatopo ./
cp ${BIN_DIR}/numatopo ./docker/numatopo
docker build --no-cache -t volcanosh/numatopo:${TAG} ./docker/
rm -rf ./docker/numatopo

image:
docker build --no-cache \
--build-arg VERSION=${RELEASE_VER} \
--build-arg GIT_SHA=${GitSHA} \
--build-arg BUILD_DATE="${Date}" \
-t ${IMAGE_REPO}:${TAG} \
-f docker/Dockerfile .

clean:
rm -rf ${BIN_DIR}
19 changes: 9 additions & 10 deletions Makefile.def
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

# If tag not explicitly set in users default to the git sha.
TAG ?= $(shell git rev-parse --verify HEAD)
GitSHA=`git rev-parse HEAD`
Date=`date "+%Y-%m-%d %H:%M:%S"`
RELEASE_VER=latest
LD_FLAGS=" \
-X '${REPO_PATH}/pkg/version.GitSHA=${GitSHA}' \
-X '${REPO_PATH}/pkg/version.Built=${Date}' \
-X '${REPO_PATH}/pkg/version.Version=${RELEASE_VER}'"
# If tag not explicitly set, default to the git sha.
TAG ?= $(shell git rev-parse --short HEAD)
GitSHA = $(shell git rev-parse HEAD)
Date = $(shell date "+%Y-%m-%d %H:%M:%S")
RELEASE_VER ?= latest
LD_FLAGS = " \
-X 'volcano.sh/resource-exporter/pkg/version.GitSHA=${GitSHA}' \
-X 'volcano.sh/resource-exporter/pkg/version.Built=${Date}' \
-X 'volcano.sh/resource-exporter/pkg/version.Version=${RELEASE_VER}'"
65 changes: 45 additions & 20 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
# Copyright 2021 The Volcano 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.


FROM alpine:latest

ADD numatopo /numatopo
ENTRYPOINT ["/numatopo"]

# Copyright 2026 The Volcano 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.

# ---- Build stage ----
FROM golang:1.25 AS builder

WORKDIR /workspace

# Cache dependency downloads.
COPY go.mod go.sum ./
RUN go mod download

# Copy source and build a fully static binary.
COPY . .

ARG VERSION=unknown
ARG GIT_SHA=unknown
ARG BUILD_DATE=unknown

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags " \
-X 'volcano.sh/resource-exporter/pkg/version.Version=${VERSION}' \
-X 'volcano.sh/resource-exporter/pkg/version.GitSHA=${GIT_SHA}' \
-X 'volcano.sh/resource-exporter/pkg/version.Built=${BUILD_DATE}'" \
-o /numatopo ./

# ---- Runtime stage ----
# This container runs as root because it must read kubelet's
# cpu_manager_state file which is owner-only (0600, root:root).
FROM alpine:latest

COPY --from=builder /numatopo /numatopo

ENTRYPOINT ["/numatopo"]
Loading