Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow long change group names #337

Merged
merged 1 commit into from
Oct 6, 2021
Merged
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
14 changes: 13 additions & 1 deletion pkg/kapp/diffgraph/change_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@ func (r ChangeGroup) Validate() error {
if len(r.Name) == 0 {
return fmt.Errorf("Expected non-empty group name")
}
errStrs := k8sval.IsQualifiedName(r.Name)
errStrs := r.isQualifiedNameWithoutLen(r.Name)
if len(errStrs) > 0 {
return fmt.Errorf("Expected change group name %q to be a qualified name: %s", r.Name, strings.Join(errStrs, "; "))
}
return nil
}

func (r ChangeGroup) isQualifiedNameWithoutLen(name string) []string {
errStrs := k8sval.IsQualifiedName(name)
var updatedErrStrs []string
for _, err := range errStrs {
// Allow change group names to have more characters than the default maxLength
if !strings.Contains(err, k8sval.MaxLenError(k8sval.DNS1035LabelMaxLength)) {
updatedErrStrs = append(updatedErrStrs, err)
}
}
return updatedErrStrs
}
45 changes: 45 additions & 0 deletions pkg/kapp/diffgraph/change_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0

package diffgraph_test

import (
"testing"
"strings"

ctldgraph "github.com/k14s/kapp/pkg/kapp/diffgraph"
"github.com/stretchr/testify/require"
)

func TestNewChangeGroupFromAnnString(t *testing.T) {
names := []string{
"valid",
"valid-name",
"valid/valid",
"valid-name/valid",
"valid-name.com",
"valid-name.com/valid",
"valid-name.com/valid-name_Another_Name--valid",
"valid-name.com/valid-name_CustomResourceDefinition--valid",
// Allow arbitrary long names since it might be populated with data via placeholders
"valid-name.com/valid-name_CustomResourceDefinition--valid"+strings.Repeat("a", 1000),
// Example from pinniped of a long name
"change-groups.kapp.k14s.io/crds-authentication.concierge.pinniped.dev-WebhookAuthenticator",
}
for _, name := range names {
cg, err := ctldgraph.NewChangeGroupFromAnnString(name)
require.NoError(t, err)
require.Equal(t, cg.Name, name)
}

names = []string{
"_",
"invalid/",
"invalid/_",
"/_",
}
for _, name := range names {
_, err := ctldgraph.NewChangeGroupFromAnnString(name)
require.Error(t, err)
}
}