Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 6668fb1

Browse files
committed
Use constants for v1beta1 and v1beta2
Signed-off-by: Joffrey F <joffrey@docker.com>
1 parent a4333e8 commit 6668fb1

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

cmd/docker-app/helm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func helmCmd() *cobra.Command {
3434
if err != nil {
3535
return err
3636
}
37-
if stackVersion != "v1beta2" && stackVersion != "v1beta1" {
38-
return fmt.Errorf("invalid stack version %q (accepted values: v1beta1, v1beta2)", stackVersion)
37+
if stackVersion != renderer.V1Beta1 && stackVersion != renderer.V1Beta2 {
38+
return fmt.Errorf("invalid stack version %q (accepted values: %s, %s)", stackVersion, renderer.V1Beta1, renderer.V1Beta2)
3939
}
4040
return renderer.Helm(appname, helmComposeFiles, helmSettingsFile, d, helmRender, stackVersion)
4141
},
@@ -49,6 +49,6 @@ be rendered instead of exported as a template.`
4949
}
5050
cmd.Flags().StringArrayVarP(&helmSettingsFile, "settings-files", "f", []string{}, "Override settings files")
5151
cmd.Flags().StringArrayVarP(&helmEnv, "set", "s", []string{}, "Override settings values")
52-
cmd.Flags().StringVarP(&stackVersion, "stack-version", "", "v1beta2", "Version of the stack specification for the produced helm chart")
52+
cmd.Flags().StringVarP(&stackVersion, "stack-version", "", renderer.V1Beta2, "Version of the stack specification for the produced helm chart")
5353
return cmd
5454
}

internal/renderer/helm.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ post-process the serialized yaml to replace all 'template_'-prefixed keys
3939
with the appropriate content (value or template)
4040
*/
4141

42+
const (
43+
// V1Beta1 is the string identifier for the v1beta1 version of the stack spec
44+
V1Beta1 = "v1beta1"
45+
// V1Beta2 is the string identifier for the v1beta2 version of the stack spec
46+
V1Beta2 = "v1beta2"
47+
)
48+
4249
type helmMaintainer struct {
4350
Name string
4451
}
@@ -219,7 +226,7 @@ func helmRender(appname string, targetDir string, composeFiles []string, setting
219226
stack = v1beta2.Stack{
220227
TypeMeta: metav1.TypeMeta{
221228
Kind: "stacks.compose.docker.com",
222-
APIVersion: "v1beta2",
229+
APIVersion: V1Beta2,
223230
},
224231
ObjectMeta: metav1.ObjectMeta{
225232
Name: internal.AppNameFromDir(appname),
@@ -234,7 +241,7 @@ func helmRender(appname string, targetDir string, composeFiles []string, setting
234241
stack = v1beta1.Stack{
235242
TypeMeta: metav1.TypeMeta{
236243
Kind: "stacks.compose.docker.com",
237-
APIVersion: "v1beta1",
244+
APIVersion: V1Beta1,
238245
},
239246
ObjectMeta: metav1.ObjectMeta{
240247
Name: internal.AppNameFromDir(appname),
@@ -268,7 +275,7 @@ func makeStack(appname string, targetDir string, data []byte, beta1 bool) error
268275
stack = templatev1beta2.Stack{
269276
TypeMeta: metav1.TypeMeta{
270277
Kind: "stacks.compose.docker.com",
271-
APIVersion: "v1beta2",
278+
APIVersion: V1Beta2,
272279
},
273280
ObjectMeta: metav1.ObjectMeta{
274281
Name: internal.AppNameFromDir(appname),
@@ -284,7 +291,7 @@ func makeStack(appname string, targetDir string, data []byte, beta1 bool) error
284291
stack = v1beta1.Stack{
285292
TypeMeta: metav1.TypeMeta{
286293
Kind: "stacks.compose.docker.com",
287-
APIVersion: "v1beta1",
294+
APIVersion: V1Beta1,
288295
},
289296
ObjectMeta: metav1.ObjectMeta{
290297
Name: internal.AppNameFromDir(appname),
@@ -318,7 +325,7 @@ func makeStack(appname string, targetDir string, data []byte, beta1 bool) error
318325
// Helm renders an app as an Helm Chart
319326
func Helm(appname string, composeFiles []string, settingsFile []string, env map[string]string, render bool, stackVersion string) error {
320327
targetDir := internal.AppNameFromDir(appname) + ".chart"
321-
beta1 := stackVersion == "v1beta1"
328+
beta1 := stackVersion == V1Beta1
322329
if err := os.Mkdir(targetDir, 0755); err != nil && !os.IsExist(err) {
323330
return errors.Wrap(err, "failed to create Chart directory")
324331
}

0 commit comments

Comments
 (0)