Skip to content

Commit 860d01a

Browse files
committed
fix: propagate kubectl error in GetPodsforDeployment, compile regexp once
1 parent c65ea19 commit 860d01a

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

pkg/chart/chart.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ func (t *Testing) CheckVersionIncrement(chart *Chart) error {
846846
}
847847

848848
if result >= 0 {
849-
return errors.New("chart version not ok. Needs a version bump! ")
849+
return errors.New("chart version not ok. Needs a version bump!")
850850
}
851851

852852
fmt.Println("Chart version ok.")

pkg/tool/kubectl.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,16 @@ func (k Kubectl) WaitForDeployments(namespace string, selector string) error {
184184
}
185185

186186
func (k Kubectl) GetPodsforDeployment(namespace string, deployment string) ([]string, error) {
187-
jsonString, _ := k.exec.RunProcessAndCaptureStdout("kubectl",
187+
jsonString, err := k.exec.RunProcessAndCaptureStdout("kubectl",
188188
fmt.Sprintf("--request-timeout=%s", k.timeout),
189189
"get", "deployment", deployment, "--namespace", namespace, "--output=json")
190-
var deploymentMap map[string]any
191-
err := json.Unmarshal([]byte(jsonString), &deploymentMap)
192190
if err != nil {
193191
return nil, err
194192
}
193+
var deploymentMap map[string]any
194+
if err := json.Unmarshal([]byte(jsonString), &deploymentMap); err != nil {
195+
return nil, err
196+
}
195197

196198
spec := deploymentMap["spec"].(map[string]any)
197199
selector := spec["selector"].(map[string]any)

pkg/util/util.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import (
3333

3434
const chars = "1234567890abcdefghijklmnopqrstuvwxyz"
3535

36+
var sanitizeNameRe = regexp.MustCompile("^[^a-zA-Z0-9]+")
37+
3638
type Maintainer struct {
3739
Name string `yaml:"name"`
3840
Email string `yaml:"email"`
@@ -217,14 +219,12 @@ func GithubGroupsEnd(w io.Writer) {
217219
}
218220

219221
func SanitizeName(s string, maxLength int) string {
220-
reg := regexp.MustCompile("^[^a-zA-Z0-9]+")
221-
222222
excess := len(s) - maxLength
223223
result := s
224224
if excess > 0 {
225225
result = s[excess:]
226226
}
227-
return reg.ReplaceAllString(result, "")
227+
return sanitizeNameRe.ReplaceAllString(result, "")
228228
}
229229

230230
func GetRandomPort() (int, error) {

0 commit comments

Comments
 (0)