Skip to content

Commit

Permalink
Creating a Golang version of reckoner
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Suderman committed Mar 17, 2021
1 parent 57ff2b4 commit 53ebe15
Show file tree
Hide file tree
Showing 29 changed files with 2,670 additions and 142 deletions.
10 changes: 0 additions & 10 deletions .circleci/build.config

This file was deleted.

146 changes: 22 additions & 124 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,154 +17,52 @@ version: 2.1
orbs:
rok8s: fairwinds/rok8s-scripts@11

executors:
python-3-7:
docker:
- image: circleci/python:3.7
python-3-8:
docker:
- image: circleci/python:3.8

references:
e2e_configuration: &e2e_configuration
pre_script: end_to_end_testing/pre.sh
script: end_to_end_testing/run.sh
command_runner_image: quay.io/reactiveops/ci-images:v11-buster
enable_docker_layer_caching: true
store-test-results: /tmp/test-results
attach-workspace: true
workspace-location: /tmp/binaries
kind_version: 0.9.0
kind_version: 0.10.0
requires:
- build-3-8
- build-3-7
- test
filters:
branches:
only: /.*/
tags:
ignore: /v.*/

ignore: /.*/
jobs:
build-3-7:
executor: python-3-7
working_directory: ~/reckoner
steps:
- run:
name: Setup PATH to support pip user installs
command: echo 'export PATH=$PATH:/home/circleci/.local/bin' >> $BASH_ENV
- checkout
- run:
name: Unit Tests
command: |
pip install --user -r development-requirements.txt
pip install --user -e .
reckoner --version
pytest --cov ./
codecov
build-3-8:
executor: python-3-8
working_directory: ~/reckoner
steps:
- run:
name: Setup PATH to support pip user installs
command: echo 'export PATH=$PATH:/home/circleci/.local/bin' >> $BASH_ENV
- checkout
- run:
name: Unit Tests
command: |
pip install --user -r development-requirements.txt
pip install --user -e .
reckoner --version
pytest --cov ./
codecov
release:
executor: python-3-8
environment:
PYPI_USERNAME: ReactiveOps
GITHUB_ORGANIZATION: $CIRCLE_PROJECT_USERNAME
GITHUB_REPOSITORY: $CIRCLE_PROJECT_REPONAME
working_directory: ~/reckoner
test:
working_directory: /go/src/github.com/fairwindsops/reckoner
docker:
- image: circleci/golang:1.15
environment:
GO111MODULE: "on"
steps:
- checkout
- run:
name: init .pypirc
command: |
echo -e "[pypi]" >> ~/.pypirc
echo -e "username = $PYPI_USERNAME" >> ~/.pypirc
echo -e "password = $PYPI_PASSWORD" >> ~/.pypirc
- run:
name: package and upload
command: |
sudo pip install twine
python setup.py sdist bdist_wheel
twine upload dist/*
- run: go mod download && go mod verify
- run: go test -v ./... -coverprofile=coverage.txt -covermode=atomic
- run: bash <(curl -s https://codecov.io/bash)
workflows:
version: 2
build_and_test:
jobs:
- build-3-7:
- test:
filters:
tags:
only: /.*/
branches:
only: /.*/
- build-3-8:
filters:
tags:
only: /.*/
ignore: /.*/
branches:
only: /.*/
- rok8s/kubernetes_e2e_tests:
name: "End-To-End Kubernetes 1.18.8"
kind_node_image: "kindest/node:v1.18.8@sha256:f4bcc97a0ad6e7abaf3f643d890add7efe6ee4ab90baeb374b4f41a4c95567eb"
name: "End-To-End Kubernetes 1.18"
kind_node_image: "kindest/node:v1.18.15@sha256:5c1b980c4d0e0e8e7eb9f36f7df525d079a96169c8a8f20d8bd108c0d0889cc4"
<<: *e2e_configuration
- rok8s/kubernetes_e2e_tests:
name: "End-To-End Kubernetes 1.19.1"
kind_node_image: "kindest/node:v1.19.1@sha256:98cf5288864662e37115e362b23e4369c8c4a408f99cbc06e58ac30ddc721600"
name: "End-To-End Kubernetes 1.19"
kind_node_image: "kindest/node:v1.19.7@sha256:a70639454e97a4b733f9d9b67e12c01f6b0297449d5b9cbbef87473458e26dca"
<<: *e2e_configuration
- rok8s/kubernetes_e2e_tests:
name: "End-To-End Kubernetes 1.20"
kind_node_image: "kindest/node:v1.20.2@sha256:8f7ea6e7642c0da54f04a7ee10431549c0257315b3a634f6ef2fecaaedb19bab"
<<: *e2e_configuration
- rok8s/docker_build_and_push:
name: build-and-push-container
docker-push: true
enable_docker_layer_caching: true
config_file: .circleci/build.config
context: org-global
docker-login: true
password-variable: "fairwinds_quay_token"
registry: quay.io
username: fairwinds+circleci
requires:
- build-3-7
- build-3-8
- "End-To-End Kubernetes 1.18.8"
- "End-To-End Kubernetes 1.19.1"
filters:
branches:
ignore: /pull\/[0-9]+/
tags:
ignore: /.*/
release:
jobs:
- release:
filters:
tags:
only: /.*/
branches:
ignore: /.*/
- rok8s/docker_build_and_push:
name: build-and-push-container
docker-push: true
enable_docker_layer_caching: false
config_file: .circleci/build.config
context: org-global
docker-login: true
password-variable: "fairwinds_quay_token"
registry: quay.io
username: fairwinds+circleci
filters:
branches:
ignore: /.*/
tags:
only: /.*/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ htmlcov/
build/
reckoner/version.txt
installer/reckoner.spec
/bin

coverage.txt
58 changes: 58 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
builds:
- ldflags:
- -X main.version={{.Version}} -X main.commit={{.Commit}} -s -w
goarch:
- amd64
- arm
- arm64
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarm:
- 6
- 7
dockers:
- image_templates:
- "quay.io/fairwinds/reckoner:{{ .Tag }}-amd64"
- "quay.io/fairwinds/reckoner:v{{ .Major }}-amd64"
- "quay.io/fairwinds/reckoner:v{{ .Major }}.{{ .Minor }}-amd64"
use_buildx: true
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/amd64"
- image_templates:
- "quay.io/fairwinds/reckoner:{{ .Tag }}-arm64v8"
- "quay.io/fairwinds/reckoner:v{{ .Major }}-arm64v8"
- "quay.io/fairwinds/reckoner:v{{ .Major }}.{{ .Minor }}-arm64v8"
use_buildx: true
goarch: arm64
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm64/v8"
- image_templates:
- "quay.io/fairwinds/reckoner:{{ .Tag }}-armv7"
- "quay.io/fairwinds/reckoner:v{{ .Major }}-armv7"
- "quay.io/fairwinds/reckoner:v{{ .Major }}.{{ .Minor }}-armv7"
use_buildx: true
goarch: arm64
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm/v7"
docker_manifests:
- name_template: quay.io/fairwinds/reckoner:{{ .Tag }}
image_templates:
- "quay.io/fairwinds/reckoner:{{ .Tag }}-amd64"
- "quay.io/fairwinds/reckoner:{{ .Tag }}-arm64v8"
- "quay.io/fairwinds/reckoner:{{ .Tag }}-armv7"
- name_template: quay.io/fairwinds/reckoner:v{{ .Major }}
image_templates:
- "quay.io/fairwinds/reckoner:v{{ .Major }}-amd64"
- "quay.io/fairwinds/reckoner:v{{ .Major }}-arm64v8"
- "quay.io/fairwinds/reckoner:v{{ .Major }}-armv7"
- name_template: quay.io/fairwinds/reckoner:v{{ .Major }}.{{ .Minor }}
image_templates:
- "quay.io/fairwinds/reckoner:v{{ .Major }}.{{ .Minor }}-amd64"
- "quay.io/fairwinds/reckoner:v{{ .Major }}.{{ .Minor }}-arm64v8"
- "quay.io/fairwinds/reckoner:v{{ .Major }}.{{ .Minor }}-armv7"
48 changes: 48 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-json
- id: detect-private-key
- id: trailing-whitespace
exclude: >
(?x)^(
docs/.+
)$
- id: check-added-large-files
args: ['--maxkb=500']
- id: check-byte-order-marker
- id: check-merge-conflict
- id: check-symlinks
- id: end-of-file-fixer
exclude: >
(?x)^(
docs/.+
)$
- id: check-executables-have-shebangs
- id: flake8
- id: no-commit-to-branch
args: [--branch, master]
- id: pretty-format-json
args: ['--autofix']
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.5
hooks:
- id: forbid-binary
exclude: >
(?x)^(
.+\.png|
.+\.woff|
.+\.woff2|
.+\.tff|
.+\.ico
)$
- id: shellcheck
- repo: https://github.com/dnephin/pre-commit-golang.git
rev: v0.3.5
hooks:
- id: go-fmt
- id: golangci-lint
- id: go-vet
- id: go-unit-tests
38 changes: 36 additions & 2 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,41 @@ Reckoner is intended to provide a declarative syntax to install and manage multi
* Overwriting portions of a chart's output (eg Kustomize or Ship)
* Managing installation versions of Helm and Tiller

## Golang Re-Write and Schema Changes

## Architecture
We will be rewriting this project in Go in order to provide a nicer UX via a pre-compiled binary. At the same time, the course file schema will be changed in order to facilitate this rewrite.

TBD
The re-write will occur in [This Pull Request](https://github.com/FairwindsOps/reckoner/pull/293). Any new branches related to the rewrite should come from here in the short term.

### Guiding principles of the re-write

- No new features will be added that are not directly related to the schema change
- Feature parity should be maintained
- The old end-to-end test suite must run with the new binary with minimal changes (pre-converting the schema may be necessary)
- A conversion path from the old schema to the new will be provided
- Unit Test coverage should be relatively high. I'm thinking >60%

### Un-answered Questions

- Should we automatically detect the old schema and convert it for the end-user?
- Should we instead just error and point them at the conversion utility?
- Do we care about ordering? If so, this may get much uglier. In the past we have maintained strict ordering of the releases.
- Can we import the helm packages instead of relying on exec to the installed helm binary?

### New Schema Changes

The new schema will align better with Go structs, rather than constantly using `map[string]interface`.

[See the new schema here, along with the conversion function](https://github.com/FairwindsOps/reckoner/blob/golang/pkg/course/course.go)

Some major changes to the functionality:

#### Repositories will _only_ be defined in the header

Each release will reference the name of the repository from the header section.

This includes git repositories. This should prevent confusion in the future, as well as allow us to not need a dynamic field in the release struct (or in the repositories section of the header)

#### Charts will be renamed Releases

This makes a lot more sense. It's what they are.
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Go parameters
GOCMD=GO111MODULE=on go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
BINARY_NAME=bin/reckoner
COMMIT := $(shell git rev-parse HEAD)
VERSION := "0.0.0"

all: lint test
build:
$(GOBUILD) -o $(BINARY_NAME) -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -s -w" -v
lint:
golangci-lint run
reportcard:
goreportcard-cli -t 100 -v
test:
GO111MODULE=on $(GOCMD) test -v --bench --benchmem -coverprofile coverage.txt -covermode=atomic ./...
GO111MODULE=on $(GOCMD) vet ./... 2> govet-report.out
GO111MODULE=on $(GOCMD) tool cover -html=coverage.txt -o cover-report.html
printf "\nCoverage report available at cover-report.html\n\n"
tidy:
$(GOCMD) mod tidy
clean:
$(GOCLEAN)
$(GOCMD) fmt ./...
rm -f $(BINARY_NAME)
# Cross compilation
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME) -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -s -w" -v
build-docker:
docker build --build-arg version=$(VERSION) --build-arg commit=$(COMMIT) -t quay.io/reactiveops/$(BINARY_NAME):dev .
Loading

0 comments on commit 53ebe15

Please sign in to comment.