• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubernetes-sigs / kubebuilder / 24467768991

15 Apr 2026 05:08PM UTC coverage: 80.969% (-1.2%) from 82.18%
24467768991

Pull #5621

github

camilamacedo86
chore(helm/v2-alpha): Refactory the code
Pull Request #5621: 🌱 (helm/v2-alpha): Refactory the code

3253 of 3670 new or added lines in 29 files covered. (88.64%)

24 existing lines in 1 file now uncovered.

7790 of 9621 relevant lines covered (80.97%)

70.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.35
/pkg/plugins/optional/helm/v2alpha/scaffolds/edit.go
1
/*
2
Copyright 2026 The Kubernetes Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package scaffolds
18

19
import (
20
        "fmt"
21
        "log/slog"
22
        "os"
23
        "os/exec"
24
        "path/filepath"
25

26
        "sigs.k8s.io/kubebuilder/v4/pkg/config"
27
        "sigs.k8s.io/kubebuilder/v4/pkg/machinery"
28
        "sigs.k8s.io/kubebuilder/v4/pkg/plugins"
29
        "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v2alpha/scaffolds/internal"
30
)
31

32
const (
33
        defaultManifestsFile = "dist/install.yaml"
34
)
35

36
var _ plugins.Scaffolder = &chartScaffolder{}
37

38
type chartScaffolder struct {
39
        config        config.Config
40
        fs            machinery.Filesystem
41
        force         bool
42
        manifestsFile string
43
        outputDir     string
44
}
45

46
// NewChartScaffolder returns a new Scaffolder for Helm chart generation from kustomize output.
47
func NewChartScaffolder(cfg config.Config, force bool, manifestsFile, outputDir string) plugins.Scaffolder {
17✔
48
        return &chartScaffolder{
17✔
49
                config:        cfg,
17✔
50
                force:         force,
17✔
51
                manifestsFile: manifestsFile,
17✔
52
                outputDir:     outputDir,
17✔
53
        }
17✔
54
}
17✔
55

56
// InjectFS implements cmdutil.Scaffolder.
57
func (s *chartScaffolder) InjectFS(fs machinery.Filesystem) {
17✔
58
        s.fs = fs
17✔
59
}
17✔
60

61
// Scaffold generates the complete Helm chart from kustomize output.
62
func (s *chartScaffolder) Scaffold() error {
17✔
63
        slog.Info("Generating Helm Chart from kustomize output")
17✔
64

17✔
65
        if err := s.ensureChartDirectoryExists(); err != nil {
17✔
NEW
66
                return fmt.Errorf("failed to create chart directory: %w", err)
×
NEW
67
        }
×
68

69
        if s.manifestsFile == defaultManifestsFile {
17✔
NEW
70
                if err := s.generateKustomizeOutput(); err != nil {
×
NEW
71
                        return fmt.Errorf("failed to generate kustomize output: %w", err)
×
NEW
72
                }
×
73
        }
74

75
        chartScaffolder := internal.NewChartScaffolder(internal.ChartScaffolderConfig{
17✔
76
                ProjectName:   s.config.GetProjectName(),
17✔
77
                ManifestsFile: s.manifestsFile,
17✔
78
                OutputDir:     s.outputDir,
17✔
79
                Force:         s.force,
17✔
80
        })
17✔
81

17✔
82
        builders, err := chartScaffolder.PrepareTemplates(s.fs)
17✔
83
        if err != nil {
17✔
NEW
84
                return fmt.Errorf("failed to prepare chart templates: %w", err)
×
NEW
85
        }
×
86

87
        scaffold := machinery.NewScaffold(s.fs, machinery.WithConfig(s.config))
17✔
88

17✔
89
        if err := scaffold.Execute(builders...); err != nil {
17✔
NEW
90
                return fmt.Errorf("failed to execute Helm chart templates: %w", err)
×
NEW
91
        }
×
92

93
        slog.Info("Helm Chart generation completed successfully")
17✔
94
        return nil
17✔
95
}
96

97
// generateKustomizeOutput runs make build-installer to generate the manifests file
NEW
98
func (s *chartScaffolder) generateKustomizeOutput() error {
×
NEW
99
        slog.Info("Generating kustomize output with make build-installer")
×
NEW
100

×
NEW
101
        // Check if Makefile exists
×
NEW
102
        if _, err := os.Stat("Makefile"); os.IsNotExist(err) {
×
NEW
103
                return fmt.Errorf("makefile not found in current directory")
×
NEW
104
        }
×
105

106
        // Run make build-installer
NEW
107
        cmd := exec.Command("make", "build-installer")
×
NEW
108
        cmd.Stdout = os.Stdout
×
NEW
109
        cmd.Stderr = os.Stderr
×
NEW
110

×
NEW
111
        if err := cmd.Run(); err != nil {
×
NEW
112
                return fmt.Errorf("failed to run make build-installer: %w", err)
×
NEW
113
        }
×
114

115
        // Verify that the manifests file was created
NEW
116
        if _, err := os.Stat(defaultManifestsFile); os.IsNotExist(err) {
×
NEW
117
                return fmt.Errorf("%s was not generated by make build-installer", defaultManifestsFile)
×
NEW
118
        }
×
119

NEW
120
        return nil
×
121
}
122

123
// ensureChartDirectoryExists creates the chart directory structure if it doesn't exist
124
func (s *chartScaffolder) ensureChartDirectoryExists() error {
17✔
125
        dirs := []string{
17✔
126
                filepath.Join(s.outputDir, "chart"),
17✔
127
                filepath.Join(s.outputDir, "chart", "templates"),
17✔
128
        }
17✔
129

17✔
130
        for _, dir := range dirs {
51✔
131
                if err := os.MkdirAll(dir, 0o755); err != nil {
34✔
NEW
132
                        return fmt.Errorf("failed to create directory %s: %w", dir, err)
×
NEW
133
                }
×
134
        }
135

136
        return nil
17✔
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc