Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Add resources limits and requests to the deployment manifests #380

Merged
merged 1 commit into from
Jan 19, 2021
Merged
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ before_install:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh |
sh -s -- -b $(go env GOPATH)/bin v1.31.0

- curl -s "https://raw.githubusercontent.com/\
kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash

- ./ci/setup_clusters.sh
install: true
script:
Expand Down
25 changes: 18 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ IMAGE_TAG ?= latest
SHIPPER_IMAGE ?= $(DOCKER_REGISTRY)/bookingcom/shipper:$(IMAGE_TAG)
SHIPPER_STATE_METRICS_IMAGE ?= $(DOCKER_REGISTRY)/bookingcom/shipper-state-metrics:$(IMAGE_TAG)

# Defines the directory of the kustomizable yaml files.
# Defaults to test directory.
# When releasing shipper, this should be set to release directory.
OVERLAY_PATH ?= kubernetes/overlays/test

# Defines the namespace where you want shipper to run.
SHIPPER_NAMESPACE ?= shipper-system

Expand Down Expand Up @@ -82,7 +87,7 @@ export CGO_ENABLED := 0
# working on shipper, or via CI scripts.

KUBECTL ?= kubectl --user $(SHIPPER_MGMT_USER) --cluster $(SHIPPER_MGMT_CLUSTER) -n $(SHIPPER_NAMESPACE)
.PHONY: setup install install-shipper install-shipper-state-metrics e2e restart logs lint test vendor verify-codegen update-codegen clean
.PHONY: setup install e2e restart logs lint test vendor verify-codegen update-codegen clean

# Set up shipper clusters with `shipperctl`. This is probably the first thing
# you should do when starting to work on shipper, as most of everything else
Expand All @@ -92,11 +97,12 @@ setup: $(SHIPPER_CLUSTERS_YAML) build/shipperctl.$(GOOS)-amd64
./build/shipperctl.$(GOOS)-amd64 clusters join -f $(SHIPPER_CLUSTERS_YAML) -n $(SHIPPER_NAMESPACE) $(SETUP_FLAGS) $(JOIN_FLAGS)

# Install shipper in kubernetes, by applying all the required deployment yamls.
install: install-shipper install-shipper-state-metrics
install-shipper: build/shipper.image.$(IMAGE_TAG) build/shipper.deployment.$(IMAGE_TAG).yaml
install: build-images build-yaml install/shipper install/shipper-state-metrics

install/shipper:
$(KUBECTL) apply -f build/shipper.deployment.$(IMAGE_TAG).yaml

install-shipper-state-metrics: build/shipper-state-metrics.image.$(IMAGE_TAG) build/shipper-state-metrics.deployment.$(IMAGE_TAG).yaml
install/shipper-state-metrics:
$(KUBECTL) apply -f build/shipper-state-metrics.deployment.$(IMAGE_TAG).yaml

# Run all end-to-end tests. It does all the work necessary to get the current
Expand Down Expand Up @@ -155,7 +161,7 @@ clean:
.PHONY: build-bin build-yaml build-images build-all
SHA = $(if $(shell which sha256sum),sha256sum,shasum -a 256)
build-bin: $(foreach bin,$(BINARIES),build/$(bin).$(GOOS)-amd64)
build-yaml: build/shipper.deployment.$(IMAGE_TAG).yaml build/shipper-state-metrics.deployment.$(IMAGE_TAG).yaml
build-yaml: build/shipper.deployment.$(IMAGE_TAG).yaml build/shipper-state-metrics.deployment.$(IMAGE_TAG).yaml build/yamls
build-images: build/shipper.image.$(IMAGE_TAG) build/shipper-state-metrics.image.$(IMAGE_TAG)
build-all: $(foreach os,$(OS),build/shipperctl.$(os)-amd64.tar.gz) build/sha256sums.txt build-yaml build-images

Expand All @@ -176,8 +182,13 @@ build/e2e.test: $(PKG) test/e2e/*

IMAGE_NAME_WITH_SHA256 = $(shell cat build/$*.image.$(IMAGE_TAG))
IMAGE_NAME_TO_USE = $(if $(USE_IMAGE_NAME_WITH_SHA256),$(IMAGE_NAME_WITH_SHA256),$(IMAGE_NAME_WITH_TAG))
build/%.deployment.$(IMAGE_TAG).yaml: kubernetes/%.deployment.yaml build/%.image.$(IMAGE_TAG) build
sed s=IMAGE=$(IMAGE_NAME_TO_USE)= $< > $@
build/%.deployment.$(IMAGE_TAG).yaml: kubernetes/base/%.deployment.yaml build/%.image.$(IMAGE_TAG) build
sed --in-place='.bkup' -e 's=IMAGE=$(IMAGE_NAME_TO_USE)=' $<

build/yamls:
kustomize build $(OVERLAY_PATH) -o build
mv build/apps_v1_deployment_shipper.yaml build/shipper.deployment.$(IMAGE_TAG).yaml
mv build/apps_v1_deployment_shipper-state-metrics.yaml build/shipper-state-metrics.deployment.$(IMAGE_TAG).yaml

build/sha256sums.txt: $(foreach os,$(OS),build/shipperctl.$(os)-amd64.tar.gz)
$(SHA) build/*.tar.gz > $@
Expand Down
6 changes: 4 additions & 2 deletions ci/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash -x
#!/bin/bash

set -ex

kubectl config use-context kind-mgmt

# Setup shipper's clusters
SETUP_MGMT_FLAGS="--webhook-ignore" make setup

# Run the e2e tests, save exit code for later
make -j e2e \
OVERLAY_PATH=kubernetes/overlays/test make -j e2e \
TEST_HELM_REPO_URL=${TEST_HELM_REPO_URL:=https://raw.githubusercontent.com/bookingcom/shipper/${GITHUB_SHA}/test/e2e/testdata} \
DOCKER_REGISTRY=${DOCKER_REGISTRY:=localhost:5000} \
E2E_FLAGS="--test.v --buildAppClientFromKubeConfig"
Expand Down
2 changes: 1 addition & 1 deletion ci/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fi

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

USE_IMAGE_NAME_WITH_SHA256= IMAGE_TAG=$TRAVIS_TAG make build-all
OVERLAY_PATH=kubernetes/overlays/release USE_IMAGE_NAME_WITH_SHA256= IMAGE_TAG=$TRAVIS_TAG make build-all

docker logout

Expand Down
6 changes: 6 additions & 0 deletions kubernetes/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resources:
- shipper.deployment.yaml
- shipper-state-metrics.deployment.yaml
images:
- name: SHIPPER_IMAGE
- name: SHIPPER_STATE_METRICS_IMAGE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ spec:
args:
- "-v"
- "2"
resources:
limits:
cpu: "4"
memory: 3Gi
requests:
cpu: "1"
memory: 1Gi
ports:
- name: metrics
containerPort: 8890
Expand Down
58 changes: 58 additions & 0 deletions kubernetes/base/shipper.deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: shipper
namespace: shipper-system
labels:
app: shipper
spec:
selector:
matchLabels:
app: shipper
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: shipper
annotations:
prometheus.io/scrape_port: '8889'
spec:
containers:
- name: shipper
image: IMAGE
imagePullPolicy: IfNotPresent
args:
- "-webhook-cert"
- "/etc/webhook/certs/tls.crt"
- "-webhook-key"
- "/etc/webhook/certs/tls.key"
- "-webhook-port"
- "9443"
- "-v"
- "4"
- "-logtostderr"
resources:
limits:
cpu: "4"
memory: 50Gi
requests:
cpu: "1"
memory: 10Gi
ports:
- name: metrics
containerPort: 8889
- name: webhook
containerPort: 9443
volumeMounts:
- mountPath: /etc/webhook/certs
name: webhook-certs
readOnly: true
serviceAccountName: shipper-mgmt-cluster
volumes:
- name: webhook-certs
secret:
secretName: shipper-validating-webhook
2 changes: 2 additions & 0 deletions kubernetes/overlays/release/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- ../../base
17 changes: 17 additions & 0 deletions kubernetes/overlays/test/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resources:
- ../../base
# In test environment we need to removes assignment of resources for shipper pods
# to allow scheduling of the pods
patches:
- patch: |-
- op: remove
path: /spec/template/spec/containers/0/resources
target:
kind: Deployment
labelSelector: app=shipper
- patch: |-
- op: remove
path: /spec/template/spec/containers/0/resources
target:
kind: Deployment
labelSelector: app=shipper-state-metrics
51 changes: 0 additions & 51 deletions kubernetes/shipper.deployment.yaml

This file was deleted.