Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IBCDPE-1004] Implement Postgres server #22

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
19f9cbf
Test postgres-CN
BryanFauble Aug 16, 2024
f9ddb88
Set branch
BryanFauble Aug 16, 2024
e3f2c7f
Create testing stack
BryanFauble Aug 16, 2024
8722778
Bump version and secret
BryanFauble Aug 16, 2024
2eb76af
Bump version
BryanFauble Aug 16, 2024
8d9058d
Move source
BryanFauble Aug 16, 2024
1df7dda
Take out version
BryanFauble Aug 16, 2024
f76c64f
commit fix
BryanFauble Aug 16, 2024
4bf77c2
fix
BryanFauble Aug 16, 2024
81187aa
[IBCDPE-1005] Create workshop for deploying hello-world (#19)
BryanFauble Aug 16, 2024
3500e14
Correct conflicting names
BryanFauble Aug 16, 2024
bb2ad91
Set secret
BryanFauble Aug 16, 2024
ec4ea7d
Turn off special
BryanFauble Aug 16, 2024
e9b05fb
Let secret automatically be created
BryanFauble Aug 16, 2024
6af391e
Don't create secret
BryanFauble Aug 16, 2024
8e01065
Don't specify secret
BryanFauble Aug 16, 2024
4f59b7d
Separate postgres operator to cluster
BryanFauble Aug 16, 2024
28d1895
Correct path
BryanFauble Aug 16, 2024
553789d
Set airflow secret
BryanFauble Aug 16, 2024
7adaf40
Set secret here to satisfy airflow
BryanFauble Aug 16, 2024
3df73ff
Correct label
BryanFauble Aug 16, 2024
213c2df
Corrections
BryanFauble Aug 16, 2024
a41b6f5
Set secret
BryanFauble Aug 16, 2024
87edd97
Correct key
BryanFauble Aug 16, 2024
b720650
Correct secret name
BryanFauble Aug 16, 2024
4e92ed4
Set with db+
BryanFauble Aug 16, 2024
7134efa
enable postgres again to see connection format
BryanFauble Aug 16, 2024
23c2371
disable postgres
BryanFauble Aug 16, 2024
74696e3
Correct connection name in secret
BryanFauble Aug 16, 2024
03aefc5
Run with verbose
BryanFauble Aug 16, 2024
31d98a0
Correct host url
BryanFauble Aug 17, 2024
1c9e5d3
Correct JDBC uri
BryanFauble Aug 17, 2024
5d15467
Merge branch 'main' into ibcdpe-1004-airflow-ops
BryanFauble Aug 17, 2024
494aabd
Remove verbose migrate
BryanFauble Aug 17, 2024
2d01091
Cleanup
BryanFauble Aug 17, 2024
ecd89b4
Enable scraping
BryanFauble Aug 19, 2024
da1ead4
Bump metrics
BryanFauble Aug 19, 2024
8f6ad73
Disable prometheusRule
BryanFauble Aug 19, 2024
6da8ebd
Try installing prometheus CRDs
BryanFauble Aug 19, 2024
1eccf91
Remove
BryanFauble Aug 19, 2024
de68d9a
Install CRDs
BryanFauble Aug 19, 2024
cd6dfc1
Add PromRule
BryanFauble Aug 19, 2024
c4e8795
randomize first pass
BryanFauble Aug 19, 2024
639c94d
Tear down airflow temporary
BryanFauble Aug 19, 2024
6b6b259
Add module for operator
BryanFauble Aug 19, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.tfstate*
.terraform
terraform.tfvars
terraform.tfvars
settings.json
1 change: 0 additions & 1 deletion deployments/README.md

This file was deleted.

72 changes: 72 additions & 0 deletions deployments/spacelift/dpe-k8s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,75 @@ resource "spacelift_aws_integration_attachment" "k8s-deployments-aws-integration
read = true
write = true
}

resource "spacelift_stack" "k8s-stack-deployments-testing" {
github_enterprise {
namespace = "Sage-Bionetworks-Workflows"
id = "sage-bionetworks-workflows-gh"
}

depends_on = [
spacelift_space.dpe-space
]

administrative = false
autodeploy = var.auto_deploy
branch = "ibcdpe-1004-airflow-ops"
description = "Deployments internal to an EKS cluster"
name = "${var.k8s_stack_deployments_name}-testing"
project_root = "deployments/stacks/dpe-k8s-deployments-testing"
repository = "eks-stack"
terraform_version = var.opentofu_version
terraform_workflow_tool = "OPEN_TOFU"
space_id = spacelift_space.dpe-space.id
additional_project_globs = [
"deployments/"
]
}

resource "spacelift_environment_variable" "k8s-stack-deployments-testing-environment-variables" {
for_each = local.k8s_stack_deployments_variables

stack_id = spacelift_stack.k8s-stack-deployments-testing.id
name = "TF_VAR_${each.key}"
value = try(tostring(each.value), jsonencode(each.value))
write_only = false
}

resource "spacelift_context_attachment" "k8s-kubeconfig-hooks-testing" {
context_id = "kubernetes-deployments-kubeconfig"
stack_id = spacelift_stack.k8s-stack-deployments-testing.id
}

resource "spacelift_stack_dependency" "k8s-stack-to-deployments-testing" {
stack_id = spacelift_stack.k8s-stack-deployments-testing.id
depends_on_stack_id = spacelift_stack.k8s-stack.id
}

resource "spacelift_stack_dependency_reference" "dependency-references-testing" {
for_each = local.k8s_stack_to_deployment_variables

stack_dependency_id = spacelift_stack_dependency.k8s-stack-to-deployments-testing.id
output_name = each.key
input_name = each.value
}

resource "spacelift_stack_dependency_reference" "region-name-testing" {
stack_dependency_id = spacelift_stack_dependency.k8s-stack-to-deployments-testing.id
output_name = "region"
input_name = "REGION"
}

resource "spacelift_stack_dependency_reference" "cluster-name-testing" {
stack_dependency_id = spacelift_stack_dependency.k8s-stack-to-deployments-testing.id
output_name = "cluster_name"
input_name = "CLUSTER_NAME"
}

resource "spacelift_aws_integration_attachment" "k8s-deployments-aws-integration-attachment-testing" {

integration_id = var.aws_integration_id
stack_id = spacelift_stack.k8s-stack-deployments-testing.id
read = true
write = true
}
15 changes: 15 additions & 0 deletions deployments/stacks/dpe-k8s-deployments-testing/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
data "aws_eks_cluster" "cluster" {
name = var.cluster_name
}

data "aws_eks_cluster_auth" "cluster" {
name = var.cluster_name
}

data "aws_secretsmanager_secret" "spotinst_token" {
name = "spotinst_token"
}

data "aws_secretsmanager_secret_version" "secret_credentials" {
secret_id = data.aws_secretsmanager_secret.spotinst_token.id
}
20 changes: 20 additions & 0 deletions deployments/stacks/dpe-k8s-deployments-testing/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module "postgres-cloud-native-operator" {
# source = "spacelift.io/sagebionetworks/postgres-cloud-native/aws"
source = "../../../modules/postgres-cloud-native-operator/"
# version = "0.2.1"
auto_deploy = true
auto_prune = true
git_revision = "ibcdpe-1004-airflow-ops"
}


# module "postgres-cloud-native" {
# # source = "spacelift.io/sagebionetworks/postgres-cloud-native/aws"
# source = "../../../modules/postgres-cloud-native/"
# # version = "0.2.1"
# auto_deploy = true
# auto_prune = true
# git_revision = "ibcdpe-1004-airflow-ops"
# namespace = "airflow"
# argo_deployment_name = "airflow-postgres-cloud-native"
# }
28 changes: 28 additions & 0 deletions deployments/stacks/dpe-k8s-deployments-testing/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
provider "aws" {
region = var.region
}

provider "kubernetes" {
config_path = var.kube_config_path
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[0].data)
token = data.aws_eks_cluster_auth.cluster.token
}

provider "helm" {
kubernetes {
config_path = var.kube_config_path
}
}

provider "spotinst" {
account = var.spotinst_account
token = data.aws_secretsmanager_secret_version.secret_credentials.secret_string
}

provider "kubectl" {
config_path = var.kube_config_path
host = data.aws_eks_cluster.cluster.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.cluster.certificate_authority[0].data)
token = data.aws_eks_cluster_auth.cluster.token
}
62 changes: 62 additions & 0 deletions deployments/stacks/dpe-k8s-deployments-testing/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
variable "vpc_id" {
description = "VPC ID"
type = string
}

variable "private_subnet_ids" {
description = "Private subnet IDs"
type = list(string)
}

variable "node_security_group_id" {
description = "Node security group ID"
type = string
}

variable "pod_to_node_dns_sg_id" {
description = "Pod to node DNS security group ID."
type = string
}

variable "vpc_cidr_block" {
description = "VPC CIDR block"
type = string
}

variable "kube_config_path" {
description = "Kube config path"
type = string
default = "~/.kube/config"
}

variable "region" {
description = "AWS region"
type = string
default = "us-east-1"
}

variable "cluster_name" {
description = "EKS cluster name"
type = string
}

variable "spotinst_account" {
description = "Spot.io account"
type = string
}

variable "auto_deploy" {
description = "Automatically deploy the stack"
type = bool
}

variable "auto_prune" {
description = "Automatically prune kubernetes resources"
type = bool
}

variable "git_revision" {
description = "The git revision to deploy"
type = string
default = "main"
}
11 changes: 11 additions & 0 deletions deployments/stacks/dpe-k8s-deployments-testing/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
required_providers {
spotinst = {
source = "spotinst/spotinst"
}
kubectl = {
source = "gavinbunney/kubectl"
version = "1.14.0"
}
}
}
18 changes: 9 additions & 9 deletions deployments/stacks/dpe-k8s-deployments/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module "sage-aws-eks-autoscaler" {
module "victoria-metrics" {
depends_on = [module.argo-cd, module.sage-aws-eks-autoscaler]
source = "spacelift.io/sagebionetworks/victoria-metrics/aws"
version = "0.4.7"
version = "0.4.8"
auto_deploy = var.auto_deploy
auto_prune = var.auto_prune
git_revision = var.git_revision
Expand All @@ -28,14 +28,14 @@ module "trivy-operator" {
git_revision = var.git_revision
}

module "airflow" {
depends_on = [module.victoria-metrics, module.argo-cd, module.sage-aws-eks-autoscaler]
source = "spacelift.io/sagebionetworks/airflow/aws"
version = "0.3.1"
auto_deploy = var.auto_deploy
auto_prune = var.auto_prune
git_revision = var.git_revision
}
# module "airflow" {
# depends_on = [module.victoria-metrics, module.argo-cd, module.sage-aws-eks-autoscaler]
# source = "spacelift.io/sagebionetworks/airflow/aws"
# version = "0.3.1"
# auto_deploy = var.auto_deploy
# auto_prune = var.auto_prune
# git_revision = var.git_revision
# }

module "argo-cd" {
depends_on = [module.sage-aws-eks-autoscaler]
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# }

locals {
git_branch = "main"
git_branch = "ibcdpe-1004-airflow-ops"
}

resource "spacelift_stack" "root_administrative_stack" {
Expand Down
28 changes: 22 additions & 6 deletions modules/apache-airflow/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

resource "kubernetes_namespace" "airflow" {
metadata {
name = "airflow"
name = var.namespace
}
}

Expand All @@ -18,7 +18,7 @@ resource "random_password" "airflow" {
resource "kubernetes_secret" "airflow_webserver_secret" {
metadata {
name = "airflow-webserver-secret"
namespace = "airflow"
namespace = var.namespace
}

data = {
Expand All @@ -28,10 +28,26 @@ resource "kubernetes_secret" "airflow_webserver_secret" {
depends_on = [kubernetes_namespace.airflow]
}

resource "random_password" "airflow-admin-user" {
length = 32
special = false
}

resource "kubernetes_secret" "airflow-admin-user-secret" {
metadata {
name = "airflow-admin-user-secret"
namespace = var.namespace
}

data = {
"password" = random_password.airflow-admin-user.result
"username" = "admin"
}

depends_on = [kubernetes_namespace.airflow]
}

# TODO: Should a long-term deployment use a managed RDS instance?
# https://github.com/apache/airflow/blob/main/chart/values.yaml#L2321-L2329
resource "kubectl_manifest" "argo-deployment" {
resource "kubectl_manifest" "airflow-deployment" {
depends_on = [kubernetes_namespace.airflow]

yaml_body = <<YAML
Expand Down Expand Up @@ -60,6 +76,6 @@ spec:
ref: values
destination:
server: 'https://kubernetes.default.svc'
namespace: airflow
namespace: ${var.namespace}
YAML
}
21 changes: 16 additions & 5 deletions modules/apache-airflow/templates/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ data:
# data:
# connection: base64_encoded_connection_string

metadataSecretName: ~
metadataSecretName: pg-user-secret
# When providing secret names and using the same database for metadata and
# result backend, for Airflow < 2.4.0 it is necessary to create a separate
# secret for result backend but with a db+ scheme prefix.
Expand Down Expand Up @@ -880,15 +880,15 @@ createUserJob:
- "-r"
- "{{ .Values.webserver.defaultUser.role }}"
- "-u"
- "{{ .Values.webserver.defaultUser.username }}"
- "${AIRFLOW_USERNAME}"
- "-e"
- "{{ .Values.webserver.defaultUser.email }}"
- "-f"
- "{{ .Values.webserver.defaultUser.firstName }}"
- "-l"
- "{{ .Values.webserver.defaultUser.lastName }}"
- "-p"
- "{{ .Values.webserver.defaultUser.password }}"
- "${AIRFLOW_PASSWORD}"

# Annotations on the create user job pod
annotations: {}
Expand Down Expand Up @@ -952,7 +952,17 @@ createUserJob:
useHelmHooks: false
applyCustomEnv: true

env: []
env:
- name: AIRFLOW_USERNAME
valueFrom:
secretKeyRef:
name: airflow-admin-user-secret
key: username
- name: AIRFLOW_PASSWORD
valueFrom:
secretKeyRef:
name: airflow-admin-user-secret
key: password

resources: {}
# limits:
Expand Down Expand Up @@ -1138,6 +1148,7 @@ webserver:
# memory: 128Mi

# Create initial user.
# TODO: Create the initial user via a random secret
defaultUser:
enabled: true
role: Admin
Expand Down Expand Up @@ -2077,7 +2088,7 @@ cleanup:
# Configuration for postgresql subchart
# Not recommended for production
postgresql:
enabled: true
enabled: false
image:
tag: "11"
auth:
Expand Down
5 changes: 5 additions & 0 deletions modules/apache-airflow/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ variable "git_revision" {
type = string
default = "main"
}

variable "namespace" {
description = "The namespace to deploy into"
type = string
}
Loading