Skip to content

Commit

Permalink
Merge pull request #125 from uche-madu/develop
Browse files Browse the repository at this point in the history
add prometheus monitoring
  • Loading branch information
uche-madu committed Nov 8, 2023
2 parents 6f401dd + d6c899c commit 19ec20b
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 23 deletions.
3 changes: 3 additions & 0 deletions argocd-app/applications/airflow-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ spec:
automated:
prune: true
selfHeal: true
syncOptions:
- allowEmpty=true
- CreateNamespace=true


3 changes: 3 additions & 0 deletions argocd-app/multi-app/applicationset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ spec:
automated:
prune: true
selfHeal: true
syncOptions:
- allowEmpty=true
- CreateNamespace=true
2 changes: 1 addition & 1 deletion argocd-app/my-airflow/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: my-airflow
description: An Umbrella Helm chart for Kubernetes
description: An Helm Umbrella chart for Airflow
version: 0.1.0
dependencies:
- name: airflow
Expand Down
4 changes: 2 additions & 2 deletions argocd-app/my-airflow/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ airflow:
airflow:
# To be replaced automatically by the Github Actions CICD workflow
# in the DEB Application repository
repository: 'us-central1-docker.pkg.dev/wizeline-deb/deb-capstone-airflow-gke/airflow2.7.1-custom'
tag: '3692b7f0'
repository: ~
tag: ~
# Specifying digest takes precedence over tag.
digest: ~
pullPolicy: IfNotPresent
Expand Down
16 changes: 12 additions & 4 deletions del_ns.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
#!/bin/bash

# Check if the correct number of arguments were provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <namespace>"
exit 1
fi

# Assign the first argument to a variable called 'namespace'
namespace=$1

# Fetch namespace details
# Fetch the details of the namespace and write them to a temporary file
# If the command fails, print an error message and exit
if ! kubectl get namespace "$namespace" -o json > /tmp/temp.json; then
echo "Failed to fetch namespace details."
exit 1
fi

# Modify finalizers
# Use 'jq' to set the 'finalizers' array to an empty array, indicating that we want to remove all finalizers
# Write the modified JSON to another temporary file
# If the command fails, print an error message and exit
if ! jq '.spec.finalizers=[]' /tmp/temp.json > /tmp/temp_final.json; then
echo "Failed to modify finalizers."
exit 1
fi

# Replace namespace finalize endpoint
# Use 'kubectl replace' to update the namespace with the modified JSON that has the finalizers removed
# This is done by sending a request to the namespace's finalize endpoint
# If the command fails, print an error message and exit
if ! kubectl replace --raw "/api/v1/namespaces/$namespace/finalize" -f /tmp/temp_final.json; then
echo "Failed to replace namespace finalize endpoint."
exit 1
fi

# Cleanup temporary files
# Remove the temporary files created during the process
rm -f /tmp/temp.json /tmp/temp_final.json

# Print a success message
echo "Finalizers removed successfully."
30 changes: 14 additions & 16 deletions terraform/gke.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,23 @@ resource "helm_release" "argocd" {

# GKE Workload identity
module "airflow_worker_workload_identity" {
source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
use_existing_gcp_sa = true
name = google_service_account.airflow_worker_workload_identity_sa.account_id #var.airflow-gke-workload-identity
namespace = var.airflow_namespace
project_id = var.project_id
impersonate_service_account = data.google_service_account.deb-sa.email
roles = ["roles/storage.admin", "roles/compute.admin", "roles/dataproc.editor", "roles/bigquery.admin", "roles/cloudsql.admin", "roles/iam.serviceAccountUser"]
module_depends_on = [helm_release.argocd]
source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
use_existing_gcp_sa = true
name = google_service_account.airflow_worker_workload_identity_sa.account_id #var.airflow-gke-workload-identity
namespace = var.airflow_namespace
project_id = var.project_id
roles = ["roles/storage.admin", "roles/compute.admin", "roles/dataproc.editor", "roles/bigquery.admin", "roles/cloudsql.admin", "roles/iam.serviceAccountUser"]
depends_on = [helm_release.argocd, google_service_account.airflow_worker_workload_identity_sa]
}

module "airflow_scheduler_workload_identity" {
source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
use_existing_gcp_sa = true
name = google_service_account.airflow_scheduler_workload_identity_sa.account_id #var.airflow-gke-workload-identity
namespace = var.airflow_namespace
project_id = var.project_id
impersonate_service_account = data.google_service_account.deb-sa.email
roles = ["roles/storage.admin", "roles/compute.admin", "roles/dataproc.editor", "roles/bigquery.admin", "roles/cloudsql.admin", "roles/iam.serviceAccountUser"]
module_depends_on = [helm_release.argocd]
source = "terraform-google-modules/kubernetes-engine/google//modules/workload-identity"
use_existing_gcp_sa = true
name = google_service_account.airflow_scheduler_workload_identity_sa.account_id #var.airflow-gke-workload-identity
namespace = var.airflow_namespace
project_id = var.project_id
roles = ["roles/storage.admin", "roles/compute.admin", "roles/dataproc.editor", "roles/bigquery.admin", "roles/cloudsql.admin", "roles/iam.serviceAccountUser"]
depends_on = [helm_release.argocd, google_service_account.airflow_scheduler_workload_identity_sa]
}

# Create NFS Storage
Expand Down
13 changes: 13 additions & 0 deletions terraform/k8s-configmaps.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,17 @@
# }
# }

# resource "kubernetes_config_map" "airflow_statsd_mappings" {
# metadata {
# name = "airflow-statsd-mappings"
# namespace = kubernetes_namespace.airflow.metadata[0].name

# }

# data = {
# "statsd-mappings.yaml" = file("${path.module}/../argocd-app/monitoring/statsd-mappings.yaml")
# }
# }



22 changes: 22 additions & 0 deletions terraform/k8s-namespaces.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,30 @@ resource "kubernetes_namespace" "argocd" {
metadata {
name = var.argocd_namespace
}

depends_on = [module.gke.endpoint]
}

# Delete finalizer on terraform destroy
resource "null_resource" "remove_finalizers" {
depends_on = [kubernetes_namespace.argocd]

provisioner "local-exec" {
when = destroy
command = <<-EOT
kubectl get namespace ${self.triggers.namespace} -o json | \
jq '.metadata.finalizers = []' | \
kubectl replace --raw "/api/v1/namespaces/${self.triggers.namespace}/finalize" -f -
EOT
on_failure = continue
}

triggers = {
namespace = var.argocd_namespace
}
}


# NFS namespace
# resource "kubernetes_namespace" "nfs" {
# metadata {
Expand Down

0 comments on commit 19ec20b

Please sign in to comment.