Skip to content
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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
19 changes: 18 additions & 1 deletion .buildkite/pipeline.elastic-agent-helm-charts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@ steps:

- label: ":elastic-stack: Create helm chart"
command: |
echo "TBC"
.buildkite/scripts/steps/helm-charts.sh
plugins:
- elastic/oblt-google-auth#v1.0.0:
lifetime: 1800 # seconds
agents:
provider: "gcp"
machineType: "n1-standard-8"

- label: ":elastic-stack: Google bucket access"
command: |
echo "Credentials are located at \$GOOGLE_APPLICATION_CREDENTIALS"
gcloud storage buckets list || true
plugins:
- elastic/oblt-google-auth#v1.0.0:
lifetime: 1800 # seconds
Copy link
Member

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

agents:
provider: "gcp"
machineType: "n1-standard-8"

- wait: ~

Expand Down
11 changes: 11 additions & 0 deletions .buildkite/scripts/steps/helm-charts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See

image

# 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

SNAPSHOT=true mage helm:package
66 changes: 66 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

@v1v v1v Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason SNAPSHOT=true is not honoured

CHARTS_URL: "https://storage.googleapis.com/elastic-agent-helm-chart/elastic-agent-9.1.0-beta.tgz"

when using SNAPSHOT=true mage helm:package

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")
Expand Down
Loading