Skip to content

Commit fc556e8

Browse files
committed
cmd/operator-sdk,internal: move HelmChartsDir constant to internal/pkg/scaffold/constants.go to avoid unnecessary dep imports in non-helm projects
1 parent d1004a9 commit fc556e8

File tree

6 files changed

+7
-12
lines changed

6 files changed

+7
-12
lines changed

cmd/operator-sdk/new/cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func doHelmScaffold() error {
278278
return fmt.Errorf("failed to create helm chart: %s", err)
279279
}
280280

281-
valuesPath := filepath.Join("<project_dir>", helm.HelmChartsDir, chart.GetMetadata().GetName(), "values.yaml")
281+
valuesPath := filepath.Join("<project_dir>", scaffold.HelmChartsDir, chart.GetMetadata().GetName(), "values.yaml")
282282
crSpec := fmt.Sprintf("# Default values copied from %s\n\n%s", valuesPath, chart.GetValues().GetRaw())
283283

284284
k8sCfg, err := config.GetConfig()

internal/pkg/scaffold/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ const (
3535
DeployDir = "deploy"
3636
OLMCatalogDir = DeployDir + filePathSep + "olm-catalog"
3737
CRDsDir = DeployDir + filePathSep + "crds"
38+
HelmChartsDir = "helm-charts"
3839
VersionDir = "version"
3940
)

internal/pkg/scaffold/helm/chart.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ import (
3535
)
3636

3737
const (
38-
39-
// HelmChartsDir is the relative directory within an SDK project where Helm
40-
// charts are stored.
41-
HelmChartsDir string = "helm-charts"
42-
4338
// DefaultAPIVersion is the Kubernetes CRD API Version used for fetched
4439
// charts when the --api-version flag is not specified
4540
DefaultAPIVersion string = "charts.helm.k8s.io/v1alpha1"
@@ -113,7 +108,7 @@ type CreateChartOptions struct {
113108
// CreateChart returns an error if an error occurs creating the scaffold.Resource or
114109
// creating the chart.
115110
func CreateChart(projectDir string, opts CreateChartOptions) (*scaffold.Resource, *chart.Chart, error) {
116-
chartsDir := filepath.Join(projectDir, HelmChartsDir)
111+
chartsDir := filepath.Join(projectDir, scaffold.HelmChartsDir)
117112
err := os.MkdirAll(chartsDir, 0755)
118113
if err != nil {
119114
return nil, nil, err
@@ -135,7 +130,7 @@ func CreateChart(projectDir string, opts CreateChartOptions) (*scaffold.Resource
135130
return nil, nil, err
136131
}
137132

138-
relChartPath := filepath.Join(HelmChartsDir, c.GetMetadata().GetName())
133+
relChartPath := filepath.Join(scaffold.HelmChartsDir, c.GetMetadata().GetName())
139134
absChartPath := filepath.Join(projectDir, relChartPath)
140135
if err := fetchChartDependencies(absChartPath); err != nil {
141136
return nil, nil, err

internal/pkg/scaffold/helm/dockerfile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (d *Dockerfile) GetInput() (input.Input, error) {
3636
if d.Path == "" {
3737
d.Path = filepath.Join(scaffold.BuildDir, scaffold.DockerfileFile)
3838
}
39-
d.HelmChartsDir = HelmChartsDir
39+
d.HelmChartsDir = scaffold.HelmChartsDir
4040
d.ImageTag = strings.TrimSuffix(version.Version, "+git")
4141
d.TemplateBody = dockerFileHelmTmpl
4242
return d.Input, nil

internal/pkg/scaffold/helm/watches.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (s *WatchesYAML) GetInput() (input.Input, error) {
3535
if s.Path == "" {
3636
s.Path = WatchesYamlFile
3737
}
38-
s.HelmChartsDir = HelmChartsDir
38+
s.HelmChartsDir = scaffold.HelmChartsDir
3939
s.TemplateBody = watchesYAMLTmpl
4040
if s.ChartName == "" {
4141
s.ChartName = s.Resource.LowerKind

internal/util/projutil/project_util.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold"
2626
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/ansible"
27-
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/helm"
2827

2928
log "github.com/sirupsen/logrus"
3029
"github.com/spf13/cobra"
@@ -106,7 +105,7 @@ func GetOperatorType() OperatorType {
106105
if stat, err := os.Stat(ansible.RolesDir); err == nil && stat.IsDir() {
107106
return OperatorTypeAnsible
108107
}
109-
if stat, err := os.Stat(helm.HelmChartsDir); err == nil && stat.IsDir() {
108+
if stat, err := os.Stat(scaffold.HelmChartsDir); err == nil && stat.IsDir() {
110109
return OperatorTypeHelm
111110
}
112111
return OperatorTypeUnknown

0 commit comments

Comments
 (0)