Skip to content

Commit

Permalink
fix: consider destination cluster name when validating destinations (#…
Browse files Browse the repository at this point in the history
…10594)

Signed-off-by: Matt Morrison <matt.morrison@zapier.com>

Signed-off-by: Matt Morrison <matt.morrison@zapier.com>
  • Loading branch information
sl1pm4t committed Oct 7, 2022
1 parent 8e38b4f commit a73c45f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/application/v1alpha1/app_project_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func (p *AppProject) ValidateProject() error {
}

key := fmt.Sprintf("%s/%s", dest.Server, dest.Namespace)
if dest.Server == "" && dest.Name != "" {
// destination cluster set using name instead of server endpoint
key = fmt.Sprintf("%s/%s", dest.Name, dest.Namespace)
}
if _, ok := destKeys[key]; ok {
return status.Errorf(codes.InvalidArgument, "destination '%s' already added", key)
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/application/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,19 @@ func TestAppProject_ValidateDestinations(t *testing.T) {
p.Spec.Destinations = []ApplicationDestination{validDestination, validDestination}
err = p.ValidateProject()
assert.Error(t, err)

cluster1Destination := ApplicationDestination{
Name: "cluster1",
Namespace: "some-namespace",
}
cluster2Destination := ApplicationDestination{
Name: "cluster2",
Namespace: "some-namespace",
}
// allow multiple destinations with blank server, same namespace but unique cluster name
p.Spec.Destinations = []ApplicationDestination{cluster1Destination, cluster2Destination}
err = p.ValidateProject()
assert.NoError(t, err)
}

// TestValidateRoleName tests for an invalid role name
Expand Down

0 comments on commit a73c45f

Please sign in to comment.