diff --git a/internal/labels/helpers.go b/internal/labels/helpers.go index 0b79fd5ed401..24f85cbbeadf 100644 --- a/internal/labels/helpers.go +++ b/internal/labels/helpers.go @@ -19,6 +19,7 @@ package labels import ( "encoding/base64" + "fmt" "hash/fnv" "k8s.io/apimachinery/pkg/util/validation" @@ -41,7 +42,7 @@ func MustFormatValue(str string) string { // If this changes in a future go version this function will panic. panic(err) } - return base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(hasher.Sum(nil)) + return fmt.Sprintf("hash_%s_z", base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(hasher.Sum(nil))) } // MustEqualValue returns true if the actualLabelValue equals either the inputLabelValue or the hashed diff --git a/internal/labels/helpers_test.go b/internal/labels/helpers_test.go index 1021e91c3333..53dfef1640b4 100644 --- a/internal/labels/helpers_test.go +++ b/internal/labels/helpers_test.go @@ -37,7 +37,7 @@ func TestNameLabelValue(t *testing.T) { { name: "return for a name with more than 63 characters", machineSetName: "machineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetName", - want: "FR_ghQ", + want: "hash_FR_ghQ_z", }, } for _, tt := range tests { @@ -71,13 +71,13 @@ func TestMustMatchLabelValueForName(t *testing.T) { { name: "don't match labels when MachineSet name is long", machineSetName: "machineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetName", - labelValue: "Nx4RdE", + labelValue: "hash_Nx4RdE_z", want: false, }, { name: "match labels when MachineSet name is long", machineSetName: "machineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetNamemachineSetName", - labelValue: "FR_ghQ", + labelValue: "hash_FR_ghQ_z", want: true, }, }