Skip to content

Commit

Permalink
Only ask for known clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
thokra-nav committed Nov 12, 2024
1 parent aad7720 commit 5255d58
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions internal/deployment/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ package deployment
import (
"context"
"fmt"
"strings"
"time"

"github.com/nais/api/internal/role"

"github.com/nais/api/internal/auth/authz"
"github.com/nais/api/internal/graph/apierror"
"github.com/nais/api/internal/graph/ident"
"github.com/nais/api/internal/graph/pagination"
"github.com/nais/api/internal/role"
"github.com/nais/api/internal/slug"
"github.com/nais/api/internal/team"
"github.com/nais/api/internal/thirdparty/hookd"
"github.com/nais/api/internal/workload"
)

func ListForTeam(ctx context.Context, teamSlug slug.Slug, page *pagination.Pagination) (*DeploymentConnection, error) {
all, err := fromContext(ctx).client.Deployments(ctx, hookd.WithTeam(teamSlug.String()), hookd.WithLimit(100))
cluster, err := withCluster(ctx, teamSlug)
if err != nil {
return nil, err
}

all, err := fromContext(ctx).client.Deployments(ctx, hookd.WithTeam(teamSlug.String()), hookd.WithLimit(100), hookd.WithCluster(cluster))
if err != nil {
return nil, fmt.Errorf("getting deploys from Hookd: %w", err)
}
Expand All @@ -27,7 +33,12 @@ func ListForTeam(ctx context.Context, teamSlug slug.Slug, page *pagination.Pagin
}

func ListForWorkload(ctx context.Context, teamSlug slug.Slug, environmentName, workloadName string, workloadType workload.Type, page *pagination.Pagination) (*DeploymentConnection, error) {
all, err := fromContext(ctx).client.Deployments(ctx, hookd.WithTeam(teamSlug.String()), hookd.WithCluster(environmentName))
cluster, err := withCluster(ctx, teamSlug)
if err != nil {
return nil, err
}

all, err := fromContext(ctx).client.Deployments(ctx, hookd.WithTeam(teamSlug.String()), hookd.WithCluster(environmentName), hookd.WithCluster(cluster))
if err != nil {
return nil, fmt.Errorf("getting deploys from Hookd: %w", err)
}
Expand Down Expand Up @@ -123,3 +134,17 @@ func getDeploymentKeyByIdent(ctx context.Context, id ident.Ident) (*DeploymentKe
func getDeploymentByIdent(ctx context.Context, id ident.Ident) (*Deployment, error) {
return nil, apierror.Errorf("deployments are not accessible by node ID")
}

func withCluster(ctx context.Context, teamSlug slug.Slug) (string, error) {
envs, err := team.ListTeamEnvironments(ctx, teamSlug)
if err != nil {
return "", err
}

names := make([]string, 0, len(envs))
for _, env := range envs {
names = append(names, env.Name)
}

return strings.Join(names, ","), nil
}

0 comments on commit 5255d58

Please sign in to comment.