From 805d0df36c5e6309e92ff333f68ab99c1fbbbbdd Mon Sep 17 00:00:00 2001 From: "Eilers, Jonas" <133217951+jdvgh@users.noreply.github.com> Date: Wed, 27 Mar 2024 12:18:09 +0100 Subject: [PATCH] feat: Add allowLongAppNames to support longer application names This introduces the helm parameter `cd.allowLongAppNames`. When true, kuberpult accepts app names longer than 39, but maximum 70 characters. This requires some configuration in Argo CD to work. See https://github.com/freiheit-com/kuberpult/pull/1183 for how to enable it in Argo CD. Closes issue https://github.com/freiheit-com/kuberpult/issues/1182 This was implemented by @jdvgh In order to get this through our CI, I had to create this new PR. Old PR: https://github.com/freiheit-com/kuberpult/pull/1183 --- charts/kuberpult/templates/cd-service.yaml | 2 ++ charts/kuberpult/values.yaml | 6 +++++ docker-compose-earthly.yml | 1 + docker-compose.yml | 1 + pkg/valid/validations.go | 25 ++++++++++++++----- services/cd-service/pkg/cmd/server.go | 2 ++ .../cd-service/pkg/repository/repository.go | 14 +++++------ .../cd-service/pkg/repository/transformer.go | 2 +- .../src/ui/components/SideBar/SideBar.scss | 1 + 9 files changed, 40 insertions(+), 14 deletions(-) diff --git a/charts/kuberpult/templates/cd-service.yaml b/charts/kuberpult/templates/cd-service.yaml index e26965e9fa..756f79f51c 100644 --- a/charts/kuberpult/templates/cd-service.yaml +++ b/charts/kuberpult/templates/cd-service.yaml @@ -193,6 +193,8 @@ spec: value: "{{ .Values.datadogProfiling.enabled }}" - name: KUBERPULT_MAXIMUM_QUEUE_SIZE value: "{{ .Values.cd.backendConfig.queueSize }}" + - name: KUBERPULT_ALLOW_LONG_APP_NAMES + value: "{{ .Values.cd.allowLongAppNames }}" volumeMounts: - name: repository mountPath: /repository diff --git a/charts/kuberpult/values.yaml b/charts/kuberpult/values.yaml index 2452abbd3d..c4f8844090 100644 --- a/charts/kuberpult/values.yaml +++ b/charts/kuberpult/values.yaml @@ -67,6 +67,12 @@ log: level: "WARN" cd: image: kuberpult-cd-service +# By default, kuberpult allows names of apps to be max 39 characters. +# This is usually enough. If you want to extend the length to up to 70 characters, +# You need to ensure that ArgoCD has no issue with this. Set the Argo CD helm parameter: +# `configs.cm.application.resourceTrackingMethod: annotation+label` +# Note that there is no simple way in kuberpult to rename an app. + allowLongAppNames: false backendConfig: create: false # Add backend config for health checks on GKE only timeoutSec: 300 # 30sec is the default on gcp loadbalancers, however kuberpult needs more with parallel requests. It is the time how long the loadbalancer waits for kuberpult to finish calls to the rest endpoint "release" diff --git a/docker-compose-earthly.yml b/docker-compose-earthly.yml index aab2913a5f..ede2126682 100644 --- a/docker-compose-earthly.yml +++ b/docker-compose-earthly.yml @@ -10,6 +10,7 @@ services: - KUBERPULT_DEX_ENABLED=false - KUBERPULT_GIT_WRITE_COMMIT_DATA=true - KUBERPULT_MAXIMUM_QUEUE_SIZE=2 + - KUBERPULT_ALLOW_LONG_APP_NAMES=true ports: - "8080:8080" - "8443:8443" diff --git a/docker-compose.yml b/docker-compose.yml index e03c2e93f5..416b913fbf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,7 @@ services: - KUBERPULT_DEX_ENABLED=false - KUBERPULT_GIT_NETWORK_TIMEOUT=3s - KUBERPULT_GIT_WRITE_COMMIT_DATA=true + - KUBERPULT_ALLOW_LONG_APP_NAMES=true ports: - "8080:8080" - "8443:8443" diff --git a/pkg/valid/validations.go b/pkg/valid/validations.go index 24ba0bca58..37a4174d0e 100644 --- a/pkg/valid/validations.go +++ b/pkg/valid/validations.go @@ -17,17 +17,20 @@ Copyright 2023 freiheit.com*/ package valid import ( + "os" "regexp" "strings" ) const ( - MaxAppNameLen = 39 - AppNameRegExp = `\A[a-z0-9]+(?:-[a-z0-9]+)*\z` - TeamNameRegExp = AppNameRegExp - EnvNameRegExp = AppNameRegExp - SHA1CommitIDLength = 40 - commitIDPrefixRegExp = `^[0-9a-fA-F]*$` + FallbackMaxAppNameLength = 39 + LongAppNameLength = 70 + KUBERPULT_ALLOW_LONG_APP_NAMES = "KUBERPULT_ALLOW_LONG_APP_NAMES" + AppNameRegExp = `\A[a-z0-9]+(?:-[a-z0-9]+)*\z` + TeamNameRegExp = AppNameRegExp + EnvNameRegExp = AppNameRegExp + SHA1CommitIDLength = 40 + commitIDPrefixRegExp = `^[0-9a-fA-F]*$` ) var ( @@ -35,8 +38,18 @@ var ( teamNameRx = regexp.MustCompile(TeamNameRegExp) envNameRx = regexp.MustCompile(EnvNameRegExp) commitIDPrefixRx = regexp.MustCompile(commitIDPrefixRegExp) + MaxAppNameLen = setupMaxAppNameLen() ) +func setupMaxAppNameLen() int { + maxAppNameLength := FallbackMaxAppNameLength + res, ok := os.LookupEnv(KUBERPULT_ALLOW_LONG_APP_NAMES) + if ok && res == "true" { + maxAppNameLength = LongAppNameLength + } + return maxAppNameLength +} + // {application}-{environment} should be a valid dns name func EnvironmentName(env string) bool { return len(env) < 21 && envNameRx.MatchString(env) diff --git a/services/cd-service/pkg/cmd/server.go b/services/cd-service/pkg/cmd/server.go index 1fa28b1acc..592c93bb64 100755 --- a/services/cd-service/pkg/cmd/server.go +++ b/services/cd-service/pkg/cmd/server.go @@ -82,6 +82,7 @@ type Config struct { GitWebUrl string `default:"" split_words:"true"` GitMaximumCommitsPerPush uint `default:"1" split_words:"true"` MaximumQueueSize uint `default:"5" split_words:"true"` + AllowLongAppNames bool `default:"false" split_words:"true"` } func (c *Config) storageBackend() repository.StorageBackend { @@ -218,6 +219,7 @@ func RunServer() { WriteCommitData: c.GitWriteCommitData, MaximumCommitsPerPush: c.GitMaximumCommitsPerPush, MaximumQueueSize: c.MaximumQueueSize, + AllowLongAppNames: c.AllowLongAppNames, } repo, repoQueue, err := repository.New2(ctx, cfg) if err != nil { diff --git a/services/cd-service/pkg/repository/repository.go b/services/cd-service/pkg/repository/repository.go index 47f1e0ede5..f7e84f9fce 100644 --- a/services/cd-service/pkg/repository/repository.go +++ b/services/cd-service/pkg/repository/repository.go @@ -193,14 +193,14 @@ type RepositoryConfig struct { // if set, kuberpult will generate push events to argoCd whenever it writes to the manifest repo: ArgoWebhookUrl string // the url to the git repo, like the browser requires it (https protocol) - WebURL string - DogstatsdEvents bool - WriteCommitData bool - WebhookResolver WebhookResolver - + WebURL string + DogstatsdEvents bool + WriteCommitData bool + WebhookResolver WebhookResolver MaximumCommitsPerPush uint - - MaximumQueueSize uint + MaximumQueueSize uint + // Extend maximum AppName length + AllowLongAppNames bool } func openOrCreate(path string, storageBackend StorageBackend) (*git.Repository, error) { diff --git a/services/cd-service/pkg/repository/transformer.go b/services/cd-service/pkg/repository/transformer.go index 89477123a3..96953364e2 100644 --- a/services/cd-service/pkg/repository/transformer.go +++ b/services/cd-service/pkg/repository/transformer.go @@ -393,7 +393,7 @@ func (c *CreateApplicationVersion) Transform( } fs := state.Filesystem if !valid.ApplicationName(c.Application) { - return "", GetCreateReleaseAppNameTooLong(c.Application, valid.AppNameRegExp, valid.MaxAppNameLen) + return "", GetCreateReleaseAppNameTooLong(c.Application, valid.AppNameRegExp, uint32(valid.MaxAppNameLen)) } releaseDir := releasesDirectoryWithVersion(fs, c.Application, version) appDir := applicationDirectory(fs, c.Application) diff --git a/services/frontend-service/src/ui/components/SideBar/SideBar.scss b/services/frontend-service/src/ui/components/SideBar/SideBar.scss index 1f349253aa..965dbb6cd8 100644 --- a/services/frontend-service/src/ui/components/SideBar/SideBar.scss +++ b/services/frontend-service/src/ui/components/SideBar/SideBar.scss @@ -71,6 +71,7 @@ Copyright 2023 freiheit.com*/ .mdc-drawer-sidebar-list-item-text-summary { @extend .text-regular; + word-break: break-word; } .mdc-drawer-sidebar-list-item-delete-all {