Parameterization of NodeSelector

This commit is contained in:
2024-02-18 02:46:26 -03:00
parent bd642fa8cc
commit 039167afc7
10 changed files with 141 additions and 120 deletions

21
.gitignore vendored
View File

@@ -1,17 +1,18 @@
.env*
.secret*
.idea/ .idea/
.vscode/ .vscode/
.env*
.secret*
**/*.json **/*.json
!**/*.example.json !**/*.example.json
*.patch
**/cert-manager-certificate.yaml **/cert-manager-certificate.yaml
**/nginx-ingress-api.yaml
**/deployment/nginx-ingress/nginx-ingress-api.yaml **/nginx-ingress-root.yaml
**/backend.yaml
**/deployment/nginx-ingress/nginx-ingress-root.yaml **/frontend.yaml
*.patch **/storage.yaml
**/storage-processor.yaml
**/cn-cluster.yaml

View File

@@ -95,9 +95,7 @@ function application_deploy() {
-n portfolio -n portfolio
kubectl apply -f \ kubectl apply -f \
./deployment/nginx-ingress/nginx-ingress-root.yaml ./deployment/nginx-ingress
kubectl apply -f \
./deployment/nginx-ingress/nginx-ingress-api.yaml
} }

View File

@@ -1,93 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: portfolio
name: storage-processor-deployment
spec:
replicas: 1
selector:
matchLabels:
app: storage-processor
template:
metadata:
labels:
app: storage-processor
spec:
nodeSelector:
node_type: worker
containers:
- name: storage-processor
image: yoshiunfriendly/storage-hideyoshi.com:latest
command: ["./run-queue.sh"]
args: ["-q"]
imagePullPolicy: "Always"
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
env:
- name: REDIS_BASE_URL
valueFrom:
configMapKeyRef:
name: redis-config
key: redis-url
- name: REDIS_PORT
valueFrom:
configMapKeyRef:
name: redis-config
key: redis-port
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-secret
key: redisPassword
- name: REDIS_URL
value: "redis://:$(REDIS_PASSWORD)@$(REDIS_BASE_URL):$(REDIS_PORT)/rq"
- name: STORAGE_TYPE
valueFrom:
secretKeyRef:
name: storage-secret
key: storageType
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: storage-secret
key: awsAccessKeyId
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: storage-secret
key: awsSecretAccessKey
- name: AWS_REGION_NAME
valueFrom:
secretKeyRef:
name: storage-secret
key: awsRegion
- name: AWS_BUCKET_NAME
valueFrom:
secretKeyRef:
name: storage-secret
key: awsBucket
- name: VIRUS_CHECKER_TYPE
valueFrom:
secretKeyRef:
name: storage-secret
key: virusCheckerType
- name: VIRUS_CHECKER_API_KEY
valueFrom:
secretKeyRef:
name: storage-secret
key: virusCheckerApiKey

View File

@@ -2,19 +2,25 @@ from base64 import b64decode, b64encode
from dotenv import load_dotenv from dotenv import load_dotenv
from envsubst import envsubst from envsubst import envsubst
from pathlib import Path, PosixPath from pathlib import Path, PosixPath
from typing import Generator
import argparse import argparse
import warnings import warnings
import json import json
import os import os
def unpack_list_dict(dl: list[dict]) -> Generator[tuple[str, str], None, None]:
for d in dl:
yield tuple(d.values())
def write_template(template: str, output: str): def write_template(template: str, output: str):
with open(template, 'r') as template,\ with open(template, 'r') as template,\
open(output, 'w') as output: open(output, 'w') as output:
output.write(envsubst(template.read())) output.write(envsubst(template.read()))
def configure_templates(environment: str): def configure_env_variables(environment: str):
if not environment in ("prod", "staging", "local"): if not environment in ("prod", "staging", "local"):
raise ValueError("Invalid Environment Selected") raise ValueError("Invalid Environment Selected")
@@ -22,25 +28,40 @@ def configure_templates(environment: str):
case "local": case "local":
DOMAIN = "local.hideyoshi.com.br" DOMAIN = "local.hideyoshi.com.br"
API_DOMAIN = "api.local.hideyoshi.com.br" API_DOMAIN = "api.local.hideyoshi.com.br"
MASTER_NODE_LABEL = "minikube.k8s.io/name: minikube"
WORKER_NODE_LABEL = "minikube.k8s.io/name: minikube"
case "staging": case "staging":
DOMAIN = "staging.hideyoshi.com.br" DOMAIN = "staging.hideyoshi.com.br"
API_DOMAIN = "api.staging.hideyoshi.com.br" API_DOMAIN = "api.staging.hideyoshi.com.br"
MASTER_NODE_LABEL = "node_type: master"
WORKER_NODE_LABEL = "node_type: worker"
case _: case _:
DOMAIN = "hideyoshi.com.br" DOMAIN = "hideyoshi.com.br"
API_DOMAIN = "api.hideyoshi.com.br" API_DOMAIN = "api.hideyoshi.com.br"
MASTER_NODE_LABEL = "node_type: master"
WORKER_NODE_LABEL = "node_type: worker"
os.environ["DOMAIN"] = DOMAIN os.environ["DOMAIN"] = DOMAIN
os.environ["API_DOMAIN"] = API_DOMAIN os.environ["API_DOMAIN"] = API_DOMAIN
os.environ["MASTER_NODE_LABEL"] = MASTER_NODE_LABEL
os.environ["WORKER_NODE_LABEL"] = WORKER_NODE_LABEL
write_template(
"template/cert-manager/cert-manager-certificate.template.yaml",
"deployment/cert-manager/cert-manager-certificate.yaml"
)
write_template( def configure_templates(environment: str):
"template/nginx-ingress/nginx-ingress-root.yaml", MAPPINS = [
"deployment/nginx-ingress/nginx-ingress-root.yaml" {"template": "template/cert-manager/cert-manager-certificate.template.yaml", "output": "deployment/cert-manager/cert-manager-certificate.yaml"},
) {"template": "template/nginx-ingress/nginx-ingress-root.template.yaml", "output": "deployment/nginx-ingress/nginx-ingress-root.yaml"},
{"template": "template/postgres/cn-cluster.template.yaml", "output": "deployment/postgres/cn-cluster.yaml"},
{"template": "template/frontend/frontend.template.yaml", "output": "deployment/frontend/frontend.yaml"},
{"template": "template/backend/backend.template.yaml", "output": "deployment/backend/backend.yaml"},
{"template": "template/storage/storage-processor.template.yaml", "output": "deployment/storage/storage-processor.yaml"},
{"template": "template/storage/storage.template.yaml", "output": "deployment/storage/storage.yaml"},
]
for template, output in unpack_list_dict(MAPPINS):
write_template(template, output)
def validate_backend_secret(secret: str): def validate_backend_secret(secret: str):
@@ -167,6 +188,8 @@ def main(file, environment):
write_secrets_to_file(env) write_secrets_to_file(env)
configure_env_variables(environment)
configure_templates(environment) configure_templates(environment)

View File

@@ -14,7 +14,7 @@ spec:
app: backend app: backend
spec: spec:
nodeSelector: nodeSelector:
node_type: worker ${WORKER_NODE_LABEL}
containers: containers:
- name: backend - name: backend
image: yoshiunfriendly/backend-hideyoshi.com image: yoshiunfriendly/backend-hideyoshi.com

View File

@@ -15,8 +15,7 @@ spec:
labels: labels:
app: frontend app: frontend
spec: spec:
nodeSelector: nodeSelector: ${WORKER_NODE_LABEL}
node_type: worker
containers: containers:
- name: frontend - name: frontend
image: yoshiunfriendly/frontend-hideyoshi.com:latest image: yoshiunfriendly/frontend-hideyoshi.com:latest

View File

@@ -21,7 +21,7 @@ spec:
affinity: affinity:
nodeSelector: nodeSelector:
node_type: master ${MASTER_NODE_LABEL}
monitoring: monitoring:
enablePodMonitor: true enablePodMonitor: true

View File

@@ -0,0 +1,93 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: portfolio
name: storage-processor-deployment
spec:
replicas: 1
selector:
matchLabels:
app: storage-processor
template:
metadata:
labels:
app: storage-processor
spec:
nodeSelector:
${WORKER_NODE_LABEL}
containers:
- name: storage-processor
image: yoshiunfriendly/storage-hideyoshi.com:latest
command: ["./run-queue.sh"]
args: ["-q"]
imagePullPolicy: "Always"
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
env:
- name: REDIS_BASE_URL
valueFrom:
configMapKeyRef:
name: redis-config
key: redis-url
- name: REDIS_PORT
valueFrom:
configMapKeyRef:
name: redis-config
key: redis-port
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: redis-secret
key: redisPassword
- name: REDIS_URL
value: "redis://:$(REDIS_PASSWORD)@$(REDIS_BASE_URL):$(REDIS_PORT)/rq"
- name: STORAGE_TYPE
valueFrom:
secretKeyRef:
name: storage-secret
key: storageType
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: storage-secret
key: awsAccessKeyId
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: storage-secret
key: awsSecretAccessKey
- name: AWS_REGION_NAME
valueFrom:
secretKeyRef:
name: storage-secret
key: awsRegion
- name: AWS_BUCKET_NAME
valueFrom:
secretKeyRef:
name: storage-secret
key: awsBucket
- name: VIRUS_CHECKER_TYPE
valueFrom:
secretKeyRef:
name: storage-secret
key: virusCheckerType
- name: VIRUS_CHECKER_API_KEY
valueFrom:
secretKeyRef:
name: storage-secret
key: virusCheckerApiKey

View File

@@ -14,7 +14,7 @@ spec:
app: storage app: storage
spec: spec:
nodeSelector: nodeSelector:
node_type: worker ${WORKER_NODE_LABEL}
containers: containers:
- name: storage - name: storage
image: yoshiunfriendly/storage-hideyoshi.com:latest image: yoshiunfriendly/storage-hideyoshi.com:latest