Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion pkg/sync/sync_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ func (sc *syncContext) getSyncTasks() (_ syncTasks, successful bool) {
if targetObj.GetName() == "" {
var syncRevision string
if len(sc.revision) >= 8 {
syncRevision = sc.revision[0:7]
syncRevision = strings.Trim(sc.revision[0:7], ".")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semver also allows dashes (-) and plus (+), I would trim for that too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dashes should be fine. Let's keep only letters, numbers and -.

} else {
syncRevision = sc.revision
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/sync/sync_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation"

"github.com/go-logr/logr"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -977,6 +978,24 @@
assert.Contains(t, tasks[1].name(), "foobar-postsync-")
assert.Equal(t, "", pod.GetName())
})

t.Run("Long revision with dots", func(t *testing.T) {
syncCtx := newTestSyncCtx(nil)
pod := testingutils.NewPod()
pod.SetName("")
pod.SetAnnotations(map[string]string{synccommon.AnnotationKeyHook: "PreSync,PostSync"})
syncCtx.hooks = []*unstructured.Unstructured{pod}
syncCtx.revision = "f.ooba.r"
tasks, successful := syncCtx.getSyncTasks()

assert.True(t, successful)
assert.Len(t, tasks, 2)
assert.Contains(t, tasks[0].name(), "f.ooba-presync-")
assert.Contains(t, tasks[1].name(), "f.ooba-postsync-")
assert.Equal(t, "", pod.GetName())
assert.Empty(t, validation.IsDNS1123Subdomain(tasks[0].name()))

Check failure on line 996 in pkg/sync/sync_context_test.go

View workflow job for this annotation

GitHub Actions / test

File is not properly formatted (gofumpt)
assert.Empty(t, validation.IsDNS1123Subdomain(tasks[1].name()))
})
}

func TestManagedResourceAreNotNamed(t *testing.T) {
Expand Down
Loading