Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions util/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/base64"
"encoding/hex"
"fmt"
"net/url"
"os"
Expand Down Expand Up @@ -235,6 +236,8 @@ const (
anonymousUserEnabledKey = "users.anonymous.enabled"
// diffOptions is the key where diff options are configured
resourceCompareOptionsKey = "resource.compareoptions"
// maximum number of allowed chars in kubernetes labels
appInstanceLabelMaxLen = 63
)

// SettingsManager holds config info for a new manager with which to access Kubernetes ConfigMaps.
Expand Down Expand Up @@ -434,6 +437,10 @@ func (mgr *SettingsManager) GetAppInstanceLabelKey() (string, error) {
if label == "" {
return common.LabelKeyAppInstance, nil
}
if len(label) > appInstanceLabelMaxLen {
hash := sha256.Sum224([]byte(label))
return "sha224-" + hex.EncodeToString(hash[:]), nil
}
return label, nil
}

Expand Down
9 changes: 9 additions & 0 deletions util/settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ func TestGetAppInstanceLabelKey(t *testing.T) {
assert.Equal(t, "testLabel", label)
}

func TestGetAppInstanceLabelForLengthyLabel(t *testing.T) {
_, settingsManager := fixtures(map[string]string{
"application.instanceLabelKey": "this.is.definitely.a.string.that.is.used.for.tests.and.that.is.longer.than.63.characters",
})
label, err := settingsManager.GetAppInstanceLabelKey()
assert.NoError(t, err)
assert.Equal(t, "sha224-e1727dad441e85277dd5948c7afa1785124be3a007b2fe11238929b6", label)
}

func TestGetResourceOverrides(t *testing.T) {
ignoreStatus := v1alpha1.ResourceOverride{IgnoreDifferences: v1alpha1.OverrideIgnoreDiff{
JSONPointers: []string{"/status"},
Expand Down