Skip to content

Commit

Permalink
Add artifact version listing to Go API
Browse files Browse the repository at this point in the history
Summary: TSIA

Test Plan: will add unit tests shortly.

Reviewers: michelle, vihang

Reviewed By: vihang

Signed-off-by: Zain Asgar <[email protected]>

Differential Revision: https://phab.corp.pixielabs.ai/D12330

GitOrigin-RevId: 0172171f4d6efdc91e05142decdf8cb5791aa626
  • Loading branch information
zasgar authored and copybaranaut committed Oct 3, 2022
1 parent e0e1b84 commit 752df5f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,31 @@ func (c *Client) DeleteAPIKey(ctx context.Context, id string) error {
_, err := apiKeyMgr.Delete(c.cloudCtxWithMD(ctx), req)
return err
}

// GetLatestVizierVersion returns the latest version of vizier available.
func (c *Client) GetLatestVizierVersion(ctx context.Context) (string, error) {
return c.getLatestArtifact(ctx, "vizier", cloudpb.AT_CONTAINER_SET_YAMLS)
}

// GetLatestOperatorVersion returns the latest version of the operator available.
func (c *Client) GetLatestOperatorVersion(ctx context.Context) (string, error) {
return c.getLatestArtifact(ctx, "operator", cloudpb.AT_CONTAINER_SET_TEMPLATE_YAMLS)
}

// Helper function to fetch artifact versions.
func (c *Client) getLatestArtifact(ctx context.Context, an string, at cloudpb.ArtifactType) (string, error) {
ac := cloudpb.NewArtifactTrackerClient(c.grpcConn)
req := &cloudpb.GetArtifactListRequest{
ArtifactName: an,
ArtifactType: at,
Limit: 1,
}
resp, err := ac.GetArtifactList(c.cloudCtxWithMD(ctx), req)
if err != nil {
return "", err
}
if len(resp.Artifact) != 1 {
return "", errdefs.ErrMissingArtifact
}
return resp.Artifact[0].VersionStr, nil
}
3 changes: 3 additions & 0 deletions errdefs/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ var (

// ErrCompilation is a generic PxL compilation error.
ErrCompilation = errors.New("compilation error")

// ErrMissingArtifact occurs when an artifact could not be found.
ErrMissingArtifact = errors.New("missing artifact")
)

// MultiError is an interface to allow access to groups of errors.
Expand Down

0 comments on commit 752df5f

Please sign in to comment.