Skip to content

perf: pre-compile templates, hoist regex, filter DescribeLoadBalancers#652

Merged
ArangoGutierrez merged 1 commit intoNVIDIA:mainfrom
ArangoGutierrez:perf/template-and-regex
Feb 13, 2026
Merged

perf: pre-compile templates, hoist regex, filter DescribeLoadBalancers#652
ArangoGutierrez merged 1 commit intoNVIDIA:mainfrom
ArangoGutierrez:perf/template-and-regex

Conversation

@ArangoGutierrez
Copy link
Collaborator

Summary

  • Move template parsing from per-call to package-level vars (eliminates 75+ recompiles per cluster)
  • Hoist regexp.MustCompile from function body to package-level var in resolver.go
  • Filter DescribeLoadBalancers by name instead of listing all LBs in the account

Audit Findings

Changes

  • pkg/provisioner/provisioner.go: Package-level template vars for addScriptHeader
  • pkg/provisioner/templates/*.go: Package-level template vars for Execute methods
  • pkg/gitref/resolver.go: Package-level regex var
  • pkg/provider/aws/delete.go: Filter DescribeLoadBalancers by name

Test plan

  • gofmt — no formatting issues
  • go build — compiles
  • go test ./pkg/... — all tests pass

Copilot AI review requested due to automatic review settings February 12, 2026 20:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements performance optimizations based on audit findings by pre-compiling templates, hoisting regex compilation, and filtering AWS API calls. The changes eliminate redundant template and regex compilations that were previously happening on every execution, and reduce the scope of AWS DescribeLoadBalancers calls by filtering by name instead of listing all load balancers in the account.

Changes:

  • Pre-compiled text/templates moved to package-level variables in provisioner and template files
  • Regex pattern compilation hoisted to package level in gitref resolver
  • AWS DescribeLoadBalancers call now filters by load balancer name

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/provisioner/templates/kubernetes.go Added package-level template variables for kubeadm (release/git/latest), kind (release/git/latest), and microk8s templates
pkg/provisioner/templates/kubeadm_cluster.go Added package-level template variables for kubeadm init, join, and prereq templates
pkg/provisioner/templates/containerd.go Added package-level template variables for containerd v1 and v2 templates
pkg/provisioner/templates/container-toolkit.go Added package-level template variables for container toolkit package, git, and latest templates
pkg/provisioner/provisioner.go Added package-level template variables for shebang and common functions templates
pkg/provider/aws/delete.go Modified DescribeLoadBalancers to filter by name instead of listing all load balancers
pkg/gitref/resolver.go Hoisted regex compilation to package-level variable
Comments suppressed due to low confidence (1)

pkg/provider/aws/delete.go:74

  • The DescribeLoadBalancers call with a specific name will return a LoadBalancerNotFoundException error if the load balancer doesn't exist. This should be handled gracefully since the load balancer may have been manually deleted or failed to create. Consider checking for this error type and treating it as a success case (load balancer already gone), similar to how other resource deletions handle NotFound errors elsewhere in this file (lines 177, 270, 345, etc.).
	describeOutput, err := p.elbv2.DescribeLoadBalancers(ctx, describeInput)
	if err != nil {
		return fmt.Errorf("error describing load balancers: %w", err)
	}

@copy-pr-bot
Copy link

copy-pr-bot bot commented Feb 13, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Templates were recompiled on every Execute call (75+ times for a
15-node cluster). Move to package-level vars. Move ParseRepoURL
regex to package level. Filter DescribeLoadBalancers by name
instead of listing all LBs in the account.

Audit findings NVIDIA#22 (MEDIUM), NVIDIA#23 (MEDIUM), NVIDIA#24 (MEDIUM).

Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
@coveralls
Copy link

Pull Request Test Coverage Report for Build 21997438359

Details

  • 26 of 30 (86.67%) changed or added relevant lines in 7 files are covered.
  • 8 unchanged lines in 5 files lost coverage.
  • Overall coverage decreased (-0.3%) to 47.874%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/provider/aws/delete.go 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
pkg/provisioner/templates/containerd.go 1 85.53%
pkg/provisioner/templates/container-toolkit.go 1 91.18%
pkg/provisioner/templates/kubernetes.go 1 85.12%
pkg/provisioner/provisioner.go 2 1.29%
pkg/provisioner/templates/kubeadm_cluster.go 3 78.72%
Totals Coverage Status
Change from base Build 21997070791: -0.3%
Covered Lines: 2567
Relevant Lines: 5362

💛 - Coveralls

@ArangoGutierrez ArangoGutierrez merged commit e79e655 into NVIDIA:main Feb 13, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants