Skip to content

Commit

Permalink
Merge pull request #565 from Alero-Awani/alero/meshkit/helm-dry-run
Browse files Browse the repository at this point in the history
Add Default Kubernetes Version for Dry-Run
  • Loading branch information
Mohd Uzair authored Aug 21, 2024
2 parents 4703712 + bee904d commit 836d0eb
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions utils/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

func extractSemVer(versionConstraint string) string {
reg := regexp.MustCompile(`v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$`)
reg := regexp.MustCompile(`v?([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$`)
match := reg.Find([]byte(versionConstraint))
if match != nil {
return string(match)
Expand All @@ -34,14 +34,20 @@ func DryRunHelmChart(chart *chart.Chart) ([]byte, error) {
act.DryRun = true
act.IncludeCRDs = true
act.ClientOnly = true

version := "v1.29.5" // Default version

if chart.Metadata.KubeVersion != "" {
version := extractSemVer(chart.Metadata.KubeVersion)
if version != "" {
act.KubeVersion = &chartutil.KubeVersion{
Version: version,
}
}
extractedVersion := extractSemVer(chart.Metadata.KubeVersion)
if extractedVersion != "" {
version = extractedVersion
}
}

act.KubeVersion = &chartutil.KubeVersion{
Version: version,
}

rel, err := act.Run(chart, nil)
if err != nil {
return nil, ErrDryRunHelmChart(err, chart.Name())
Expand Down

0 comments on commit 836d0eb

Please sign in to comment.