Skip to content

Commit 1930aff

Browse files
authored
Merge pull request #90 from almaslennikov/housekeeping
Housekeeping in the ib-kubernetes
2 parents 803881e + 4ff6c42 commit 1930aff

File tree

9 files changed

+736
-298
lines changed

9 files changed

+736
-298
lines changed

.github/workflows/build-images.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: build-images
2+
on: [pull_request]
3+
jobs:
4+
build-images:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Set repository as lower-case output variable
8+
id: repo_name
9+
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
10+
11+
- name: Check out code into the Go module directory
12+
uses: actions/checkout@v3
13+
14+
- name: Set up Docker Buildx
15+
uses: docker/setup-buildx-action@v2
16+
17+
- name: Build container image
18+
uses: docker/build-push-action@v3
19+
with:
20+
push: false
21+
tags: ghcr.io/${{ steps.repo_name.outputs.repository }}:latest-amd64
22+
file: ./Dockerfile

.github/workflows/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
on: [push, pull_request]
2+
name: build
3+
jobs:
4+
build:
5+
strategy:
6+
matrix:
7+
go-version: [1.19.x]
8+
goarch: [amd64]
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check out code into the Go module directory
12+
uses: actions/checkout@v3
13+
14+
- name: Install Go
15+
uses: actions/setup-go@v3
16+
with:
17+
go-version: ${{ matrix.go-version }}
18+
19+
- name: Build
20+
env:
21+
GOARCH: ${{ matrix.goarch }}
22+
run: make build

.github/workflows/push-main.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: push-main
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
build-push-amd64:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Set repository as lower-case output variable
11+
id: repo_name
12+
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
13+
14+
- name: Check out code into the Go module directory
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
20+
- name: Docker meta
21+
id: docker_meta
22+
uses: docker/metadata-action@v4
23+
with:
24+
images: ghcr.io/${{ steps.repo_name.outputs.repository }}
25+
26+
- name: Login to GitHub Container Registry
27+
uses: docker/login-action@v2
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.repository_owner }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Push to GitHub Container Registry
34+
uses: docker/build-push-action@v2
35+
with:
36+
push: true
37+
tags: |
38+
ghcr.io/${{ steps.repo_name.outputs.repository }}:latest-amd64
39+
labels: ${{ steps.docker_meta.outputs.labels }}
40+
file: ./Dockerfile
41+
42+
create-push-manifest:
43+
needs: [build-push-amd64]
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Set repository as lower-case output variable
47+
id: repo_name
48+
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v2
52+
53+
- name: Login to GitHub Container Registry
54+
uses: docker/login-action@v2
55+
with:
56+
registry: ghcr.io
57+
username: ${{ github.repository_owner }}
58+
password: ${{ secrets.GITHUB_TOKEN }}
59+
60+
- name: Create manifest for multi-arch images
61+
env:
62+
REPOSITORY: ghcr.io/${{ steps.repo_name.outputs.repository }}
63+
run: |
64+
# Get artifacts from previous steps
65+
docker pull ${{ env.REPOSITORY }}:latest-amd64
66+
# Create and update manifest
67+
docker manifest create ${{ env.REPOSITORY }}:latest ${{ env.REPOSITORY }}:latest-amd64
68+
docker manifest annotate ${{ env.REPOSITORY }}:latest ${{ env.REPOSITORY }}:latest-amd64 --arch amd64
69+
# Push manifest
70+
docker manifest push ${{ env.REPOSITORY }}:latest

.github/workflows/push-release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Image push release
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
jobs:
7+
build-push-amd64:
8+
name: Image push/amd64
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Set repository as lower-case output variable
12+
id: repo_name
13+
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
14+
15+
- name: Check out code into the Go module directory
16+
uses: actions/checkout@v3
17+
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v2
20+
21+
- name: Login to GitHub Container Registry
22+
uses: docker/login-action@v2
23+
with:
24+
registry: ghcr.io
25+
username: ${{ github.repository_owner }}
26+
password: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Docker meta
29+
id: docker_meta
30+
uses: docker/metadata-action@v4
31+
with:
32+
images: ghcr.io/${{ steps.repo_name.outputs.repository }}
33+
flavor: |
34+
latest=false
35+
36+
- name: Push container image
37+
uses: docker/build-push-action@v3
38+
with:
39+
context: .
40+
push: true
41+
tags: |
42+
ghcr.io/${{ steps.repo_name.outputs.repository }}:stable-amd64
43+
${{ steps.docker_meta.outputs.tags }}-amd64
44+
labels: ${{ steps.docker_meta.outputs.labels }}
45+
file: ./Dockerfile
46+
47+
create-push-manifest:
48+
needs: [build-push-amd64]
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Set repository as lower-case output variable
52+
id: repo_name
53+
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v2
57+
58+
- name: Docker meta
59+
id: docker_meta
60+
uses: docker/metadata-action@v4
61+
with:
62+
images: ghcr.io/${{ steps.repo_name.outputs.repository }}
63+
flavor: |
64+
latest=false
65+
66+
- name: Login to GitHub Container Registry
67+
uses: docker/login-action@v2
68+
with:
69+
registry: ghcr.io
70+
username: ${{ github.repository_owner }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
72+
73+
- name: Create manifest for multi-arch images
74+
env:
75+
REPOSITORY: ghcr.io/${{ steps.repo_name.outputs.repository }}
76+
run: |
77+
# Get artifacts from previous steps
78+
docker pull ${{ steps.docker_meta.outputs.tags }}-amd64
79+
docker pull ${{ env.REPOSITORY }}:stable-amd64
80+
# Create and update manifests
81+
docker manifest create ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-amd64
82+
docker manifest annotate ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-amd64 --arch amd64
83+
docker manifest create ${{ env.REPOSITORY }}:stable ${{ env.REPOSITORY }}:stable-amd64
84+
docker manifest annotate ${{ env.REPOSITORY }}:stable ${{ env.REPOSITORY }}:stable-amd64 --arch amd64
85+
# push manifests
86+
docker manifest push ${{ steps.docker_meta.outputs.tags }}
87+
docker manifest push ${{ env.REPOSITORY }}:stable

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
on: [push, pull_request]
2+
name: test
3+
jobs:
4+
test:
5+
strategy:
6+
matrix:
7+
go-version: [1.19.x]
8+
os: [ubuntu-latest]
9+
runs-on: ${{ matrix.os }}
10+
steps:
11+
- name: Install Go
12+
uses: actions/setup-go@v3
13+
with:
14+
go-version: ${{ matrix.go-version }}
15+
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: lint
20+
run: make lint
21+
22+
- name: test
23+
run: make test
24+
25+
coverage:
26+
runs-on: ubuntu-latest
27+
name: coverage
28+
needs: test
29+
steps:
30+
- name: Install Go
31+
uses: actions/setup-go@v3
32+
with:
33+
go-version: 1.19.x
34+
35+
- name: Checkout code
36+
uses: actions/checkout@v3
37+
38+
- name: Go test with coverage
39+
run: make test-coverage
40+
41+
- name: Coveralls
42+
uses: coverallsapp/[email protected]
43+
with:
44+
github-token: ${{ secrets.GITHUB_TOKEN }}
45+
path-to-lcov: build/coverage/lcov.info

Makefile

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ REPO_PATH=$(ORG_PATH)/$(PACKAGE)
66
GOPATH=$(CURDIR)/.gopath
77
GOBIN =$(CURDIR)/bin
88
BUILDDIR=$(CURDIR)/build
9+
COVERAGE_DIR := $(BUILDDIR)/coverage
10+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
11+
BIN_DIR := $(PROJECT_DIR)/bin
912
PLUGINSSOURCEDIR=$(CURDIR)/pkg/sm/plugins
1013
PLUGINSBUILDDIR=$(BUILDDIR)/plugins
1114
GOFILES=$(shell find . -name *.go | grep -vE "(\/vendor\/)|(_test.go)")
15+
PKGS := $(shell cd $(PROJECT_DIR) && go list ./... | grep -v mocks)
16+
TESTPKGS := $(shell go list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS))
1217

1318
export GOPATH
1419
export GOBIN
@@ -43,6 +48,10 @@ GOLANGCI_LINT = $(GOBIN)/golangci-lint
4348
TIMEOUT = 15
4449
Q = $(if $(filter 1,$V),,@)
4550

51+
ENVTEST := $(BIN_DIR)/setup-envtest
52+
GOCOVMERGE := $(BIN_DIR)/gocovmerge
53+
GCOV2LCOV := $(BIN_DIR)/gcov2lcov
54+
4655
.PHONY: all
4756
all: build plugins
4857

@@ -83,7 +92,7 @@ plugins: noop-plugin ufm-plugin ; $(info Building plugins...) ## Build plugins
8392

8493
%-plugin: $(PLUGINSBUILDDIR)
8594
@echo Building $* plugin
86-
$Q $(GO) build $(GOFLAGS) -ldflags "-X $(REPO_PATH)/version=1.0" -o $(PLUGINSBUILDDIR)/$*.so -buildmode=plugin -i $(REPO_PATH)/pkg/sm/plugins/$*
95+
$Q $(GO) build $(GOFLAGS) -ldflags "-X $(REPO_PATH)/version=1.0" -o $(PLUGINSBUILDDIR)/$*.so -buildmode=plugin $(REPO_PATH)/pkg/sm/plugins/$*
8796
@echo Done building $* plugin
8897

8998
TEST_TARGETS := test-bench test-short test-verbose test-race
@@ -100,9 +109,27 @@ test: | plugins; $(info running $(NAME:%=% )tests...) @ ## Run tests
100109

101110
COVERAGE_MODE = count
102111
.PHONY: test-coverage test-coverage-tools
103-
test-coverage-tools: | $(GOVERALLS)
104-
test-coverage: test-coverage-tools | plugins; $(info running coverage tests...) @ ## Run coverage tests
105-
$Q $(GO) test -covermode=$(COVERAGE_MODE) -coverprofile=coverage.out ./...
112+
test-coverage: | envtest gocovmerge gcov2lcov ## Run coverage tests
113+
mkdir -p $(BUILDDIR)/coverage/pkgs
114+
for pkg in $(TESTPKGS); do \
115+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test \
116+
-covermode=atomic \
117+
-coverprofile="$(COVERAGE_DIR)/pkgs/`echo $$pkg | tr "/" "-"`.cover" $$pkg ;\
118+
done
119+
$(GOCOVMERGE) $(COVERAGE_DIR)/pkgs/*.cover > $(COVERAGE_DIR)/profile.out
120+
$(GCOV2LCOV) -infile $(COVERAGE_DIR)/profile.out -outfile $(COVERAGE_DIR)/lcov.info
121+
122+
.PHONY: envtest
123+
envtest: ## Download envtest if necessary
124+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
125+
126+
.PHONY: gocovmerge
127+
gocovmerge: ## Download gocovmerge if necessary
128+
$(call go-install-tool,$(GOCOVMERGE),github.com/wadey/gocovmerge@latest)
129+
130+
.PHONY: gcov2lcov
131+
gcov2lcov: ## Download gcov2lcov if necessary
132+
$(call go-install-tool,$(GCOV2LCOV),github.com/jandelgado/[email protected])
106133

107134
# Container image
108135
.PHONY: image
@@ -123,3 +150,12 @@ clean: ; $(info Cleaning...) ## Cleanup everything
123150
help: ## Show this message
124151
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
125152
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
153+
154+
# go-get-tool will 'go get' any package $2 and install it to $1.
155+
define go-install-tool
156+
@[ -f $(1) ] || { \
157+
set -e ;\
158+
echo "Downloading $(2)" ;\
159+
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
160+
}
161+
endef

deployment/ib-kubernetes.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ spec:
7373
operator: In
7474
values:
7575
- "linux"
76+
- matchExpressions:
77+
- key: node-role.kubernetes.io/control-plane
78+
operator: In
79+
values:
80+
- ""
81+
- key: kubernetes.io/os
82+
operator: In
83+
values:
84+
- "linux"
7685
podAntiAffinity:
7786
requiredDuringSchedulingIgnoredDuringExecution:
7887
- labelSelector:

0 commit comments

Comments
 (0)