Skip to content

Commit

Permalink
Initial changes
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Aneci <aneci@adobe.com>
  • Loading branch information
adriananeci committed Dec 4, 2024
1 parent 522d07a commit 666316f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions util/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,17 @@ func ValidateDestination(ctx context.Context, dest *argoappv1.ApplicationDestina
} else if !dest.IsServerInferred() {
return fmt.Errorf("application destination can't have both name and server defined: %s %s", dest.Name, dest.Server)
}
} else if dest.Server != "" {
if dest.Name == "" {
serverName, err := getDestinationServerName(ctx, db, dest.Server)
if err != nil {
return fmt.Errorf("unable to find destination server: %w", err)
}
if serverName == "" {
return fmt.Errorf("application references destination cluster %s which does not exist", dest.Server)
}
dest.SetInferredServer(serverName)
}
}
return nil
}
Expand Down Expand Up @@ -959,6 +970,18 @@ func getDestinationServer(ctx context.Context, db db.ArgoDB, clusterName string)
return servers[0], nil
}

func getDestinationServerName(ctx context.Context, db db.ArgoDB, server string) (string, error) {
cluster, err := db.GetCluster(ctx, server)
if err != nil {
return "", fmt.Errorf("error getting cluster name by server %q: %w", server, err)
}

if cluster.Name == "" {
return "", fmt.Errorf("there are no clusters with this URL: %s", server)
}
return cluster.Name, nil
}

func GetGlobalProjects(proj *argoappv1.AppProject, projLister applicationsv1.AppProjectLister, settingsManager *settings.SettingsManager) []*argoappv1.AppProject {
gps, err := settingsManager.GetGlobalProjectsSettings()
globalProjects := make([]*argoappv1.AppProject, 0)
Expand Down
2 changes: 1 addition & 1 deletion util/argo/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ func TestValidatePermissions(t *testing.T) {
SourceRepos: []string{"http://some/where/else"},
},
}
cluster := &argoappv1.Cluster{Server: "https://127.0.0.1:6443"}
cluster := &argoappv1.Cluster{Server: "https://127.0.0.1:6443", Name: "test"}
db := &dbmocks.ArgoDB{}
db.On("GetCluster", context.Background(), spec.Destination.Server).Return(cluster, nil)
conditions, err := ValidatePermissions(context.Background(), &spec, &proj, db)
Expand Down

0 comments on commit 666316f

Please sign in to comment.