Skip to content

Commit

Permalink
Remove Pipelines from Satellite commands (#4184)
Browse files Browse the repository at this point in the history
This PR removes Pipelines-related code from the Satellite commands.

It also seems reasonable to remove the `IsHidden` Satellite listing
parameter as, IFAIK, this is only used to include Satellites associated
with pipelines.

I'll create another PR to remove the `PIPELINE` keywords.
  • Loading branch information
mikejholly authored Jun 4, 2024
1 parent 4f4b479 commit 32eaa57
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 267 deletions.
14 changes: 6 additions & 8 deletions autocomplete/cached_cloud_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
type cloudListClient interface {
ListOrgs(ctx context.Context) ([]*cloud.OrgDetail, error)
ListProjects(ctx context.Context, orgName string) ([]*cloud.Project, error)
ListSatellites(ctx context.Context, orgName string, includeHidden bool) ([]cloud.SatelliteInstance, error)
ListSatellites(ctx context.Context, orgName string) ([]cloud.SatelliteInstance, error)
}

type cachedCloudClient struct {
Expand Down Expand Up @@ -139,14 +139,13 @@ func (ccc *cachedCloudClient) ListProjects(ctx context.Context, orgName string)
return projects, nil
}

func (ccc *cachedCloudClient) ListSatellites(ctx context.Context, orgName string, includeHidden bool) ([]cloud.SatelliteInstance, error) {
func (ccc *cachedCloudClient) ListSatellites(ctx context.Context, orgName string) ([]cloud.SatelliteInstance, error) {
cached := struct {
Org string
IncludeHidden bool
Satellites []string `json:"satellites"`
Org string
Satellites []string `json:"satellites"`
}{}
filename := ".autocomplete.satellites"
if err := readJSON(ccc.installationName, filename, &cached); err == nil && cached.Org == orgName && cached.IncludeHidden == includeHidden {
if err := readJSON(ccc.installationName, filename, &cached); err == nil && cached.Org == orgName {
res := []cloud.SatelliteInstance{}
for _, s := range cached.Satellites {
res = append(res, cloud.SatelliteInstance{
Expand All @@ -156,15 +155,14 @@ func (ccc *cachedCloudClient) ListSatellites(ctx context.Context, orgName string
return res, nil
}
cached.Satellites = nil
satellites, err := ccc.c.ListSatellites(ctx, orgName, includeHidden)
satellites, err := ccc.c.ListSatellites(ctx, orgName)
if err != nil {
return nil, err
}
for _, sat := range satellites {
cached.Satellites = append(cached.Satellites, sat.Name)
}
cached.Org = orgName
cached.IncludeHidden = includeHidden
_ = saveJSON(ccc.installationName, filename, &cached)
return satellites, nil
}
4 changes: 2 additions & 2 deletions autocomplete/cached_cloud_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func TestCachedCloudClient(topT *testing.T) {

o.Spec("caches satellites", func(tc testCtx) {
for i := 0; i < 3; i++ {
projects, err := tc.ccc.ListSatellites(context.Background(), "abba", false)
projects, err := tc.ccc.ListSatellites(context.Background(), "abba")
tc.expect(err).To(not(haveOccurred()))
tc.expect(len(projects)).To(equal(2))
tc.expect(projects[0].Name).To(equal("sat-one"))
tc.expect(projects[1].Name).To(equal("sat-two"))
tc.expect(tc.mclc.listSatellitesCallCount).To(equal(1))
}
for i := 0; i < 3; i++ {
projects, err := tc.ccc.ListSatellites(context.Background(), "abc", false)
projects, err := tc.ccc.ListSatellites(context.Background(), "abc")
tc.expect(err).To(not(haveOccurred()))
tc.expect(len(projects)).To(equal(1))
tc.expect(projects[0].Name).To(equal("xyz"))
Expand Down
2 changes: 1 addition & 1 deletion autocomplete/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func GetPotentials(ctx context.Context, resolver *buildcontext.Resolver, gwClien
return []string{}
}

satellites, err := cloudClient.ListSatellites(ctx, org, false)
satellites, err := cloudClient.ListSatellites(ctx, org)
if err != nil {
return []string{}
}
Expand Down
2 changes: 1 addition & 1 deletion autocomplete/complete_cloud_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (mclc *mockCloudListClient) ListProjects(ctx context.Context, orgName strin
return []*cloud.Project{}, nil
}

func (mclc *mockCloudListClient) ListSatellites(ctx context.Context, orgName string, includeHidden bool) ([]cloud.SatelliteInstance, error) {
func (mclc *mockCloudListClient) ListSatellites(ctx context.Context, orgName string) ([]cloud.SatelliteInstance, error) {
mclc.listSatellitesCallCount += 1
if orgName == "abba" {
return []cloud.SatelliteInstance{
Expand Down
81 changes: 0 additions & 81 deletions cloud/pipeline.go

This file was deleted.

8 changes: 2 additions & 6 deletions cloud/satellite.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type SatelliteInstance struct {
MaintenanceWindowEnd string
MaintenanceWeekendsOnly bool
RevisionID int32
Hidden bool
LastUsed time.Time
CacheRetention time.Duration
Address string
Expand All @@ -83,14 +82,13 @@ type SatelliteInstance struct {
CloudName string
}

func (c *Client) ListSatellites(ctx context.Context, orgName string, includeHidden bool) ([]SatelliteInstance, error) {
func (c *Client) ListSatellites(ctx context.Context, orgName string) ([]SatelliteInstance, error) {
orgID, err := c.GetOrgID(ctx, orgName)
if err != nil {
return nil, errors.Wrap(err, "failed listing satellites")
}
resp, err := c.compute.ListSatellites(c.withAuth(ctx), &pb.ListSatellitesRequest{
OrgId: orgID,
IncludeHidden: includeHidden,
OrgId: orgID,
})
if err != nil {
return nil, errors.Wrap(err, "failed listing satellites")
Expand All @@ -104,7 +102,6 @@ func (c *Client) ListSatellites(ctx context.Context, orgName string, includeHidd
Size: s.Size,
State: satelliteStatus(s.Status),
Version: s.Version,
Hidden: s.Hidden,
LastUsed: s.LastUsed.AsTime(),
CacheRetention: s.CacheRetention.AsDuration(),
CloudName: s.CloudName,
Expand Down Expand Up @@ -138,7 +135,6 @@ func (c *Client) GetSatellite(ctx context.Context, name, orgName string) (*Satel
MaintenanceWindowEnd: resp.MaintenanceWindowEnd,
MaintenanceWeekendsOnly: resp.MaintenanceWeekendsOnly,
RevisionID: resp.RevisionId,
Hidden: resp.Hidden,
LastUsed: resp.LastUsed.AsTime(),
CacheRetention: resp.CacheRetention.AsDuration(),
IsManaged: resp.IsManaged,
Expand Down
35 changes: 1 addition & 34 deletions cmd/earthly/base/buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (c *CLI) GetSatelliteOrg(ctx context.Context, cloudClient *cloud.Client) (o
}

func GetSatelliteName(ctx context.Context, orgName, satelliteName string, cloudClient *cloud.Client) (string, error) {
satellites, err := cloudClient.ListSatellites(ctx, orgName, true)
satellites, err := cloudClient.ListSatellites(ctx, orgName)
if err != nil {
return "", err
}
Expand All @@ -185,16 +185,6 @@ func GetSatelliteName(ctx context.Context, orgName, satelliteName string, cloudC
}
}

pipelines, err := GetAllPipelinesForAllProjects(ctx, orgName, cloudClient)
if err != nil {
return "", err
}
for _, p := range pipelines {
if satelliteName == PipelineSatelliteName(&p) {
return p.SatelliteName, nil
}
}

return "", fmt.Errorf("satellite %q not found", satelliteName)
}

Expand All @@ -208,26 +198,3 @@ func (cli *CLI) reserveSatellite(ctx context.Context, cloudClient *cloud.Client,
}
return nil
}

func GetAllPipelinesForAllProjects(ctx context.Context, orgName string, cloudClient *cloud.Client) ([]cloud.Pipeline, error) {
projects, err := cloudClient.ListProjects(ctx, orgName)
if err != nil {
return nil, err
}

allPipelines := make([]cloud.Pipeline, 0)
for _, pr := range projects {
pipelines, err := cloudClient.ListPipelines(ctx, pr.Name, orgName, "")
if err != nil {
return nil, err
}

allPipelines = append(allPipelines, pipelines...)
}

return allPipelines, nil
}

func PipelineSatelliteName(p *cloud.Pipeline) string {
return fmt.Sprintf("%s/%s", p.Project, p.Name)
}
Loading

0 comments on commit 32eaa57

Please sign in to comment.