Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

[wip] Introducing SchedulerExtended #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions k8s-scheduler/.github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Master

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: '0'
- name: Bump version and push tag
id: bump-version
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
- name: Push Docker Image to Github Registry
uses: whoan/docker-build-with-cache-action@v5
with:
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"
image_name: ${{ secrets.package_name }}
image_tag: latest,${{ github.sha }},${{ steps.bump-version.outputs.tag }}
push_git_tag: true
registry: docker.pkg.github.com
build_extra_args: "--compress=true"
19 changes: 19 additions & 0 deletions k8s-scheduler/.github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Pull Request

on:
pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Push Docker Image to Github Registry
uses: whoan/docker-build-with-cache-action@v5
with:
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"
image_name: ${{ secrets.package_name }}
image_tag: ${{ github.sha }}
push_git_tag: true
registry: docker.pkg.github.com
30 changes: 30 additions & 0 deletions k8s-scheduler/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

run:
skip-dirs:
- pkg/client

linters:
disable-all: true
enable:
- deadcode
- errcheck
- gas
- goconst
- goimports
- golint
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
32 changes: 32 additions & 0 deletions k8s-scheduler/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

FROM golang:1.13.3-alpine3.10 as builder
RUN apk add git openssh-client make curl

# COPY only the go mod files for efficient caching
COPY go.mod go.sum /go/src/github.com/lyft/flytepropeller/
WORKDIR /go/src/github.com/lyft/flytepropeller

# Pull dependencies
RUN go mod download

# COPY the rest of the source code
COPY . /go/src/github.com/lyft/flytepropeller/

# This 'linux_compile' target should compile binaries to the /artifacts directory
# The main entrypoint should be compiled to /artifacts/flytepropeller
RUN make linux_compile

# update the PATH to include the /artifacts directory
ENV PATH="/artifacts:${PATH}"

# This will eventually move to centurylink/ca-certs:latest for minimum possible image size
FROM alpine:3.10
COPY --from=builder /artifacts /bin

RUN apk --update add ca-certificates

CMD ["flytepropeller"]
34 changes: 34 additions & 0 deletions k8s-scheduler/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export REPOSITORY=flytepropeller
include ../boilerplate/lyft/docker_build/Makefile
include ../boilerplate/lyft/golang_test_targets/Makefile
include ../boilerplate/lyft/end2end/Makefile

.PHONY: update_boilerplate
update_boilerplate:
@boilerplate/update.sh

.PHONY: linux_compile
linux_compile:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /artifacts/k8s-scheduler ./cmd/k8sschedulerextender/main.go

.PHONY: compile
compile:
mkdir -p ./bin
go build -o bin/k8s-scheduler ./cmd/k8sschedulerextender/main.go

cross_compile:
@glide install
@mkdir -p ./bin/cross
GOOS=linux GOARCH=amd64 go build -o bin/cross/k8s-scheduler ./cmd/controller/main.go

op_code_generate:
@RESOURCE_NAME=resourceRequest OPERATOR_PKG=github.com/lyft/flytepropeller/k8s-scheduler/pkg GENERATORS=deepcopy,client ./hack/update-codegen.sh

# server starts the service in development mode
.PHONY: server
server:
@go run ./cmd/controller/main.go --alsologtostderr --propeller.kube-config=$(HOME)/.kube/config

.PHONY: generate
generate: download_tooling
@go generate ./...
12 changes: 12 additions & 0 deletions k8s-scheduler/boilerplate/lyft/docker_build/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

.PHONY: docker_build
docker_build:
IMAGE_NAME=$$REPOSITORY ./boilerplate/lyft/docker_build/docker_build.sh

.PHONY: dockerhub_push
dockerhub_push:
IMAGE_NAME=lyft/$$REPOSITORY REGISTRY=docker.io ./boilerplate/lyft/docker_build/docker_build.sh
23 changes: 23 additions & 0 deletions k8s-scheduler/boilerplate/lyft/docker_build/Readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Docker Build and Push
~~~~~~~~~~~~~~~~~~~~~

Provides a ``make docker_build`` target that builds your image locally.

Provides a ``make dockerhub_push`` target that pushes your final image to Dockerhub.

The Dockerhub image will tagged ``<REPOSITORY>:<GIT COMMIT SHA>``

If git head has a git tag, the Dockerhub image will also be tagged ``<IMAGE>:<GIT_TAG>``.

**To Enable:**

Add ``lyft/docker_build`` to your ``boilerplate/update.cfg`` file.

Add ``include boilerplate/lyft/docker_build/Makefile`` in your main ``Makefile`` _after_ your REPOSITORY environment variable

::

REPOSITORY=<myreponame>
include boilerplate/lyft/docker_build/Makefile

(this ensures the extra Make targets get included in your main Makefile)
67 changes: 67 additions & 0 deletions k8s-scheduler/boilerplate/lyft/docker_build/docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

set -e

echo ""
echo "------------------------------------"
echo " DOCKER BUILD"
echo "------------------------------------"
echo ""

if [ -n "$REGISTRY" ]; then
# Do not push if there are unstaged git changes
CHANGED=$(git status --porcelain)
if [ -n "$CHANGED" ]; then
echo "Please commit git changes before pushing to a registry"
exit 1
fi
fi


GIT_SHA=$(git rev-parse HEAD)

IMAGE_TAG_SUFFIX=""
# for intermediate build phases, append -$BUILD_PHASE to all image tags
if [ -n "$BUILD_PHASE" ]; then
IMAGE_TAG_SUFFIX="-${BUILD_PHASE}"
fi

IMAGE_TAG_WITH_SHA="${IMAGE_NAME}:${GIT_SHA}${IMAGE_TAG_SUFFIX}"

RELEASE_SEMVER=$(git describe --tags --exact-match "$GIT_SHA" 2>/dev/null) || true
if [ -n "$RELEASE_SEMVER" ]; then
IMAGE_TAG_WITH_SEMVER="${IMAGE_NAME}:${RELEASE_SEMVER}${IMAGE_TAG_SUFFIX}"
fi

# build the image
# passing no build phase will build the final image
docker build -t "$IMAGE_TAG_WITH_SHA" --target=${BUILD_PHASE} .
echo "${IMAGE_TAG_WITH_SHA} built locally."

# if REGISTRY specified, push the images to the remote registy
if [ -n "$REGISTRY" ]; then

if [ -n "${DOCKER_REGISTRY_PASSWORD}" ]; then
docker login --username="$DOCKER_REGISTRY_USERNAME" --password="$DOCKER_REGISTRY_PASSWORD"
fi

docker tag "$IMAGE_TAG_WITH_SHA" "${REGISTRY}/${IMAGE_TAG_WITH_SHA}"

docker push "${REGISTRY}/${IMAGE_TAG_WITH_SHA}"
echo "${REGISTRY}/${IMAGE_TAG_WITH_SHA} pushed to remote."

# If the current commit has a semver tag, also push the images with the semver tag
if [ -n "$RELEASE_SEMVER" ]; then

docker tag "$IMAGE_TAG_WITH_SHA" "${REGISTRY}/${IMAGE_TAG_WITH_SEMVER}"

docker push "${REGISTRY}/${IMAGE_TAG_WITH_SEMVER}"
echo "${REGISTRY}/${IMAGE_TAG_WITH_SEMVER} pushed to remote."

fi
fi
8 changes: 8 additions & 0 deletions k8s-scheduler/boilerplate/lyft/end2end/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

.PHONY: end2end_execute
end2end_execute:
./boilerplate/lyft/end2end/end2end.sh
28 changes: 28 additions & 0 deletions k8s-scheduler/boilerplate/lyft/end2end/end2end.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

OUT="${DIR}/tmp"
rm -rf ${OUT}
git clone https://github.com/lyft/flyte.git "${OUT}"

# TODO: load all images
echo "Loading github docker images into 'kind' cluster to workaround this issue: https://github.com/containerd/containerd/issues/3291#issuecomment-631746985"
docker login --username ${DOCKER_USERNAME} --password ${DOCKER_PASSWORD} docker.pkg.github.com
docker pull docker.pkg.github.com/${PROPELLER}
kind load docker-image docker.pkg.github.com/${PROPELLER}

pushd ${OUT}
# TODO: Only replace propeller if it's passed in
# TODO: Support replacing other images too
sed -i.bak -e "s_docker.io/lyft/flytepropeller:.*_docker.pkg.github.com/${PROPELLER}_g" ${OUT}/kustomize/base/propeller/deployment.yaml
make kustomize
make end2end_execute
popd
22 changes: 22 additions & 0 deletions k8s-scheduler/boilerplate/lyft/github_workflows/Readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Golang Github Actions
~~~~~~~~~~~~~~~~~

Provides a two github actions workflows.

**To Enable:**

Add ``lyft/github_workflows`` to your ``boilerplate/update.cfg`` file.

Add a github secret ``package_name`` with the name to use for publishing (e.g. ``flytepropeller``). Typicaly, this will be the same name as the repository.

*Note*: If you are working on a fork, include that prefix in your package name (``myfork/flytepropeller``).

The actions will push to 2 repos:

1. ``docker.pkg.github.com/lyft/<repo>/<package_name>``
2. ``docker.pkg.github.com/lyft/<repo>/<package_name>-stages`` : this repo is used to cache build stages to speed up iterative builds after.

There are two workflows that get deployed:

1. A workflow that runs on Pull Requests to build and push images to github registy tagged with the commit sha.
2. A workflow that runs on master merges that bump the patch version of release tag, builds and pushes images to github registry tagged with the version, commit sha as well as "latest"
31 changes: 31 additions & 0 deletions k8s-scheduler/boilerplate/lyft/github_workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Master

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: '0'
- name: Bump version and push tag
id: bump-version
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
- name: Push Docker Image to Github Registry
uses: whoan/docker-build-with-cache-action@v5
with:
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"
image_name: ${{ secrets.package_name }}
image_tag: latest,${{ github.sha }},${{ steps.bump-version.outputs.tag }}
push_git_tag: true
registry: docker.pkg.github.com
build_extra_args: "--compress=true"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Pull Request

on:
pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Push Docker Image to Github Registry
uses: whoan/docker-build-with-cache-action@v5
with:
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"
image_name: ${{ secrets.package_name }}
image_tag: ${{ github.sha }}
push_git_tag: true
registry: docker.pkg.github.com
16 changes: 16 additions & 0 deletions k8s-scheduler/boilerplate/lyft/github_workflows/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES.
# ONLY EDIT THIS FILE FROM WITHIN THE 'LYFT/BOILERPLATE' REPOSITORY:
#
# TO OPT OUT OF UPDATES, SEE https://github.com/lyft/boilerplate/blob/master/Readme.rst

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

mkdir -p ${DIR}/../../../.github/workflows

echo " - generating github action workflows in root directory."
sed -e "s/{{REPOSITORY}}/${REPOSITORY}/g" ${DIR}/master.yml > ${DIR}/../../../.github/workflows/master.yml
sed -e "s/{{REPOSITORY}}/${REPOSITORY}/g" ${DIR}/pull_request.yml > ${DIR}/../../../.github/workflows/pull_request.yml
Loading