forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configurable cluster resource sync: in cluster or standalone (flyteor…
…g#326) * refactor Signed-off-by: Katrina Rogan <[email protected]> * Add mocks Signed-off-by: Katrina Rogan <[email protected]> * lint Signed-off-by: Katrina Rogan <[email protected]> * Review comments Signed-off-by: Katrina Rogan <[email protected]>
- Loading branch information
Katrina Rogan
authored
Jan 21, 2022
1 parent
cf76955
commit a6932ce
Showing
14 changed files
with
609 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
flyteadmin/pkg/clusterresource/impl/admin_service_data_provider.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
} | ||
} |
Oops, something went wrong.