Skip to content

Commit

Permalink
Everest 1673 custom helm dir in db namespaces (#1007)
Browse files Browse the repository at this point in the history
* EVEREST-1673 allow custom helm dir for db namespaces
  • Loading branch information
oksana-grishchenko authored Jan 14, 2025
1 parent ccb8a49 commit da3b809
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
12 changes: 1 addition & 11 deletions pkg/cli/namespaces/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io"
"os"
"path"
"regexp"
"strings"

Expand All @@ -29,11 +28,6 @@ import (
"github.com/percona/everest/pkg/version"
)

const (
// Path to the everest-db-namespace subchart, relative to the main chart.
dbNamespaceSubChartPath = "/charts/everest-db-namespace"
)

//nolint:gochecknoglobals
var (
// ErrNSEmpty appears when the provided list of the namespaces is considered empty.
Expand Down Expand Up @@ -271,10 +265,6 @@ func (n *NamespaceAdder) provisionDBNamespace(
if err != nil {
return err
}
chartDir := ""
if n.cfg.ChartDir != "" {
chartDir = path.Join(n.cfg.ChartDir, dbNamespaceSubChartPath)
}
values := Must(helmutils.MergeVals(n.getValues(), nil))
installer := helm.Installer{
ReleaseName: namespace,
Expand All @@ -283,7 +273,7 @@ func (n *NamespaceAdder) provisionDBNamespace(
CreateReleaseNamespace: !nsExists,
}
if err := installer.Init(n.cfg.KubeconfigPath, helm.ChartOptions{
Directory: chartDir,
Directory: cliutils.DBNamespaceSubChartPath(n.cfg.ChartDir),
URL: n.cfg.RepoURL,
Name: helm.EverestDBNamespaceChartName,
Version: version,
Expand Down
15 changes: 6 additions & 9 deletions pkg/cli/upgrade/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package upgrade
import (
"context"
"fmt"
"path/filepath"

"github.com/AlekSi/pointer"
"helm.sh/helm/v3/pkg/cli/values"
Expand All @@ -16,6 +15,7 @@ import (
"github.com/percona/everest/pkg/cli/helm"
helmutils "github.com/percona/everest/pkg/cli/helm/utils"
"github.com/percona/everest/pkg/cli/steps"
"github.com/percona/everest/pkg/cli/utils"
"github.com/percona/everest/pkg/common"
"github.com/percona/everest/pkg/kubernetes"
. "github.com/percona/everest/pkg/utils/must" //nolint:revive,stylecheck
Expand Down Expand Up @@ -140,9 +140,10 @@ func (u *Upgrade) upgradeEverestDBNamespaceHelmChart(ctx context.Context, namesp
ReleaseNamespace: namespace,
}
if err := installer.Init(u.config.KubeconfigPath, helm.ChartOptions{
URL: u.config.RepoURL,
Name: helm.EverestDBNamespaceChartName,
Version: u.upgradeToVersion,
URL: u.config.RepoURL,
Directory: utils.DBNamespaceSubChartPath(u.config.ChartDir),
Name: helm.EverestDBNamespaceChartName,
Version: u.upgradeToVersion,
}); err != nil {
return fmt.Errorf("could not initialize Helm installer: %w", err)
}
Expand Down Expand Up @@ -191,13 +192,9 @@ func (u *Upgrade) helmAdoptDBNamespaces(ctx context.Context, namespace, version
Values: values,
}

var directory string
if u.config.ChartDir != "" {
directory = filepath.Join(u.config.ChartDir, "charts/everest-db-namespace")
}
if err := installer.Init(u.config.KubeconfigPath, helm.ChartOptions{
URL: u.config.RepoURL,
Directory: directory,
Directory: utils.DBNamespaceSubChartPath(u.config.ChartDir),
Name: helm.EverestDBNamespaceChartName,
Version: version,
}); err != nil {
Expand Down
13 changes: 13 additions & 0 deletions pkg/cli/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"net/url"
"path"

"go.uber.org/zap"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -14,6 +15,18 @@ import (
"github.com/percona/everest/pkg/version"
)

const (
dbNamespaceSubChartPath = "/charts/everest-db-namespace"
)

// DBNamespaceSubChartPath returns the path to the everest-db-namespace sub-chart.
func DBNamespaceSubChartPath(dir string) string {
if dir == "" {
return ""
}
return path.Join(dir, dbNamespaceSubChartPath)
}

// CheckHelmInstallation ensures that the current installation was done using Helm chart.
// Returns the version of Everest installed in the cluster.
// Returns an error if the installation was not done using Helm chart.
Expand Down

0 comments on commit da3b809

Please sign in to comment.