forked from LaconicNetwork/kompose
Merge pull request #1955 from jvitor83/feature/no-interpolate
Add no-interpolate feature option to the CLI
This commit is contained in:
commit
6b704502d6
@ -62,6 +62,9 @@ var (
|
|||||||
// default is true.
|
// default is true.
|
||||||
WithKomposeAnnotation bool
|
WithKomposeAnnotation bool
|
||||||
|
|
||||||
|
// NoInterpolation decides if we will interpolate environment variables in the compose file.
|
||||||
|
NoInterpolate bool
|
||||||
|
|
||||||
// MultipleContainerMode which enables creating multi containers in a single pod is a developing function.
|
// MultipleContainerMode which enables creating multi containers in a single pod is a developing function.
|
||||||
// default is false
|
// default is false
|
||||||
MultipleContainerMode bool
|
MultipleContainerMode bool
|
||||||
@ -121,6 +124,7 @@ var convertCmd = &cobra.Command{
|
|||||||
YAMLIndent: ConvertYAMLIndent,
|
YAMLIndent: ConvertYAMLIndent,
|
||||||
Profiles: ConvertProfiles,
|
Profiles: ConvertProfiles,
|
||||||
WithKomposeAnnotation: WithKomposeAnnotation,
|
WithKomposeAnnotation: WithKomposeAnnotation,
|
||||||
|
NoInterpolate: NoInterpolate,
|
||||||
MultipleContainerMode: MultipleContainerMode,
|
MultipleContainerMode: MultipleContainerMode,
|
||||||
ServiceGroupMode: ServiceGroupMode,
|
ServiceGroupMode: ServiceGroupMode,
|
||||||
ServiceGroupName: ServiceGroupName,
|
ServiceGroupName: ServiceGroupName,
|
||||||
@ -202,6 +206,7 @@ func init() {
|
|||||||
convertCmd.Flags().BoolVar(&GenerateNetworkPolicies, "generate-network-policies", false, "Specify whether to generate network policies or not")
|
convertCmd.Flags().BoolVar(&GenerateNetworkPolicies, "generate-network-policies", false, "Specify whether to generate network policies or not")
|
||||||
|
|
||||||
convertCmd.Flags().BoolVar(&WithKomposeAnnotation, "with-kompose-annotation", true, "Add kompose annotations to generated resource")
|
convertCmd.Flags().BoolVar(&WithKomposeAnnotation, "with-kompose-annotation", true, "Add kompose annotations to generated resource")
|
||||||
|
convertCmd.Flags().BoolVar(&NoInterpolate, "no-interpolate", false, "Keep environment variable names in the Compose file")
|
||||||
|
|
||||||
// Deprecated commands
|
// Deprecated commands
|
||||||
convertCmd.Flags().BoolVar(&ConvertEmptyVols, "emptyvols", false, "Use Empty Volumes. Do not generate PVCs")
|
convertCmd.Flags().BoolVar(&ConvertEmptyVols, "emptyvols", false, "Use Empty Volumes. Do not generate PVCs")
|
||||||
|
|||||||
@ -218,7 +218,7 @@ func Convert(opt kobject.ConvertOptions) ([]runtime.Object, error) {
|
|||||||
komposeObject := kobject.KomposeObject{
|
komposeObject := kobject.KomposeObject{
|
||||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||||
}
|
}
|
||||||
komposeObject, err = l.LoadFile(opt.InputFiles, opt.Profiles)
|
komposeObject, err = l.LoadFile(opt.InputFiles, opt.Profiles, opt.NoInterpolate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf(err.Error())
|
log.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,6 +92,7 @@ type ConvertOptions struct {
|
|||||||
ServiceGroupName string
|
ServiceGroupName string
|
||||||
SecretsAsFiles bool
|
SecretsAsFiles bool
|
||||||
GenerateNetworkPolicies bool
|
GenerateNetworkPolicies bool
|
||||||
|
NoInterpolate bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsPodController indicate if the user want to use a controller
|
// IsPodController indicate if the user want to use a controller
|
||||||
|
|||||||
@ -151,7 +151,7 @@ func checkUnsupportedKey(composeProject *types.Project) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadFile loads a compose file into KomposeObject
|
// LoadFile loads a compose file into KomposeObject
|
||||||
func (c *Compose) LoadFile(files []string, profiles []string) (kobject.KomposeObject, error) {
|
func (c *Compose) LoadFile(files []string, profiles []string, noInterpolate bool) (kobject.KomposeObject, error) {
|
||||||
// Gather the working directory
|
// Gather the working directory
|
||||||
workingDir, err := transformer.GetComposeFileDir(files)
|
workingDir, err := transformer.GetComposeFileDir(files)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -161,7 +161,7 @@ func (c *Compose) LoadFile(files []string, profiles []string) (kobject.KomposeOb
|
|||||||
projectOptions, err := cli.NewProjectOptions(
|
projectOptions, err := cli.NewProjectOptions(
|
||||||
files, cli.WithOsEnv,
|
files, cli.WithOsEnv,
|
||||||
cli.WithWorkingDirectory(workingDir),
|
cli.WithWorkingDirectory(workingDir),
|
||||||
cli.WithInterpolation(true),
|
cli.WithInterpolation(!noInterpolate),
|
||||||
cli.WithProfiles(profiles),
|
cli.WithProfiles(profiles),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import (
|
|||||||
|
|
||||||
// Loader interface defines loader that loads files and converts it to kobject representation
|
// Loader interface defines loader that loads files and converts it to kobject representation
|
||||||
type Loader interface {
|
type Loader interface {
|
||||||
LoadFile(files []string, profiles []string) (kobject.KomposeObject, error)
|
LoadFile(files []string, profiles []string, noInterpolate bool) (kobject.KomposeObject, error)
|
||||||
///Name() string
|
///Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -276,6 +276,12 @@ k8s_output="$KOMPOSE_ROOT/script/test/fixtures/compose-env-interpolation/output-
|
|||||||
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
|
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
|
||||||
convert::expect_success "$os_cmd" "$os_output" || exit 1
|
convert::expect_success "$os_cmd" "$os_output" || exit 1
|
||||||
|
|
||||||
|
# Test support for compose env without interpolation
|
||||||
|
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/compose-env-no-interpolation/compose.yaml convert --stdout --no-interpolate --with-kompose-annotation=false"
|
||||||
|
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/compose-env-no-interpolation/output-k8s.yaml"
|
||||||
|
convert::expect_success "$k8s_cmd" "$k8s_output" || exit 1
|
||||||
|
convert::expect_success "$os_cmd" "$os_output" || exit 1
|
||||||
|
|
||||||
# Test support for subpath volume
|
# Test support for subpath volume
|
||||||
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/vols-subpath/compose.yaml convert --stdout --with-kompose-annotation=false"
|
k8s_cmd="kompose -f $KOMPOSE_ROOT/script/test/fixtures/vols-subpath/compose.yaml convert --stdout --with-kompose-annotation=false"
|
||||||
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/vols-subpath/output-k8s.yaml"
|
k8s_output="$KOMPOSE_ROOT/script/test/fixtures/vols-subpath/output-k8s.yaml"
|
||||||
|
|||||||
10
script/test/fixtures/compose-env-no-interpolation/compose.yaml
vendored
Normal file
10
script/test/fixtures/compose-env-no-interpolation/compose.yaml
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
foo:
|
||||||
|
image: ${DOCKER_REGISTRY-}foo:${IMAGE_TAG:-latest}
|
||||||
|
build: .
|
||||||
|
environment:
|
||||||
|
- VERSION=${IMAGE_TAG:-latest}
|
||||||
|
ports:
|
||||||
|
- 80:80
|
||||||
43
script/test/fixtures/compose-env-no-interpolation/output-k8s.yaml
vendored
Normal file
43
script/test/fixtures/compose-env-no-interpolation/output-k8s.yaml
vendored
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
io.kompose.service: foo
|
||||||
|
name: foo
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: "80"
|
||||||
|
port: 80
|
||||||
|
targetPort: 80
|
||||||
|
selector:
|
||||||
|
io.kompose.service: foo
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
io.kompose.service: foo
|
||||||
|
name: foo
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
io.kompose.service: foo
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
io.kompose.service: foo
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- env:
|
||||||
|
- name: VERSION
|
||||||
|
value: ${IMAGE_TAG:-latest}
|
||||||
|
image: ${DOCKER_REGISTRY-}foo:${IMAGE_TAG:-latest}
|
||||||
|
name: foo
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
protocol: TCP
|
||||||
|
restartPolicy: Always
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user