Skip to content

Commit 48bab49

Browse files
refactor: add healthy builder helper, safe cluster cancel, and preallocate slice (#1667)
Co-authored-by: Jakub Novák <[email protected]>
1 parent 6d5f422 commit 48bab49

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

packages/api/internal/edge/cluster.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ func NewCluster(ctx context.Context, tel *telemetry.Client, endpoint string, end
6262
}
6363

6464
// generate the full endpoint URL
65-
var endpointBaseUrl string
65+
scheme := "http"
6666
if endpointTLS {
67-
endpointBaseUrl = fmt.Sprintf("https://%s", endpoint)
68-
} else {
69-
endpointBaseUrl = fmt.Sprintf("http://%s", endpoint)
67+
scheme = "https"
7068
}
69+
endpointBaseUrl := fmt.Sprintf("%s://%s", scheme, endpoint)
7170

7271
httpClient, err := api.NewClientWithResponses(endpointBaseUrl, clientAuthMiddleware)
7372
if err != nil {
@@ -133,8 +132,10 @@ func (c *Cluster) GetAvailableTemplateBuilder(ctx context.Context) (*ClusterInst
133132
span.SetAttributes(telemetry.WithClusterID(c.ID))
134133
defer span.End()
135134

136-
var instances []*ClusterInstance
137-
for _, instance := range c.instances.Items() {
135+
// convert map to slice
136+
mapItems := c.instances.Items()
137+
instances := make([]*ClusterInstance, 0, len(mapItems))
138+
for _, instance := range mapItems {
138139
instances = append(instances, instance)
139140
}
140141

@@ -167,10 +168,11 @@ func (c *Cluster) GetHTTP() *ClusterHTTP {
167168
}
168169

169170
func (c *Cluster) GetOrchestrators() []*ClusterInstance {
170-
instances := make([]*ClusterInstance, 0)
171-
for _, i := range c.instances.Items() {
172-
if i.IsOrchestrator() {
173-
instances = append(instances, i)
171+
mapItems := c.instances.Items()
172+
instances := make([]*ClusterInstance, 0, len(mapItems))
173+
for _, instance := range mapItems {
174+
if instance.IsOrchestrator() {
175+
instances = append(instances, instance)
174176
}
175177
}
176178

0 commit comments

Comments
 (0)