From 9ceea1724484075badff0f0062f292913f8b272b Mon Sep 17 00:00:00 2001 From: Matias Insaurralde Date: Wed, 17 Jul 2024 12:00:02 -0300 Subject: [PATCH] refactor: compile local cluster service format regexp just once (#2727) Signed-off-by: Austin Abro --- src/pkg/packager/deploy.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 8c0eb6b7a4..9044772169 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -38,6 +38,11 @@ import ( "github.com/defenseunicorns/zarf/src/types" ) +var ( + // localClusterServiceRegex is used to match the local cluster service format: + localClusterServiceRegex = regexp.MustCompile(`^(?P[^\.]+)\.(?P[^\.]+)\.svc\.cluster\.local$`) +) + func (p *Packager) resetRegistryHPA(ctx context.Context) { if p.isConnectedToCluster() && p.hpaModified { if err := p.cluster.EnableRegHPAScaleDown(ctx); err != nil { @@ -742,11 +747,7 @@ func serviceInfoFromServiceURL(serviceURL string) (string, string, int, error) { } // Match hostname against local cluster service format. - pattern, err := regexp.Compile(`^(?P[^\.]+)\.(?P[^\.]+)\.svc\.cluster\.local$`) - if err != nil { - return "", "", 0, err - } - get, err := helpers.MatchRegex(pattern, parsedURL.Hostname()) + get, err := helpers.MatchRegex(localClusterServiceRegex, parsedURL.Hostname()) // If incomplete match, return an error. if err != nil {