Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deployment #36

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4fa569e
Add deployment
paurosello Jan 26, 2021
f2cef41
Update chart docs
paurosello Jan 26, 2021
e57bfad
Add reporter to e2e
paurosello Jan 26, 2021
9b90837
fix tests
paurosello Jan 26, 2021
b282bbb
Fix image pull policy
paurosello Jan 26, 2021
346e8b1
Test increase wait
paurosello Jan 26, 2021
734e27e
FIX: missing pykube dependency
angelbarrera92 Feb 4, 2021
a2df3cc
Update every component to python3.9
angelbarrera92 Feb 4, 2021
491c7a3
Merge branch 'k8spin_reporter' into deployment
angelbarrera92 Feb 4, 2021
8d3acca
merge
paurosello Feb 4, 2021
fe4bfb6
init html
paurosello Feb 4, 2021
5d13e96
revert schema
paurosello Feb 4, 2021
91daa29
queries
paurosello Feb 4, 2021
c1d1b00
Add tenant and org ids to the space_usage table
angelbarrera92 Feb 6, 2021
65c7117
add some organization related endpoints
angelbarrera92 Feb 6, 2021
005e4bd
Add debug page that uses bulma and fontawesome
angelbarrera92 Feb 6, 2021
b0cbacd
Add usage/allocated queries
angelbarrera92 Feb 7, 2021
0387154
Add first graph to debug.html page
angelbarrera92 Feb 7, 2021
9c9c54b
Add queries.sql file with example queries
angelbarrera92 Feb 7, 2021
040e54e
FIX: Makefile format
angelbarrera92 Feb 16, 2021
a42a07a
Add k8spin_reporter skeleton
angelbarrera92 Jan 19, 2021
af6e3b6
Add linting command while fixing some rules
angelbarrera92 Jan 19, 2021
bcd2f23
Add resources to organization and tenants
angelbarrera92 Jan 23, 2021
ee57f08
Refactor: move memory and cpu converter to the common module
angelbarrera92 Jan 23, 2021
de69475
Add feed database plus example of querying the DB via API
angelbarrera92 Jan 23, 2021
043e2c0
Add deployment
paurosello Jan 26, 2021
bca836a
Update chart docs
paurosello Jan 26, 2021
93e8faf
Add reporter to e2e
paurosello Jan 26, 2021
abec9c4
fix tests
paurosello Jan 26, 2021
4277678
Fix image pull policy
paurosello Jan 26, 2021
73be357
Test increase wait
paurosello Jan 26, 2021
70dc3dd
FIX: missing pykube dependency
angelbarrera92 Feb 4, 2021
5c40c06
Update every component to python3.9
angelbarrera92 Feb 4, 2021
f5c677d
Change sql connectivity to use sqlalchemy
angelbarrera92 Jan 26, 2021
2ce5a5a
merge
paurosello Feb 4, 2021
5aa803f
init html
paurosello Feb 4, 2021
0ec53da
revert schema
paurosello Feb 4, 2021
b7041ec
queries
paurosello Feb 4, 2021
0ba69a6
Add tenant and org ids to the space_usage table
angelbarrera92 Feb 6, 2021
00165eb
add some organization related endpoints
angelbarrera92 Feb 6, 2021
77047ef
Add debug page that uses bulma and fontawesome
angelbarrera92 Feb 6, 2021
d519aa8
Add usage/allocated queries
angelbarrera92 Feb 7, 2021
bbb1ca9
Add first graph to debug.html page
angelbarrera92 Feb 7, 2021
dbe91b1
Add queries.sql file with example queries
angelbarrera92 Feb 7, 2021
bbfdbf6
Merge branch 'deployment' of github.com:k8spin/k8spin-operator into d…
angelbarrera92 Feb 19, 2021
e25e6a5
Split the history chart in two
angelbarrera92 Feb 19, 2021
150b2e6
Add dummy data generator
angelbarrera92 Mar 5, 2021
2936a5d
Start adding tenant information
angelbarrera92 Mar 5, 2021
694c187
Add spaces info
angelbarrera92 Mar 7, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.venv-operator
.venv-validator
.venv-test
.venv-chart-docs
.venv
.kube
.pytest_cache
Expand Down
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ cluster-down:
build:
@docker build -t $(REGISTRY)/k8spin/k8spin-operator:latest -t $(REGISTRY)/k8spin/k8spin-operator:$(TAG_VERSION) . -f build/operator.Dockerfile
@docker build -t $(REGISTRY)/k8spin/k8spin-webhook:latest -t $(REGISTRY)/k8spin/k8spin-webhook:$(TAG_VERSION) . -f build/webhook.Dockerfile
@docker build -t $(REGISTRY)/k8spin/k8spin-reporter:latest -t $(REGISTRY)/k8spin/k8spin-reporter:$(TAG_VERSION) . -f build/reporter.Dockerfile

## build: Local build the operator using buildx and multiple platforms
## platforms defined in https://github.com/containerd/containerd/blob/v1.2.6/platforms/platforms.go#L63
## docker > 19.03 required
## build: Local build the operator using buildx and multiple platforms platforms defined in github.com/containerd/containerd/blob/v1.2.6/platforms/platforms.go#L63 docker 19.03 required
buildx:
@DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 -t $(REGISTRY)/k8spin/k8spin-operator:latest -t $(REGISTRY)/k8spin/k8spin-operator:$(TAG_VERSION) . -f build/operator.Dockerfile
@DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 -t $(REGISTRY)/k8spin/k8spin-webhook:latest -t $(REGISTRY)/k8spin/k8spin-webhook:$(TAG_VERSION) . -f build/webhook.Dockerfile
@DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 -t $(REGISTRY)/k8spin/k8spin-reporter:latest -t $(REGISTRY)/k8spin/k8spin-reporter:$(TAG_VERSION) . -f build/reporter.Dockerfile

## deploy: Deploys the complete solution
deploy: load
Expand All @@ -49,10 +49,9 @@ update: load
@kubectl --context kind-$(KIND_CLUSTER_NAME) delete -f ./deployments/kubernetes/ --wait=true -n default
@kubectl --context kind-$(KIND_CLUSTER_NAME) apply -f ./deployments/kubernetes/ -n default

## test-e2e: End-to-End tests. Use `PYTEST_ADDOPTS=--keep-cluster make test-e2e` to keep cluster
## --workers auto could be added when we want multiple workers installing the package pytest-parallel
## test-e2e: End-to-End tests. Use `PYTEST_ADDOPTS=--keep-cluster make test-e2e` to keep cluster --workers auto could be added when we want multiple workers installing the package pytest-parallel
test-e2e: build
@virtualenv -p python3.8 .venv-test
@virtualenv -p python3.9 .venv-test
source .venv-test/bin/activate; \
pip install -r test/requirements.txt; \
pip install -e k8spin_common; \
Expand All @@ -64,11 +63,12 @@ test-e2e: build
test/e2e;

test-kubeconfig:
@export KUBECONFIG=.pytest-kind/k8spin-operator/kind-config-k8spin-operator
@export KUBECONFIG=.pytest-kind/k8spin-operator/kubeconfig

load: cluster-up build
@kind load docker-image --name $(KIND_CLUSTER_NAME) $(REGISTRY)/k8spin/k8spin-operator:latest
@kind load docker-image --name $(KIND_CLUSTER_NAME) $(REGISTRY)/k8spin/k8spin-webhook:latest
@kind load docker-image --name $(KIND_CLUSTER_NAME) $(REGISTRY)/k8spin/k8spin-reporter:latest

## kubie: Sets the kind cluster context
kubie:
Expand All @@ -77,13 +77,16 @@ kubie:
publish_container_image:
@docker tag $(REGISTRY)/k8spin/k8spin-operator:latest $(REGISTRY)/k8spin/k8spin-operator:$(TAG_VERSION)
@docker tag $(REGISTRY)/k8spin/k8spin-webhook:latest $(REGISTRY)/k8spin/k8spin-webhook:$(TAG_VERSION)
@docker tag $(REGISTRY)/k8spin/k8spin-reporter:latest $(REGISTRY)/k8spin/k8spin-reporter:$(TAG_VERSION)
@docker push $(REGISTRY)/k8spin/k8spin-operator:$(TAG_VERSION)
@docker push $(REGISTRY)/k8spin/k8spin-webhook:$(TAG_VERSION)
@docker push $(REGISTRY)/k8spin/k8spin-reporter:$(TAG_VERSION)


publish_container_image_multiarch:
@DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 -t $(REGISTRY)/k8spin/k8spin-operator:$(TAG_VERSION) . -f build/operator.Dockerfile --push
@DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 -t $(REGISTRY)/k8spin/k8spin-webhook:$(TAG_VERSION) . -f build/webhook.Dockerfile --push
@DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 -t $(REGISTRY)/k8spin/k8spin-reporter:$(TAG_VERSION) . -f build/reporter.Dockerfile --push

## clean: Remove cached files
clean:
Expand All @@ -105,7 +108,7 @@ lint:

## helm_chart_docs: Creates the Helm Chart Docs
helm_chart_docs:
@virtualenv -p python3.8 .venv-chart-docs
@virtualenv -p python3.9 .venv-chart-docs
source .venv-chart-docs/bin/activate; \
pip install frigate; \
frigate gen deployments/helm/k8spin-operator > deployments/helm/k8spin-operator/README.md;
Expand Down
12 changes: 12 additions & 0 deletions build/reporter.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.9

COPY k8spin_reporter/requirements.txt /src/requirements.txt
RUN pip install -r /src/requirements.txt

COPY k8spin_common /src/k8spin_common
RUN pip install -e /src/k8spin_common

COPY k8spin_reporter /app/k8spin_reporter

ENTRYPOINT [ "python" ]
CMD ["/app/k8spin_reporter/app.py"]
6 changes: 6 additions & 0 deletions deployments/helm/k8spin-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ The following table lists the configurable parameters of the K8spin-operator cha
| `k8spin_webhook.logging_level` | K8spin-webhook logging level | `"DEBUG"` |
| `k8spin_webhook.serviceAccount.create` | Create the k8spin-webhook service account | `true` |
| `k8spin_webhook.serviceAccount.name` | The k8spin-webhook service account name | `null` |
| `k8spin_reporter.image.name` | K8spin-reporter image name | `"ghcr.io/k8spin/k8spin-reporter"` |
| `k8spin_reporter.image.tag` | K8spin-reporter image tag | `"v1.0.6"` |
| `k8spin_reporter.image.pullPolicy` | K8spin-reporter image pull policy | `"IfNotPresent"` |
| `k8spin_reporter.logging_level` | K8spin-reporter logging level | `"DEBUG"` |
| `k8spin_reporter.serviceAccount.create` | Create the k8spin-reporter service account | `true` |
| `k8spin_reporter.serviceAccount.name` | The k8spin-reporter service account name | `null` |
| `rbac.create` | Deploys default roles | `true` |


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: k8spin-reporter
labels:
app.kubernetes.io/name: {{ template "k8spin-reporter.name" . }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: {{ (include "reporter.serviceAccountName" .) }}
namespace: {{ .Release.Namespace }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: k8spin-reporter
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: {{ template "k8spin-reporter.name" . }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
application: k8spin-reporter
template:
metadata:
labels:
application: k8spin-reporter
app.kubernetes.io/name: {{ template "k8spin-reporter.name" . }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
serviceAccountName: {{ (include "reporter.serviceAccountName" .) }}
containers:
- name: k8spin-reporter
image: "{{ .Values.k8spin_reporter.image.name }}:{{ .Values.k8spin_reporter.image.tag }}"
imagePullPolicy: {{ .Values.k8spin_reporter.image.pullPolicy }}
env:
- name: LOGGING_LEVEL
value: "{{ .Values.k8spin_reporter.logging_level }}"
- name: RECONCILIATION_INTERVAL_SECONDS
value: "{{ .Values.k8spin_reporter.reconciliation_interval_seconds }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.k8spin_reporter.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ (include "k8spin_reporter.serviceAccountName" .) }}
namespace: {{ .Release.Namespace }}
labels:
app.kubernetes.io/name: {{ template "k8spin-reporter.name" . }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
10 changes: 10 additions & 0 deletions deployments/helm/k8spin-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,15 @@ k8spin_webhook:
create: true # Create the k8spin-webhook service account
name: # The k8spin-webhook service account name

k8spin_reporter:
image:
name: ghcr.io/k8spin/k8spin-reporter # k8spin-reporter image name
tag: v1.0.6 # k8spin-reporter image tag
pullPolicy: IfNotPresent # k8spin-reporter image pull policy
logging_level: DEBUG # k8spin-reporter logging level
serviceAccount:
create: true # Create the k8spin-reporter service account
name: # The k8spin-reporter service account name

rbac:
create: true # Deploys default roles
1 change: 1 addition & 0 deletions deployments/kubernetes/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
containers:
- name: k8spin-operator
image: ghcr.io/k8spin/k8spin-operator:latest
imagePullPolicy: IfNotPresent
env:
- name: LOGGING_LEVEL
value: DEBUG
Expand Down
47 changes: 47 additions & 0 deletions deployments/kubernetes/reporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: k8spin-reporter
namespace: default
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
application: k8spin-reporter
template:
metadata:
labels:
application: k8spin-reporter
spec:
serviceAccountName: k8spin-reporter
containers:
- name: k8spin-reporter
image: ghcr.io/k8spin/k8spin-reporter:latest
imagePullPolicy: IfNotPresent
env:
- name: LOGGING_LEVEL
value: DEBUG
- name: RECONCILIATION_INTERVAL_SECONDS
value: "15"
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: k8spin-reporter
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: k8spin-reporter
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: k8spin-reporter
namespace: default
1 change: 1 addition & 0 deletions deployments/kubernetes/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spec:
containers:
- name: k8spin-webhook
image: ghcr.io/k8spin/k8spin-webhook:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 443
env:
Expand Down
2 changes: 1 addition & 1 deletion k8spin_common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ help: Makefile

## install: Install the project
install:
@virtualenv -p python3.8 .venv
@virtualenv -p python3.9 .venv
source .venv/bin/activate; \
pip install -r requirements-dev.txt; \

Expand Down
2 changes: 1 addition & 1 deletion k8spin_operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ help: Makefile

## install: Install the project
install:
@virtualenv -p python3.8 .venv
@virtualenv -p python3.9 .venv
source .venv/bin/activate; \
pip install -r requirements-dev.txt; \
pip install -e ../k8spin_common; \
Expand Down
3 changes: 2 additions & 1 deletion k8spin_reporter/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
k8spin.db
k8spin.db
dataset.sql
10 changes: 7 additions & 3 deletions k8spin_reporter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ lint: install
pylint app.py k8spin_reporter; \

## run: Run it locally
run: install kubeconfig resetdb
run: install kubeconfig
source .venv/bin/activate; \
KUBECONFIG=$(shell pwd)/kubeconfig python app.py

## kubeconfig: Gather k8spin-operator kubeconfig (kind). Requires to run make deploy in the root project
kubeconfig:
@kind get kubeconfig --name k8spin-operator > kubeconfig

## resetdb: Reset the database
## resetdb: Reset the database. Takes some time
resetdb:
@rm -f k8spin.db && sqlite3 k8spin.db < schema.sql
@virtualenv -p python3.9 .venv
source .venv/bin/activate; \
pip install -r requirements-dev.txt; \
python gen.py > dataset.sql
@rm -f k8spin.db && sqlite3 k8spin.db < schema.sql && sqlite3 k8spin.db < dataset.sql
Loading