Merge pull request #88 from HideyoshiNakazone/node-selector-via-parameter

Parameterization of NodeSelector
This commit is contained in:
2024-02-18 12:13:15 -03:00
committed by GitHub
10 changed files with 141 additions and 120 deletions

21
.gitignore vendored
View File

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

View File

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

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 envsubst import envsubst
from pathlib import Path, PosixPath
from typing import Generator
import argparse
import warnings
import json
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):
with open(template, 'r') as template,\
open(output, 'w') as output:
output.write(envsubst(template.read()))
def configure_templates(environment: str):
def configure_env_variables(environment: str):
if not environment in ("prod", "staging", "local"):
raise ValueError("Invalid Environment Selected")
@@ -22,25 +28,40 @@ def configure_templates(environment: str):
case "local":
DOMAIN = "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":
DOMAIN = "staging.hideyoshi.com.br"
API_DOMAIN = "api.staging.hideyoshi.com.br"
MASTER_NODE_LABEL = "node_type: master"
WORKER_NODE_LABEL = "node_type: worker"
case _:
DOMAIN = "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["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(
"template/nginx-ingress/nginx-ingress-root.yaml",
"deployment/nginx-ingress/nginx-ingress-root.yaml"
)
def configure_templates(environment: str):
MAPPINS = [
{"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):
@@ -167,6 +188,8 @@ def main(file, environment):
write_secrets_to_file(env)
configure_env_variables(environment)
configure_templates(environment)

View File

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

View File

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

View File

@@ -21,7 +21,7 @@ spec:
affinity:
nodeSelector:
node_type: master
${MASTER_NODE_LABEL}
monitoring:
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
spec:
nodeSelector:
node_type: worker
${WORKER_NODE_LABEL}
containers:
- name: storage
image: yoshiunfriendly/storage-hideyoshi.com:latest