fix: ApplicationSet DuckType Generator panics on non-string values in Clus… (cherry-pick #27265 for 3.3) (#27525)

Signed-off-by: Xiangjing Li <[email protected]>
Co-authored-by: Xiangjing Li <[email protected]>
This commit is contained in:
argo-cd-cherry-pick-bot[bot]
2026-04-23 23:18:04 +02:00
committed by GitHub
co-authored by Xiangjing Li
parent 9ca507af48
commit 49a98d36f6
2 changed files with 34 additions and 3 deletions
+3 -3
View File
@@ -162,7 +162,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 {
@@ -198,12 +198,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 {
@@ -117,6 +117,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,
@@ -183,6 +204,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,