Skip to content

Commit

Permalink
Merge pull request #90 from almaslennikov/housekeeping
Browse files Browse the repository at this point in the history
Housekeeping in the ib-kubernetes
  • Loading branch information
moshe010 authored Sep 21, 2022
2 parents 803881e + 4ff6c42 commit 1930aff
Show file tree
Hide file tree
Showing 9 changed files with 736 additions and 298 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: build-images
on: [pull_request]
jobs:
build-images:
runs-on: ubuntu-latest
steps:
- name: Set repository as lower-case output variable
id: repo_name
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')

- name: Check out code into the Go module directory
uses: actions/checkout@v3

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

- name: Build container image
uses: docker/build-push-action@v3
with:
push: false
tags: ghcr.io/${{ steps.repo_name.outputs.repository }}:latest-amd64
file: ./Dockerfile
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on: [push, pull_request]
name: build
jobs:
build:
strategy:
matrix:
go-version: [1.19.x]
goarch: [amd64]
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Build
env:
GOARCH: ${{ matrix.goarch }}
run: make build
70 changes: 70 additions & 0 deletions .github/workflows/push-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: push-main
on:
push:
branches:
- main
jobs:
build-push-amd64:
runs-on: ubuntu-latest
steps:
- name: Set repository as lower-case output variable
id: repo_name
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')

- name: Check out code into the Go module directory
uses: actions/checkout@v3

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

- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ steps.repo_name.outputs.repository }}

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

- name: Push to GitHub Container Registry
uses: docker/build-push-action@v2
with:
push: true
tags: |
ghcr.io/${{ steps.repo_name.outputs.repository }}:latest-amd64
labels: ${{ steps.docker_meta.outputs.labels }}
file: ./Dockerfile

create-push-manifest:
needs: [build-push-amd64]
runs-on: ubuntu-latest
steps:
- name: Set repository as lower-case output variable
id: repo_name
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')

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

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

- name: Create manifest for multi-arch images
env:
REPOSITORY: ghcr.io/${{ steps.repo_name.outputs.repository }}
run: |
# Get artifacts from previous steps
docker pull ${{ env.REPOSITORY }}:latest-amd64
# Create and update manifest
docker manifest create ${{ env.REPOSITORY }}:latest ${{ env.REPOSITORY }}:latest-amd64
docker manifest annotate ${{ env.REPOSITORY }}:latest ${{ env.REPOSITORY }}:latest-amd64 --arch amd64
# Push manifest
docker manifest push ${{ env.REPOSITORY }}:latest
87 changes: 87 additions & 0 deletions .github/workflows/push-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Image push release
on:
push:
tags:
- v*
jobs:
build-push-amd64:
name: Image push/amd64
runs-on: ubuntu-latest
steps:
- name: Set repository as lower-case output variable
id: repo_name
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')

- name: Check out code into the Go module directory
uses: actions/checkout@v3

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

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

- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ steps.repo_name.outputs.repository }}
flavor: |
latest=false
- name: Push container image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: |
ghcr.io/${{ steps.repo_name.outputs.repository }}:stable-amd64
${{ steps.docker_meta.outputs.tags }}-amd64
labels: ${{ steps.docker_meta.outputs.labels }}
file: ./Dockerfile

create-push-manifest:
needs: [build-push-amd64]
runs-on: ubuntu-latest
steps:
- name: Set repository as lower-case output variable
id: repo_name
run: echo ::set-output name=repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')

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

- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ steps.repo_name.outputs.repository }}
flavor: |
latest=false
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest for multi-arch images
env:
REPOSITORY: ghcr.io/${{ steps.repo_name.outputs.repository }}
run: |
# Get artifacts from previous steps
docker pull ${{ steps.docker_meta.outputs.tags }}-amd64
docker pull ${{ env.REPOSITORY }}:stable-amd64
# Create and update manifests
docker manifest create ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-amd64
docker manifest annotate ${{ steps.docker_meta.outputs.tags }} ${{ steps.docker_meta.outputs.tags }}-amd64 --arch amd64
docker manifest create ${{ env.REPOSITORY }}:stable ${{ env.REPOSITORY }}:stable-amd64
docker manifest annotate ${{ env.REPOSITORY }}:stable ${{ env.REPOSITORY }}:stable-amd64 --arch amd64
# push manifests
docker manifest push ${{ steps.docker_meta.outputs.tags }}
docker manifest push ${{ env.REPOSITORY }}:stable
45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on: [push, pull_request]
name: test
jobs:
test:
strategy:
matrix:
go-version: [1.19.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3

- name: lint
run: make lint

- name: test
run: make test

coverage:
runs-on: ubuntu-latest
name: coverage
needs: test
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x

- name: Checkout code
uses: actions/checkout@v3

- name: Go test with coverage
run: make test-coverage

- name: Coveralls
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: build/coverage/lcov.info
44 changes: 40 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ REPO_PATH=$(ORG_PATH)/$(PACKAGE)
GOPATH=$(CURDIR)/.gopath
GOBIN =$(CURDIR)/bin
BUILDDIR=$(CURDIR)/build
COVERAGE_DIR := $(BUILDDIR)/coverage
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
BIN_DIR := $(PROJECT_DIR)/bin
PLUGINSSOURCEDIR=$(CURDIR)/pkg/sm/plugins
PLUGINSBUILDDIR=$(BUILDDIR)/plugins
GOFILES=$(shell find . -name *.go | grep -vE "(\/vendor\/)|(_test.go)")
PKGS := $(shell cd $(PROJECT_DIR) && go list ./... | grep -v mocks)
TESTPKGS := $(shell go list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS))

export GOPATH
export GOBIN
Expand Down Expand Up @@ -43,6 +48,10 @@ GOLANGCI_LINT = $(GOBIN)/golangci-lint
TIMEOUT = 15
Q = $(if $(filter 1,$V),,@)

ENVTEST := $(BIN_DIR)/setup-envtest
GOCOVMERGE := $(BIN_DIR)/gocovmerge
GCOV2LCOV := $(BIN_DIR)/gcov2lcov

.PHONY: all
all: build plugins

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

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

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

COVERAGE_MODE = count
.PHONY: test-coverage test-coverage-tools
test-coverage-tools: | $(GOVERALLS)
test-coverage: test-coverage-tools | plugins; $(info running coverage tests...) @ ## Run coverage tests
$Q $(GO) test -covermode=$(COVERAGE_MODE) -coverprofile=coverage.out ./...
test-coverage: | envtest gocovmerge gcov2lcov ## Run coverage tests
mkdir -p $(BUILDDIR)/coverage/pkgs
for pkg in $(TESTPKGS); do \
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test \
-covermode=atomic \
-coverprofile="$(COVERAGE_DIR)/pkgs/`echo $$pkg | tr "/" "-"`.cover" $$pkg ;\
done
$(GOCOVMERGE) $(COVERAGE_DIR)/pkgs/*.cover > $(COVERAGE_DIR)/profile.out
$(GCOV2LCOV) -infile $(COVERAGE_DIR)/profile.out -outfile $(COVERAGE_DIR)/lcov.info

.PHONY: envtest
envtest: ## Download envtest if necessary
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

.PHONY: gocovmerge
gocovmerge: ## Download gocovmerge if necessary
$(call go-install-tool,$(GOCOVMERGE),github.com/wadey/gocovmerge@latest)

.PHONY: gcov2lcov
gcov2lcov: ## Download gcov2lcov if necessary
$(call go-install-tool,$(GCOV2LCOV),github.com/jandelgado/[email protected])

# Container image
.PHONY: image
Expand All @@ -123,3 +150,12 @@ clean: ; $(info Cleaning...) ## Cleanup everything
help: ## Show this message
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

# go-get-tool will 'go get' any package $2 and install it to $1.
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
}
endef
9 changes: 9 additions & 0 deletions deployment/ib-kubernetes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ spec:
operator: In
values:
- "linux"
- matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: In
values:
- ""
- key: kubernetes.io/os
operator: In
values:
- "linux"
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
Expand Down
Loading

0 comments on commit 1930aff

Please sign in to comment.