mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
ApplicationSet DuckType Generator panics on non-string values in ClusterDecisionResource status
Signed-off-by: Xiangjing Li <xiangli@redhat.com>
This commit is contained in:
parent
b37d389f62
commit
e80adc5bc3
2 changed files with 34 additions and 3 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue