feat: allow overriding release name

This commit is contained in:
Kevin Franklin Kim 2025-04-10 09:03:27 +02:00
parent 5866731e84
commit f18a6240e7
No known key found for this signature in database
3 changed files with 31 additions and 18 deletions

View File

@ -17,20 +17,22 @@ import (
)
type Unit struct {
// Optional release name
Name string `json:"name,omitempty" yaml:"name,omitempty"`
// Chart settings
Chart Chart `json:"chart,omitempty" yaml:"chart,omitempty" jsonschema:"anyof_type=string,anyof_ref=#/$defs/Chart"`
// Kustomize files path
Kustomize string `json:"kustomize,omitempty" yaml:"kustomize,omitempty"`
// List of tags
Tags Tags `json:"tags,omitempty" yaml:"tags,omitempty"`
// Installation priority, higher comes first
Priority int `json:"priority,omitempty" yaml:"priority,omitempty"`
// Extend chart values
Extends string `json:"extends,omitempty" yaml:"extends,omitempty"`
// Kustomize files path
Kustomize string `json:"kustomize,omitempty" yaml:"kustomize,omitempty"`
// Map of containers to build
Builds map[string]Build `json:"builds,omitempty" yaml:"builds,omitempty"`
// Chart values
Values map[string]any `json:"values,omitempty" yaml:"values,omitempty"`
// Extend chart values
Extends string `json:"extends,omitempty" yaml:"extends,omitempty"`
}
// ------------------------------------------------------------------------------------------------

View File

@ -32,6 +32,7 @@ const (
type Squadron struct {
basePath string
nameFn func() string
namespace string
files []string
config string
@ -389,7 +390,7 @@ func (sq *Squadron) Down(ctx context.Context, helmArgs []string, parallel int) e
return err
}
name := fmt.Sprintf("%s-%s", key, k)
name := sq.getReleaseName(key, k, v)
namespace, err := sq.Namespace(ctx, key, k)
if err != nil {
return err
@ -471,7 +472,7 @@ func (sq *Squadron) Diff(ctx context.Context, helmArgs []string, parallel int) (
return err
}
name := fmt.Sprintf("%s-%s", key, k)
name := sq.getReleaseName(key, k, v)
namespace, err := sq.Namespace(ctx, key, k)
if err != nil {
return err
@ -590,7 +591,7 @@ func (sq *Squadron) Status(ctx context.Context, helmArgs []string, parallel int)
_ = sq.Config().Squadrons.Iterate(ctx, func(ctx context.Context, key string, value config.Map[*config.Unit]) error {
return value.Iterate(ctx, func(ctx context.Context, k string, v *config.Unit) error {
var status statusType
name := fmt.Sprintf("%s-%s", key, k)
name := sq.getReleaseName(key, k, v)
namespace, err := sq.Namespace(ctx, key, k)
if err != nil {
return errors.Errorf("failed to retrieve namsspace: %s/%s", key, k)
@ -701,7 +702,7 @@ func (sq *Squadron) Rollback(ctx context.Context, revision string, helmArgs []st
_ = sq.Config().Squadrons.Iterate(ctx, func(ctx context.Context, key string, value config.Map[*config.Unit]) error {
return value.Iterate(ctx, func(ctx context.Context, k string, v *config.Unit) error {
name := fmt.Sprintf("%s-%s", key, k)
name := sq.getReleaseName(key, k, v)
namespace, err := sq.Namespace(ctx, key, k)
if err != nil {
return err
@ -854,7 +855,6 @@ func (sq *Squadron) Up(ctx context.Context, helmArgs []string, username, version
// install chart
cmd := util.NewHelmCommand().
Stdin(bytes.NewReader(valueBytes)).
// Stdout(os.Stdout).
Args("upgrade", name, "--install").
Args("--set", "global.foomo.squadron.name="+a.squadron).
Args("--set", "global.foomo.squadron.unit="+a.unit).
@ -924,7 +924,7 @@ func (sq *Squadron) Template(ctx context.Context, helmArgs []string, parallel in
return err
}
name := fmt.Sprintf("%s-%s", key, k)
name := sq.getReleaseName(key, k, v)
namespace, err := sq.Namespace(ctx, key, k)
if err != nil {
spinner.Fail(err.Error())
@ -956,3 +956,10 @@ func (sq *Squadron) Template(ctx context.Context, helmArgs []string, parallel in
return ret.String(), nil
}
func (sq *Squadron) getReleaseName(squadron, unit string, u *config.Unit) string {
if u.Name != "" {
return u.Name
}
return squadron + "-" + unit
}

View File

@ -233,6 +233,10 @@
},
"Unit": {
"properties": {
"name": {
"type": "string",
"description": "Optional release name"
},
"chart": {
"anyOf": [
{
@ -244,10 +248,6 @@
],
"description": "Chart settings"
},
"kustomize": {
"type": "string",
"description": "Kustomize files path"
},
"tags": {
"$ref": "#/$defs/Tags",
"description": "List of tags"
@ -256,6 +256,14 @@
"type": "integer",
"description": "Installation priority, higher comes first"
},
"extends": {
"type": "string",
"description": "Extend chart values"
},
"kustomize": {
"type": "string",
"description": "Kustomize files path"
},
"builds": {
"additionalProperties": {
"$ref": "#/$defs/Build"
@ -266,10 +274,6 @@
"values": {
"type": "object",
"description": "Chart values"
},
"extends": {
"type": "string",
"description": "Extend chart values"
}
},
"additionalProperties": false,