Skip to content

Commit

Permalink
refactor: compile local cluster service format regexp just once (zarf…
Browse files Browse the repository at this point in the history
…-dev#2727)

Signed-off-by: Tim Seagren <[email protected]>
  • Loading branch information
matiasinsaurralde authored and chaospuppy committed Aug 5, 2024
1 parent dba3bc9 commit e30bcb9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<name>[^\.]+)\.(?P<namespace>[^\.]+)\.svc\.cluster\.local$`)
)

func (p *Packager) resetRegistryHPA(ctx context.Context) {
if p.isConnectedToCluster() && p.hpaModified {
if err := p.cluster.EnableRegHPAScaleDown(ctx); err != nil {
Expand Down Expand Up @@ -742,11 +747,7 @@ func serviceInfoFromServiceURL(serviceURL string) (string, string, int, error) {
}

// Match hostname against local cluster service format.
pattern, err := regexp.Compile(`^(?P<name>[^\.]+)\.(?P<namespace>[^\.]+)\.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 {
Expand Down

0 comments on commit e30bcb9

Please sign in to comment.