Skip to content

Commit

Permalink
Merge pull request #7764 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…7763-to-release-1.3

[release-1.3] 🐛 Add deterministic prefix and suffix to label hash
  • Loading branch information
k8s-ci-robot authored Dec 14, 2022
2 parents fc07794 + bc5dc3c commit a9f75ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/labels/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package labels

import (
"encoding/base64"
"fmt"
"hash/fnv"

"k8s.io/apimachinery/pkg/util/validation"
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/labels/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
}
Expand Down

0 comments on commit a9f75ad

Please sign in to comment.