This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
admin_service_data_provider.go
66 lines (58 loc) · 2.09 KB
/
admin_service_data_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package impl
import (
"context"
"fmt"
"github.com/flyteorg/flyteadmin/pkg/clusterresource/interfaces"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/service"
)
// Implementation of an interfaces.FlyteAdminDataProvider which fetches data using a flyteadmin service client
type serviceAdminProvider struct {
adminClient service.AdminServiceClient
}
func (p serviceAdminProvider) GetClusterResourceAttributes(ctx context.Context, project, domain string) (*admin.ClusterResourceAttributes, error) {
resource, err := p.adminClient.GetProjectDomainAttributes(ctx, &admin.ProjectDomainAttributesGetRequest{
Project: project,
Domain: domain,
ResourceType: admin.MatchableResource_CLUSTER_RESOURCE,
})
if err != nil {
return nil, err
}
if resource != nil && resource.Attributes != nil && resource.Attributes.MatchingAttributes != nil &&
resource.Attributes.MatchingAttributes.GetClusterResourceAttributes() != nil {
return resource.Attributes.MatchingAttributes.GetClusterResourceAttributes(), nil
}
return nil, NewMissingEntityError("cluster resource attributes")
}
var activeProjectsFilter = fmt.Sprintf("ne(state,%d)", admin.Project_ARCHIVED)
func (p serviceAdminProvider) GetProjects(ctx context.Context) (*admin.Projects, error) {
projects := make([]*admin.Project, 0)
listReq := &admin.ProjectListRequest{
Limit: 100,
Filters: activeProjectsFilter,
// Prefer to sync projects most newly created to ensure their resources get created first when other resources exist.
SortBy: &descCreatedAtSortParam,
}
// Iterate through all pages of projects
for {
projectResp, err := p.adminClient.ListProjects(ctx, listReq)
if err != nil {
return nil, err
}
projects = append(projects, projectResp.Projects...)
if len(projectResp.Token) == 0 {
break
}
listReq.Token = projectResp.Token
}
return &admin.Projects{
Projects: projects,
}, nil
}
func NewAdminServiceDataProvider(
adminClient service.AdminServiceClient) interfaces.FlyteAdminDataProvider {
return &serviceAdminProvider{
adminClient: adminClient,
}
}