Skip to content

Commit 5a2c8de

Browse files
authored
chore: optimize stack fetching in deployment operator (#362)
* optimize stack fetching in deployment operator * bump helm/kind-action * update go client * update go client * fix linter
1 parent 0a0cb7c commit 5a2c8de

8 files changed

Lines changed: 19 additions & 18 deletions

File tree

.github/workflows/e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
go-version-file: go.mod
1717
cache: false
1818
- name: Create kind cluster
19-
uses: helm/kind-action@v1.10.0
19+
uses: helm/kind-action@v1.12.0
2020
- run: kind get clusters
2121
- run: go test -v -race ./pkg/cache/... -tags="e2e"
2222
- run: go test -v -race ./pkg/applier/filters/... -tags="e2e"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ require (
3434
github.com/opencost/opencost/core v0.0.0-20241216191657-30e5d9a27f41
3535
github.com/orcaman/concurrent-map/v2 v2.0.1
3636
github.com/pkg/errors v0.9.1
37-
github.com/pluralsh/console/go/client v1.28.2
37+
github.com/pluralsh/console/go/client v1.28.3
3838
github.com/pluralsh/controller-reconcile-helper v0.1.0
3939
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34
4040
github.com/pluralsh/polly v0.1.10

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,8 +1199,8 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjL
11991199
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
12001200
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
12011201
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1202-
github.com/pluralsh/console/go/client v1.28.2 h1:fNK0xPuGtbGKK1RTbGyRXP9HN5nCHoZUddRxYIdoWUE=
1203-
github.com/pluralsh/console/go/client v1.28.2/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
1202+
github.com/pluralsh/console/go/client v1.28.3 h1:KyHpOoVHhMRMAZp99k7LqZqX6+FrOwy9sGVXaDSi9FA=
1203+
github.com/pluralsh/console/go/client v1.28.3/go.mod h1:lpoWASYsM9keNePS3dpFiEisUHEfObIVlSL3tzpKn8k=
12041204
github.com/pluralsh/controller-reconcile-helper v0.1.0 h1:BV3dYZFH5rn8ZvZjtpkACSv/GmLEtRftNQj/Y4ddHEo=
12051205
github.com/pluralsh/controller-reconcile-helper v0.1.0/go.mod h1:RxAbvSB4/jkvx616krCdNQXPbpGJXW3J1L3rASxeFOA=
12061206
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw=

pkg/client/console.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type Client interface {
7171
CompleteStackRun(id string, attributes console.StackRunAttributes) error
7272
UpdateStackRun(id string, attributes console.StackRunAttributes) error
7373
UpdateStackRunStep(id string, attributes console.RunStepAttributes) error
74-
ListClusterStackRuns(after *string, first *int64) (*console.ListClusterStackIds_ClusterStackRuns, error)
74+
ListClusterStackRuns(after *string, first *int64) (*console.ListClusterMinimalStacks_ClusterStackRuns, error)
7575
GetUser(email string) (*console.UserFragment, error)
7676
GetGroup(name string) (*console.GroupFragment, error)
7777
SaveUpgradeInsights(attributes []*console.UpgradeInsightAttributes, addons []*console.CloudAddonAttributes) (*console.SaveUpgradeInsights, error)

pkg/client/stack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func (c *client) GetStackRun(id string) (*gqlclient.StackRunMinimalFragment, err
7272
return restore.StackRun, nil
7373
}
7474

75-
func (c *client) ListClusterStackRuns(after *string, first *int64) (*gqlclient.ListClusterStackIds_ClusterStackRuns, error) {
76-
resp, err := c.consoleClient.ListClusterStackIds(c.ctx, after, first, nil, nil)
75+
func (c *client) ListClusterStackRuns(after *string, first *int64) (*gqlclient.ListClusterMinimalStacks_ClusterStackRuns, error) {
76+
resp, err := c.consoleClient.ListClusterMinimalStacks(c.ctx, after, first, nil, nil)
7777
if err != nil {
7878
return nil, err
7979
}

pkg/controller/service/reconciler_scraper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package service
22

33
import (
44
"context"
5-
"github.com/pluralsh/deployment-operator/pkg/client"
65
"strings"
76

87
"github.com/Masterminds/semver/v3"
8+
"github.com/pluralsh/deployment-operator/pkg/client"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010
"sigs.k8s.io/controller-runtime/pkg/log"
1111
)

pkg/controller/stacks/reconciler.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ func (r *StackReconciler) ShutdownQueue() {
8888
r.stackQueue.ShutDown()
8989
}
9090

91-
func (r *StackReconciler) ListStacks(ctx context.Context) *algorithms.Pager[*console.StackRunIDEdgeFragment] {
91+
func (r *StackReconciler) ListStacks(ctx context.Context) *algorithms.Pager[*console.MinimalStackRunEdgeFragment] {
9292
logger := log.FromContext(ctx)
9393
logger.Info("create stack run pager")
94-
fetch := func(page *string, size int64) ([]*console.StackRunIDEdgeFragment, *algorithms.PageInfo, error) {
94+
fetch := func(page *string, size int64) ([]*console.MinimalStackRunEdgeFragment, *algorithms.PageInfo, error) {
9595
resp, err := r.consoleClient.ListClusterStackRuns(page, &size)
9696
if err != nil {
9797
logger.Error(err, "failed to fetch stack run")
@@ -104,7 +104,7 @@ func (r *StackReconciler) ListStacks(ctx context.Context) *algorithms.Pager[*con
104104
}
105105
return resp.Edges, pageInfo, nil
106106
}
107-
return algorithms.NewPager[*console.StackRunIDEdgeFragment](common.DefaultPageSize, fetch)
107+
return algorithms.NewPager[*console.MinimalStackRunEdgeFragment](common.DefaultPageSize, fetch)
108108
}
109109

110110
func (r *StackReconciler) Poll(ctx context.Context) error {
@@ -120,6 +120,7 @@ func (r *StackReconciler) Poll(ctx context.Context) error {
120120
}
121121
for _, stack := range stacks {
122122
logger.Info("sending update for", "stack run", stack.Node.ID)
123+
r.stackCache.Add(stack.Node.ID, stack.Node)
123124
r.stackQueue.Add(stack.Node.ID)
124125
}
125126
}

pkg/test/mocks/Client_mock.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)