test/cmd/process.sh has been merged into test/cmd/templates.sh since
they test the same functionality.
... | ... |
@@ -10432,6 +10432,10 @@ _oc_new-app() |
10432 | 10432 |
flags+=("--env=") |
10433 | 10433 |
two_word_flags+=("-e") |
10434 | 10434 |
local_nonpersistent_flags+=("--env=") |
10435 |
+ flags+=("--env-file=") |
|
10436 |
+ flags_with_completion+=("--env-file") |
|
10437 |
+ flags_completion+=("_filedir") |
|
10438 |
+ local_nonpersistent_flags+=("--env-file=") |
|
10435 | 10439 |
flags+=("--file=") |
10436 | 10440 |
flags_with_completion+=("--file") |
10437 | 10441 |
flags_completion+=("__handle_filename_extension_flag yaml|yml|json") |
... | ... |
@@ -10466,6 +10470,10 @@ _oc_new-app() |
10466 | 10466 |
flags+=("--param=") |
10467 | 10467 |
two_word_flags+=("-p") |
10468 | 10468 |
local_nonpersistent_flags+=("--param=") |
10469 |
+ flags+=("--param-file=") |
|
10470 |
+ flags_with_completion+=("--param-file") |
|
10471 |
+ flags_completion+=("_filedir") |
|
10472 |
+ local_nonpersistent_flags+=("--param-file=") |
|
10469 | 10473 |
flags+=("--search") |
10470 | 10474 |
flags+=("-S") |
10471 | 10475 |
local_nonpersistent_flags+=("--search") |
... | ... |
@@ -10538,6 +10546,10 @@ _oc_new-build() |
10538 | 10538 |
flags+=("--env=") |
10539 | 10539 |
two_word_flags+=("-e") |
10540 | 10540 |
local_nonpersistent_flags+=("--env=") |
10541 |
+ flags+=("--env-file=") |
|
10542 |
+ flags_with_completion+=("--env-file") |
|
10543 |
+ flags_completion+=("_filedir") |
|
10544 |
+ local_nonpersistent_flags+=("--env-file=") |
|
10541 | 10545 |
flags+=("--image-stream=") |
10542 | 10546 |
two_word_flags+=("-i") |
10543 | 10547 |
local_nonpersistent_flags+=("--image-stream=") |
... | ... |
@@ -11510,6 +11522,10 @@ _oc_process() |
11510 | 11510 |
flags+=("--param=") |
11511 | 11511 |
two_word_flags+=("-p") |
11512 | 11512 |
local_nonpersistent_flags+=("--param=") |
11513 |
+ flags+=("--param-file=") |
|
11514 |
+ flags_with_completion+=("--param-file") |
|
11515 |
+ flags_completion+=("_filedir") |
|
11516 |
+ local_nonpersistent_flags+=("--param-file=") |
|
11513 | 11517 |
flags+=("--parameters") |
11514 | 11518 |
local_nonpersistent_flags+=("--parameters") |
11515 | 11519 |
flags+=("--raw") |
... | ... |
@@ -15080,6 +15080,10 @@ _openshift_cli_new-app() |
15080 | 15080 |
flags+=("--env=") |
15081 | 15081 |
two_word_flags+=("-e") |
15082 | 15082 |
local_nonpersistent_flags+=("--env=") |
15083 |
+ flags+=("--env-file=") |
|
15084 |
+ flags_with_completion+=("--env-file") |
|
15085 |
+ flags_completion+=("_filedir") |
|
15086 |
+ local_nonpersistent_flags+=("--env-file=") |
|
15083 | 15087 |
flags+=("--file=") |
15084 | 15088 |
flags_with_completion+=("--file") |
15085 | 15089 |
flags_completion+=("__handle_filename_extension_flag yaml|yml|json") |
... | ... |
@@ -15114,6 +15118,10 @@ _openshift_cli_new-app() |
15114 | 15114 |
flags+=("--param=") |
15115 | 15115 |
two_word_flags+=("-p") |
15116 | 15116 |
local_nonpersistent_flags+=("--param=") |
15117 |
+ flags+=("--param-file=") |
|
15118 |
+ flags_with_completion+=("--param-file") |
|
15119 |
+ flags_completion+=("_filedir") |
|
15120 |
+ local_nonpersistent_flags+=("--param-file=") |
|
15117 | 15121 |
flags+=("--search") |
15118 | 15122 |
flags+=("-S") |
15119 | 15123 |
local_nonpersistent_flags+=("--search") |
... | ... |
@@ -15187,6 +15195,10 @@ _openshift_cli_new-build() |
15187 | 15187 |
flags+=("--env=") |
15188 | 15188 |
two_word_flags+=("-e") |
15189 | 15189 |
local_nonpersistent_flags+=("--env=") |
15190 |
+ flags+=("--env-file=") |
|
15191 |
+ flags_with_completion+=("--env-file") |
|
15192 |
+ flags_completion+=("_filedir") |
|
15193 |
+ local_nonpersistent_flags+=("--env-file=") |
|
15190 | 15194 |
flags+=("--image-stream=") |
15191 | 15195 |
two_word_flags+=("-i") |
15192 | 15196 |
local_nonpersistent_flags+=("--image-stream=") |
... | ... |
@@ -16174,6 +16186,10 @@ _openshift_cli_process() |
16174 | 16174 |
flags+=("--param=") |
16175 | 16175 |
two_word_flags+=("-p") |
16176 | 16176 |
local_nonpersistent_flags+=("--param=") |
16177 |
+ flags+=("--param-file=") |
|
16178 |
+ flags_with_completion+=("--param-file") |
|
16179 |
+ flags_completion+=("_filedir") |
|
16180 |
+ local_nonpersistent_flags+=("--param-file=") |
|
16177 | 16181 |
flags+=("--parameters") |
16178 | 16182 |
local_nonpersistent_flags+=("--parameters") |
16179 | 16183 |
flags+=("--raw") |
... | ... |
@@ -10593,6 +10593,10 @@ _oc_new-app() |
10593 | 10593 |
flags+=("--env=") |
10594 | 10594 |
two_word_flags+=("-e") |
10595 | 10595 |
local_nonpersistent_flags+=("--env=") |
10596 |
+ flags+=("--env-file=") |
|
10597 |
+ flags_with_completion+=("--env-file") |
|
10598 |
+ flags_completion+=("_filedir") |
|
10599 |
+ local_nonpersistent_flags+=("--env-file=") |
|
10596 | 10600 |
flags+=("--file=") |
10597 | 10601 |
flags_with_completion+=("--file") |
10598 | 10602 |
flags_completion+=("__handle_filename_extension_flag yaml|yml|json") |
... | ... |
@@ -10627,6 +10631,10 @@ _oc_new-app() |
10627 | 10627 |
flags+=("--param=") |
10628 | 10628 |
two_word_flags+=("-p") |
10629 | 10629 |
local_nonpersistent_flags+=("--param=") |
10630 |
+ flags+=("--param-file=") |
|
10631 |
+ flags_with_completion+=("--param-file") |
|
10632 |
+ flags_completion+=("_filedir") |
|
10633 |
+ local_nonpersistent_flags+=("--param-file=") |
|
10630 | 10634 |
flags+=("--search") |
10631 | 10635 |
flags+=("-S") |
10632 | 10636 |
local_nonpersistent_flags+=("--search") |
... | ... |
@@ -10699,6 +10707,10 @@ _oc_new-build() |
10699 | 10699 |
flags+=("--env=") |
10700 | 10700 |
two_word_flags+=("-e") |
10701 | 10701 |
local_nonpersistent_flags+=("--env=") |
10702 |
+ flags+=("--env-file=") |
|
10703 |
+ flags_with_completion+=("--env-file") |
|
10704 |
+ flags_completion+=("_filedir") |
|
10705 |
+ local_nonpersistent_flags+=("--env-file=") |
|
10702 | 10706 |
flags+=("--image-stream=") |
10703 | 10707 |
two_word_flags+=("-i") |
10704 | 10708 |
local_nonpersistent_flags+=("--image-stream=") |
... | ... |
@@ -11671,6 +11683,10 @@ _oc_process() |
11671 | 11671 |
flags+=("--param=") |
11672 | 11672 |
two_word_flags+=("-p") |
11673 | 11673 |
local_nonpersistent_flags+=("--param=") |
11674 |
+ flags+=("--param-file=") |
|
11675 |
+ flags_with_completion+=("--param-file") |
|
11676 |
+ flags_completion+=("_filedir") |
|
11677 |
+ local_nonpersistent_flags+=("--param-file=") |
|
11674 | 11678 |
flags+=("--parameters") |
11675 | 11679 |
local_nonpersistent_flags+=("--parameters") |
11676 | 11680 |
flags+=("--raw") |
... | ... |
@@ -15241,6 +15241,10 @@ _openshift_cli_new-app() |
15241 | 15241 |
flags+=("--env=") |
15242 | 15242 |
two_word_flags+=("-e") |
15243 | 15243 |
local_nonpersistent_flags+=("--env=") |
15244 |
+ flags+=("--env-file=") |
|
15245 |
+ flags_with_completion+=("--env-file") |
|
15246 |
+ flags_completion+=("_filedir") |
|
15247 |
+ local_nonpersistent_flags+=("--env-file=") |
|
15244 | 15248 |
flags+=("--file=") |
15245 | 15249 |
flags_with_completion+=("--file") |
15246 | 15250 |
flags_completion+=("__handle_filename_extension_flag yaml|yml|json") |
... | ... |
@@ -15275,6 +15279,10 @@ _openshift_cli_new-app() |
15275 | 15275 |
flags+=("--param=") |
15276 | 15276 |
two_word_flags+=("-p") |
15277 | 15277 |
local_nonpersistent_flags+=("--param=") |
15278 |
+ flags+=("--param-file=") |
|
15279 |
+ flags_with_completion+=("--param-file") |
|
15280 |
+ flags_completion+=("_filedir") |
|
15281 |
+ local_nonpersistent_flags+=("--param-file=") |
|
15278 | 15282 |
flags+=("--search") |
15279 | 15283 |
flags+=("-S") |
15280 | 15284 |
local_nonpersistent_flags+=("--search") |
... | ... |
@@ -15348,6 +15356,10 @@ _openshift_cli_new-build() |
15348 | 15348 |
flags+=("--env=") |
15349 | 15349 |
two_word_flags+=("-e") |
15350 | 15350 |
local_nonpersistent_flags+=("--env=") |
15351 |
+ flags+=("--env-file=") |
|
15352 |
+ flags_with_completion+=("--env-file") |
|
15353 |
+ flags_completion+=("_filedir") |
|
15354 |
+ local_nonpersistent_flags+=("--env-file=") |
|
15351 | 15355 |
flags+=("--image-stream=") |
15352 | 15356 |
two_word_flags+=("-i") |
15353 | 15357 |
local_nonpersistent_flags+=("--image-stream=") |
... | ... |
@@ -16335,6 +16347,10 @@ _openshift_cli_process() |
16335 | 16335 |
flags+=("--param=") |
16336 | 16336 |
two_word_flags+=("-p") |
16337 | 16337 |
local_nonpersistent_flags+=("--param=") |
16338 |
+ flags+=("--param-file=") |
|
16339 |
+ flags_with_completion+=("--param-file") |
|
16340 |
+ flags_completion+=("_filedir") |
|
16341 |
+ local_nonpersistent_flags+=("--param-file=") |
|
16338 | 16342 |
flags+=("--parameters") |
16339 | 16343 |
local_nonpersistent_flags+=("--parameters") |
16340 | 16344 |
flags+=("--raw") |
... | ... |
@@ -59,6 +59,10 @@ If you provide source code, a new build will be automatically triggered. You can |
59 | 59 |
Specify a key\-value pair for an environment variable to set into each container. |
60 | 60 |
|
61 | 61 |
.PP |
62 |
+\fB\-\-env\-file\fP=[] |
|
63 |
+ File containing key\-value pairs of environment variables to set into each container. |
|
64 |
+ |
|
65 |
+.PP |
|
62 | 66 |
\fB\-f\fP, \fB\-\-file\fP=[] |
63 | 67 |
Path to a template file to use for the app. |
64 | 68 |
|
... | ... |
@@ -111,6 +115,10 @@ If you provide source code, a new build will be automatically triggered. You can |
111 | 111 |
Specify a key\-value pair (e.g., \-p FOO=BAR) to set/override a parameter value in the template. |
112 | 112 |
|
113 | 113 |
.PP |
114 |
+\fB\-\-param\-file\fP=[] |
|
115 |
+ File containing parameter values to set/override in the template. |
|
116 |
+ |
|
117 |
+.PP |
|
114 | 118 |
\fB\-S\fP, \fB\-\-search\fP=false |
115 | 119 |
Search all templates, image streams, and Docker images that match the arguments provided. |
116 | 120 |
|
... | ... |
@@ -67,6 +67,10 @@ Once the build configuration is created a new build will be automatically trigge |
67 | 67 |
Specify a key\-value pair for an environment variable to set into resulting image. |
68 | 68 |
|
69 | 69 |
.PP |
70 |
+\fB\-\-env\-file\fP=[] |
|
71 |
+ File containing key\-value pairs of environment variables to set into each container. |
|
72 |
+ |
|
73 |
+.PP |
|
70 | 74 |
\fB\-\-image\fP=[] |
71 | 75 |
Name of an image stream to to use as a builder. (deprecated) |
72 | 76 |
|
... | ... |
@@ -44,6 +44,10 @@ The output of the process command is always a list of one or more resources. You |
44 | 44 |
Specify a key\-value pair (eg. \-p FOO=BAR) to set/override a parameter value in the template. |
45 | 45 |
|
46 | 46 |
.PP |
47 |
+\fB\-\-param\-file\fP=[] |
|
48 |
+ File containing template parameter values to set/override in the template. |
|
49 |
+ |
|
50 |
+.PP |
|
47 | 51 |
\fB\-\-parameters\fP=false |
48 | 52 |
Do not process but only print available parameters |
49 | 53 |
|
... | ... |
@@ -59,6 +59,10 @@ If you provide source code, a new build will be automatically triggered. You can |
59 | 59 |
Specify a key\-value pair for an environment variable to set into each container. |
60 | 60 |
|
61 | 61 |
.PP |
62 |
+\fB\-\-env\-file\fP=[] |
|
63 |
+ File containing key\-value pairs of environment variables to set into each container. |
|
64 |
+ |
|
65 |
+.PP |
|
62 | 66 |
\fB\-f\fP, \fB\-\-file\fP=[] |
63 | 67 |
Path to a template file to use for the app. |
64 | 68 |
|
... | ... |
@@ -111,6 +115,10 @@ If you provide source code, a new build will be automatically triggered. You can |
111 | 111 |
Specify a key\-value pair (e.g., \-p FOO=BAR) to set/override a parameter value in the template. |
112 | 112 |
|
113 | 113 |
.PP |
114 |
+\fB\-\-param\-file\fP=[] |
|
115 |
+ File containing parameter values to set/override in the template. |
|
116 |
+ |
|
117 |
+.PP |
|
114 | 118 |
\fB\-S\fP, \fB\-\-search\fP=false |
115 | 119 |
Search all templates, image streams, and Docker images that match the arguments provided. |
116 | 120 |
|
... | ... |
@@ -67,6 +67,10 @@ Once the build configuration is created a new build will be automatically trigge |
67 | 67 |
Specify a key\-value pair for an environment variable to set into resulting image. |
68 | 68 |
|
69 | 69 |
.PP |
70 |
+\fB\-\-env\-file\fP=[] |
|
71 |
+ File containing key\-value pairs of environment variables to set into each container. |
|
72 |
+ |
|
73 |
+.PP |
|
70 | 74 |
\fB\-\-image\fP=[] |
71 | 75 |
Name of an image stream to to use as a builder. (deprecated) |
72 | 76 |
|
... | ... |
@@ -44,6 +44,10 @@ The output of the process command is always a list of one or more resources. You |
44 | 44 |
Specify a key\-value pair (eg. \-p FOO=BAR) to set/override a parameter value in the template. |
45 | 45 |
|
46 | 46 |
.PP |
47 |
+\fB\-\-param\-file\fP=[] |
|
48 |
+ File containing template parameter values to set/override in the template. |
|
49 |
+ |
|
50 |
+.PP |
|
47 | 51 |
\fB\-\-parameters\fP=false |
48 | 52 |
Do not process but only print available parameters |
49 | 53 |
|
... | ... |
@@ -95,7 +95,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) * |
95 | 95 |
cmd.NewCmdTypes(fullName, f, out), |
96 | 96 |
loginCmd, |
97 | 97 |
cmd.NewCmdRequestProject(cmd.RequestProjectRecommendedCommandName, fullName, f, out, errout), |
98 |
- cmd.NewCmdNewApplication(cmd.NewAppRecommendedCommandName, fullName, f, out, errout), |
|
98 |
+ cmd.NewCmdNewApplication(cmd.NewAppRecommendedCommandName, fullName, f, in, out, errout), |
|
99 | 99 |
cmd.NewCmdStatus(cmd.StatusRecommendedName, fullName, fullName+" "+cmd.StatusRecommendedName, f, out), |
100 | 100 |
cmd.NewCmdProject(fullName+" project", f, out), |
101 | 101 |
cmd.NewCmdProjects(fullName, f, out), |
... | ... |
@@ -156,7 +156,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) * |
156 | 156 |
cmd.NewCmdReplace(fullName, f, out), |
157 | 157 |
cmd.NewCmdApply(fullName, f, out), |
158 | 158 |
cmd.NewCmdPatch(fullName, f, out), |
159 |
- cmd.NewCmdProcess(fullName, f, out, errout), |
|
159 |
+ cmd.NewCmdProcess(fullName, f, in, out, errout), |
|
160 | 160 |
cmd.NewCmdExport(fullName, f, in, out), |
161 | 161 |
cmd.NewCmdExtract(fullName, f, in, out, errout), |
162 | 162 |
observe.NewCmdObserve(fullName, f, out, errout), |
... | ... |
@@ -20,6 +20,7 @@ import ( |
20 | 20 |
"github.com/openshift/origin/pkg/cmd/templates" |
21 | 21 |
cmdutil "github.com/openshift/origin/pkg/cmd/util" |
22 | 22 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
23 |
+ "github.com/openshift/origin/pkg/generate/app" |
|
23 | 24 |
) |
24 | 25 |
|
25 | 26 |
var ( |
... | ... |
@@ -55,7 +56,7 @@ type DockerbuildOptions struct { |
55 | 55 |
DockerfilePath string |
56 | 56 |
AllowPull bool |
57 | 57 |
Keyring credentialprovider.DockerKeyring |
58 |
- Arguments cmdutil.Environment |
|
58 |
+ Arguments app.Environment |
|
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
func NewCmdDockerbuild(fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command { |
... | ... |
@@ -97,7 +98,7 @@ func (o *DockerbuildOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, |
97 | 97 |
if len(paths) != 2 { |
98 | 98 |
return kcmdutil.UsageError(cmd, "the directory to build and tag must be specified") |
99 | 99 |
} |
100 |
- o.Arguments, _, _ = cmdutil.ParseEnvironmentArguments(envArgs) |
|
100 |
+ o.Arguments, _, _ = app.ParseEnvironment(envArgs...) |
|
101 | 101 |
o.Directory = paths[0] |
102 | 102 |
o.Tag = paths[1] |
103 | 103 |
if len(o.DockerfilePath) == 0 { |
... | ... |
@@ -45,10 +45,6 @@ import ( |
45 | 45 |
// NewAppRecommendedCommandName is the recommended command name. |
46 | 46 |
const NewAppRecommendedCommandName = "new-app" |
47 | 47 |
|
48 |
-type usage interface { |
|
49 |
- UsageError(baseName string) string |
|
50 |
-} |
|
51 |
- |
|
52 | 48 |
var ( |
53 | 49 |
newAppLong = templates.LongDesc(` |
54 | 50 |
Create a new application by specifying source code, templates, and/or images |
... | ... |
@@ -129,6 +125,7 @@ type NewAppOptions struct { |
129 | 129 |
CommandPath string |
130 | 130 |
CommandName string |
131 | 131 |
|
132 |
+ In io.Reader |
|
132 | 133 |
Out, ErrOut io.Writer |
133 | 134 |
Output string |
134 | 135 |
PrintObject func(obj runtime.Object) error |
... | ... |
@@ -136,7 +133,7 @@ type NewAppOptions struct { |
136 | 136 |
} |
137 | 137 |
|
138 | 138 |
// NewCmdNewApplication implements the OpenShift cli new-app command. |
139 |
-func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, errout io.Writer) *cobra.Command { |
|
139 |
+func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, in io.Reader, out, errout io.Writer) *cobra.Command { |
|
140 | 140 |
config := newcmd.NewAppConfig() |
141 | 141 |
config.Deploy = true |
142 | 142 |
o := &NewAppOptions{Config: config} |
... | ... |
@@ -148,7 +145,7 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro |
148 | 148 |
Example: fmt.Sprintf(newAppExample, baseName, name), |
149 | 149 |
SuggestFor: []string{"app", "application"}, |
150 | 150 |
Run: func(c *cobra.Command, args []string) { |
151 |
- kcmdutil.CheckErr(o.Complete(baseName, name, f, c, args, out, errout)) |
|
151 |
+ kcmdutil.CheckErr(o.Complete(baseName, name, f, c, args, in, out, errout)) |
|
152 | 152 |
err := o.RunNewApp() |
153 | 153 |
if err == cmdutil.ErrExit { |
154 | 154 |
os.Exit(1) |
... | ... |
@@ -168,8 +165,12 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro |
168 | 168 |
cmd.Flags().StringSliceVarP(&config.TemplateFiles, "file", "f", config.TemplateFiles, "Path to a template file to use for the app.") |
169 | 169 |
cmd.MarkFlagFilename("file", "yaml", "yml", "json") |
170 | 170 |
cmd.Flags().StringArrayVarP(&config.TemplateParameters, "param", "p", config.TemplateParameters, "Specify a key-value pair (e.g., -p FOO=BAR) to set/override a parameter value in the template.") |
171 |
+ cmd.Flags().StringArrayVar(&config.TemplateParameterFiles, "param-file", config.TemplateParameterFiles, "File containing parameter values to set/override in the template.") |
|
172 |
+ cmd.MarkFlagFilename("param-file") |
|
171 | 173 |
cmd.Flags().StringSliceVar(&config.Groups, "group", config.Groups, "Indicate components that should be grouped together as <comp1>+<comp2>.") |
172 | 174 |
cmd.Flags().StringArrayVarP(&config.Environment, "env", "e", config.Environment, "Specify a key-value pair for an environment variable to set into each container.") |
175 |
+ cmd.Flags().StringArrayVar(&config.EnvironmentFiles, "env-file", config.EnvironmentFiles, "File containing key-value pairs of environment variables to set into each container.") |
|
176 |
+ cmd.MarkFlagFilename("env-file") |
|
173 | 177 |
cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated application artifacts") |
174 | 178 |
cmd.Flags().Var(&config.Strategy, "strategy", "Specify the build strategy to use if you don't want to detect (docker|pipeline|source).") |
175 | 179 |
cmd.Flags().StringP("labels", "l", "", "Label to set in all resources for this application.") |
... | ... |
@@ -188,12 +189,14 @@ func NewCmdNewApplication(name, baseName string, f *clientcmd.Factory, out, erro |
188 | 188 |
} |
189 | 189 |
|
190 | 190 |
// Complete sets any default behavior for the command |
191 |
-func (o *NewAppOptions) Complete(baseName, name string, f *clientcmd.Factory, c *cobra.Command, args []string, out, errout io.Writer) error { |
|
191 |
+func (o *NewAppOptions) Complete(baseName, name string, f *clientcmd.Factory, c *cobra.Command, args []string, in io.Reader, out, errout io.Writer) error { |
|
192 |
+ o.In = in |
|
192 | 193 |
o.Out = out |
193 | 194 |
o.ErrOut = errout |
194 | 195 |
o.Output = kcmdutil.GetFlagString(c, "output") |
195 | 196 |
// Only output="" should print descriptions of intermediate steps. Everything |
196 | 197 |
// else should print only some specific output (json, yaml, go-template, ...) |
198 |
+ o.Config.In = o.In |
|
197 | 199 |
if len(o.Output) == 0 { |
198 | 200 |
o.Config.Out = o.Out |
199 | 201 |
} else { |
... | ... |
@@ -112,7 +112,7 @@ func TestNewAppDefaultFlags(t *testing.T) { |
112 | 112 |
}, |
113 | 113 |
} |
114 | 114 |
|
115 |
- cmd := NewCmdNewApplication("oc", NewAppRecommendedCommandName, nil, nil, nil) |
|
115 |
+ cmd := NewCmdNewApplication("oc", NewAppRecommendedCommandName, nil, nil, nil, nil) |
|
116 | 116 |
|
117 | 117 |
for _, v := range tests { |
118 | 118 |
f := cmd.Flag(v.flagName) |
... | ... |
@@ -90,6 +90,7 @@ type NewBuildOptions struct { |
90 | 90 |
CommandPath string |
91 | 91 |
CommandName string |
92 | 92 |
|
93 |
+ In io.Reader |
|
93 | 94 |
Out, ErrOut io.Writer |
94 | 95 |
Output string |
95 | 96 |
PrintObject func(obj runtime.Object) error |
... | ... |
@@ -129,6 +130,8 @@ func NewCmdNewBuild(name, baseName string, f *clientcmd.Factory, in io.Reader, o |
129 | 129 |
cmd.Flags().StringVar(&config.To, "to", "", "Push built images to this image stream tag (or Docker image repository if --to-docker is set).") |
130 | 130 |
cmd.Flags().BoolVar(&config.OutputDocker, "to-docker", false, "Have the build output push to a Docker repository.") |
131 | 131 |
cmd.Flags().StringArrayVarP(&config.Environment, "env", "e", config.Environment, "Specify a key-value pair for an environment variable to set into resulting image.") |
132 |
+ cmd.Flags().StringArrayVar(&config.EnvironmentFiles, "env-file", config.EnvironmentFiles, "File containing key-value pairs of environment variables to set into each container.") |
|
133 |
+ cmd.MarkFlagFilename("env-file") |
|
132 | 134 |
cmd.Flags().Var(&config.Strategy, "strategy", "Specify the build strategy to use if you don't want to detect (docker|pipeline|source).") |
133 | 135 |
cmd.Flags().StringVarP(&config.Dockerfile, "dockerfile", "D", "", "Specify the contents of a Dockerfile to build directly, implies --strategy=docker. Pass '-' to read from STDIN.") |
134 | 136 |
cmd.Flags().BoolVar(&config.BinaryBuild, "binary", false, "Instead of expecting a source URL, set the build to expect binary contents. Will disable triggers.") |
... | ... |
@@ -148,11 +151,13 @@ func NewCmdNewBuild(name, baseName string, f *clientcmd.Factory, in io.Reader, o |
148 | 148 |
|
149 | 149 |
// Complete sets any default behavior for the command |
150 | 150 |
func (o *NewBuildOptions) Complete(baseName, commandName string, f *clientcmd.Factory, c *cobra.Command, args []string, out, errout io.Writer, in io.Reader) error { |
151 |
+ o.In = in |
|
151 | 152 |
o.Out = out |
152 | 153 |
o.ErrOut = errout |
153 | 154 |
o.Output = kcmdutil.GetFlagString(c, "output") |
154 | 155 |
// Only output="" should print descriptions of intermediate steps. Everything |
155 | 156 |
// else should print only some specific output (json, yaml, go-template, ...) |
157 |
+ o.Config.In = in |
|
156 | 158 |
if len(o.Output) == 0 { |
157 | 159 |
o.Config.Out = o.Out |
158 | 160 |
} else { |
... | ... |
@@ -22,6 +22,7 @@ import ( |
22 | 22 |
"github.com/openshift/origin/pkg/cmd/templates" |
23 | 23 |
cmdutil "github.com/openshift/origin/pkg/cmd/util" |
24 | 24 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
25 |
+ "github.com/openshift/origin/pkg/generate/app" |
|
25 | 26 |
"github.com/openshift/origin/pkg/template" |
26 | 27 |
templateapi "github.com/openshift/origin/pkg/template/api" |
27 | 28 |
) |
... | ... |
@@ -58,14 +59,14 @@ var ( |
58 | 58 |
) |
59 | 59 |
|
60 | 60 |
// NewCmdProcess implements the OpenShift cli process command |
61 |
-func NewCmdProcess(fullName string, f *clientcmd.Factory, out, errout io.Writer) *cobra.Command { |
|
61 |
+func NewCmdProcess(fullName string, f *clientcmd.Factory, in io.Reader, out, errout io.Writer) *cobra.Command { |
|
62 | 62 |
cmd := &cobra.Command{ |
63 | 63 |
Use: "process (TEMPLATE | -f FILENAME) [-v=KEY=VALUE]", |
64 | 64 |
Short: "Process a template into list of resources", |
65 | 65 |
Long: processLong, |
66 | 66 |
Example: fmt.Sprintf(processExample, fullName), |
67 | 67 |
Run: func(cmd *cobra.Command, args []string) { |
68 |
- err := RunProcess(f, out, errout, cmd, args) |
|
68 |
+ err := RunProcess(f, in, out, errout, cmd, args) |
|
69 | 69 |
kcmdutil.CheckErr(err) |
70 | 70 |
}, |
71 | 71 |
} |
... | ... |
@@ -75,6 +76,8 @@ func NewCmdProcess(fullName string, f *clientcmd.Factory, out, errout io.Writer) |
75 | 75 |
cmd.Flags().MarkDeprecated("value", "Use -p, --param instead.") |
76 | 76 |
cmd.Flags().MarkHidden("value") |
77 | 77 |
cmd.Flags().StringArrayVarP(params, "param", "p", nil, "Specify a key-value pair (eg. -p FOO=BAR) to set/override a parameter value in the template.") |
78 |
+ cmd.Flags().StringArray("param-file", []string{}, "File containing template parameter values to set/override in the template.") |
|
79 |
+ cmd.MarkFlagFilename("param-file") |
|
78 | 80 |
cmd.Flags().BoolP("parameters", "", false, "Do not process but only print available parameters") |
79 | 81 |
cmd.Flags().StringP("labels", "l", "", "Label to set in all resources for this template") |
80 | 82 |
|
... | ... |
@@ -95,13 +98,13 @@ func NewCmdProcess(fullName string, f *clientcmd.Factory, out, errout io.Writer) |
95 | 95 |
} |
96 | 96 |
|
97 | 97 |
// RunProcess contains all the necessary functionality for the OpenShift cli process command |
98 |
-func RunProcess(f *clientcmd.Factory, out, errout io.Writer, cmd *cobra.Command, args []string) error { |
|
99 |
- templateName, valueArgs := "", []string{} |
|
98 |
+func RunProcess(f *clientcmd.Factory, in io.Reader, out, errout io.Writer, cmd *cobra.Command, args []string) error { |
|
99 |
+ templateName, templateParams := "", []string{} |
|
100 | 100 |
for _, s := range args { |
101 | 101 |
isValue := strings.Contains(s, "=") |
102 | 102 |
switch { |
103 | 103 |
case isValue: |
104 |
- valueArgs = append(valueArgs, s) |
|
104 |
+ templateParams = append(templateParams, s) |
|
105 | 105 |
case !isValue && len(templateName) == 0: |
106 | 106 |
templateName = s |
107 | 107 |
case !isValue && len(templateName) > 0: |
... | ... |
@@ -109,33 +112,23 @@ func RunProcess(f *clientcmd.Factory, out, errout io.Writer, cmd *cobra.Command, |
109 | 109 |
} |
110 | 110 |
} |
111 | 111 |
|
112 |
- keys := sets.NewString() |
|
113 |
- duplicatedKeys := sets.NewString() |
|
114 |
- |
|
115 |
- var flagValues []string |
|
116 | 112 |
if cmd.Flag("value").Changed || cmd.Flag("param").Changed { |
117 |
- flagValues = getFlagStringArray(cmd, "param") |
|
113 |
+ flagValues := getFlagStringArray(cmd, "param") |
|
118 | 114 |
cmdutil.WarnAboutCommaSeparation(errout, flagValues, "--param") |
115 |
+ templateParams = append(templateParams, flagValues...) |
|
119 | 116 |
} |
120 | 117 |
|
121 |
- for _, value := range flagValues { |
|
122 |
- key := strings.Split(value, "=")[0] |
|
123 |
- if keys.Has(key) { |
|
124 |
- duplicatedKeys.Insert(key) |
|
125 |
- } |
|
126 |
- keys.Insert(key) |
|
127 |
- } |
|
128 |
- |
|
129 |
- for _, value := range valueArgs { |
|
130 |
- key := strings.Split(value, "=")[0] |
|
131 |
- if keys.Has(key) { |
|
118 |
+ duplicatedKeys := sets.NewString() |
|
119 |
+ params, paramErr := app.ParseAndCombineEnvironment(templateParams, getFlagStringArray(cmd, "param-file"), in, func(key, file string) error { |
|
120 |
+ if file == "" { |
|
132 | 121 |
duplicatedKeys.Insert(key) |
122 |
+ } else { |
|
123 |
+ fmt.Fprintf(errout, "warning: Template parameter %q already defined, ignoring value from file %q", key, file) |
|
133 | 124 |
} |
134 |
- keys.Insert(key) |
|
135 |
- } |
|
136 |
- |
|
125 |
+ return nil |
|
126 |
+ }) |
|
137 | 127 |
if len(duplicatedKeys) != 0 { |
138 |
- return kcmdutil.UsageError(cmd, fmt.Sprintf("The following values were provided more than once: %s", strings.Join(duplicatedKeys.List(), ", "))) |
|
128 |
+ return kcmdutil.UsageError(cmd, fmt.Sprintf("The following parameters were provided more than once: %s", strings.Join(duplicatedKeys.List(), ", "))) |
|
139 | 129 |
} |
140 | 130 |
|
141 | 131 |
filename := kcmdutil.GetFlagString(cmd, "filename") |
... | ... |
@@ -248,16 +241,11 @@ func RunProcess(f *clientcmd.Factory, out, errout io.Writer, cmd *cobra.Command, |
248 | 248 |
} |
249 | 249 |
} |
250 | 250 |
|
251 |
- // Override the parameter values for the current template parameters |
|
252 |
- // when user specifies --param |
|
253 |
- if cmd.Flag("value").Changed || cmd.Flag("param").Changed { |
|
254 |
- values := getFlagStringArray(cmd, "param") |
|
255 |
- if errs := injectUserVars(values, obj); errs != nil { |
|
256 |
- return kerrors.NewAggregate(errs) |
|
257 |
- } |
|
251 |
+ // Raise parameter parsing errors here after we had chance to return UsageErrors first |
|
252 |
+ if paramErr != nil { |
|
253 |
+ return paramErr |
|
258 | 254 |
} |
259 |
- |
|
260 |
- if errs := injectUserVars(valueArgs, obj); errs != nil { |
|
255 |
+ if errs := injectUserVars(params, obj); errs != nil { |
|
261 | 256 |
return kerrors.NewAggregate(errs) |
262 | 257 |
} |
263 | 258 |
|
... | ... |
@@ -307,19 +295,14 @@ func RunProcess(f *clientcmd.Factory, out, errout io.Writer, cmd *cobra.Command, |
307 | 307 |
} |
308 | 308 |
|
309 | 309 |
// injectUserVars injects user specified variables into the Template |
310 |
-func injectUserVars(values []string, t *templateapi.Template) []error { |
|
310 |
+func injectUserVars(values app.Environment, t *templateapi.Template) []error { |
|
311 | 311 |
var errors []error |
312 |
- for _, keypair := range values { |
|
313 |
- p := strings.SplitN(keypair, "=", 2) |
|
314 |
- if len(p) != 2 { |
|
315 |
- errors = append(errors, fmt.Errorf("invalid parameter assignment in %q: %q\n", t.Name, keypair)) |
|
312 |
+ for param, val := range values { |
|
313 |
+ if v := template.GetParameterByName(t, param); v != nil { |
|
314 |
+ v.Value = val |
|
315 |
+ v.Generate = "" |
|
316 | 316 |
} else { |
317 |
- if v := template.GetParameterByName(t, p[0]); v != nil { |
|
318 |
- v.Value = p[1] |
|
319 |
- v.Generate = "" |
|
320 |
- } else { |
|
321 |
- errors = append(errors, fmt.Errorf("unknown parameter name %q\n", p[0])) |
|
322 |
- } |
|
317 |
+ errors = append(errors, fmt.Errorf("unknown parameter name %q\n", param)) |
|
323 | 318 |
} |
324 | 319 |
} |
325 | 320 |
return errors |
... | ... |
@@ -13,9 +13,11 @@ func TestInjectUserVars(t *testing.T) { |
13 | 13 |
{Name: "parameter_foo_bar_2", Value: "value_foo_bar_2"}}, |
14 | 14 |
} |
15 | 15 |
oldParameterNum := len(template.Parameters) |
16 |
- testParam := []string{"parameter_foo_bar_exist=value_foo_bar_exist_new", |
|
17 |
- "parameter_foo_bar_no_exist=value_foo_bar_no_exist", |
|
18 |
- "parameter_foo_bar_error=value_foo_bar_error=value_foo_bar_error"} |
|
16 |
+ testParam := map[string]string{ |
|
17 |
+ "parameter_foo_bar_exist": "value_foo_bar_exist_new", |
|
18 |
+ "parameter_foo_bar_no_exist": "value_foo_bar_no_exist", |
|
19 |
+ "parameter_foo_bar_error": "value_foo_bar_error=value_foo_bar_error", |
|
20 |
+ } |
|
19 | 21 |
|
20 | 22 |
errors := injectUserVars(testParam, template) |
21 | 23 |
if len(errors) != 2 { |
... | ... |
@@ -39,8 +39,6 @@ func GetEnv(key string) (string, bool) { |
39 | 39 |
return val, true |
40 | 40 |
} |
41 | 41 |
|
42 |
-type Environment map[string]string |
|
43 |
- |
|
44 | 42 |
var argumentEnvironment = regexp.MustCompile("(?ms)^(.+)\\=(.*)$") |
45 | 43 |
var validArgumentEnvironment = regexp.MustCompile("(?ms)^(\\w+)\\=(.*)$") |
46 | 44 |
|
... | ... |
@@ -72,25 +70,6 @@ func SplitEnvironmentFromResources(args []string) (resources, envArgs []string, |
72 | 72 |
return resources, envArgs, true |
73 | 73 |
} |
74 | 74 |
|
75 |
-func ParseEnvironmentArguments(s []string) (Environment, []string, []error) { |
|
76 |
- errs := []error{} |
|
77 |
- duplicates := []string{} |
|
78 |
- env := make(Environment) |
|
79 |
- for _, s := range s { |
|
80 |
- switch matches := validArgumentEnvironment.FindStringSubmatch(s); len(matches) { |
|
81 |
- case 3: |
|
82 |
- k, v := matches[1], matches[2] |
|
83 |
- if exist, ok := env[k]; ok { |
|
84 |
- duplicates = append(duplicates, fmt.Sprintf("%s=%s", k, exist)) |
|
85 |
- } |
|
86 |
- env[k] = v |
|
87 |
- default: |
|
88 |
- errs = append(errs, fmt.Errorf("environment variables must be of the form key=value: %s", s)) |
|
89 |
- } |
|
90 |
- } |
|
91 |
- return env, duplicates, errs |
|
92 |
-} |
|
93 |
- |
|
94 | 75 |
// ParseEnv parses the list of environment variables into kubernetes EnvVar |
95 | 76 |
func ParseEnv(spec []string, defaultReader io.Reader) ([]kapi.EnvVar, []string, error) { |
96 | 77 |
env := []kapi.EnvVar{} |
... | ... |
@@ -54,6 +54,9 @@ type GenerationInputs struct { |
54 | 54 |
Environment []string |
55 | 55 |
Labels map[string]string |
56 | 56 |
|
57 |
+ TemplateParameterFiles []string |
|
58 |
+ EnvironmentFiles []string |
|
59 |
+ |
|
57 | 60 |
AddEnvironmentToBuild bool |
58 | 61 |
|
59 | 62 |
InsecureRegistry bool |
... | ... |
@@ -100,6 +103,7 @@ type AppConfig struct { |
100 | 100 |
AsList bool |
101 | 101 |
DryRun bool |
102 | 102 |
|
103 |
+ In io.Reader |
|
103 | 104 |
Out io.Writer |
104 | 105 |
ErrOut io.Writer |
105 | 106 |
|
... | ... |
@@ -115,16 +119,6 @@ type AppConfig struct { |
115 | 115 |
OriginNamespace string |
116 | 116 |
} |
117 | 117 |
|
118 |
-// UsageError is an interface for printing usage errors |
|
119 |
-type UsageError interface { |
|
120 |
- UsageError(commandName string) string |
|
121 |
-} |
|
122 |
- |
|
123 |
-// TODO: replace with upstream converting [1]error to error |
|
124 |
-type errlist interface { |
|
125 |
- Errors() []error |
|
126 |
-} |
|
127 |
- |
|
128 | 118 |
type ErrRequiresExplicitAccess struct { |
129 | 119 |
Match app.ComponentMatch |
130 | 120 |
Input app.GeneratorInput |
... | ... |
@@ -579,27 +573,35 @@ func (c *AppConfig) RunQuery() (*QueryResult, error) { |
579 | 579 |
}, nil |
580 | 580 |
} |
581 | 581 |
|
582 |
-func (c *AppConfig) validate() (cmdutil.Environment, cmdutil.Environment, error) { |
|
583 |
- var errs []error |
|
584 |
- |
|
585 |
- env, duplicateEnv, envErrs := cmdutil.ParseEnvironmentArguments(c.Environment) |
|
586 |
- for _, s := range duplicateEnv { |
|
587 |
- fmt.Fprintf(c.ErrOut, "warning: The environment variable %q was overwritten", s) |
|
582 |
+func (c *AppConfig) validate() (app.Environment, app.Environment, error) { |
|
583 |
+ env, err := app.ParseAndCombineEnvironment(c.Environment, c.EnvironmentFiles, c.In, func(key, file string) error { |
|
584 |
+ if file == "" { |
|
585 |
+ fmt.Fprintf(c.ErrOut, "warning: Environment variable %q was overwritten\n", key) |
|
586 |
+ } else { |
|
587 |
+ fmt.Fprintf(c.ErrOut, "warning: Environment variable %q already defined, ignoring value from file %q\n", key, file) |
|
588 |
+ } |
|
589 |
+ return nil |
|
590 |
+ }) |
|
591 |
+ if err != nil { |
|
592 |
+ return nil, nil, err |
|
588 | 593 |
} |
589 |
- errs = append(errs, envErrs...) |
|
590 |
- |
|
591 |
- params, duplicateParams, paramsErrs := cmdutil.ParseEnvironmentArguments(c.TemplateParameters) |
|
592 |
- for _, s := range duplicateParams { |
|
593 |
- fmt.Fprintf(c.ErrOut, "warning: The template parameter %q was overwritten", s) |
|
594 |
+ params, err := app.ParseAndCombineEnvironment(c.TemplateParameters, c.TemplateParameterFiles, c.In, func(key, file string) error { |
|
595 |
+ if file == "" { |
|
596 |
+ fmt.Fprintf(c.ErrOut, "warning: Template parameter %q was overwritten\n", key) |
|
597 |
+ } else { |
|
598 |
+ fmt.Fprintf(c.ErrOut, "warning: Template parameter %q already defined, ignoring value from file %q\n", key, file) |
|
599 |
+ } |
|
600 |
+ return nil |
|
601 |
+ }) |
|
602 |
+ if err != nil { |
|
603 |
+ return nil, nil, err |
|
594 | 604 |
} |
595 |
- errs = append(errs, paramsErrs...) |
|
596 |
- |
|
597 |
- return env, params, kutilerrors.NewAggregate(errs) |
|
605 |
+ return env, params, nil |
|
598 | 606 |
} |
599 | 607 |
|
600 | 608 |
// Run executes the provided config to generate objects. |
601 | 609 |
func (c *AppConfig) Run() (*AppResult, error) { |
602 |
- environment, parameters, err := c.validate() |
|
610 |
+ env, parameters, err := c.validate() |
|
603 | 611 |
if err != nil { |
604 | 612 |
return nil, err |
605 | 613 |
} |
... | ... |
@@ -645,8 +647,6 @@ func (c *AppConfig) Run() (*AppResult, error) { |
645 | 645 |
return nil, errors.New("only one component with source can be used when specifying an output image reference") |
646 | 646 |
} |
647 | 647 |
|
648 |
- env := app.Environment(environment) |
|
649 |
- |
|
650 | 648 |
// identify if there are installable components in the input provided by the user |
651 | 649 |
installables, name, err := c.installComponents(components, env) |
652 | 650 |
if err != nil { |
... | ... |
@@ -680,7 +680,7 @@ func (c *AppConfig) Run() (*AppResult, error) { |
680 | 680 |
|
681 | 681 |
objects = app.AddServices(objects, false) |
682 | 682 |
|
683 |
- templateName, templateObjects, err := c.buildTemplates(components.TemplateComponentRefs(), app.Environment(parameters), app.Environment(environment)) |
|
683 |
+ templateName, templateObjects, err := c.buildTemplates(components.TemplateComponentRefs(), parameters, env) |
|
684 | 684 |
if err != nil { |
685 | 685 |
return nil, err |
686 | 686 |
} |
... | ... |
@@ -1,18 +1,25 @@ |
1 | 1 |
package app |
2 | 2 |
|
3 | 3 |
import ( |
4 |
+ "fmt" |
|
5 |
+ "io" |
|
6 |
+ "io/ioutil" |
|
7 |
+ "os" |
|
4 | 8 |
"sort" |
5 | 9 |
"strings" |
6 | 10 |
|
11 |
+ "github.com/joho/godotenv" |
|
12 |
+ cmdutil "github.com/openshift/origin/pkg/cmd/util" |
|
7 | 13 |
kapi "k8s.io/kubernetes/pkg/api" |
8 | 14 |
) |
9 | 15 |
|
10 | 16 |
// Environment holds environment variables for new-app |
11 | 17 |
type Environment map[string]string |
12 | 18 |
|
13 |
-// ParseEnvironment converts the provided strings in key=value form into environment |
|
14 |
-// entries. |
|
15 |
-func ParseEnvironment(vals ...string) Environment { |
|
19 |
+// ParseEnvironmentAllowEmpty converts the provided strings in key=value form |
|
20 |
+// into environment entries. In case there's no equals sign in a string, it's |
|
21 |
+// considered as a key with empty value. |
|
22 |
+func ParseEnvironmentAllowEmpty(vals ...string) Environment { |
|
16 | 23 |
env := make(Environment) |
17 | 24 |
for _, s := range vals { |
18 | 25 |
if i := strings.Index(s, "="); i == -1 { |
... | ... |
@@ -24,6 +31,30 @@ func ParseEnvironment(vals ...string) Environment { |
24 | 24 |
return env |
25 | 25 |
} |
26 | 26 |
|
27 |
+// ParseEnvironment takes a slice of strings in key=value format and transforms |
|
28 |
+// them into a map. List of duplicate keys is returned in the second return |
|
29 |
+// value. |
|
30 |
+func ParseEnvironment(vals ...string) (Environment, []string, []error) { |
|
31 |
+ errs := []error{} |
|
32 |
+ duplicates := []string{} |
|
33 |
+ env := make(Environment) |
|
34 |
+ for _, s := range vals { |
|
35 |
+ valid := cmdutil.IsValidEnvironmentArgument(s) |
|
36 |
+ p := strings.SplitN(s, "=", 2) |
|
37 |
+ if !valid || len(p) != 2 { |
|
38 |
+ errs = append(errs, fmt.Errorf("invalid parameter assignment in %q", s)) |
|
39 |
+ continue |
|
40 |
+ } |
|
41 |
+ key, val := p[0], p[1] |
|
42 |
+ if _, exists := env[key]; exists { |
|
43 |
+ duplicates = append(duplicates, key) |
|
44 |
+ continue |
|
45 |
+ } |
|
46 |
+ env[key] = val |
|
47 |
+ } |
|
48 |
+ return env, duplicates, errs |
|
49 |
+} |
|
50 |
+ |
|
27 | 51 |
// NewEnvironment returns a new set of environment variables based on all |
28 | 52 |
// the provided environment variables |
29 | 53 |
func NewEnvironment(envs ...map[string]string) Environment { |
... | ... |
@@ -44,6 +75,22 @@ func (e Environment) Add(envs ...map[string]string) { |
44 | 44 |
} |
45 | 45 |
} |
46 | 46 |
|
47 |
+// AddIfNotPresent adds the environment variables to the current environment. |
|
48 |
+// In case of key conflict the old value is kept. Conflicting keys are returned |
|
49 |
+// as a slice. |
|
50 |
+func (e Environment) AddIfNotPresent(more Environment) []string { |
|
51 |
+ duplicates := []string{} |
|
52 |
+ for k, v := range more { |
|
53 |
+ if _, exists := e[k]; exists { |
|
54 |
+ duplicates = append(duplicates, k) |
|
55 |
+ } else { |
|
56 |
+ e[k] = v |
|
57 |
+ } |
|
58 |
+ } |
|
59 |
+ |
|
60 |
+ return duplicates |
|
61 |
+} |
|
62 |
+ |
|
47 | 63 |
// List sorts and returns all the environment variables |
48 | 64 |
func (e Environment) List() []kapi.EnvVar { |
49 | 65 |
env := []kapi.EnvVar{} |
... | ... |
@@ -82,3 +129,85 @@ func JoinEnvironment(a, b []kapi.EnvVar) (out []kapi.EnvVar) { |
82 | 82 |
} |
83 | 83 |
return out |
84 | 84 |
} |
85 |
+ |
|
86 |
+// LoadEnvironmentFile accepts filename of a file containing key=value pairs |
|
87 |
+// and puts these pairs into a map. If filename is "-" the file contents are |
|
88 |
+// read from the stdin argument, provided it is not nil. |
|
89 |
+func LoadEnvironmentFile(filename string, stdin io.Reader) (Environment, error) { |
|
90 |
+ errorFilename := filename |
|
91 |
+ |
|
92 |
+ if filename == "-" && stdin != nil { |
|
93 |
+ //once https://github.com/joho/godotenv/pull/20 is merged we can get rid of using tempfile |
|
94 |
+ temp, err := ioutil.TempFile("", "origin-env-stdin") |
|
95 |
+ if err != nil { |
|
96 |
+ return nil, fmt.Errorf("Cannot create temporary file: %s", err) |
|
97 |
+ } |
|
98 |
+ |
|
99 |
+ filename = temp.Name() |
|
100 |
+ errorFilename = "stdin" |
|
101 |
+ defer os.Remove(filename) |
|
102 |
+ |
|
103 |
+ if _, err = io.Copy(temp, stdin); err != nil { |
|
104 |
+ return nil, fmt.Errorf("Cannot write to temporary file %q: %s", filename, err) |
|
105 |
+ } |
|
106 |
+ temp.Close() |
|
107 |
+ } |
|
108 |
+ |
|
109 |
+ // godotenv successfuly returns empty map when given path to a directory, |
|
110 |
+ // remove this once https://github.com/joho/godotenv/pull/22 is merged |
|
111 |
+ if info, err := os.Stat(filename); err == nil && info.IsDir() { |
|
112 |
+ return nil, fmt.Errorf("Cannot read varaiables from %q: is a directory", filename) |
|
113 |
+ } else if err != nil { |
|
114 |
+ return nil, fmt.Errorf("Cannot stat %q: %s", filename, err) |
|
115 |
+ } |
|
116 |
+ |
|
117 |
+ env, err := godotenv.Read(filename) |
|
118 |
+ if err != nil { |
|
119 |
+ return nil, fmt.Errorf("Cannot read variables from file %q: %s", errorFilename, err) |
|
120 |
+ } |
|
121 |
+ for k, v := range env { |
|
122 |
+ if !cmdutil.IsValidEnvironmentArgument(fmt.Sprintf("%s=%s", k, v)) { |
|
123 |
+ return nil, fmt.Errorf("invalid parameter assignment in %s=%s", k, v) |
|
124 |
+ } |
|
125 |
+ } |
|
126 |
+ return env, nil |
|
127 |
+} |
|
128 |
+ |
|
129 |
+// ParseAndCombineEnvironment parses key=value records from slice of strings |
|
130 |
+// (typically obtained from the command line) and from given files and combines |
|
131 |
+// them into single map. Key=value pairs from the envs slice have precedence |
|
132 |
+// over those read from file. |
|
133 |
+// |
|
134 |
+// The dupfn function is called for all duplicate keys that encountered. If the |
|
135 |
+// function returns an error this error is returned by |
|
136 |
+// ParseAndCombineEnvironment. |
|
137 |
+// |
|
138 |
+// If a file is "-" the file contents will be read from argument stdin (unless |
|
139 |
+// it's nil). |
|
140 |
+func ParseAndCombineEnvironment(envs []string, filenames []string, stdin io.Reader, dupfn func(string, string) error) (Environment, error) { |
|
141 |
+ vars, duplicates, errs := ParseEnvironment(envs...) |
|
142 |
+ if len(errs) > 0 { |
|
143 |
+ return nil, errs[0] |
|
144 |
+ } |
|
145 |
+ for _, s := range duplicates { |
|
146 |
+ if err := dupfn(s, ""); err != nil { |
|
147 |
+ return nil, err |
|
148 |
+ } |
|
149 |
+ } |
|
150 |
+ |
|
151 |
+ for _, fname := range filenames { |
|
152 |
+ fileVars, err := LoadEnvironmentFile(fname, stdin) |
|
153 |
+ if err != nil { |
|
154 |
+ return nil, err |
|
155 |
+ } |
|
156 |
+ |
|
157 |
+ duplicates = vars.AddIfNotPresent(fileVars) |
|
158 |
+ for _, s := range duplicates { |
|
159 |
+ if err := dupfn(s, fname); err != nil { |
|
160 |
+ return nil, err |
|
161 |
+ } |
|
162 |
+ } |
|
163 |
+ } |
|
164 |
+ |
|
165 |
+ return vars, nil |
|
166 |
+} |
... | ... |
@@ -280,7 +280,7 @@ func Generate(paths ...string) (*templateapi.Template, error) { |
280 | 280 |
if len(v.WorkingDir) > 0 { |
281 | 281 |
c.WorkingDir = v.WorkingDir |
282 | 282 |
} |
283 |
- c.Env = append(c.Env, app.ParseEnvironment(v.Environment.Slice()...).List()...) |
|
283 |
+ c.Env = append(c.Env, app.ParseEnvironmentAllowEmpty(v.Environment.Slice()...).List()...) |
|
284 | 284 |
if uid, err := strconv.Atoi(v.User); err == nil { |
285 | 285 |
uid64 := int64(uid) |
286 | 286 |
if c.SecurityContext == nil { |
... | ... |
@@ -82,6 +82,34 @@ os::cmd::expect_success_and_not_text 'oc new-app ruby-helloworld-sample --param |
82 | 82 |
os::cmd::expect_success_and_text 'oc new-app php PASS=one,two=three -o yaml' 'value: one,two=three' |
83 | 83 |
os::cmd::expect_success_and_not_text 'oc new-app php PASS=one,two=three -o yaml' 'no longer accepts comma-separated list' |
84 | 84 |
|
85 |
+# check that we can populate template parameters from file |
|
86 |
+param_file="${OS_ROOT}/test/testdata/test-cmd-newapp-params.env" |
|
87 |
+os::cmd::expect_success_and_text "oc new-app ruby-helloworld-sample --param-file ${param_file} -o jsonpath='{.items[?(@.kind==\"DeploymentConfig\")].spec.template.spec.containers[0].env[?(@.name==\"MYSQL_PASSWORD\")].value}'" 'thisisapassword' |
|
88 |
+os::cmd::expect_success_and_text "oc new-app ruby-helloworld-sample --param-file ${param_file} --param MYSQL_PASSWORD=otherpass -o jsonpath='{.items[?(@.kind==\"DeploymentConfig\")].spec.template.spec.containers[0].env[?(@.name==\"MYSQL_PASSWORD\")].value}'" 'otherpass' |
|
89 |
+os::cmd::expect_success_and_text "oc new-app ruby-helloworld-sample --param-file ${param_file} --param MYSQL_PASSWORD=otherpass -o yaml" 'ignoring value from file' |
|
90 |
+os::cmd::expect_success_and_text "cat ${param_file} | oc new-app ruby-helloworld-sample --param-file - -o jsonpath='{.items[?(@.kind==\"DeploymentConfig\")].spec.template.spec.containers[0].env[?(@.name==\"MYSQL_PASSWORD\")].value}'" 'thisisapassword' |
|
91 |
+ |
|
92 |
+os::cmd::expect_failure_and_text "oc new-app ruby-helloworld-sample --param-file does/not/exist" 'no such file or directory' |
|
93 |
+os::cmd::expect_failure_and_text "oc new-app ruby-helloworld-sample --param-file test/testdata" 'is a directory' |
|
94 |
+os::cmd::expect_success "oc new-app ruby-helloworld-sample --param-file /dev/null -o yaml" |
|
95 |
+os::cmd::expect_success "oc new-app ruby-helloworld-sample --param-file /dev/null --param-file ${param_file} -o yaml" |
|
96 |
+os::cmd::expect_failure_and_text "echo 'fo%(o=bar' | oc new-app ruby-helloworld-sample --param-file -" 'invalid parameter assignment' |
|
97 |
+os::cmd::expect_failure_and_text "echo 'S P A C E S=test' | oc new-app ruby-helloworld-sample --param-file -" 'invalid parameter assignment' |
|
98 |
+ |
|
99 |
+# check that we can set environment variables from env file |
|
100 |
+env_file="${OS_ROOT}/test/testdata/test-cmd-newapp-env.env" |
|
101 |
+os::cmd::expect_success_and_text "oc new-app php --env-file ${env_file} -o jsonpath='{.items[?(@.kind==\"DeploymentConfig\")].spec.template.spec.containers[0].env[?(@.name==\"SOME_VAR\")].value}'" 'envvarfromfile' |
|
102 |
+os::cmd::expect_success_and_text "oc new-app php --env-file ${env_file} --env SOME_VAR=fromcmdline -o jsonpath='{.items[?(@.kind==\"DeploymentConfig\")].spec.template.spec.containers[0].env[?(@.name==\"SOME_VAR\")].value}'" 'fromcmdline' |
|
103 |
+os::cmd::expect_success_and_text "oc new-app php --env-file ${env_file} --env SOME_VAR=fromcmdline -o yaml" 'ignoring value from file' |
|
104 |
+os::cmd::expect_success_and_text "cat ${env_file} | oc new-app php --env-file - -o jsonpath='{.items[?(@.kind==\"DeploymentConfig\")].spec.template.spec.containers[0].env[?(@.name==\"SOME_VAR\")].value}'" 'envvarfromfile' |
|
105 |
+ |
|
106 |
+os::cmd::expect_failure_and_text "oc new-app php --env-file does/not/exist" 'no such file or directory' |
|
107 |
+os::cmd::expect_failure_and_text "oc new-app php --env-file test/testdata" 'is a directory' |
|
108 |
+os::cmd::expect_success "oc new-app php --env-file /dev/null -o yaml" |
|
109 |
+os::cmd::expect_success "oc new-app php --env-file /dev/null --env-file ${env_file} -o yaml" |
|
110 |
+os::cmd::expect_failure_and_text "echo 'fo%(o=bar' | oc new-app php --env-file -" 'invalid parameter assignment' |
|
111 |
+os::cmd::expect_failure_and_text "echo 'S P A C E S=test' | oc new-app php --env-file -" 'invalid parameter assignment' |
|
112 |
+ |
|
85 | 113 |
# new-build |
86 | 114 |
# check that env vars are not split on commas and warning is printed where they previously have |
87 | 115 |
os::cmd::expect_success_and_text 'oc new-build --binary php --env X=Y,Z=W -o yaml' 'value: Y,Z=W' |
... | ... |
@@ -92,6 +120,19 @@ os::cmd::expect_success_and_not_text 'oc new-build --binary php --env X=Y -o yam |
92 | 92 |
os::cmd::expect_success_and_text 'oc new-build --binary php X=Y,Z=W -o yaml' 'value: Y,Z=W' |
93 | 93 |
os::cmd::expect_success_and_not_text 'oc new-build --binary php X=Y,Z=W -o yaml' 'no longer accepts comma-separated list' |
94 | 94 |
|
95 |
+# new-build - load envvars from file |
|
96 |
+os::cmd::expect_success_and_text "oc new-build --binary php --env-file ${env_file} -o jsonpath='{.items[?(@.kind==\"BuildConfig\")].spec.strategy.sourceStrategy.env[?(@.name==\"SOME_VAR\")].value}'" 'envvarfromfile' |
|
97 |
+os::cmd::expect_success_and_text "oc new-build --binary php --env-file ${env_file} --env SOME_VAR=fromcmdline -o jsonpath='{.items[?(@.kind==\"BuildConfig\")].spec.strategy.sourceStrategy.env[?(@.name==\"SOME_VAR\")].value}'" 'fromcmdline' |
|
98 |
+os::cmd::expect_success_and_text "oc new-build --binary php --env-file ${env_file} --env SOME_VAR=fromcmdline -o yaml" 'ignoring value from file' |
|
99 |
+os::cmd::expect_success_and_text "cat ${env_file} | oc new-build --binary php --env-file ${env_file} -o jsonpath='{.items[?(@.kind==\"BuildConfig\")].spec.strategy.sourceStrategy.env[?(@.name==\"SOME_VAR\")].value}'" 'envvarfromfile' |
|
100 |
+ |
|
101 |
+os::cmd::expect_failure_and_text "oc new-build --binary php --env-file does/not/exist" 'no such file or directory' |
|
102 |
+os::cmd::expect_failure_and_text "oc new-build --binary php --env-file test/testdata" 'is a directory' |
|
103 |
+os::cmd::expect_success "oc new-build --binary php --env-file /dev/null -o yaml" |
|
104 |
+os::cmd::expect_success "oc new-build --binary php --env-file /dev/null --env-file ${env_file} -o yaml" |
|
105 |
+os::cmd::expect_failure_and_text "echo 'fo%(o=bar' | oc new-build --binary php --env-file -" 'invalid parameter assignment' |
|
106 |
+os::cmd::expect_failure_and_text "echo 'S P A C E S=test' | oc new-build --binary php --env-file -" 'invalid parameter assignment' |
|
107 |
+ |
|
95 | 108 |
# verify we can create from a template when some objects in the template declare an app label |
96 | 109 |
# the app label will not be applied to any objects in the template. |
97 | 110 |
os::cmd::expect_success_and_not_text 'oc new-app -f test/testdata/template-with-app-label.json -o yaml' 'app: ruby-helloworld-sample' |
98 | 111 |
deleted file mode 100755 |
... | ... |
@@ -1,93 +0,0 @@ |
1 |
-#!/bin/bash |
|
2 |
-source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh" |
|
3 |
-trap os::test::junit::reconcile_output EXIT |
|
4 |
- |
|
5 |
-# Cleanup cluster resources created by this test |
|
6 |
-( |
|
7 |
- set +e |
|
8 |
- oc delete all,templates --all |
|
9 |
- oc delete user someval |
|
10 |
- exit 0 |
|
11 |
-) &>/dev/null |
|
12 |
- |
|
13 |
-os::test::junit::declare_suite_start "cmd/process" |
|
14 |
-# This test validates oc process |
|
15 |
- |
|
16 |
-# fail to process two templates by name |
|
17 |
-os::cmd::expect_failure_and_text 'oc process name1 name2' 'template name must be specified only once' |
|
18 |
-# fail to pass a filename or template by name |
|
19 |
-os::cmd::expect_failure_and_text 'oc process' 'Must pass a filename or name of stored template' |
|
20 |
-# can't ask for parameters and try process the template (include tests for deprecated -v/--value) |
|
21 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters --value=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-value' |
|
22 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters -v someval' '\-\-parameters flag does not process the template, can.t be used with \-\-value' |
|
23 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters --param=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-param' |
|
24 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters -p someval' '\-\-parameters flag does not process the template, can.t be used with \-\-param' |
|
25 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters --labels=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-labels' |
|
26 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters -l someval' '\-\-parameters flag does not process the template, can.t be used with \-\-labels' |
|
27 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters --output=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-output' |
|
28 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters -o someval' '\-\-parameters flag does not process the template, can.t be used with \-\-output' |
|
29 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters --output-version=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-output-version' |
|
30 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters --raw' '\-\-parameters flag does not process the template, can.t be used with \-\-raw' |
|
31 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters --template=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-template' |
|
32 |
-os::cmd::expect_failure_and_text 'oc process template-name --parameters -t someval' '\-\-parameters flag does not process the template, can.t be used with \-\-template' |
|
33 |
- |
|
34 |
-# providing a value more than once should fail (include tests for deprecated -v/--value) |
|
35 |
-os::cmd::expect_failure_and_text 'oc process template-name key=value key=value' 'provided more than once: key' |
|
36 |
-os::cmd::expect_failure_and_text 'oc process template-name --value=key=value --value=key=value' 'provided more than once: key' |
|
37 |
-os::cmd::expect_failure_and_text 'oc process template-name --param=key=value --param=key=value' 'provided more than once: key' |
|
38 |
-os::cmd::expect_failure_and_text 'oc process template-name key=value --value=key=value' 'provided more than once: key' |
|
39 |
-os::cmd::expect_failure_and_text 'oc process template-name key=value --param=key=value' 'provided more than once: key' |
|
40 |
-os::cmd::expect_failure_and_text 'oc process template-name key=value other=foo --value=key=value --value=other=baz' 'provided more than once: key, other' |
|
41 |
-os::cmd::expect_failure_and_text 'oc process template-name key=value other=foo --param=key=value --param=other=baz' 'provided more than once: key, other' |
|
42 |
- |
|
43 |
-required_params="${OS_ROOT}/test/testdata/template_required_params.yaml" |
|
44 |
- |
|
45 |
-# providing something other than a template is not OK |
|
46 |
-os::cmd::expect_failure_and_text "oc process -f '${OS_ROOT}/test/testdata/basic-users-binding.json'" 'not a valid Template but' |
|
47 |
- |
|
48 |
-# not providing required parameter should fail |
|
49 |
-os::cmd::expect_failure_and_text "oc process -f '${required_params}'" 'parameter required_param is required and must be specified' |
|
50 |
-# not providing an optional param is OK |
|
51 |
-os::cmd::expect_success "oc process -f '${required_params}' --value=required_param=someval" |
|
52 |
-os::cmd::expect_success "oc process -f '${required_params}' -v required_param=someval" |
|
53 |
-os::cmd::expect_success "oc process -f '${required_params}' --param=required_param=someval" |
|
54 |
-os::cmd::expect_success "oc process -f '${required_params}' -p required_param=someval | oc create -f -" |
|
55 |
-# parameters with multiple equal signs are OK |
|
56 |
-os::cmd::expect_success "oc process -f '${required_params}' required_param=someval=moreval | oc create -f -" |
|
57 |
-os::cmd::expect_success "oc process -f '${required_params}' -v required_param=someval=moreval2 | oc create -f -" |
|
58 |
-os::cmd::expect_success "oc process -f '${required_params}' -p required_param=someval=moreval3 | oc create -f -" |
|
59 |
-# we should have overwritten the template param |
|
60 |
-os::cmd::expect_success_and_text 'oc get user someval -o jsonpath={.Name}' 'someval' |
|
61 |
-os::cmd::expect_success_and_text 'oc get user someval=moreval -o jsonpath={.Name}' 'someval=moreval' |
|
62 |
-os::cmd::expect_success_and_text 'oc get user someval=moreval2 -o jsonpath={.Name}' 'someval=moreval2' |
|
63 |
-os::cmd::expect_success_and_text 'oc get user someval=moreval3 -o jsonpath={.Name}' 'someval=moreval3' |
|
64 |
-# providing a value not in the template should fail |
|
65 |
-os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=required_param=someval --value=other_param=otherval" 'unknown parameter name "other_param"' |
|
66 |
-os::cmd::expect_failure_and_text "oc process -f '${required_params}' --param=required_param=someval --param=other_param=otherval" 'unknown parameter name "other_param"' |
|
67 |
-# failure on values fails the entire call |
|
68 |
-os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=required_param=someval --value=optional_param" 'invalid parameter assignment in' |
|
69 |
-os::cmd::expect_failure_and_text "oc process -f '${required_params}' --param=required_param=someval --param=optional_param" 'invalid parameter assignment in' |
|
70 |
-# failure on labels fails the entire call |
|
71 |
-os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=required_param=someval --labels======" 'error parsing labels' |
|
72 |
-os::cmd::expect_failure_and_text "oc process -f '${required_params}' --param=required_param=someval --labels======" 'error parsing labels' |
|
73 |
- |
|
74 |
-# values are not split on commas, required parameter is not recognized |
|
75 |
-os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=optional_param=a,required_param=b" 'parameter required_param is required and must be specified' |
|
76 |
-os::cmd::expect_failure_and_text "oc process -f '${required_params}' --param=optional_param=a,required_param=b" 'parameter required_param is required and must be specified' |
|
77 |
-# warning is printed iff --value/--param looks like two k-v pairs separated by comma |
|
78 |
-os::cmd::expect_success_and_text "oc process -f '${required_params}' --value=required_param=a,b=c,d" 'no longer accepts comma-separated list' |
|
79 |
-os::cmd::expect_success_and_not_text "oc process -f '${required_params}' --value=required_param=a_b_c_d" 'no longer accepts comma-separated list' |
|
80 |
-os::cmd::expect_success_and_not_text "oc process -f '${required_params}' --value=required_param=a,b,c,d" 'no longer accepts comma-separated list' |
|
81 |
-os::cmd::expect_success_and_text "oc process -f '${required_params}' --param=required_param=a,b=c,d" 'no longer accepts comma-separated list' |
|
82 |
-os::cmd::expect_success_and_not_text "oc process -f '${required_params}' --param=required_param=a_b_c_d" 'no longer accepts comma-separated list' |
|
83 |
-os::cmd::expect_success_and_not_text "oc process -f '${required_params}' --param=required_param=a,b,c,d" 'no longer accepts comma-separated list' |
|
84 |
-# warning is not printed for template values passed as positional arguments |
|
85 |
-os::cmd::expect_success_and_not_text "oc process -f '${required_params}' required_param=a,b=c,d" 'no longer accepts comma-separated list' |
|
86 |
- |
|
87 |
-# set template parameter to contents of file |
|
88 |
-os::cmd::expect_success_and_text "oc process -f '${required_params}' --value=required_param='`cat ${OS_ROOT}/test/testdata/multiline.txt`'" 'also,with=commas' |
|
89 |
-os::cmd::expect_success_and_text "oc process -f '${required_params}' --param=required_param='`cat ${OS_ROOT}/test/testdata/multiline.txt`'" 'also,with=commas' |
|
90 |
- |
|
91 |
- |
|
92 |
-echo "process: ok" |
|
93 |
-os::test::junit::declare_suite_end |
|
94 | 1 |
\ No newline at end of file |
... | ... |
@@ -8,6 +8,7 @@ trap os::test::junit::reconcile_output EXIT |
8 | 8 |
oc delete all,templates --all |
9 | 9 |
oc delete template/ruby-helloworld-sample -n openshift |
10 | 10 |
oc delete project test-template-project |
11 |
+ oc delete user someval someval=moreval someval=moreval2 someval=moreval3 |
|
11 | 12 |
exit 0 |
12 | 13 |
) &>/dev/null |
13 | 14 |
|
... | ... |
@@ -41,25 +42,49 @@ echo "templates: ok" |
41 | 41 |
os::test::junit::declare_suite_end |
42 | 42 |
|
43 | 43 |
os::test::junit::declare_suite_start "cmd/templates/config" |
44 |
-os::cmd::expect_success 'oc process -f test/templates/testdata/guestbook.json -l app=guestbook | oc create -f -' |
|
44 |
+guestbook_template="${OS_ROOT}/test/templates/testdata/guestbook.json" |
|
45 |
+os::cmd::expect_success "oc process -f '${guestbook_template}' -l app=guestbook | oc create -f -" |
|
45 | 46 |
os::cmd::expect_success_and_text 'oc status' 'frontend-service' |
46 | 47 |
echo "template+config: ok" |
47 | 48 |
os::test::junit::declare_suite_end |
48 | 49 |
|
49 | 50 |
os::test::junit::declare_suite_start "cmd/templates/parameters" |
51 |
+guestbook_params="${OS_ROOT}/test/templates/testdata/guestbook.env" |
|
50 | 52 |
# Individually specified parameter values are honored |
51 |
-os::cmd::expect_success_and_text 'oc process -f test/templates/testdata/guestbook.json -p ADMIN_USERNAME=myuser -p ADMIN_PASSWORD=mypassword' '"myuser"' |
|
52 |
-os::cmd::expect_success_and_text 'oc process -f test/templates/testdata/guestbook.json -p ADMIN_USERNAME=myuser -p ADMIN_PASSWORD=mypassword' '"mypassword"' |
|
53 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' -p ADMIN_USERNAME=myuser -p ADMIN_PASSWORD=mypassword" '"myuser"' |
|
54 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' -p ADMIN_USERNAME=myuser -p ADMIN_PASSWORD=mypassword" '"mypassword"' |
|
53 | 55 |
# Argument values are honored |
54 |
-os::cmd::expect_success_and_text 'oc process ADMIN_USERNAME=myuser ADMIN_PASSWORD=mypassword -f test/templates/testdata/guestbook.json' '"myuser"' |
|
55 |
-os::cmd::expect_success_and_text 'oc process -f test/templates/testdata/guestbook.json ADMIN_USERNAME=myuser ADMIN_PASSWORD=mypassword' '"mypassword"' |
|
56 |
+os::cmd::expect_success_and_text "oc process ADMIN_USERNAME=myuser ADMIN_PASSWORD=mypassword -f '${guestbook_template}'" '"myuser"' |
|
57 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' ADMIN_USERNAME=myuser ADMIN_PASSWORD=mypassword" '"mypassword"' |
|
56 | 58 |
# Argument values with commas are honored |
57 | 59 |
os::cmd::expect_success 'oc create -f examples/sample-app/application-template-stibuild.json' |
58 | 60 |
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample MYSQL_USER=myself MYSQL_PASSWORD=my,1%pa=s' '"myself"' |
59 | 61 |
os::cmd::expect_success_and_text 'oc process MYSQL_USER=myself MYSQL_PASSWORD=my,1%pa=s ruby-helloworld-sample' '"my,1%pa=s"' |
60 | 62 |
os::cmd::expect_success_and_text 'oc process ruby-helloworld-sample -p MYSQL_USER=myself -p MYSQL_PASSWORD=my,1%pa=s' '"myself"' |
61 | 63 |
os::cmd::expect_success_and_text 'oc process -p MYSQL_USER=myself -p MYSQL_PASSWORD=my,1%pa=s ruby-helloworld-sample' '"my,1%pa=s"' |
64 |
+# Argument values can be read from file |
|
65 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' --param-file='${guestbook_params}'" '"root"' |
|
66 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' --param-file='${guestbook_params}'" '"adminpass"' |
|
67 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' --param-file='${guestbook_params}'" '"redispass"' |
|
68 |
+# Argument values can be read from stdin |
|
69 |
+os::cmd::expect_success_and_text "cat '${guestbook_params}' | oc process -f '${guestbook_template}' --param-file=-" '"root"' |
|
70 |
+os::cmd::expect_success_and_text "cat '${guestbook_params}' | oc process -f '${guestbook_template}' --param-file=-" '"adminpass"' |
|
71 |
+os::cmd::expect_success_and_text "cat '${guestbook_params}' | oc process -f '${guestbook_template}' --param-file=-" '"redispass"' |
|
72 |
+# Argument values from command line have precedence over those from file |
|
73 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' --param-file='${guestbook_params}' -p ADMIN_USERNAME=myuser" 'ignoring value from file' |
|
74 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' --param-file='${guestbook_params}' -p ADMIN_USERNAME=myuser" '"myuser"' |
|
75 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' --param-file='${guestbook_params}' -p ADMIN_PASSWORD=mypassword" '"mypassword"' |
|
76 |
+os::cmd::expect_success_and_text "oc process -f '${guestbook_template}' --param-file='${guestbook_params}' -p REDIS_PASSWORD=rrr" '"rrr"' |
|
77 |
+# Set template parameters from parameter file with multiline values |
|
78 |
+os::cmd::expect_success_and_text "oc process -f test/testdata/template_required_params.yaml --param-file=test/testdata/template_required_params.env -o yaml" 'first$' |
|
62 | 79 |
os::cmd::expect_success 'oc delete template ruby-helloworld-sample' |
80 |
+# Parameter file failure cases |
|
81 |
+os::cmd::expect_failure_and_text "oc process -f test/testdata/template_required_params.yaml --param-file=does/not/exist" 'no such file or directory' |
|
82 |
+os::cmd::expect_failure_and_text "oc process -f test/testdata/template_required_params.yaml --param-file=test/testdata" 'is a directory' |
|
83 |
+os::cmd::expect_failure_and_text "oc process -f test/testdata/template_required_params.yaml --param-file=/dev/null" 'parameter required_param is required and must be specified' |
|
84 |
+os::cmd::expect_success "oc process -f '${guestbook_template}' --param-file=/dev/null --param-file='${guestbook_params}'" |
|
85 |
+os::cmd::expect_failure_and_text "echo 'fo%(o=bar' | oc process -f test/testdata/template_required_params.yaml --param-file=-" 'invalid parameter assignment' |
|
86 |
+os::cmd::expect_failure_and_text "echo 'S P A C E S=test' | oc process -f test/testdata/template_required_params.yaml --param-file=-" 'invalid parameter assignment' |
|
63 | 87 |
echo "template+parameters: ok" |
64 | 88 |
os::test::junit::declare_suite_end |
65 | 89 |
|
... | ... |
@@ -92,6 +117,7 @@ os::cmd::expect_success 'oc create -f examples/sample-app/application-template-d |
92 | 92 |
os::cmd::expect_success 'oc policy add-role-to-user admin test-user' |
93 | 93 |
new="$(mktemp -d)/tempconfig" |
94 | 94 |
os::cmd::expect_success "oc config view --raw > ${new}" |
95 |
+old="${KUBECONFIG}" |
|
95 | 96 |
export KUBECONFIG=${new} |
96 | 97 |
os::cmd::expect_success 'oc login -u test-user -p password' |
97 | 98 |
os::cmd::expect_success 'oc new-project test-template-project' |
... | ... |
@@ -102,7 +128,81 @@ os::cmd::expect_success 'oc process template/ruby-helloworld-sample' |
102 | 102 |
os::cmd::expect_success 'oc process templates/ruby-helloworld-sample' |
103 | 103 |
os::cmd::expect_success 'oc process openshift//ruby-helloworld-sample' |
104 | 104 |
os::cmd::expect_success 'oc process openshift/template/ruby-helloworld-sample' |
105 |
+export KUBECONFIG=${old} |
|
105 | 106 |
echo "processing templates in different namespace: ok" |
106 | 107 |
os::test::junit::declare_suite_end |
107 | 108 |
|
109 |
+os::test::junit::declare_suite_start "cmd/templates/process" |
|
110 |
+# This test validates oc process |
|
111 |
+# fail to process two templates by name |
|
112 |
+os::cmd::expect_failure_and_text 'oc process name1 name2' 'template name must be specified only once' |
|
113 |
+# fail to pass a filename or template by name |
|
114 |
+os::cmd::expect_failure_and_text 'oc process' 'Must pass a filename or name of stored template' |
|
115 |
+# can't ask for parameters and try process the template (include tests for deprecated -v/--value) |
|
116 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters --value=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-value' |
|
117 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters -v someval' '\-\-parameters flag does not process the template, can.t be used with \-\-value' |
|
118 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters --param=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-param' |
|
119 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters -p someval' '\-\-parameters flag does not process the template, can.t be used with \-\-param' |
|
120 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters --labels=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-labels' |
|
121 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters -l someval' '\-\-parameters flag does not process the template, can.t be used with \-\-labels' |
|
122 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters --output=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-output' |
|
123 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters -o someval' '\-\-parameters flag does not process the template, can.t be used with \-\-output' |
|
124 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters --output-version=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-output-version' |
|
125 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters --raw' '\-\-parameters flag does not process the template, can.t be used with \-\-raw' |
|
126 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters --template=someval' '\-\-parameters flag does not process the template, can.t be used with \-\-template' |
|
127 |
+os::cmd::expect_failure_and_text 'oc process template-name --parameters -t someval' '\-\-parameters flag does not process the template, can.t be used with \-\-template' |
|
128 |
+# providing a value more than once should fail (include tests for deprecated -v/--value) |
|
129 |
+os::cmd::expect_failure_and_text 'oc process template-name key=value key=value' 'provided more than once: key' |
|
130 |
+os::cmd::expect_failure_and_text 'oc process template-name --value=key=value --value=key=value' 'provided more than once: key' |
|
131 |
+os::cmd::expect_failure_and_text 'oc process template-name --param=key=value --param=key=value' 'provided more than once: key' |
|
132 |
+os::cmd::expect_failure_and_text 'oc process template-name key=value --value=key=value' 'provided more than once: key' |
|
133 |
+os::cmd::expect_failure_and_text 'oc process template-name key=value --param=key=value' 'provided more than once: key' |
|
134 |
+os::cmd::expect_failure_and_text 'oc process template-name key=value other=foo --value=key=value --value=other=baz' 'provided more than once: key, other' |
|
135 |
+os::cmd::expect_failure_and_text 'oc process template-name key=value other=foo --param=key=value --param=other=baz' 'provided more than once: key, other' |
|
136 |
+required_params="${OS_ROOT}/test/testdata/template_required_params.yaml" |
|
137 |
+# providing something other than a template is not OK |
|
138 |
+os::cmd::expect_failure_and_text "oc process -f '${OS_ROOT}/test/testdata/basic-users-binding.json'" 'not a valid Template but' |
|
139 |
+# not providing required parameter should fail |
|
140 |
+os::cmd::expect_failure_and_text "oc process -f '${required_params}'" 'parameter required_param is required and must be specified' |
|
141 |
+# not providing an optional param is OK |
|
142 |
+os::cmd::expect_success "oc process -f '${required_params}' --value=required_param=someval" |
|
143 |
+os::cmd::expect_success "oc process -f '${required_params}' -v required_param=someval" |
|
144 |
+os::cmd::expect_success "oc process -f '${required_params}' --param=required_param=someval" |
|
145 |
+os::cmd::expect_success "oc process -f '${required_params}' -p required_param=someval | oc create -f -" |
|
146 |
+# parameters with multiple equal signs are OK |
|
147 |
+os::cmd::expect_success "oc process -f '${required_params}' required_param=someval=moreval | oc create -f -" |
|
148 |
+os::cmd::expect_success "oc process -f '${required_params}' -v required_param=someval=moreval2 | oc create -f -" |
|
149 |
+os::cmd::expect_success "oc process -f '${required_params}' -p required_param=someval=moreval3 | oc create -f -" |
|
150 |
+# we should have overwritten the template param |
|
151 |
+os::cmd::expect_success_and_text 'oc get user someval -o jsonpath={.Name}' 'someval' |
|
152 |
+os::cmd::expect_success_and_text 'oc get user someval=moreval -o jsonpath={.Name}' 'someval=moreval' |
|
153 |
+os::cmd::expect_success_and_text 'oc get user someval=moreval2 -o jsonpath={.Name}' 'someval=moreval2' |
|
154 |
+os::cmd::expect_success_and_text 'oc get user someval=moreval3 -o jsonpath={.Name}' 'someval=moreval3' |
|
155 |
+# providing a value not in the template should fail |
|
156 |
+os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=required_param=someval --value=other_param=otherval" 'unknown parameter name "other_param"' |
|
157 |
+os::cmd::expect_failure_and_text "oc process -f '${required_params}' --param=required_param=someval --param=other_param=otherval" 'unknown parameter name "other_param"' |
|
158 |
+# failure on values fails the entire call |
|
159 |
+os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=required_param=someval --value=optional_param" 'invalid parameter assignment in' |
|
160 |
+os::cmd::expect_failure_and_text "oc process -f '${required_params}' --param=required_param=someval --param=optional_param" 'invalid parameter assignment in' |
|
161 |
+# failure on labels fails the entire call |
|
162 |
+os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=required_param=someval --labels======" 'error parsing labels' |
|
163 |
+os::cmd::expect_failure_and_text "oc process -f '${required_params}' --param=required_param=someval --labels======" 'error parsing labels' |
|
164 |
+# values are not split on commas, required parameter is not recognized |
|
165 |
+os::cmd::expect_failure_and_text "oc process -f '${required_params}' --value=optional_param=a,required_param=b" 'parameter required_param is required and must be specified' |
|
166 |
+os::cmd::expect_failure_and_text "oc process -f '${required_params}' --param=optional_param=a,required_param=b" 'parameter required_param is required and must be specified' |
|
167 |
+# warning is printed iff --value/--param looks like two k-v pairs separated by comma |
|
168 |
+os::cmd::expect_success_and_text "oc process -f '${required_params}' --value=required_param=a,b=c,d" 'no longer accepts comma-separated list' |
|
169 |
+os::cmd::expect_success_and_not_text "oc process -f '${required_params}' --value=required_param=a_b_c_d" 'no longer accepts comma-separated list' |
|
170 |
+os::cmd::expect_success_and_not_text "oc process -f '${required_params}' --value=required_param=a,b,c,d" 'no longer accepts comma-separated list' |
|
171 |
+os::cmd::expect_success_and_text "oc process -f '${required_params}' --param=required_param=a,b=c,d" 'no longer accepts comma-separated list' |
|
172 |
+os::cmd::expect_success_and_not_text "oc process -f '${required_params}' --param=required_param=a_b_c_d" 'no longer accepts comma-separated list' |
|
173 |
+os::cmd::expect_success_and_not_text "oc process -f '${required_params}' --param=required_param=a,b,c,d" 'no longer accepts comma-separated list' |
|
174 |
+# warning is not printed for template values passed as positional arguments |
|
175 |
+os::cmd::expect_success_and_not_text "oc process -f '${required_params}' required_param=a,b=c,d" 'no longer accepts comma-separated list' |
|
176 |
+# set template parameter to contents of file |
|
177 |
+os::cmd::expect_success_and_text "oc process -f '${required_params}' --value=required_param='`cat ${OS_ROOT}/test/testdata/multiline.txt`'" 'also,with=commas' |
|
178 |
+os::cmd::expect_success_and_text "oc process -f '${required_params}' --param=required_param='`cat ${OS_ROOT}/test/testdata/multiline.txt`'" 'also,with=commas' |
|
179 |
+echo "process: ok" |
|
180 |
+os::test::junit::declare_suite_end |
|
181 |
+ |
|
108 | 182 |
os::test::junit::declare_suite_end |