Skip to content

Commit 333341b

Browse files
authored
Merge pull request #7763 from killianmuldoon/pr-update-label-hash
🐛 Add deterministic prefix and suffix to label hash
2 parents 6fe2426 + 2a2dc85 commit 333341b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

internal/labels/helpers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package labels
1919

2020
import (
2121
"encoding/base64"
22+
"fmt"
2223
"hash/fnv"
2324

2425
"k8s.io/apimachinery/pkg/util/validation"
@@ -41,7 +42,7 @@ func MustFormatValue(str string) string {
4142
// If this changes in a future go version this function will panic.
4243
panic(err)
4344
}
44-
return base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(hasher.Sum(nil))
45+
return fmt.Sprintf("hash_%s_z", base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(hasher.Sum(nil)))
4546
}
4647

4748
// MustEqualValue returns true if the actualLabelValue equals either the inputLabelValue or the hashed

internal/labels/helpers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestNameLabelValue(t *testing.T) {
3737
{
3838
name: "return for a name with more than 63 characters",
3939
machineSetName: "machineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetName",
40-
want: "FR_ghQ",
40+
want: "hash_FR_ghQ_z",
4141
},
4242
}
4343
for _, tt := range tests {
@@ -71,13 +71,13 @@ func TestMustMatchLabelValueForName(t *testing.T) {
7171
{
7272
name: "don't match labels when MachineSet name is long",
7373
machineSetName: "machineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetName",
74-
labelValue: "Nx4RdE",
74+
labelValue: "hash_Nx4RdE_z",
7575
want: false,
7676
},
7777
{
7878
name: "match labels when MachineSet name is long",
7979
machineSetName: "machineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetName",
80-
labelValue: "FR_ghQ",
80+
labelValue: "hash_FR_ghQ_z",
8181
want: true,
8282
},
8383
}

0 commit comments

Comments
 (0)