Skip to content
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
10 changes: 9 additions & 1 deletion k8s/deployment/build_context
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,27 @@ IMAGE_PULL_SECRETS=$(echo "$IMAGE_PULL_SECRETS" | jq .)

TRAFFIC_CONTAINER_IMAGE=${TRAFFIC_CONTAINER_IMAGE:-"public.ecr.aws/nullplatform/k8s-traffic-manager:latest"}

# Pod Disruption Budget configuration
PDB_ENABLED=${POD_DISRUPTION_BUDGET_ENABLED:-"false"}
PDB_MAX_UNAVAILABLE=${POD_DISRUPTION_BUDGET_MAX_UNAVAILABLE:-"25%"}

CONTEXT=$(echo "$CONTEXT" | jq \
--arg blue_deployment_id "$BLUE_DEPLOYMENT_ID" \
--arg blue_replicas "$BLUE_REPLICAS" \
--arg green_replicas "$GREEN_REPLICAS" \
--arg total_replicas "$REPLICAS" \
--arg traffic_image "$TRAFFIC_CONTAINER_IMAGE" \
--argjson pull_secrets "$IMAGE_PULL_SECRETS" \
--arg pdb_enabled "$PDB_ENABLED" \
--arg pdb_max_unavailable "$PDB_MAX_UNAVAILABLE" \
'. + {blue_deployment_id: $blue_deployment_id,
blue_replicas: $blue_replicas,
green_replicas: $green_replicas,
total_replicas: $total_replicas,
pull_secrets: $pull_secrets,
traffic_image: $traffic_image
traffic_image: $traffic_image,
pdb_enabled: $pdb_enabled,
pdb_max_unavailable: $pdb_max_unavailable
}')

DEPLOYMENT_ID=$(echo "$CONTEXT" | jq -r '.deployment.id')
Expand Down
16 changes: 15 additions & 1 deletion k8s/deployment/build_deployment
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ DEPLOYMENT_PATH="$OUTPUT_DIR/deployment-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
SECRET_PATH="$OUTPUT_DIR/secret-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
SCALING_PATH="$OUTPUT_DIR/scaling-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
SERVICE_TEMPLATE_PATH="$OUTPUT_DIR/service-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
PDB_PATH="$OUTPUT_DIR/pdb-$SCOPE_ID-$DEPLOYMENT_ID.yaml"
CONTEXT_PATH="$OUTPUT_DIR/context-$SCOPE_ID.json"

echo "$CONTEXT" | jq --arg replicas "$REPLICAS" --arg service_account_name "$SERVICE_ACCOUNT_NAME" '. + {replicas: $replicas, service_account_name: $service_account_name}' > "$CONTEXT_PATH"
Expand Down Expand Up @@ -94,7 +95,20 @@ gomplate -c .="$CONTEXT_PATH" \
TEMPLATE_GENERATION_STATUS=$?

if [[ $TEMPLATE_GENERATION_STATUS -ne 0 ]]; then
echo "Error building scaling template"
echo "Error building service template"
exit 1
fi

echo "Building Template: $PDB_TEMPLATE to $PDB_PATH"

gomplate -c .="$CONTEXT_PATH" \
--file "$PDB_TEMPLATE" \
--out "$PDB_PATH"

TEMPLATE_GENERATION_STATUS=$?

if [[ $TEMPLATE_GENERATION_STATUS -ne 0 ]]; then
echo "Error building PDB template"
exit 1
fi

Expand Down
53 changes: 53 additions & 0 deletions k8s/deployment/templates/pdb.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{if eq .pdb_enabled "true"}}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: pdb-d-{{ .scope.id }}-{{ .deployment.id }}
namespace: {{ .k8s_namespace }}
labels:
name: pdb-d-{{ .scope.id }}-{{ .deployment.id }}
app.kubernetes.io/part-of: {{ .namespace.slug }}-{{ .application.slug }}
app.kubernetes.io/component: application
app.kubernetes.io/instance: {{ .scope.slug }}
app.kubernetes.io/name: {{ .scope.slug }}
{{- $global := index .k8s_modifiers "global" }}
{{- if $global }}
{{- $labels := index $global "labels" }}
{{- if $labels }}
{{ data.ToYAML $labels | indent 4 }}
{{- end }}
{{- end }}
{{- $pdb := index .k8s_modifiers "pdb" }}
{{- if $pdb }}
{{- $labels := index $pdb "labels" }}
{{- if $labels }}
{{ data.ToYAML $labels | indent 4 }}
{{- end }}
{{- end }}
annotations:
nullplatform.com/managed-by: nullplatform
nullplatform.com/account: {{ .account.slug }}
nullplatform.com/namespace: {{ .namespace.slug }}
nullplatform.com/application: {{ .application.slug }}
nullplatform.com/scope: {{ .scope.slug }}
nullplatform.com/deployment-id: "{{ .deployment.id }}"
{{- $global := index .k8s_modifiers "global" }}
{{- if $global }}
{{- $annotations := index $global "annotations" }}
{{- if $annotations }}
{{ data.ToYAML $annotations | indent 4 }}
{{- end }}
{{- end }}
{{- $pdb := index .k8s_modifiers "pdb" }}
{{- if $pdb }}
{{- $annotations := index $pdb "annotations" }}
{{- if $annotations }}
{{ data.ToYAML $annotations | indent 4 }}
{{- end }}
{{- end }}
spec:
maxUnavailable: {{ .pdb_max_unavailable }}
selector:
matchLabels:
app: d-{{ .scope.id }}-{{ .deployment.id }}
{{- end }}
4 changes: 4 additions & 0 deletions k8s/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ configuration:
SECRET_TEMPLATE: "$SERVICE_PATH/deployment/templates/secret.yaml.tpl"
SCALING_TEMPLATE: "$SERVICE_PATH/deployment/templates/scaling.yaml.tpl"
SERVICE_TEMPLATE: "$SERVICE_PATH/deployment/templates/service.yaml.tpl"
PDB_TEMPLATE: "$SERVICE_PATH/deployment/templates/pdb.yaml.tpl"
INITIAL_INGRESS_PATH: "$SERVICE_PATH/deployment/templates/initial-ingress.yaml.tpl"
BLUE_GREEN_INGRESS_PATH: "$SERVICE_PATH/deployment/templates/blue-green-ingress.yaml.tpl"
SERVICE_ACCOUNT_TEMPLATE: "$SERVICE_PATH/scope/templates/service-account.yaml.tpl"
Expand Down Expand Up @@ -53,6 +54,9 @@ configuration:
# BUCKET: bucket-name
# PREFIX: path-prefix
# DEPLOY_STRATEGY: rolling
# POD_DISRUPTION_BUDGET:
# ENABLED: false
# MAX_UNAVAILABLE: "25%" # Can be percentage or number (e.g., "2")
# K8S_MODIFIERS:
# global:
# annotations:
Expand Down