Skip to content

Commit

Permalink
Issue argoproj#1701 - UI will crash when create application without d…
Browse files Browse the repository at this point in the history
…estination namespace
  • Loading branch information
Alexander Matyushentsev authored and Alexander Matyushentsev committed Jun 7, 2019
1 parent 0088955 commit ca4d7be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class ApplicationsFilter extends React.Component<ApplicationsFilterProps,
<ul>
<li>
<TagsInput placeholder='https://kubernetes.default.svc'
autocomplete={Array.from(new Set(applications.map((app) => app.spec.destination.server)))
autocomplete={Array.from(new Set(applications.map((app) => app.spec.destination.server).filter((item) => !!item)))
.filter((ns) => pref.clustersFilter.indexOf(ns) === -1)}
tags={pref.clustersFilter}
onChange={(selected) => onChange({...pref, clustersFilter: selected})}/>
Expand All @@ -127,7 +127,7 @@ export class ApplicationsFilter extends React.Component<ApplicationsFilterProps,
<ul>
<li>
<TagsInput placeholder='*-us-west-*'
autocomplete={Array.from(new Set(applications.map((app) => app.spec.destination.namespace)))
autocomplete={Array.from(new Set(applications.map((app) => app.spec.destination.namespace).filter((item) => !!item)))
.filter((ns) => pref.namespacesFilter.indexOf(ns) === -1)}
tags={pref.namespacesFilter}
onChange={(selected) => onChange({...pref, namespacesFilter: selected})}/>
Expand Down
2 changes: 2 additions & 0 deletions util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ func ValidatePermissions(ctx context.Context, spec *argoappv1.ApplicationSpec, p
return nil, err
}
}
} else {
conditions = append(conditions, argoappv1.ApplicationCondition{Type: argoappv1.ApplicationConditionInvalidSpecError, Message: errDestinationMissing})
}
return conditions, nil
}
Expand Down
13 changes: 13 additions & 0 deletions util/argo/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,16 @@ func TestNilOutZerValueAppSources(t *testing.T) {
assert.Nil(t, spec.Source.Directory)
}
}

func TestValidatePermissionsEmptyDestination(t *testing.T) {
conditions, err := ValidatePermissions(context.Background(), &argoappv1.ApplicationSpec{
Source: argoappv1.ApplicationSource{RepoURL: "https://github.com/argoproj/argo-cd", Path: "."},
}, &argoappv1.AppProject{
Spec: argoappv1.AppProjectSpec{
SourceRepos: []string{"*"},
Destinations: []argoappv1.ApplicationDestination{{Server: "*", Namespace: "*"}},
},
}, nil)
assert.NoError(t, err)
assert.ElementsMatch(t, conditions, []argoappv1.ApplicationCondition{{Type: argoappv1.ApplicationConditionInvalidSpecError, Message: "Destination server and/or namespace missing from app spec"}})
}

0 comments on commit ca4d7be

Please sign in to comment.