From fbd55a547144373e044980b9a9738e19962d187d Mon Sep 17 00:00:00 2001 From: Simon Gottschlag Date: Fri, 14 Oct 2022 23:07:08 +0200 Subject: [PATCH] Fix gitops-promotion compatibility (#30) * change notifications to replicate fluxcd behaviour * fix compat --- src/config/config.go | 2 ++ src/config/config_test.go | 4 ++++ src/notification/azure_devops.go | 3 ++- src/reconcile/reconcile.go | 4 +--- terraform-module/azcagit.tf | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/config/config.go b/src/config/config.go index 03c8fa6..70a87ac 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -8,6 +8,7 @@ import ( type Config struct { ResourceGroupName string `json:"resource_group_name" arg:"-g,--resource-group-name,env:RESOURCE_GROUP_NAME,required" help:"Azure Resource Group Name"` + Environment string `json:"environment" arg:"--environment,env:ENVIRONMENT,required" help:"The current environment that azcagit is running in"` SubscriptionID string `json:"subscription_id" arg:"-s,--subscription-id,env:AZURE_SUBSCRIPTION_ID,required" help:"Azure Subscription ID"` ManagedEnvironmentID string `json:"managed_environment_id" arg:"-m,--managed-environment-id,env:MANAGED_ENVIRONMENT_ID,required" help:"Azure Container Apps Managed Environment ID"` KeyVaultName string `json:"key_vault_name" arg:"-k,--key-vault-name,env:KEY_VAULT_NAME,required" help:"Azure KeyVault name to extract secrets from"` @@ -26,6 +27,7 @@ type Config struct { DaprPubsubName string `json:"dapr_pubsub_name" arg:"--dapr-pubsub-name,env:DAPR_PUBSUB_NAME" default:"azcagit-trigger" help:"The PubSub name for the trigger"` DaprTopic string `json:"dapr_topic" arg:"--dapr-topic-name,env:DAPR_TOPIC_NAME,required" help:"The PubSub topic name for the trigger"` NotificationsEnabled bool `json:"notifications_enabled" arg:"--notifications-enabled,env:NOTIFICATIONS_ENABLED" default:"false" help:"Sets if Notifications should be sent to the git provider, should be disabled if no token is provided in git url"` + NotificationGroup string `json:"notification_group" arg:"--notification-group,env:NOTIFICATION_GROUP" default:"apps" help:"The notification group used by gitops-promotion"` DebugEnabled bool `json:"debug_enabled" arg:"--debug,env:DEBUG" default:"false" help:"Enabled debug logging"` } diff --git a/src/config/config_test.go b/src/config/config_test.go index f8e4ec9..70519b7 100644 --- a/src/config/config_test.go +++ b/src/config/config_test.go @@ -11,6 +11,8 @@ func TestNewConfig(t *testing.T) { "/foo/bar/bin", "--resource-group-name", "foo", + "--environment", + "foobar", "--subscription-id", "bar", "--managed-environment-id", @@ -30,6 +32,7 @@ func TestNewConfig(t *testing.T) { require.NoError(t, err) require.Equal(t, Config{ ResourceGroupName: "foo", + Environment: "foobar", SubscriptionID: "bar", ManagedEnvironmentID: "baz", KeyVaultName: "ze-keyvault", @@ -43,6 +46,7 @@ func TestNewConfig(t *testing.T) { DaprAppPort: 8080, DaprPubsubName: "azcagit-trigger", DaprTopic: "ze-topic", + NotificationGroup: "apps", }, cfg) } diff --git a/src/notification/azure_devops.go b/src/notification/azure_devops.go index a524db7..e6688a4 100644 --- a/src/notification/azure_devops.go +++ b/src/notification/azure_devops.go @@ -78,7 +78,8 @@ func (a *AzureDevOpsNotification) Send(ctx context.Context, event NotificationEv Description: &event.Description, State: &state, Context: &git.GitStatusContext{ - Genre: toPtr("azcagit"), + // using fluxcd to be compatible with gitops-promotion + Genre: toPtr("fluxcd"), Name: &event.Name, }, }, diff --git a/src/reconcile/reconcile.go b/src/reconcile/reconcile.go index d2e78db..e03fe08 100644 --- a/src/reconcile/reconcile.go +++ b/src/reconcile/reconcile.go @@ -334,9 +334,7 @@ func (r *Reconciler) sendNotification(ctx context.Context, revision string, reco state = notification.NotificationStateFailure } - location := strings.ReplaceAll(r.cfg.Location, " ", "") - resourceGroup := r.cfg.ResourceGroupName - name := strings.ToLower(fmt.Sprintf("%s/%s", location, resourceGroup)) + name := strings.ToLower(fmt.Sprintf("%s/%s-%s", r.cfg.ResourceGroupName, r.cfg.NotificationGroup, r.cfg.Environment)) event := notification.NotificationEvent{ Revision: revision, State: state, diff --git a/terraform-module/azcagit.tf b/terraform-module/azcagit.tf index 4e64a9c..e65e220 100644 --- a/terraform-module/azcagit.tf +++ b/terraform-module/azcagit.tf @@ -88,6 +88,7 @@ resource "azapi_resource" "container_app_azcagit" { image = "ghcr.io/xenitab/azcagit:${var.azcagit_version}" args = [ "--resource-group-name", azurerm_resource_group.tenant.name, + "--environment", var.environment, "--subscription-id", data.azurerm_client_config.current.subscription_id, "--managed-environment-id", azapi_resource.managed_environment.id, "--key-vault-name", azurerm_key_vault.tenant_kv.name,