Skip to content

Commit

Permalink
upgrade blue-green-upgrade sample addons to V5 with gitops-bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
allamand committed Sep 20, 2023
1 parent e281f77 commit 2e09cf8
Show file tree
Hide file tree
Showing 17 changed files with 395 additions and 97 deletions.
33 changes: 33 additions & 0 deletions patterns/blue-green-upgrade/bootstrap/addons.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: bootstrap-addons
namespace: argocd
spec:
syncPolicy:
preserveResourcesOnDeletion: true
generators:
- clusters:
selector:
matchExpressions:
- key: akuity.io/argo-cd-cluster-name
operator: NotIn
values: [in-cluster]
template:
metadata:
name: 'bootstrap-addons'
spec:
project: default
source:
repoURL: '{{metadata.annotations.addons_repo_url}}'
path: '{{metadata.annotations.addons_repo_path}}'
targetRevision: '{{metadata.annotations.addons_repo_revision}}'
directory:
recurse: true
exclude: exclude/*
destination:
namespace: 'argocd'
name: '{{name}}'
syncPolicy:
automated: {}
68 changes: 68 additions & 0 deletions patterns/blue-green-upgrade/bootstrap/workloads.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: bootstrap-workloads
namespace: argocd
spec:
goTemplate: true
syncPolicy:
preserveResourcesOnDeletion: true
generators:
- matrix:
generators:
- clusters:
selector:
matchExpressions:
- key: akuity.io/argo-cd-cluster-name
operator: NotIn
values:
- in-cluster
- git:
repoURL: '{{.metadata.annotations.gitops_workloads_url}}'
revision: '{{.metadata.annotations.gitops_workloads_revision}}'
directories:
- path: '{{.metadata.annotations.gitops_workloads_path}}/*'
template:
metadata:
name: 'bootstrap-workload-{{.name}}'
spec:
project: default
sources:
- repoURL: '{{.metadata.annotations.gitops_workloads_url}}'
targetRevision: '{{.metadata.annotations.gitops_workloads_revision}}'
ref: values
path: '{{.metadata.annotations.gitops_workloads_path}}'
helm:
releaseName: 'bootstrap-workload-{{.name}}'
ignoreMissingValueFiles: true
values: |
"account": "{{.metadata.annotations.aws_account_id}}"
"clusterName": "{{.metadata.annotations.cluster_name}}"
"labels":
"env": "{{.metadata.annotations.env}}"
"region": "{{.metadata.annotations.aws_region}}"
"repoUrl": "{{.metadata.annotations.gitops_workloads_url}}"
"spec":
"source":
"repoURL": "{{.metadata.annotations.gitops_workloads_url}}"
"targetRevision": "{{.metadata.annotations.gitops_workloads_revision}}"
"blueprint": "terraform"
"clusterName": "{{.metadata.annotations.cluster_name}}"
"env": "{{.metadata.annotations.env}}"
"ingress":
"route53_weight": {{default "0" .metadata.annotations.route53_weight}}
"argocd_route53_weight": {{default "0" .metadata.annotations.argocd_route53_weight}}
"ecsfrontend_route53_weight": {{default "0" .metadata.annotations.ecsfrontend_route53_weight}}
"host": {{ default "" .metadata.annotations.eks_cluster_domain }}
"type": "{{.metadata.annotations.ingress_type}}"
"karpenterInstanceProfile": "{{.metadata.annotations.karpenter_node_instance_profile_name}}"
"target_group_arn": {{ default "" .metadata.annotations.target_group_arn }}
"external_lb_url": {{ if index .metadata.annotations "external_lb_dns" }} http://{{ .metadata.annotations.external_lb_dns }}{{ else }}{{ end }}
destination:
name: '{{.name}}'
syncPolicy:
automated: {}
syncOptions:
- CreateNamespace=true
- ServerSideApply=true # Big CRDs.
30 changes: 19 additions & 11 deletions patterns/blue-green-upgrade/eks-blue/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,35 @@ provider "kubectl" {
args = ["eks", "get-token", "--cluster-name", module.eks_cluster.eks_cluster_id]
}
}

module "eks_cluster" {
source = "../modules/eks_cluster"

aws_region = var.aws_region
service_name = "blue"
cluster_version = "1.25"
cluster_version = "1.26"

argocd_route53_weight = "100"
route53_weight = "100"
ecsfrontend_route53_weight = "100"

environment_name = var.environment_name
hosted_zone_name = var.hosted_zone_name
eks_admin_role_name = var.eks_admin_role_name
workload_repo_url = var.workload_repo_url
workload_repo_secret = var.workload_repo_secret
workload_repo_revision = var.workload_repo_revision
workload_repo_path = var.workload_repo_path
environment_name = var.environment_name
hosted_zone_name = var.hosted_zone_name
eks_admin_role_name = var.eks_admin_role_name

aws_secret_manager_git_private_ssh_key_name = var.aws_secret_manager_git_private_ssh_key_name
argocd_secret_manager_name_suffix = var.argocd_secret_manager_name_suffix
ingress_type = var.ingress_type

gitops_addons_org = var.gitops_addons_org
gitops_addons_repo = var.gitops_addons_repo
gitops_addons_basepath = var.gitops_addons_basepath
gitops_addons_path = var.gitops_addons_path
gitops_addons_revision = var.gitops_addons_revision

addons_repo_url = var.addons_repo_url
gitops_workloads_org = var.gitops_workloads_org
gitops_workloads_repo = var.gitops_workloads_repo
gitops_workloads_revision = var.gitops_workloads_revision
gitops_workloads_path = var.gitops_workloads_path

iam_platform_user = var.iam_platform_user
argocd_secret_manager_name_suffix = var.argocd_secret_manager_name_suffix
}
20 changes: 18 additions & 2 deletions patterns/blue-green-upgrade/eks-blue/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,33 @@ output "eks_cluster_id" {
value = module.eks_cluster.eks_cluster_id
}

output "configure_kubectl" {
description = "Configure kubectl: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
value = module.eks_cluster.configure_kubectl
}

output "eks_blueprints_platform_teams_configure_kubectl" {
description = "Configure kubectl for each Application Teams: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
description = "Configure kubectl for Platform Team: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
value = module.eks_cluster.eks_blueprints_platform_teams_configure_kubectl
}

output "eks_blueprints_dev_teams_configure_kubectl" {
description = "Configure kubectl for each Application Teams: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
description = "Configure kubectl for each Dev Application Teams: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
value = module.eks_cluster.eks_blueprints_dev_teams_configure_kubectl
}

output "eks_blueprints_ecsdemo_teams_configure_kubectl" {
description = "Configure kubectl for each Application Teams: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
value = module.eks_cluster.eks_blueprints_ecsdemo_teams_configure_kubectl
}

output "access_argocd" {
description = "ArgoCD Access"
value = module.eks_cluster.access_argocd
}

output "gitops_metadata" {
description = "export gitops_metadata"
value = module.eks_cluster.gitops_metadata
sensitive = true
}
2 changes: 1 addition & 1 deletion patterns/blue-green-upgrade/eks-blue/providers.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.0.1"
required_version = ">= 1.4.0"

required_providers {
aws = {
Expand Down
63 changes: 44 additions & 19 deletions patterns/blue-green-upgrade/eks-blue/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ variable "environment_name" {
default = "eks-blueprint"
}

variable "ingress_type" {
type = string
description = "Type of ingress to uses (alb | nginx | ...). this parameter will be sent to arocd via gitops bridge"
default = "alb"
}

variable "hosted_zone_name" {
type = string
description = "Route53 domain for the cluster."
Expand All @@ -22,44 +28,63 @@ variable "eks_admin_role_name" {
default = ""
}

variable "workload_repo_url" {
variable "aws_secret_manager_git_private_ssh_key_name" {
type = string
description = "Git repo URL for the ArgoCD workload deployment"
default = "https://github.com/aws-samples/eks-blueprints-workloads.git"
description = "Secret Manager secret name for hosting Github SSH-Key to Access private repository"
default = "github-blueprint-ssh-key"
}

variable "workload_repo_secret" {
variable "argocd_secret_manager_name_suffix" {
type = string
description = "Secret Manager secret name for hosting Github SSH-Key to Access private repository"
default = "github-blueprint-ssh-key"
description = "Name of secret manager secret for ArgoCD Admin UI Password"
default = "argocd-admin-secret"
}

variable "gitops_workloads_org" {
type = string
description = "Git repository org/user contains for workloads"
default = "https://github.com/aws-samples"
}

variable "workload_repo_revision" {
variable "gitops_workloads_repo" {
type = string
description = "Git repository contains for workloads"
default = "eks-blueprints-workloads"
}

variable "gitops_workloads_revision" {
type = string
description = "Git repo revision in workload_repo_url for the ArgoCD workload deployment"
default = "main"
}

variable "workload_repo_path" {
variable "gitops_workloads_path" {
type = string
description = "Git repo path in workload_repo_url for the ArgoCD workload deployment"
default = "envs/dev"
}

variable "addons_repo_url" {
variable "gitops_addons_org" {
type = string
description = "Git repo URL for the ArgoCD addons deployment"
default = "https://github.com/aws-samples/eks-blueprints-add-ons.git"
description = "Git repository org/user contains for addons"
default = "https://github.com/gitops-bridge-dev"
}

variable "iam_platform_user" {
variable "gitops_addons_repo" {
type = string
description = "Git repository contains for addons"
default = "gitops-bridge-argocd-control-plane-template"
}
variable "gitops_addons_basepath" {
type = string
description = "IAM user used as platform-user"
description = "Git repository base path for addons"
default = ""
}

variable "argocd_secret_manager_name_suffix" {
variable "gitops_addons_path" {
type = string
description = "Name of secret manager secret for ArgoCD Admin UI Password"
default = "argocd-admin-secret"
description = "Git repository path for addons"
default = "bootstrap/control-plane/addons"
}
variable "gitops_addons_revision" {
type = string
description = "Git repository revision/branch/ref for addons"
default = "HEAD"
}
29 changes: 18 additions & 11 deletions patterns/blue-green-upgrade/eks-green/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,29 @@ module "eks_cluster" {

aws_region = var.aws_region
service_name = "green"
cluster_version = "1.26" # Here, we deploy the cluster with the N+1 Kubernetes Version
cluster_version = "1.27" # Here, we deploy the cluster with the N+1 Kubernetes Version

argocd_route53_weight = "0" # We control with theses parameters how we send traffic to the workloads in the new cluster
route53_weight = "0"
ecsfrontend_route53_weight = "0"

environment_name = var.environment_name
hosted_zone_name = var.hosted_zone_name
eks_admin_role_name = var.eks_admin_role_name
workload_repo_url = var.workload_repo_url
workload_repo_secret = var.workload_repo_secret
workload_repo_revision = var.workload_repo_revision
workload_repo_path = var.workload_repo_path
environment_name = var.environment_name
hosted_zone_name = var.hosted_zone_name
eks_admin_role_name = var.eks_admin_role_name

addons_repo_url = var.addons_repo_url
aws_secret_manager_git_private_ssh_key_name = var.aws_secret_manager_git_private_ssh_key_name
argocd_secret_manager_name_suffix = var.argocd_secret_manager_name_suffix
ingress_type = var.ingress_type

gitops_addons_org = var.gitops_addons_org
gitops_addons_repo = var.gitops_addons_repo
gitops_addons_basepath = var.gitops_addons_basepath
gitops_addons_path = var.gitops_addons_path
gitops_addons_revision = var.gitops_addons_revision

gitops_workloads_org = var.gitops_workloads_org
gitops_workloads_repo = var.gitops_workloads_repo
gitops_workloads_revision = var.gitops_workloads_revision
gitops_workloads_path = var.gitops_workloads_path

iam_platform_user = var.iam_platform_user
argocd_secret_manager_name_suffix = var.argocd_secret_manager_name_suffix
}
20 changes: 18 additions & 2 deletions patterns/blue-green-upgrade/eks-green/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ output "eks_cluster_id" {
value = module.eks_cluster.eks_cluster_id
}

output "configure_kubectl" {
description = "Configure kubectl: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
value = module.eks_cluster.configure_kubectl
}

output "eks_blueprints_platform_teams_configure_kubectl" {
description = "Configure kubectl Platform Team: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
description = "Configure kubectl for Platform Team: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
value = module.eks_cluster.eks_blueprints_platform_teams_configure_kubectl
}

Expand All @@ -14,6 +19,17 @@ output "eks_blueprints_dev_teams_configure_kubectl" {
}

output "eks_blueprints_ecsdemo_teams_configure_kubectl" {
description = "Configure kubectl for each ECSDEMO Application Teams: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
description = "Configure kubectl for each Application Teams: make sure you're logged in with the correct AWS profile and run the following command to update your kubeconfig"
value = module.eks_cluster.eks_blueprints_ecsdemo_teams_configure_kubectl
}

output "access_argocd" {
description = "ArgoCD Access"
value = module.eks_cluster.access_argocd
}

output "gitops_metadata" {
description = "export gitops_metadata"
value = module.eks_cluster.gitops_metadata
sensitive = true
}
2 changes: 1 addition & 1 deletion patterns/blue-green-upgrade/eks-green/providers.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.4"
required_version = ">= 1.4.0"

required_providers {
aws = {
Expand Down
Loading

0 comments on commit 2e09cf8

Please sign in to comment.