This commit is contained in:
Xiangjing Li 2026-04-21 09:00:22 +03:00 committed by GitHub
commit 7ac300ec3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 3 deletions

View file

@ -164,7 +164,7 @@ func (g *DuckTypeGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.A
}
for key, value := range clusterDecision.(map[string]any) {
params[key] = value.(string)
params[key] = fmt.Sprintf("%v", value)
}
for key, value := range appSetGenerator.ClusterDecisionResource.Values {
@ -200,12 +200,12 @@ func buildClusterDecisions(duckResources *unstructured.UnstructuredList, statusL
func findCluster(clustersFromArgoCD []utils.ClusterSpecifier, cluster any, matchKey string, statusListKey string) *utils.ClusterSpecifier {
log.Infof("cluster: %v", cluster)
matchValue := cluster.(map[string]any)[matchKey]
if matchValue == nil || matchValue.(string) == "" {
if matchValue == nil || fmt.Sprintf("%v", matchValue) == "" {
log.Warningf("matchKey=%v not found in \"%v\" list: %v\n", matchKey, statusListKey, cluster.(map[string]any))
return nil // no match
}
strMatchValue := matchValue.(string)
strMatchValue := fmt.Sprintf("%v", matchValue)
log.WithField(matchKey, strMatchValue).Debug("validate against ArgoCD")
for _, argoCluster := range clustersFromArgoCD {

View file

@ -119,6 +119,27 @@ func TestGenerateParamsForDuckType(t *testing.T) {
},
}
duckTypeWithNonStringValues := &unstructured.Unstructured{
Object: map[string]any{
"apiVersion": resourceAPIVersion,
"kind": "Duck",
"metadata": map[string]any{
"name": resourceName,
"namespace": "namespace",
"labels": map[string]any{"duck": "all-species"},
},
"status": map[string]any{
"decisions": []any{
map[string]any{
"clusterName": "staging-01",
"reason": "",
"score": int64(0),
},
},
},
},
}
duckTypeEmpty := &unstructured.Unstructured{
Object: map[string]any{
"apiVersion": resourceAPIVersion,
@ -185,6 +206,16 @@ func TestGenerateParamsForDuckType(t *testing.T) {
},
expectedError: nil,
},
{
name: "non-string values in cluster decisions are converted to strings",
resourceName: resourceName,
resource: duckTypeWithNonStringValues,
values: nil,
expected: []map[string]any{
{"clusterName": "staging-01", "reason": "", "score": "0", "name": "staging-01", "server": "https://staging-01.example.com"},
},
expectedError: nil,
},
{
name: "production-only",
resourceName: resourceName,