Skip to content
Snippets Groups Projects
Unverified Commit 722aa71f authored by Alex Clemmer's avatar Alex Clemmer Committed by GitHub
Browse files

Merge pull request #95 from jessicayuen/preview-fix

YAML, JSON handling for prototype commands
parents 527db11b f5a1463b
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ import (
"github.com/ksonnet/ksonnet/metadata"
"github.com/ksonnet/ksonnet/prototype"
"github.com/ksonnet/ksonnet/prototype/snippet"
"github.com/ksonnet/ksonnet/prototype/snippet/jsonnet"
"github.com/ksonnet/ksonnet/utils"
"github.com/spf13/cobra"
......@@ -309,13 +310,6 @@ unique enough to resolve to 'io.ksonnet.pkg.single-port-deployment'.`,
# introduction of help message for more information on how this works.
ks prototype preview simple-deployment \
--name=nginx \
--image=nginx
# Preview prototype 'io.ksonnet.pkg.single-port-deployment' as YAML,
# placing the result in 'components/nginx-depl.yaml. Note that some templates
# do not have a YAML or JSON versions.
ks prototype preview deployment nginx-depl yaml \
--name=nginx \
--image=nginx`,
}
......@@ -414,10 +408,6 @@ ksonnet will expand templates as Jsonnet).
--name=nginx \
--image=nginx
Note that if we were to specify to expand the template as JSON or YAML, we would
generate a file with a '.json' or '.yaml' extension, respectively. See examples
below for an example of how to do this.
Note also that 'prototype-name' need only contain enough of the suffix of a name
to uniquely disambiguate it among known names. For example, 'deployment' may
resolve ambiguously, in which case 'use' will fail, while 'deployment' might be
......@@ -436,13 +426,6 @@ unique enough to resolve to 'io.ksonnet.pkg.single-port-deployment'.`,
# information on how this works. Note that if you have imported another
# prototype with this suffix, this may resolve ambiguously for you.
ks prototype use deployment nginx-depl \
--name=nginx \
--image=nginx
# Instantiate prototype 'io.ksonnet.pkg.single-port-deployment' as YAML,
# placing the result in 'components/nginx-depl.yaml. Note that some templates
# do not have a YAML or JSON versions.
ks prototype use deployment nginx-depl yaml \
--name=nginx \
--image=nginx`,
}
......@@ -468,9 +451,11 @@ func expandPrototype(proto *prototype.SpecificationSchema, templateType prototyp
componentsText = fmt.Sprintf(`components["%s"]`, componentName)
}
template = append([]string{`local params = std.extVar("` + metadata.ParamsExtCodeKey + `").` + componentsText + ";"}, template...)
return jsonnet.Parse(componentName, strings.Join(template, "\n"))
}
return jsonnet.Parse(componentName, strings.Join(template, "\n"))
tm := snippet.Parse(strings.Join(template, "\n"))
return tm.Evaluate(params)
}
func getParameters(proto *prototype.SpecificationSchema, flags *pflag.FlagSet) (map[string]string, error) {
......
......@@ -16,10 +16,6 @@ ksonnet will expand templates as Jsonnet).
--name=nginx \
--image=nginx
Note that if we were to specify to expand the template as JSON or YAML, we would
generate a file with a '.json' or '.yaml' extension, respectively. See examples
below for an example of how to do this.
Note also that 'prototype-name' need only contain enough of the suffix of a name
to uniquely disambiguate it among known names. For example, 'deployment' may
resolve ambiguously, in which case 'use' will fail, while 'deployment' might be
......
......@@ -32,13 +32,6 @@ ks prototype preview <prototype-name> [type] [parameter-flags]
ks prototype preview simple-deployment \
--name=nginx \
--image=nginx
# Preview prototype 'io.ksonnet.pkg.single-port-deployment' as YAML,
# placing the result in 'components/nginx-depl.yaml. Note that some templates
# do not have a YAML or JSON versions.
ks prototype preview deployment nginx-depl yaml \
--name=nginx \
--image=nginx
```
### Options inherited from parent commands
......
......@@ -16,10 +16,6 @@ ksonnet will expand templates as Jsonnet).
--name=nginx \
--image=nginx
Note that if we were to specify to expand the template as JSON or YAML, we would
generate a file with a '.json' or '.yaml' extension, respectively. See examples
below for an example of how to do this.
Note also that 'prototype-name' need only contain enough of the suffix of a name
to uniquely disambiguate it among known names. For example, 'deployment' may
resolve ambiguously, in which case 'use' will fail, while 'deployment' might be
......@@ -47,13 +43,6 @@ ks prototype use <prototype-name> <componentName> [type] [parameter-flags]
ks prototype use deployment nginx-depl \
--name=nginx \
--image=nginx
# Instantiate prototype 'io.ksonnet.pkg.single-port-deployment' as YAML,
# placing the result in 'components/nginx-depl.yaml. Note that some templates
# do not have a YAML or JSON versions.
ks prototype use deployment nginx-depl yaml \
--name=nginx \
--image=nginx
```
### Options inherited from parent commands
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment