From efeb5e7063f850b772866431eeb9381a0b720ba5 Mon Sep 17 00:00:00 2001 From: Edaena Salinas Date: Mon, 16 Dec 2019 11:03:46 -0800 Subject: [PATCH] Add git-label variable to terraform template for flux (#851) --- cluster/azure/aks-gitops/main.tf | 1 + cluster/azure/aks-gitops/variables.tf | 5 +++++ cluster/common/flux/deploy_flux.sh | 5 +++-- cluster/common/flux/main.tf | 2 +- cluster/common/flux/variables.tf | 5 +++++ .../azure-multiple-clusters-waf-tm-apimgmt/aks-centralus.tf | 1 + .../azure-multiple-clusters-waf-tm-apimgmt/aks-eastus.tf | 1 + .../azure-multiple-clusters-waf-tm-apimgmt/aks-variables.tf | 5 +++++ .../azure-multiple-clusters-waf-tm-apimgmt/aks-westus.tf | 1 + .../gotest/bedrock_Azure_apim_waf_mc_test.go | 1 + .../environments/azure-multiple-clusters/aks-centralus.tf | 1 + cluster/environments/azure-multiple-clusters/aks-eastus.tf | 1 + .../environments/azure-multiple-clusters/aks-variables.tf | 5 +++++ cluster/environments/azure-multiple-clusters/aks-westus.tf | 1 + cluster/environments/azure-simple/main.tf | 1 + cluster/environments/azure-simple/terraform.tfvars | 1 + cluster/environments/azure-simple/variables.tf | 5 +++++ .../azure-single-keyvault-cosmos-mongo-db-simple/README.md | 1 + .../azure-single-keyvault-cosmos-mongo-db-simple/main.tf | 1 + .../variables.tf | 5 +++++ cluster/environments/azure-single-keyvault/README.md | 2 ++ cluster/environments/azure-single-keyvault/main.tf | 1 + cluster/environments/azure-single-keyvault/variables.tf | 5 +++++ cluster/environments/azure-velero-restore/variables.tf | 5 +++++ docs/azure-simple/README.md | 1 + test/bedrock_Azure_mc_test.go | 1 + 26 files changed, 61 insertions(+), 3 deletions(-) diff --git a/cluster/azure/aks-gitops/main.tf b/cluster/azure/aks-gitops/main.tf index f88b470..80c2d08 100644 --- a/cluster/azure/aks-gitops/main.tf +++ b/cluster/azure/aks-gitops/main.tf @@ -31,6 +31,7 @@ module "flux" { gitops_ssh_key = "${var.gitops_ssh_key}" gitops_path = "${var.gitops_path}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" gitops_url_branch = "${var.gitops_url_branch}" enable_flux = "${var.enable_flux}" flux_recreate = "${var.flux_recreate}" diff --git a/cluster/azure/aks-gitops/variables.tf b/cluster/azure/aks-gitops/variables.tf index 7e79cf7..f2ef63e 100644 --- a/cluster/azure/aks-gitops/variables.tf +++ b/cluster/azure/aks-gitops/variables.tf @@ -50,6 +50,11 @@ variable "gitops_poll_interval" { default = "5m" } +variable "gitops_label" { + type = "string" + default = "flux-sync" +} + variable "gitops_url_branch" { type = "string" } diff --git a/cluster/common/flux/deploy_flux.sh b/cluster/common/flux/deploy_flux.sh index 7c7c466..cbd58e9 100755 --- a/cluster/common/flux/deploy_flux.sh +++ b/cluster/common/flux/deploy_flux.sh @@ -1,5 +1,5 @@ #!/bin/sh -while getopts :b:f:g:k:d:e:c:s:r:t:z: option +while getopts :b:f:g:k:d:e:c:l:s:r:t:z: option do case "${option}" in b) GITOPS_URL_BRANCH=${OPTARG};; @@ -9,6 +9,7 @@ do d) REPO_ROOT_DIR=${OPTARG};; e) GITOPS_PATH=${OPTARG};; c) GITOPS_POLL_INTERVAL=${OPTARG};; + l) GITOPS_LABEL=${OPTARG};; s) ACR_ENABLED=${OPTARG};; r) FLUX_IMAGE_REPOSITORY=${OPTARG};; t) FLUX_IMAGE_TAG=${OPTARG};; @@ -58,7 +59,7 @@ fi # git url: where flux monitors for manifests # git ssh secret: kubernetes secret object for flux to read/write access to manifests repo echo "generating flux manifests with helm template" -if ! helm template . --name "$RELEASE_NAME" --namespace "$KUBE_NAMESPACE" --values values.yaml --set image.repository="$FLUX_IMAGE_REPOSITORY" --set image.tag="$FLUX_IMAGE_TAG" --output-dir "./$FLUX_MANIFESTS" --set git.url="$GITOPS_SSH_URL" --set git.branch="$GITOPS_URL_BRANCH" --set git.secretName="$KUBE_SECRET_NAME" --set git.path="$GITOPS_PATH" --set git.pollInterval="$GITOPS_POLL_INTERVAL" --set registry.acr.enabled="$ACR_ENABLED" --set syncGarbageCollection.enabled="$GC_ENABLED"; then +if ! helm template . --name "$RELEASE_NAME" --namespace "$KUBE_NAMESPACE" --values values.yaml --set image.repository="$FLUX_IMAGE_REPOSITORY" --set image.tag="$FLUX_IMAGE_TAG" --output-dir "./$FLUX_MANIFESTS" --set git.url="$GITOPS_SSH_URL" --set git.branch="$GITOPS_URL_BRANCH" --set git.secretName="$KUBE_SECRET_NAME" --set git.path="$GITOPS_PATH" --set git.pollInterval="$GITOPS_POLL_INTERVAL" --set git.label="$GITOPS_LABEL" --set registry.acr.enabled="$ACR_ENABLED" --set syncGarbageCollection.enabled="$GC_ENABLED"; then echo "ERROR: failed to helm template" exit 1 fi diff --git a/cluster/common/flux/main.tf b/cluster/common/flux/main.tf index d98ec1f..5ec93ac 100644 --- a/cluster/common/flux/main.tf +++ b/cluster/common/flux/main.tf @@ -6,7 +6,7 @@ resource "null_resource" "deploy_flux" { count = "${var.enable_flux ? 1 : 0}" provisioner "local-exec" { - command = "echo 'Need to use this var so terraform waits for kubeconfig ' ${var.kubeconfig_complete};KUBECONFIG=${var.output_directory}/${var.kubeconfig_filename} ${path.module}/deploy_flux.sh -b '${var.gitops_url_branch}' -f '${var.flux_repo_url}' -g '${var.gitops_ssh_url}' -k '${var.gitops_ssh_key}' -d '${var.flux_clone_dir}' -c '${var.gitops_poll_interval}' -e '${var.gitops_path}' -s '${var.acr_enabled}' -r '${var.flux_image_repository}' -t '${var.flux_image_tag}' -z '${var.gc_enabled}'" + command = "echo 'Need to use this var so terraform waits for kubeconfig ' ${var.kubeconfig_complete};KUBECONFIG=${var.output_directory}/${var.kubeconfig_filename} ${path.module}/deploy_flux.sh -b '${var.gitops_url_branch}' -f '${var.flux_repo_url}' -g '${var.gitops_ssh_url}' -k '${var.gitops_ssh_key}' -d '${var.flux_clone_dir}' -c '${var.gitops_poll_interval}' -l '${var.gitops_label}' -e '${var.gitops_path}' -s '${var.acr_enabled}' -r '${var.flux_image_repository}' -t '${var.flux_image_tag}' -z '${var.gc_enabled}'" } triggers = { diff --git a/cluster/common/flux/variables.tf b/cluster/common/flux/variables.tf index d49a234..d08f31c 100644 --- a/cluster/common/flux/variables.tf +++ b/cluster/common/flux/variables.tf @@ -25,6 +25,11 @@ variable "gitops_poll_interval" { default = "5m" } +variable "gitops_label" { + type = "string" + default = "flux-sync" +} + variable "gitops_ssh_url" { description = "ssh git clone repository URL with Kubernetes manifests including services which runs in the cluster. Flux monitors this repo for Kubernetes manifest additions/changes preriodiaclly and apply them in the cluster." type = "string" diff --git a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-centralus.tf b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-centralus.tf index 18cb2c3..5e676d6 100644 --- a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-centralus.tf +++ b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-centralus.tf @@ -58,6 +58,7 @@ module "central_flux" { flux_clone_dir = "${local.central_flux_clone_dir}" gitops_path = "${var.gitops_central_path}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" } module "central_tm_endpoint" { diff --git a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-eastus.tf b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-eastus.tf index 3f8257a..534f948 100644 --- a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-eastus.tf +++ b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-eastus.tf @@ -58,6 +58,7 @@ module "east_flux" { flux_clone_dir = "${local.east_flux_clone_dir}" gitops_path = "${var.gitops_east_path}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" } # # create a dynamic public ip and associate with traffic manger endpoint diff --git a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-variables.tf b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-variables.tf index b62d803..e1da464 100644 --- a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-variables.tf +++ b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-variables.tf @@ -36,6 +36,11 @@ variable "gitops_poll_interval" { type = "string" } +variable "gitops_label" { + type = "string" + default = "flux-sync" +} + variable "gitops_ssh_key" { type = "string" } diff --git a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-westus.tf b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-westus.tf index 20eee79..f61feb3 100644 --- a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-westus.tf +++ b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/aks-westus.tf @@ -58,6 +58,7 @@ module "west_flux" { flux_clone_dir = "${local.west_flux_clone_dir}" gitops_path = "${var.gitops_west_path}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" } # create a dynamic public ip and associate with traffic manger endpoint diff --git a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/gotest/bedrock_Azure_apim_waf_mc_test.go b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/gotest/bedrock_Azure_apim_waf_mc_test.go index 88ff7b4..8a5a0c0 100644 --- a/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/gotest/bedrock_Azure_apim_waf_mc_test.go +++ b/cluster/environments/azure-multiple-clusters-waf-tm-apimgmt/gotest/bedrock_Azure_apim_waf_mc_test.go @@ -79,6 +79,7 @@ func TestIT_Bedrock_AzureMC_APIM_Test(t *testing.T) { "gitops_ssh_url": "git@github.com:timfpark/fabrikate-cloud-native-manifests.git", "gitops_ssh_key": sshkey, "gitops_poll_interval": "5m", + "gitops_label": "flux-sync" "traffic_manager_profile_name": tmName, "traffic_manager_dns_name": tm_dnsprefix, diff --git a/cluster/environments/azure-multiple-clusters/aks-centralus.tf b/cluster/environments/azure-multiple-clusters/aks-centralus.tf index 7401b32..ef9df40 100644 --- a/cluster/environments/azure-multiple-clusters/aks-centralus.tf +++ b/cluster/environments/azure-multiple-clusters/aks-centralus.tf @@ -42,6 +42,7 @@ module "central_aks_gitops" { gitops_path = "${var.gitops_central_path}" gitops_url_branch = "${var.gitops_central_url_branch}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" resource_group_name = "${local.central_rg_name}" service_cidr = "${var.central_service_cidr}" service_principal_id = "${var.service_principal_id}" diff --git a/cluster/environments/azure-multiple-clusters/aks-eastus.tf b/cluster/environments/azure-multiple-clusters/aks-eastus.tf index c4672c6..0c5559e 100644 --- a/cluster/environments/azure-multiple-clusters/aks-eastus.tf +++ b/cluster/environments/azure-multiple-clusters/aks-eastus.tf @@ -42,6 +42,7 @@ module "east_aks_gitops" { gitops_path = "${var.gitops_east_path}" gitops_url_branch = "${var.gitops_east_url_branch}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" resource_group_name = "${local.east_rg_name}" service_cidr = "${var.east_service_cidr}" service_principal_id = "${var.service_principal_id}" diff --git a/cluster/environments/azure-multiple-clusters/aks-variables.tf b/cluster/environments/azure-multiple-clusters/aks-variables.tf index d5bf0ec..82a8510 100644 --- a/cluster/environments/azure-multiple-clusters/aks-variables.tf +++ b/cluster/environments/azure-multiple-clusters/aks-variables.tf @@ -36,6 +36,11 @@ variable "gitops_poll_interval" { default = "5m" } +variable "gitops_label" { + type = "string" + default = "flux-sync" +} + variable "gitops_ssh_key" { type = "string" } diff --git a/cluster/environments/azure-multiple-clusters/aks-westus.tf b/cluster/environments/azure-multiple-clusters/aks-westus.tf index 2bcba6c..fbf1da2 100644 --- a/cluster/environments/azure-multiple-clusters/aks-westus.tf +++ b/cluster/environments/azure-multiple-clusters/aks-westus.tf @@ -42,6 +42,7 @@ module "west_aks_gitops" { gitops_path = "${var.gitops_west_path}" gitops_url_branch = "${var.gitops_west_url_branch}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" resource_group_name = "${local.west_rg_name}" service_cidr = "${var.west_service_cidr}" service_principal_id = "${var.service_principal_id}" diff --git a/cluster/environments/azure-simple/main.tf b/cluster/environments/azure-simple/main.tf index a292cf9..254f291 100644 --- a/cluster/environments/azure-simple/main.tf +++ b/cluster/environments/azure-simple/main.tf @@ -35,6 +35,7 @@ module "aks-gitops" { gitops_ssh_key = "${var.gitops_ssh_key}" gitops_path = "${var.gitops_path}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" gitops_url_branch = "${var.gitops_url_branch}" ssh_public_key = "${var.ssh_public_key}" resource_group_name = "${data.azurerm_resource_group.cluster_rg.name}" diff --git a/cluster/environments/azure-simple/terraform.tfvars b/cluster/environments/azure-simple/terraform.tfvars index 2ab3ae9..fcc96e4 100644 --- a/cluster/environments/azure-simple/terraform.tfvars +++ b/cluster/environments/azure-simple/terraform.tfvars @@ -17,3 +17,4 @@ vnet_name = "" # gitops_path = "prod" # network_policy = "calico" # oms_agent_enabled = "false" +# gitops_label = "custom-flux-sync" diff --git a/cluster/environments/azure-simple/variables.tf b/cluster/environments/azure-simple/variables.tf index 553b8c7..7221aec 100644 --- a/cluster/environments/azure-simple/variables.tf +++ b/cluster/environments/azure-simple/variables.tf @@ -77,6 +77,11 @@ variable "gitops_poll_interval" { default = "5m" } +variable "gitops_label" { + type = "string" + default = "flux-sync" +} + variable "vnet_name" { type = "string" } diff --git a/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/README.md b/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/README.md index ee87c68..9f1cc7f 100644 --- a/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/README.md +++ b/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/README.md @@ -77,6 +77,7 @@ service_principal_secret = "" # gitops_url_branch = "release-123" # gitops_poll_interval = "30s" # gitops_path = "prod" +# gitops_label = "custom-flux-sync" ``` diff --git a/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/main.tf b/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/main.tf index 3280902..a00249d 100644 --- a/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/main.tf +++ b/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/main.tf @@ -32,6 +32,7 @@ module "aks-gitops" { gitops_ssh_key = "${var.gitops_ssh_key}" gitops_path = "${var.gitops_path}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" gitops_url_branch = "${var.gitops_url_branch}" resource_group_name = "${data.azurerm_resource_group.cluster_rg.name}" service_principal_id = "${var.service_principal_id}" diff --git a/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/variables.tf b/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/variables.tf index 1bf6039..aeb67d8 100644 --- a/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/variables.tf +++ b/cluster/environments/azure-single-keyvault-cosmos-mongo-db-simple/variables.tf @@ -40,6 +40,11 @@ variable "gitops_poll_interval" { default = "5m" } +variable "gitops_label" { + type = "string" + default = "flux-sync" +} + variable "gitops_ssh_url" { type = "string" } diff --git a/cluster/environments/azure-single-keyvault/README.md b/cluster/environments/azure-single-keyvault/README.md index f61b02e..a5951ba 100644 --- a/cluster/environments/azure-single-keyvault/README.md +++ b/cluster/environments/azure-single-keyvault/README.md @@ -91,6 +91,8 @@ tenant_id = "" # gitops_poll_interval = "30s" # gitops_path = "prod" + +# gitops_label = "custom-flux-sync" ``` To deploy the azure-single-keyvault environment, run the following commands in your environment directory: diff --git a/cluster/environments/azure-single-keyvault/main.tf b/cluster/environments/azure-single-keyvault/main.tf index 139f6d3..3c7d432 100644 --- a/cluster/environments/azure-single-keyvault/main.tf +++ b/cluster/environments/azure-single-keyvault/main.tf @@ -33,6 +33,7 @@ module "aks-gitops" { gitops_ssh_key = "${var.gitops_ssh_key}" gitops_path = "${var.gitops_path}" gitops_poll_interval = "${var.gitops_poll_interval}" + gitops_label = "${var.gitops_label}" gitops_url_branch = "${var.gitops_url_branch}" resource_group_name = "${data.azurerm_resource_group.cluster_rg.name}" service_principal_id = "${var.service_principal_id}" diff --git a/cluster/environments/azure-single-keyvault/variables.tf b/cluster/environments/azure-single-keyvault/variables.tf index 6971df3..cd51efc 100644 --- a/cluster/environments/azure-single-keyvault/variables.tf +++ b/cluster/environments/azure-single-keyvault/variables.tf @@ -45,6 +45,11 @@ variable "gitops_poll_interval" { default = "5m" } +variable "gitops_label" { + type = "string" + default = "flux-sync" +} + variable "gitops_ssh_url" { type = "string" } diff --git a/cluster/environments/azure-velero-restore/variables.tf b/cluster/environments/azure-velero-restore/variables.tf index 71925d9..95b3ce5 100644 --- a/cluster/environments/azure-velero-restore/variables.tf +++ b/cluster/environments/azure-velero-restore/variables.tf @@ -45,6 +45,11 @@ variable "gitops_poll_interval" { default = "5m" } +variable "gitops_label" { + type = "string" + default = "flux-sync" +} + variable "gitops_ssh_url" { type = "string" } diff --git a/docs/azure-simple/README.md b/docs/azure-simple/README.md index d1d8666..01df6a2 100644 --- a/docs/azure-simple/README.md +++ b/docs/azure-simple/README.md @@ -277,6 +277,7 @@ vnet_name = "" #-------------------------------------------------------------- # gitops_url_branch = "release-123" # gitops_poll_interval = "30s" +# gitops_label = "custom-flux-sync" # gitops_path = "prod" # network_policy = "calico" # network_plugin = "azure" diff --git a/test/bedrock_Azure_mc_test.go b/test/bedrock_Azure_mc_test.go index 7195101..60c7cc7 100644 --- a/test/bedrock_Azure_mc_test.go +++ b/test/bedrock_Azure_mc_test.go @@ -183,6 +183,7 @@ func TestIT_Bedrock_AzureMC_Test(t *testing.T) { "gitops_ssh_url": "git@github.com:timfpark/fabrikate-cloud-native-manifests.git", "gitops_ssh_key": sshkey, "gitops_poll_interval": "5m", + "gitops_label": "flux-sync", "keyvault_name": kvName, "keyvault_resource_group": kvRG,