-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add helm package mage target #7232
base: main
Are you sure you want to change the base?
Changes from 3 commits
9094768
afa1caa
f1c97c8
c159278
f92db32
7f81d30
84e9b55
30e8941
ef31de9
819480c
260bfac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# This script runs the helm-charts for the given environment | ||
# STAGING OR SNAPSHOT | ||
|
||
# shellcheck disable=SC1091 | ||
source .buildkite/scripts/common.sh | ||
|
||
set -euo pipefail | ||
|
||
echo "--- mage package tests" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
SNAPSHOT=true mage helm:package |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3628,10 +3628,76 @@ func updateYamlFile(path string, keyVal ...struct { | |
return nil | ||
} | ||
|
||
// BuildDependencies builds the dependencies for the Elastic-Agent Helm chart. | ||
func (Helm) BuildDependencies() error { | ||
return helm.BuildChartDependencies(helmChartPath) | ||
} | ||
|
||
// Package packages the Elastic-Agent Helm chart. Note that you need to set SNAPSHOT="false" to build a production-ready package. | ||
func (h Helm) Package() error { | ||
mg.SerialDeps(h.BuildDependencies) | ||
|
||
agentVersion := bversion.GetParsedAgentPackageVersion() | ||
agentCoreVersion := agentVersion.CoreVersion() | ||
agentImageTag := agentCoreVersion + "-SNAPSHOT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for some reason
when using is that the expected behaviour? |
||
|
||
// need to explicitly set SNAPSHOT="false" to produce a production-ready package | ||
productionPackage := os.Getenv("SNAPSHOT") == "false" | ||
|
||
agentChartVersion := agentCoreVersion + "-beta" | ||
switch { | ||
case productionPackage && agentVersion.Major() >= 9: | ||
// for 9.0.0 and later versions, elastic-agent Helm chart is GA | ||
agentChartVersion = agentCoreVersion | ||
case productionPackage && agentVersion.Major() >= 8 && agentVersion.Minor() >= 18: | ||
// for 8.18.0 and later versions, elastic-agent Helm chart is GA | ||
agentChartVersion = agentCoreVersion | ||
} | ||
|
||
for yamlFile, keyVals := range map[string][]struct { | ||
key string | ||
value string | ||
}{ | ||
// values file for elastic-agent Helm Chart | ||
filepath.Join(helmChartPath, "values.yaml"): { | ||
{"agent.version", agentCoreVersion}, | ||
// always use the SNAPSHOT version for image tag | ||
// for the chart that resides in the git repo | ||
{"agent.image.tag", agentImageTag}, | ||
}, | ||
// Chart.yaml for elastic-agent Helm Chart | ||
filepath.Join(helmChartPath, "Chart.yaml"): { | ||
{"appVersion", agentCoreVersion}, | ||
{"version", agentChartVersion}, | ||
}, | ||
} { | ||
if err := updateYamlFile(yamlFile, keyVals...); err != nil { | ||
return fmt.Errorf("failed to update agent version: %w", err) | ||
} | ||
} | ||
|
||
// lint before packaging | ||
if err := h.Lint(); err != nil { | ||
return err | ||
} | ||
|
||
settings := cli.New() // Helm CLI settings | ||
actionConfig := &action.Configuration{} | ||
|
||
err := actionConfig.Init(settings.RESTClientGetter(), "default", "", | ||
func(format string, v ...interface{}) {}) | ||
if err != nil { | ||
return fmt.Errorf("failed to init helm action config: %w", err) | ||
} | ||
|
||
packageAction := action.NewPackage() | ||
_, err = packageAction.Run(helmChartPath, nil) | ||
if err != nil { | ||
return fmt.Errorf("failed to package helm chart: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func updateYamlNodes(rootNode *yaml.Node, value string, keys ...string) error { | ||
if len(keys) == 0 { | ||
return fmt.Errorf("no keys provided") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use https://github.com/elastic/oblt-google-auth-buildkite-plugin
Still need to create the relevant copy file from local to the specific bucket