Skip to content

Commit

Permalink
Merge pull request #103 from spotahome/refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
slok authored Jul 10, 2020
2 parents 3fcbf0c + 5c3bdc7 commit 81a35ab
Show file tree
Hide file tree
Showing 124 changed files with 3,102 additions and 6,125 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on: [push, pull_request]

jobs:
check:
name: Check
runs-on: ubuntu-latest
# Execute the checks inside the container instead the VM.
container: golangci/golangci-lint:v1.24.0-alpine
steps:
- uses: actions/checkout@v1
- run: ./hack/scripts/check.sh

unit-test:
name: Unit test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2-beta
with:
go-version: 1.14
- run: make ci-unit-test

integration-test:
name: Integration test
runs-on: ubuntu-latest
needs: [check, unit-test]
strategy:
matrix:
kubernetes: [1.15.7, 1.16.4, 1.17.0, 1.18.0]
env:
KIND_VERSION: v0.7.0
steps:
- uses: actions/checkout@v1
- run: curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64 && chmod +x kind && sudo mv kind /usr/local/bin/
- run: curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v${{ matrix.kubernetes }}/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- run: KUBERNETES_VERSION=${{ matrix.kubernetes }} make ci-integration-test



17 changes: 10 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# Binaries for programs and plugins
# Binaries for programs and plugins.
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
# Test binary, build with `go test -c`.
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
# Output of the go coverage tool, specifically when used with LiteIDE.
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736.
.glide/

# binary
# Binary.
bin/

# vendor
vendor/
# Vendor.
vendor/

# Test coverage.
.test_coverage.txt
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

32 changes: 30 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
## [unreleased]

- Support for Kubernetes 1.13.
NOTE: Breaking release in controllers.

- Refactor controller package.
- Refactor metrics package.
- Refactor log package.
- Remove operator concept and remove CRD initialization in favor of using only
controllers and let the CRD initialization outside Kooper (e.g CRD yaml).
- Default resync time to 3 minutes.
- Default workers to 3.
- Disable retry handling on controllers in case of error by default.
- Remove tracing.
- Minimum Go version v1.13 (error wrapping required).
- Refactor Logger with structured logging.
- Add Logrus helper wrapper.
- Refactor to simplify the retrievers.
- Refactor metrics recorder implementation including the prometheus backend.
- Refactor internal controller queue into a decorator implementation approach.
- Remove `Delete` method from `controller.Handler` and simplify to only `Handle` method
- Add `DisableResync` flag on controller configuration to disable the resync of all resources.

## [0.8.0] - 2019-12-11

- Support for Kubernetes 1.15.

## [0.7.0] - 2019-11-26

- Support for Kubernetes 1.14.

## [0.6.0] - 2019-06-01

Expand Down Expand Up @@ -83,7 +109,9 @@ This release breaks controllers constructors to allow passing a metrics recorder
- sequential controller implementation.
- Dependencies managed by dep and vendored.

[unreleased]: https://github.com/spotahome/kooper/compare/v0.6.0...HEAD
[unreleased]: https://github.com/spotahome/kooper/compare/v0.8.0...HEAD
[0.8.0]: https://github.com/spotahome/kooper/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/spotahome/kooper/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/spotahome/kooper/compare/v0.5.1...v0.6.0
[0.5.1]: https://github.com/spotahome/kooper/compare/v0.5.0...v0.5.1
[0.5.0]: https://github.com/spotahome/kooper/compare/v0.4.1...v0.5.0
Expand Down
93 changes: 25 additions & 68 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,103 +1,60 @@

# Name of this service/application
SERVICE_NAME := kooper

# Path of the go service inside docker
DOCKER_GO_SERVICE_PATH := /src

# Shell to use for running scripts
SHELL := $(shell which bash)

# Get docker path or an empty string
DOCKER := $(shell command -v docker)

# Get the main unix group for the user running make (to be used by docker-compose later)
OSTYPE := $(shell uname)
GID := $(shell id -g)

# Get the unix user id for the user running make (to be used by docker-compose later)
UID := $(shell id -u)

# cmds
UNIT_TEST_CMD := ./hack/scripts/unit-test.sh
INTEGRATION_TEST_CMD := ./hack/scripts/integration-test.sh
CI_INTEGRATION_TEST_CMD := ./hack/scripts/integration-test-kind.sh
MOCKS_CMD := ./hack/scripts/mockgen.sh
DOCKER_RUN_CMD := docker run -v ${PWD}:$(DOCKER_GO_SERVICE_PATH) --rm -it $(SERVICE_NAME)
RUN_EXAMPLE_POD_ECHO := go run ./examples/echo-pod-controller/cmd/* --development
RUN_EXAMPLE_POD_ECHO_ONEFILE := go run ./examples/onefile-echo-pod-controller/main.go --development
RUN_EXAMPLE_POD_TERM := go run ./examples/pod-terminator-operator/cmd/* --development
DEPS_CMD := GO111MODULE=on go mod tidy && GO111MODULE=on go mod vendor
K8S_VERSION := "1.15.6"
SET_K8S_DEPS_CMD := GO111MODULE=on go mod edit \
-require=k8s.io/apiextensions-apiserver@kubernetes-${K8S_VERSION} \
-require=k8s.io/client-go@kubernetes-${K8S_VERSION} \
-require=k8s.io/apimachinery@kubernetes-${K8S_VERSION} \
-require=k8s.io/api@kubernetes-${K8S_VERSION} \
-require=k8s.io/kubernetes@v${K8S_VERSION} && \
$(DEPS_CMD)
DOCKER_RUN_CMD := docker run --env ostype=$(OSTYPE) -v ${PWD}:/src --rm -it ${SERVICE_NAME}
DEPS_CMD := go mod tidy
CHECK_CMD := ./hack/scripts/check.sh


# environment dirs
DEV_DIR := docker/dev
help: ## Show this help
@echo "Help"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[93m %s\n", $$1, $$2}'

# The default action of this Makefile is to build the development docker image
.PHONY: default
default: build
default: help

# Test if the dependencies we need to run this Makefile are installed
.PHONY: deps-development
deps-development:
ifndef DOCKER
@echo "Docker is not available. Please install docker"
@exit 1
endif

# Build the development docker image
.PHONY: build
build:
build: ## Build the development docker image.
docker build -t $(SERVICE_NAME) --build-arg uid=$(UID) --build-arg gid=$(GID) -f ./docker/dev/Dockerfile .

# Dependency stuff.
.PHONY: set-k8s-deps
set-k8s-deps:
$(SET_K8S_DEPS_CMD)

.PHONY: deps
deps:
deps: ## Updates the required dependencies.
$(DEPS_CMD)

# Test stuff in dev
.PHONY: unit-test
unit-test: build
$(DOCKER_RUN_CMD) /bin/sh -c '$(UNIT_TEST_CMD)'
.PHONY: integration-test
integration-test: build
integration-test: build ## Runs integration tests out of CI.
echo "[WARNING] Requires a kubernetes cluster configured (and running) on your kubeconfig!!"
$(INTEGRATION_TEST_CMD)

.PHONY: test
test: unit-test
test: build ## Runs unit tests out of CI.
$(DOCKER_RUN_CMD) /bin/sh -c '$(UNIT_TEST_CMD)'

.PHONY: check
check: build ## Runs checks.
@$(DOCKER_RUN_CMD) /bin/sh -c '$(CHECK_CMD)'

# Test stuff in ci
.PHONY: ci-unit-test
ci-unit-test:
ci-unit-test: ## Runs unit tests in CI.
$(UNIT_TEST_CMD)

.PHONY: ci-integration-test
ci-integration-test:
ci-integration-test: ## Runs integration tests in CI.
$(CI_INTEGRATION_TEST_CMD)
.PHONY: ci

.PHONY: ci ## Runs all tests in CI.
ci: ci-unit-test ci-integration-test

# Mocks stuff in dev
.PHONY: mocks
mocks: build
mocks: build ## Generates mocks.
$(DOCKER_RUN_CMD) /bin/sh -c '$(MOCKS_CMD)'

# Run examples.
.PHONY: controller-example
controller-example:
$(RUN_EXAMPLE_POD_ECHO)
.PHONY: controller-example-onefile
controller-example-onefile:
$(RUN_EXAMPLE_POD_ECHO_ONEFILE)
.PHONY: operator-example
operator-example:
$(RUN_EXAMPLE_POD_TERM)
Loading

0 comments on commit 81a35ab

Please sign in to comment.