Skip to content

Commit

Permalink
refactor: compile local cluster service format regexp just once (#2727)
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasinsaurralde authored Jul 17, 2024
1 parent 891e96e commit ff50f77
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 ff50f77

Please sign in to comment.