Skip to content

Commit

Permalink
allow long change group names (#337)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitriy Kalinin <dkalinin@vmware.com>
  • Loading branch information
cppforlife and Dmitriy Kalinin authored Oct 6, 2021
1 parent 3dd4181 commit b2c6da6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
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)
}
}

0 comments on commit b2c6da6

Please sign in to comment.