Skip to content

Commit 7e2afa1

Browse files
author
Ryan Zhang
committed
address comments
1 parent 18b3905 commit 7e2afa1

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

apis/placement/v1alpha1/common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const (
1919
OverrideClusterNameVariable = "${MEMBER-CLUSTER-NAME}"
2020

2121
// OverrideClusterLabelKeyVariablePrefix is the reserved variable prefix in the override expression.
22-
// The string will be replaced by the actual label value with the given the name of the key following the prefix.
23-
// The key name ends with a "}" character.
24-
// The key name has a maximum length of 63 characters and must be a valid label name.
25-
// For example, if the key name is "region", the variable will be "${MEMBER-CLUSTER-LABEL-KEY-region}"
22+
// The string will be replaced by the actual label value associated with the key following the prefix.
23+
// The key name ends with a "}" character (but not include it).
24+
// The key name must be a valid label name and case-sensitive.
25+
// For example, if the key name is "kube-fleet.io/region", the variable will be "${MEMBER-CLUSTER-LABEL-KEY-kube-fleet.io/region}"
2626
OverrideClusterLabelKeyVariablePrefix = "${MEMBER-CLUSTER-LABEL-KEY-"
2727
)

pkg/controllers/workgenerator/override.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func applyJSONPatchOverride(resourceContent *placementv1beta1.ResourceContent, c
239239
// replaceClusterLabelKeyVariables finds all occurrences of the OverrideClusterLabelKeyVariablePrefix pattern
240240
// (e.g. ${MEMBER-CLUSTER-LABEL-KEY-region}) in the input string and replaces them with
241241
// the corresponding label values from the cluster.
242-
// If a label with the specified key doesn't exist, the variable remains unchanged.
242+
// If a label with the specified key doesn't exist, it returns an error.
243243
func replaceClusterLabelKeyVariables(input string, cluster *clusterv1beta1.MemberCluster) (string, error) {
244244
prefixLen := len(placementv1alpha1.OverrideClusterLabelKeyVariablePrefix)
245245
result := input

pkg/controllers/workgenerator/override_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,7 @@ func TestApplyJSONPatchOverride(t *testing.T) {
27602760
}
27612761
}
27622762

2763-
func Test_replaceClusterLabelKeyVariables(t *testing.T) {
2763+
func TestReplaceClusterLabelKeyVariables(t *testing.T) {
27642764
tests := map[string]struct {
27652765
cluster *clusterv1beta1.MemberCluster
27662766
input string
@@ -2819,6 +2819,17 @@ func Test_replaceClusterLabelKeyVariables(t *testing.T) {
28192819
input: "The cluster is in ${MEMBER-CLUSTER-LABEL-KEY-region}",
28202820
expectErr: true,
28212821
},
2822+
"ClusterLabelKey Variable key case not match": {
2823+
cluster: &clusterv1beta1.MemberCluster{
2824+
ObjectMeta: metav1.ObjectMeta{
2825+
Labels: map[string]string{
2826+
"region": "us-west-1",
2827+
},
2828+
},
2829+
},
2830+
input: "The cluster is in ${MEMBER-CLUSTER-LABEL-KEY-REGION}",
2831+
expectErr: true,
2832+
},
28222833
"Invalid clusterLabelKey variable format": {
28232834
cluster: &clusterv1beta1.MemberCluster{
28242835
ObjectMeta: metav1.ObjectMeta{
@@ -2830,6 +2841,17 @@ func Test_replaceClusterLabelKeyVariables(t *testing.T) {
28302841
input: "The cluster is in ${MEMBER-CLUSTER-LABEL-KEY-region",
28312842
expectErr: true,
28322843
},
2844+
"ClusterLabelKey variable key empty": {
2845+
cluster: &clusterv1beta1.MemberCluster{
2846+
ObjectMeta: metav1.ObjectMeta{
2847+
Labels: map[string]string{
2848+
"region": "us-west-1",
2849+
},
2850+
},
2851+
},
2852+
input: "The cluster is in ${MEMBER-CLUSTER-LABEL-KEY-}",
2853+
expectErr: true,
2854+
},
28332855
}
28342856

28352857
for name, tc := range tests {

0 commit comments

Comments
 (0)