Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit 407ca5d

Browse files
Merge pull request #2398 from ibuildthecloud/main
Change app generated namespace to be deterministic
2 parents 46a667b + 8cc6896 commit 407ca5d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pkg/controller/appdefinition/namespace.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
99
"github.com/acorn-io/runtime/pkg/condition"
1010
"github.com/acorn-io/runtime/pkg/labels"
11+
"golang.org/x/exp/slices"
1112
corev1 "k8s.io/api/core/v1"
1213
kclient "sigs.k8s.io/controller-runtime/pkg/client"
1314
)
@@ -21,8 +22,12 @@ func AssignNamespace(req router.Request, resp router.Response) (err error) {
2122
err = nil
2223
}()
2324

24-
parts := strings.Split(appInstance.Name, ".")
25-
appInstance.Status.Namespace = name.SafeConcatName(parts[len(parts)-1], appInstance.ShortID())
25+
if appInstance.Status.Namespace == "" {
26+
parts := strings.Split(appInstance.Name, ".")
27+
slices.Reverse(parts)
28+
parts = append(parts, appInstance.Namespace)
29+
appInstance.Status.Namespace = name.SafeHashConcatName(parts...)
30+
}
2631

2732
resp.Objects(appInstance)
2833
return nil

pkg/controller/appdefinition/testdata/assignnamespace/expected.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ status:
2020
success: true
2121
type: namespace
2222
defaults: {}
23-
namespace: default-1234567890ab
23+
namespace: default-random-2fcaa72a
2424
resolvedOfferings: {}
2525
staged:
2626
appImage:
@@ -52,7 +52,7 @@ status:
5252
success: true
5353
type: namespace
5454
defaults: {}
55-
namespace: default-1234567890ab
55+
namespace: default-random-2fcaa72a
5656
resolvedOfferings: {}
5757
staged:
5858
appImage:

0 commit comments

Comments
 (0)