Skip to content

Commit

Permalink
setup repository
Browse files Browse the repository at this point in the history
  • Loading branch information
lterrac committed Jun 22, 2021
1 parent e3062dd commit 4856ace
Show file tree
Hide file tree
Showing 28 changed files with 657 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*]
indent_style = space
indent_size = tab
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120

[*.md]
trim_trailing_whitespace = false

[*.go]
indent_style = tab

[Makefile]
indent_style = tab
tab_width = 4
50 changes: 50 additions & 0 deletions .github/workflows/base-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: base-pipeline

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:

build:
name: Build and test with coverage
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.15
uses: actions/setup-go@v2
with:
go-version: ^1.15

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

- name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: |
make build
- name: Test
run: |
make test
- name: Coverage
run: |
make coverage
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

.vscode/

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

pkg/*/community-controller
pkg/*/system-controller
pkg/*/edge-scheduler
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
MAKEFLAGS += --no-print-directory
COMPONENTS = community-controller system-controller edge-scheduler

ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

CRD_OPTIONS ?= "crd:trivialVersions=true"

.PHONY: all build coverage clean manifests test

all: build coverage clean manifests test

build:
$(call action, build)

coverage:
$(call action, coverage)

clean:
$(call action, clean)

test:
$(call action, test)

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=systemautoscaler-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif


define action
@for c in $(COMPONENTS); \
do \
$(MAKE) $(1) -C pkg/$$c; \
done
endef
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/lterrac/edge-autoscaler

go 1.16

require (
k8s.io/code-generator v0.21.2
k8s.io/kube-openapi v0.0.0-20210527164424-3c818078ee3d
)
226 changes: 226 additions & 0 deletions go.sum

Large diffs are not rendered by default.

Empty file added hack/boilerplate.go.txt
Empty file.
6 changes: 6 additions & 0 deletions hack/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tools

import (
_ "k8s.io/code-generator" // This package imports things required by build scripts, to force `go mod` to see them as dependencies
_ "k8s.io/kube-openapi/cmd/openapi-gen"
)
37 changes: 37 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

# Copyright 2017 The Kubernetes 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.

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}

# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
bash "${CODEGEN_PKG}"/generate-groups.sh "all" \
github.com/lterrac/edge-autoscaler/pkg/generated github.com/lterrac/edge-autoscaler/pkg/apis \
systemautoscaler:v1beta1 \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../../.." \
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt

# To use your own boilerplate text append:
# --go-header-file "${SCRIPT_ROOT}"/hack/custom-boilerplate.go.txt


48 changes: 48 additions & 0 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# Copyright 2017 The Kubernetes 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.

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

DIFFROOT="${SCRIPT_ROOT}/pkg"
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg"
_tmp="${SCRIPT_ROOT}/_tmp"

cleanup() {
rm -rf "${_tmp}"
}
trap "cleanup" EXIT SIGINT

cleanup

mkdir -p "${TMP_DIFFROOT}"
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}"

"${SCRIPT_ROOT}/hack/update-codegen.sh"
echo "diffing ${DIFFROOT} against freshly generated codegen"
ret=0
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}"
if [[ $ret -eq 0 ]]
then
echo "${DIFFROOT} up to date."
else
echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh"
exit 1
fi
5 changes: 5 additions & 0 deletions pkg/community-controller/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/testdata
.dockerignore
Dockerfile
README.md
*.out
7 changes: 7 additions & 0 deletions pkg/community-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM gcr.io/distroless/static:nonroot

LABEL name="Community Controller"

COPY community-controller /usr/local/bin/

CMD ["community-controller"]
41 changes: 41 additions & 0 deletions pkg/community-controller/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
BUILD_SETTINGS = CGO_ENABLED=0 GOOS=linux GOARCH=amd64
IMAGE = community-controller
IMAGE_VERSION = $(shell git tag --points-at HEAD | sed '/$(IMAGE)\/.*/!s/.*//' | sed 's/\//:/')
REPO = systemautoscaler


.PHONY: all build coverage clean e2e fmt release test vet

all: build test coverage clean

build: fmt vet test
$(BUILD_SETTINGS) go build -trimpath -o "$(IMAGE)" ./main.go

fmt:
@go fmt ./...

test:
@go test -race $(shell go list ./... | grep -v e2e) --coverprofile=coverage.out

e2e:
@go test -race $(shell go list ./... | grep e2e)

coverage: test
@go tool cover -func=coverage.out

release:
@if [ -n "$(IMAGE_VERSION)" ]; then \
echo "Building $(IMAGE_VERSION)" ;\
docker build -t $(REPO)/$(IMAGE_VERSION) . ;\
docker push $(REPO)/$(IMAGE_VERSION) ;\
else \
echo "$(IMAGE) unchanged: no version tag on HEAD commit" ;\
fi

vet:
@go vet ./...

clean:
@rm -rf ./$(IMAGE)
@go clean -cache
@rm -rf *.out
1 change: 1 addition & 0 deletions pkg/community-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Community Controller
5 changes: 5 additions & 0 deletions pkg/community-controller/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {
println("Hello World!")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package controller

type CommunityController struct {
}

func NewController() *CommunityController {
return &CommunityController{}
}
5 changes: 5 additions & 0 deletions pkg/edge-scheduler/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/testdata
.dockerignore
Dockerfile
README.md
*.out
7 changes: 7 additions & 0 deletions pkg/edge-scheduler/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM gcr.io/distroless/static:nonroot

LABEL name="Edge Scheduler"

COPY edge-scheduler /usr/local/bin/

CMD ["edge-scheduler"]
41 changes: 41 additions & 0 deletions pkg/edge-scheduler/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
BUILD_SETTINGS = CGO_ENABLED=0 GOOS=linux GOARCH=amd64
IMAGE = edge-scheduler
IMAGE_VERSION = $(shell git tag --points-at HEAD | sed '/$(IMAGE)\/.*/!s/.*//' | sed 's/\//:/')
REPO = systemautoscaler


.PHONY: all build coverage clean e2e fmt release test vet

all: build test coverage clean

build: fmt vet test
$(BUILD_SETTINGS) go build -trimpath -o "$(IMAGE)" ./main.go

fmt:
@go fmt ./...

test:
@go test -race $(shell go list ./... | grep -v e2e) --coverprofile=coverage.out

e2e:
@go test -race $(shell go list ./... | grep e2e)

coverage: test
@go tool cover -func=coverage.out

release:
@if [ -n "$(IMAGE_VERSION)" ]; then \
echo "Building $(IMAGE_VERSION)" ;\
docker build -t $(REPO)/$(IMAGE_VERSION) . ;\
docker push $(REPO)/$(IMAGE_VERSION) ;\
else \
echo "$(IMAGE) unchanged: no version tag on HEAD commit" ;\
fi

vet:
@go vet ./...

clean:
@rm -rf ./$(IMAGE)
@go clean -cache
@rm -rf *.out
1 change: 1 addition & 0 deletions pkg/edge-scheduler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Edge Scheduler
5 changes: 5 additions & 0 deletions pkg/edge-scheduler/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {
println("Hello World!")
}
8 changes: 8 additions & 0 deletions pkg/edge-scheduler/pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package scheduler

type Scheduler struct {
}

func NewScheduler() *Scheduler {
return &Scheduler{}
}
5 changes: 5 additions & 0 deletions pkg/sys-controller/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/testdata
.dockerignore
Dockerfile
README.md
*.out
Loading

0 comments on commit 4856ace

Please sign in to comment.