Skip to content

Commit

Permalink
Merge branch 'develop' into release-prep
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Meyers committed Nov 4, 2024
2 parents e5294c2 + 95dad09 commit 853c855
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 20 deletions.
1 change: 0 additions & 1 deletion airflow/dags/cwl_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
# The Kubernetes namespace within which the Pod is run (it must already exist)
POD_NAMESPACE = "sps"
POD_LABEL = "cwl_task"
# SPS_DOCKER_CWL_IMAGE = "ghcr.io/unity-sds/unity-sps/sps-docker-cwl:2.1.0"
SPS_DOCKER_CWL_IMAGE = "ghcr.io/unity-sds/unity-sps/sps-docker-cwl:2.2.0"

NODE_POOL_DEFAULT = "airflow-kubernetes-pod-operator"
Expand Down
15 changes: 10 additions & 5 deletions airflow/dags/sbg_preprocess_cwl_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,18 @@

# common parameters
CONTAINER_RESOURCES = k8s.V1ResourceRequirements(
requests={"ephemeral-storage": "5Gi"},
requests={
"memory": "4Gi",
# "cpu": "8",
"ephemeral-storage": "10Gi",
},
)
INPUT_PROCESSING_LABELS = ["SBG", "CWL"]
INPUT_PROCESSING_LABELS = ["SBG", "CWL", "Preprocess"]

dag = DAG(
dag_id="sbg_preprocess_cwl_dag",
description="SBG Preprocess Workflow as CWL",
dag_display_name="CWL Preprocess DAG",
tags=["SBG", "Unity", "SPS", "NASA", "JPL"],
is_paused_upon_creation=False,
catchup=False,
Expand All @@ -56,13 +61,13 @@
"cwl_workflow": Param(
DEFAULT_CWL_WORKFLOW,
type="string",
title="CWL workflow",
title="SBG Preprocess workflow",
description="The SBG Pre-process CWL workflow URL",
),
"cwl_args": Param(
DEFAULT_CWL_ARGUMENTS,
type="string",
title="CWL workflow parameters",
title="SBG Preprocess workflow parameters",
description="The SBG Pre-process YAML parameters URL",
),
},
Expand Down Expand Up @@ -95,7 +100,7 @@ def setup(ti=None, **context):
in_cluster=True,
get_logs=True,
startup_timeout_seconds=1800,
arguments=["{{ params.cwl_workflow }}", "{{ params.cwl_args }}"],
arguments=["-w", "{{ params.cwl_workflow }}", "-j", "{{ params.cwl_args }}", "-e", "None"],
container_security_context={"privileged": True},
container_resources=CONTAINER_RESOURCES,
container_logs=True,
Expand Down
7 changes: 5 additions & 2 deletions terraform-unity/modules/terraform-unity-sps-airflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ No modules.
| [aws_s3_bucket.airflow_logs](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/s3_bucket) | resource |
| [aws_security_group.airflow_efs](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/security_group) | resource |
| [aws_security_group.airflow_ingress_sg](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/security_group) | resource |
| [aws_security_group.airflow_ingress_sg_internal](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/security_group) | resource |
| [aws_security_group_rule.airflow_efs](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/security_group_rule) | resource |
| [aws_ssm_parameter.airflow_api_health_check_endpoint](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/ssm_parameter) | resource |
| [aws_ssm_parameter.airflow_api_url](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/ssm_parameter) | resource |
Expand All @@ -54,6 +55,7 @@ No modules.
| [helm_release.airflow](https://registry.terraform.io/providers/hashicorp/helm/2.15.0/docs/resources/release) | resource |
| [helm_release.keda](https://registry.terraform.io/providers/hashicorp/helm/2.15.0/docs/resources/release) | resource |
| [kubernetes_ingress_v1.airflow_ingress](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/ingress_v1) | resource |
| [kubernetes_ingress_v1.airflow_ingress_internal](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/ingress_v1) | resource |
| [kubernetes_namespace.keda](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/namespace) | resource |
| [kubernetes_persistent_volume.airflow_deployed_dags](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/persistent_volume) | resource |
| [kubernetes_persistent_volume.airflow_kpo](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/persistent_volume) | resource |
Expand All @@ -77,6 +79,7 @@ No modules.
| [aws_ssm_parameter.subnet_ids](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/data-sources/ssm_parameter) | data source |
| [aws_vpc.cluster_vpc](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/data-sources/vpc) | data source |
| [kubernetes_ingress_v1.airflow_ingress](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/data-sources/ingress_v1) | data source |
| [kubernetes_ingress_v1.airflow_ingress_internal](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/data-sources/ingress_v1) | data source |
| [kubernetes_namespace.service_area](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/data-sources/namespace) | data source |

## Inputs
Expand All @@ -87,9 +90,9 @@ No modules.
| <a name="input_airflow_webserver_username"></a> [airflow\_webserver\_username](#input\_airflow\_webserver\_username) | The username for the Airflow webserver and UI. | `string` | n/a | yes |
| <a name="input_db_instance_identifier"></a> [db\_instance\_identifier](#input\_db\_instance\_identifier) | The AWS DB instance identifier | `string` | n/a | yes |
| <a name="input_db_secret_arn"></a> [db\_secret\_arn](#input\_db\_secret\_arn) | The version of the database secret in AWS Secrets Manager | `string` | n/a | yes |
| <a name="input_docker_images"></a> [docker\_images](#input\_docker\_images) | Docker images for the associated services. | <pre>object({<br> airflow = object({<br> name = string<br> tag = string<br> })<br> })</pre> | n/a | yes |
| <a name="input_docker_images"></a> [docker\_images](#input\_docker\_images) | Docker images for the associated services. | <pre>object({<br/> airflow = object({<br/> name = string<br/> tag = string<br/> })<br/> })</pre> | n/a | yes |
| <a name="input_efs_file_system_id"></a> [efs\_file\_system\_id](#input\_efs\_file\_system\_id) | The EFS file system ID | `string` | n/a | yes |
| <a name="input_helm_charts"></a> [helm\_charts](#input\_helm\_charts) | Helm charts for the associated services. | <pre>map(object({<br> repository = string<br> chart = string<br> version = string<br> }))</pre> | n/a | yes |
| <a name="input_helm_charts"></a> [helm\_charts](#input\_helm\_charts) | Helm charts for the associated services. | <pre>map(object({<br/> repository = string<br/> chart = string<br/> version = string<br/> }))</pre> | n/a | yes |
| <a name="input_karpenter_node_pools"></a> [karpenter\_node\_pools](#input\_karpenter\_node\_pools) | Names of the Karpenter node pools | `list(string)` | n/a | yes |
| <a name="input_kubeconfig_filepath"></a> [kubeconfig\_filepath](#input\_kubeconfig\_filepath) | The path to the kubeconfig file for the Kubernetes cluster. | `string` | n/a | yes |
| <a name="input_kubernetes_namespace"></a> [kubernetes\_namespace](#input\_kubernetes\_namespace) | The kubernetes namespace for Airflow resources. | `string` | n/a | yes |
Expand Down
7 changes: 7 additions & 0 deletions terraform-unity/modules/terraform-unity-sps-airflow/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ data "kubernetes_ingress_v1" "airflow_ingress" {
}
}

data "kubernetes_ingress_v1" "airflow_ingress_internal" {
metadata {
name = kubernetes_ingress_v1.airflow_ingress_internal.metadata[0].name
namespace = data.kubernetes_namespace.service_area.metadata[0].name
}
}

data "aws_db_instance" "db" {
db_instance_identifier = var.db_instance_identifier
}
Expand Down
60 changes: 54 additions & 6 deletions terraform-unity/modules/terraform-unity-sps-airflow/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ resource "aws_security_group" "airflow_ingress_sg" {
})
}

resource "aws_security_group" "airflow_ingress_sg_internal" {
name = "${var.project}-${var.venue}-airflow-internal-ingress-sg"
description = "SecurityGroup for Airflow LoadBalancer internal ingress"
vpc_id = data.aws_vpc.cluster_vpc.id
tags = merge(local.common_tags, {
Name = format(local.resource_name_prefix, "AirflowLBSg")
Component = "airflow"
Stack = "airflow"
})
}

#tfsec:ignore:AVD-AWS-0107
resource "aws_vpc_security_group_ingress_rule" "airflow_ingress_sg_jpl_rule" {
for_each = toset(["128.149.0.0/16", "137.78.0.0/16", "137.79.0.0/16"])
Expand All @@ -438,7 +449,7 @@ data "aws_security_groups" "venue_proxy_sg" {
#tfsec:ignore:AVD-AWS-0107
resource "aws_vpc_security_group_ingress_rule" "airflow_ingress_sg_proxy_rule" {
count = length(data.aws_security_groups.venue_proxy_sg.ids) > 0 ? 1 : 0
security_group_id = aws_security_group.airflow_ingress_sg.id
security_group_id = aws_security_group.airflow_ingress_sg_internal.id
description = "SecurityGroup ingress rule for venue-services proxy"
ip_protocol = "tcp"
from_port = local.load_balancer_port
Expand Down Expand Up @@ -483,6 +494,43 @@ resource "kubernetes_ingress_v1" "airflow_ingress" {
depends_on = [helm_release.airflow]
}

resource "kubernetes_ingress_v1" "airflow_ingress_internal" {
metadata {
name = "airflow-ingress-internal"
namespace = data.kubernetes_namespace.service_area.metadata[0].name
annotations = {
"alb.ingress.kubernetes.io/scheme" = "internal"
"alb.ingress.kubernetes.io/target-type" = "ip"
"alb.ingress.kubernetes.io/subnets" = join(",", jsondecode(data.aws_ssm_parameter.subnet_ids.value)["private"])
"alb.ingress.kubernetes.io/listen-ports" = "[{\"HTTP\": ${local.load_balancer_port}}]"
"alb.ingress.kubernetes.io/security-groups" = aws_security_group.airflow_ingress_sg_internal.id
"alb.ingress.kubernetes.io/manage-backend-security-group-rules" = "true"
"alb.ingress.kubernetes.io/healthcheck-path" = "/health"
}
}
spec {
ingress_class_name = "alb"
rule {
http {
path {
path = "/"
path_type = "Prefix"
backend {
service {
name = "airflow-webserver"
port {
number = 8080
}
}
}
}
}
}
}
wait_for_load_balancer = true
depends_on = [helm_release.airflow]
}

resource "aws_ssm_parameter" "airflow_ui_url" {
name = format("/%s", join("/", compact(["", var.project, var.venue, var.service_area, "processing", "airflow", "ui_url"])))
description = "The URL of the Airflow UI."
Expand All @@ -501,8 +549,8 @@ resource "aws_ssm_parameter" "airflow_ui_health_check_endpoint" {
type = "String"
value = jsonencode({
"componentName" : "Airflow UI"
"healthCheckUrl" : "http://${data.kubernetes_ingress_v1.airflow_ingress.status[0].load_balancer[0].ingress[0].hostname}:5000/health"
"landingPageUrl" : "http://${data.kubernetes_ingress_v1.airflow_ingress.status[0].load_balancer[0].ingress[0].hostname}:5000"
"healthCheckUrl" : "http://${data.kubernetes_ingress_v1.airflow_ingress_internal.status[0].load_balancer[0].ingress[0].hostname}:5000/health"
"landingPageUrl" : "http://${data.kubernetes_ingress_v1.airflow_ingress_internal.status[0].load_balancer[0].ingress[0].hostname}:5000"
})
tags = merge(local.common_tags, {
Name = format(local.resource_name_prefix, "health-check-endpoints-airflow_ui")
Expand Down Expand Up @@ -532,8 +580,8 @@ resource "aws_ssm_parameter" "airflow_api_health_check_endpoint" {
type = "String"
value = jsonencode({
"componentName" : "Airflow API"
"healthCheckUrl" : "http://${data.kubernetes_ingress_v1.airflow_ingress.status[0].load_balancer[0].ingress[0].hostname}:5000/api/v1/health"
"landingPageUrl" : "http://${data.kubernetes_ingress_v1.airflow_ingress.status[0].load_balancer[0].ingress[0].hostname}:5000/api/v1"
"healthCheckUrl" : "http://${data.kubernetes_ingress_v1.airflow_ingress_internal.status[0].load_balancer[0].ingress[0].hostname}:5000/api/v1/health"
"landingPageUrl" : "http://${data.kubernetes_ingress_v1.airflow_ingress_internal.status[0].load_balancer[0].ingress[0].hostname}:5000/api/v1"
})
tags = merge(local.common_tags, {
Name = format(local.resource_name_prefix, "health-check-endpoints-airflow_api")
Expand All @@ -558,7 +606,7 @@ resource "aws_ssm_parameter" "unity_proxy_airflow_ui" {
Redirect "/${var.project}/${var.venue}/sps/home"
</Location>
<LocationMatch "^/${var.project}/${var.venue}/sps/(.*)$">
ProxyPassMatch "http://${data.kubernetes_ingress_v1.airflow_ingress.status[0].load_balancer[0].ingress[0].hostname}:5000/$1"
ProxyPassMatch "http://${data.kubernetes_ingress_v1.airflow_ingress_internal.status[0].load_balancer[0].ingress[0].hostname}:5000/$1"
ProxyPreserveHost On
FallbackResource /management/index.html
AddOutputFilterByType INFLATE;SUBSTITUTE;DEFLATE text/html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ No modules.
|------|------|
| [aws_lambda_invocation.unity_proxy_lambda_invocation](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/lambda_invocation) | resource |
| [aws_security_group.ogc_ingress_sg](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/security_group) | resource |
| [aws_security_group.ogc_ingress_sg_internal](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/security_group) | resource |
| [aws_ssm_parameter.ogc_processes_api_health_check_endpoint](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/ssm_parameter) | resource |
| [aws_ssm_parameter.ogc_processes_api_url](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/ssm_parameter) | resource |
| [aws_ssm_parameter.ogc_processes_ui_url](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/resources/ssm_parameter) | resource |
Expand All @@ -33,6 +34,7 @@ No modules.
| [kubernetes_deployment.ogc_processes_api](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/deployment) | resource |
| [kubernetes_deployment.redis](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/deployment) | resource |
| [kubernetes_ingress_v1.ogc_processes_api_ingress](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/ingress_v1) | resource |
| [kubernetes_ingress_v1.ogc_processes_api_ingress_internal](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/ingress_v1) | resource |
| [kubernetes_service.ogc_processes_api](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/service) | resource |
| [kubernetes_service.redis](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/resources/service) | resource |
| [aws_db_instance.db](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/data-sources/db_instance) | data source |
Expand All @@ -43,6 +45,7 @@ No modules.
| [aws_ssm_parameter.subnet_ids](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/data-sources/ssm_parameter) | data source |
| [aws_vpc.cluster_vpc](https://registry.terraform.io/providers/hashicorp/aws/5.67.0/docs/data-sources/vpc) | data source |
| [kubernetes_ingress_v1.ogc_processes_api_ingress](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/data-sources/ingress_v1) | data source |
| [kubernetes_ingress_v1.ogc_processes_api_ingress_internal](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/data-sources/ingress_v1) | data source |
| [kubernetes_namespace.service_area](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/data-sources/namespace) | data source |
| [kubernetes_persistent_volume_claim.airflow_deployed_dags](https://registry.terraform.io/providers/hashicorp/kubernetes/2.32.0/docs/data-sources/persistent_volume_claim) | data source |

Expand All @@ -53,10 +56,10 @@ No modules.
| <a name="input_airflow_deployed_dags_pvc"></a> [airflow\_deployed\_dags\_pvc](#input\_airflow\_deployed\_dags\_pvc) | The name of the PVC for Airflow deployed DAGs | `string` | n/a | yes |
| <a name="input_airflow_webserver_password"></a> [airflow\_webserver\_password](#input\_airflow\_webserver\_password) | The password for the Airflow webserver and UI. | `string` | n/a | yes |
| <a name="input_airflow_webserver_username"></a> [airflow\_webserver\_username](#input\_airflow\_webserver\_username) | The username for the Airflow webserver and UI. | `string` | n/a | yes |
| <a name="input_dag_catalog_repo"></a> [dag\_catalog\_repo](#input\_dag\_catalog\_repo) | Git repository that stores the catalog of Airflow DAGs. | <pre>object({<br> url = string<br> ref = string<br> dags_directory_path = string<br> })</pre> | n/a | yes |
| <a name="input_dag_catalog_repo"></a> [dag\_catalog\_repo](#input\_dag\_catalog\_repo) | Git repository that stores the catalog of Airflow DAGs. | <pre>object({<br/> url = string<br/> ref = string<br/> dags_directory_path = string<br/> })</pre> | n/a | yes |
| <a name="input_db_instance_identifier"></a> [db\_instance\_identifier](#input\_db\_instance\_identifier) | The AWS DB instance identifier | `string` | n/a | yes |
| <a name="input_db_secret_arn"></a> [db\_secret\_arn](#input\_db\_secret\_arn) | The version of the database secret in AWS Secrets Manager | `string` | n/a | yes |
| <a name="input_docker_images"></a> [docker\_images](#input\_docker\_images) | Docker images for the associated services. | <pre>object({<br> ogc_processes_api = object({<br> name = string<br> tag = string<br> })<br> git_sync = object({<br> name = string<br> tag = string<br> })<br> redis = object({<br> name = string<br> tag = string<br> })<br> })</pre> | n/a | yes |
| <a name="input_docker_images"></a> [docker\_images](#input\_docker\_images) | Docker images for the associated services. | <pre>object({<br/> ogc_processes_api = object({<br/> name = string<br/> tag = string<br/> })<br/> git_sync = object({<br/> name = string<br/> tag = string<br/> })<br/> redis = object({<br/> name = string<br/> tag = string<br/> })<br/> })</pre> | n/a | yes |
| <a name="input_karpenter_node_pools"></a> [karpenter\_node\_pools](#input\_karpenter\_node\_pools) | Names of the Karpenter node pools | `list(string)` | n/a | yes |
| <a name="input_kubernetes_namespace"></a> [kubernetes\_namespace](#input\_kubernetes\_namespace) | The kubernetes namespace for the API's resources. | `string` | n/a | yes |
| <a name="input_project"></a> [project](#input\_project) | The project or mission deploying Unity SPS | `string` | n/a | yes |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ data "kubernetes_ingress_v1" "ogc_processes_api_ingress" {
namespace = data.kubernetes_namespace.service_area.metadata[0].name
}
}

data "kubernetes_ingress_v1" "ogc_processes_api_ingress_internal" {
metadata {
name = kubernetes_ingress_v1.ogc_processes_api_ingress_internal.metadata[0].name
namespace = data.kubernetes_namespace.service_area.metadata[0].name
}
}
Loading

0 comments on commit 853c855

Please sign in to comment.