-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite from a CPA to dedicated CR and operator (#70)
- Loading branch information
1 parent
25696d6
commit 9872904
Showing
100 changed files
with
6,020 additions
and
5,824 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file | ||
# Ignore build and test binaries. | ||
bin/ | ||
testbin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,41 +9,49 @@ jobs: | |
name: Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go 1.17 | ||
|
||
- name: Set up Go 1.18 | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.17 | ||
id: go | ||
- uses: actions/setup-python@v2 | ||
go-version: 1.18 | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.8.x' | ||
|
||
- uses: azure/setup-helm@v1 | ||
with: | ||
python-version: '3.8.5' | ||
version: 'v3.9.0' | ||
id: helm | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v1 | ||
|
||
- name: Lint, test and build | ||
run: | | ||
# Get staticcheck | ||
# Get tooling | ||
export PATH=$PATH:$(go env GOPATH)/bin | ||
go install honnef.co/go/tools/cmd/[email protected] | ||
go get | ||
# Lint and test | ||
pip install -r requirements-dev.txt | ||
make generate | ||
make lint | ||
make format | ||
# Exit if after formatting there are any code differences | ||
git diff --exit-code | ||
make test | ||
# Build | ||
if [ ${{ github.event_name }} == "release" ]; then | ||
# github.ref is in the form refs/tags/VERSION, so apply regex to just get version | ||
VERSION=$(echo "${{ github.ref }}" | grep -P '([^\/]+$)' -o) | ||
VERSION="${{ github.ref_name }}" | ||
else | ||
VERSION=$(git rev-parse --short ${{ github.sha }}) | ||
VERSION="${{ github.sha }}" | ||
fi | ||
make docker VERSION=${VERSION} | ||
- name: Deploy | ||
env: | ||
DOCKER_USER: ${{ secrets.DOCKER_USER }} | ||
|
@@ -52,14 +60,39 @@ jobs: | |
run: | | ||
if [ ${{ github.event_name }} == "release" ]; then | ||
# github.ref is in the form refs/tags/VERSION, so apply regex to just get version | ||
VERSION=$(echo "${{ github.ref }}" | grep -P '([^\/]+$)' -o) | ||
VERSION="${{ github.ref_name }}" | ||
else | ||
VERSION=$(git rev-parse --short ${{ github.sha }}) | ||
VERSION="${{ github.sha }}" | ||
fi | ||
echo "$DOCKER_PASS" | docker login --username=$DOCKER_USER --password-stdin | ||
docker push jthomperoo/predictive-horizontal-pod-autoscaler:${VERSION} | ||
if [ ${{ github.event_name }} == "release" ]; then | ||
docker tag jthomperoo/predictive-horizontal-pod-autoscaler:${VERSION} jthomperoo/predictive-horizontal-pod-autoscaler:latest | ||
docker push jthomperoo/predictive-horizontal-pod-autoscaler:latest | ||
fi | ||
- name: Bundle YAML config | ||
if: github.event_name == 'release' && github.repository == 'jthomperoo/predictive-horizontal-pod-autoscaler' | ||
run: | | ||
# Variables to sub into k8s templates | ||
if [ ${{ github.event_name }} == "release" ]; then | ||
VERSION="${{ github.ref_name }}" | ||
else | ||
VERSION="${{ github.sha }}" | ||
fi | ||
export VERSION="${VERSION}" | ||
sed -i "/version: 0.0.0/c\version: ${VERSION}" helm/Chart.yaml | ||
helm package helm/ | ||
- name: Deploy helm package | ||
if: github.event_name == 'release' && github.repository == 'jthomperoo/predictive-horizontal-pod-autoscaler' | ||
uses: Shopify/[email protected] | ||
with: | ||
name: predictive-horizontal-pod-autoscaler-${{ github.ref_name }}.tgz | ||
path: predictive-horizontal-pod-autoscaler-${{ github.ref_name }}.tgz | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
/vendor/ | ||
/dist/ | ||
*.out | ||
__pycache__ | ||
.algorithm_coverage | ||
.coverage | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
bin | ||
dist | ||
tmp | ||
testbin/* | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Kubernetes Generated files - skip generated files, except for vendored files | ||
|
||
!vendor/**/zz_generated.* | ||
|
||
# editor and IDE paraphernalia | ||
.idea | ||
*.swp | ||
*.swo | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2022 The Predictive Horizontal Pod Autoscaler 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 the manager binary | ||
FROM golang:1.18 as builder | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
RUN go mod download | ||
|
||
# Copy the go source | ||
COPY . . | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go | ||
|
||
FROM python:3.8-slim-buster | ||
WORKDIR /app | ||
|
||
# Install Python dependencies | ||
COPY algorithms/requirements.txt ./algorithms/requirements.txt | ||
RUN python -m pip install -r algorithms/requirements.txt | ||
|
||
COPY algorithms/ ./algorithms | ||
COPY --from=builder /workspace/manager . | ||
USER 65532:65532 | ||
|
||
ENTRYPOINT ["/app/manager"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,23 @@ REGISTRY = jthomperoo | |
NAME = predictive-horizontal-pod-autoscaler | ||
VERSION = latest | ||
|
||
default: | ||
@echo "=============Building=============" | ||
go build -o dist/$(NAME) main.go | ||
cp LICENSE dist/LICENSE | ||
LOCAL_HELM_CHART_NAME=predictive-horizontal-pod-autoscaler-operator | ||
|
||
test: | ||
@echo "=============Running tests=============" | ||
go test ./... -cover -coverprofile application_coverage.out | ||
pytest algorithms/ --cov-report term --cov-report=xml:algorithm_coverage.out --cov-report=html:.algorithm_coverage --cov=algorithms/ | ||
run: deploy py_dependencies | ||
go run github.com/cosmtrek/air | ||
|
||
py_dependencies: | ||
python -m pip install -r requirements-dev.txt | ||
|
||
undeploy: generate | ||
helm uninstall $(LOCAL_HELM_CHART_NAME) | ||
|
||
lint: | ||
deploy: generate | ||
helm upgrade --install --set mode=development $(LOCAL_HELM_CHART_NAME) helm/ | ||
|
||
lint: generate | ||
@echo "=============Linting=============" | ||
staticcheck ./... | ||
go run honnef.co/go/tools/cmd/staticcheck ./... | ||
pylint algorithms --rcfile=.pylintrc | ||
|
||
format: | ||
|
@@ -23,15 +27,31 @@ format: | |
go mod tidy | ||
find algorithms -name '*.py' -print0 | xargs -0 yapf -i | ||
|
||
test: generate | ||
@echo "=============Running tests=============" | ||
go test ./... -cover -coverprofile unit_cover.out | ||
pytest algorithms/ --cov-report term --cov-report=xml:algorithm_coverage.out --cov-report=html:.algorithm_coverage --cov=algorithms/ | ||
|
||
docker: | ||
@echo "=============Building docker images=============" | ||
docker build -f build/Dockerfile -t $(REGISTRY)/$(NAME):$(VERSION) . | ||
docker build . -t $(REGISTRY)/$(NAME):$(VERSION) | ||
|
||
doc: | ||
@echo "=============Serving docs=============" | ||
mkdocs serve | ||
generate: get_controller-gen | ||
@echo "=============Generating Golang and YAML=============" | ||
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
controller-gen rbac:roleName=predictive-horizontal-pod-autoscaler webhook crd:allowDangerousTypes=true \ | ||
paths="./..." \ | ||
output:crd:artifacts:config=helm/templates/crd \ | ||
output:rbac:artifacts:config=helm/templates/cluster \ | ||
output:webhook:artifacts:config=helm/templates/cluster | ||
|
||
coverage: | ||
view_coverage: | ||
@echo "=============Loading coverage HTML=============" | ||
go tool cover -html=application_coverage.out | ||
go tool cover -html=unit_cover.out | ||
python -m webbrowser file://$(shell pwd)/.algorithm_coverage/index.html | ||
|
||
get_controller-gen: | ||
go install sigs.k8s.io/controller-tools/cmd/[email protected] | ||
|
||
doc: | ||
@echo "=============Serving docs=============" | ||
mkdocs serve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
domain: jamiethompson.me | ||
layout: | ||
- go.kubebuilder.io/v3 | ||
plugins: | ||
manifests.sdk.operatorframework.io/v2: {} | ||
scorecard.sdk.operatorframework.io/v2: {} | ||
projectName: predictive-horizontal-pod-autoscaler | ||
repo: github.com/jthomperoo/predictive-horizontal-pod-autoscaler | ||
resources: | ||
- api: | ||
crdVersion: v1 | ||
namespaced: true | ||
controller: true | ||
domain: jamiethompson.me | ||
group: jamiethompson.me | ||
kind: PredictiveHorizontalPodAutoscaler | ||
path: github.com/jthomperoo/predictive-horizontal-pod-autoscaler/api/v1alpha1 | ||
version: v1alpha1 | ||
webhooks: | ||
defaulting: true | ||
validation: true | ||
webhookVersion: v1 | ||
version: "3" |
Oops, something went wrong.