Skip to content

Commit

Permalink
feat: Add allowLongAppNames to support longer application names
Browse files Browse the repository at this point in the history
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 #1183 for how to enable it in Argo CD.

Closes issue #1182

This was implemented by @jdvgh
In order to get this through our CI, I had to create this new PR.
Old PR: #1183
  • Loading branch information
jdvgh authored and sven-urbanski-freiheit-com committed Mar 27, 2024
1 parent cb094ef commit 805d0df
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 14 deletions.
2 changes: 2 additions & 0 deletions charts/kuberpult/templates/cd-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions charts/kuberpult/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions docker-compose-earthly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 19 additions & 6 deletions pkg/valid/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,39 @@ 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 (
applicationNameRx = regexp.MustCompile(AppNameRegExp)
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)
Expand Down
2 changes: 2 additions & 0 deletions services/cd-service/pkg/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions services/cd-service/pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion services/cd-service/pkg/repository/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 805d0df

Please sign in to comment.