Skip to content

Commit

Permalink
test for skip-tests and suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Jan 27, 2022
1 parent c2d46b9 commit 1e7e56c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ generators:
rules:
- apiGroups: [""]
verbs: ["*"]
resources: ["*"]
resources: ["*"]
28 changes: 1 addition & 27 deletions examples/render-helm-chart-local/.expected/diff.patch
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,6 @@ index 0000000..8ba7f5c
+ path: /
+ port: http
+ resources: {}
diff --git a/pod_test-helloworld-chart-test-connection.yaml b/pod_test-helloworld-chart-test-connection.yaml
new file mode 100644
index 0000000..8793304
--- /dev/null
+++ b/pod_test-helloworld-chart-test-connection.yaml
@@ -0,0 +1,20 @@
+# Source: helloworld-chart/templates/tests/test-connection.yaml
+apiVersion: v1
+kind: Pod
+metadata:
+ name: "test-helloworld-chart-test-connection"
+ labels:
+ helm.sh/chart: helloworld-chart-0.1.0
+ app.kubernetes.io/name: helloworld-chart
+ app.kubernetes.io/instance: test
+ app.kubernetes.io/version: "1.16.0"
+ app.kubernetes.io/managed-by: Helm
+ annotations:
+ "helm.sh/hook": test-success
+spec:
+ containers:
+ - name: wget
+ image: busybox
+ command: ['wget']
+ args: ['test-helloworld-chart:80']
+ restartPolicy: Never
diff --git a/service_test-helloworld-chart.yaml b/service_test-helloworld-chart.yaml
new file mode 100644
index 0000000..7d734d3
Expand Down Expand Up @@ -116,4 +90,4 @@ index 0000000..5800f2a
+ app.kubernetes.io/name: helloworld-chart
+ app.kubernetes.io/instance: test
+ app.kubernetes.io/version: "1.16.0"
+ app.kubernetes.io/managed-by: Helm
+ app.kubernetes.io/managed-by: Helm
3 changes: 2 additions & 1 deletion examples/render-helm-chart-local/.expected/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ kpt fn eval --image-pull-policy never --image gcr.io/kpt-fn/render-helm-chart:un
--mount type=bind,src="$(pwd)",dst=/tmp/charts -- \
name=helloworld-chart \
releaseName=test \
valuesFile=/tmp/charts/helloworld-values/values.yaml
valuesFile=/tmp/charts/helloworld-values/values.yaml \
skipTests=true
16 changes: 15 additions & 1 deletion examples/render-helm-chart-local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $ kpt fn eval --image gcr.io/kpt-fn/render-helm-chart:unstable \
releaseName=test
```

You can optionally provide your own values files using `--valuesFile`.
You can optionally provide your own values files using `valuesFile`.

```shell
$ kpt fn eval --image gcr.io/kpt-fn/render-helm-chart:unstable \
Expand All @@ -37,6 +37,17 @@ releaseName=test \
valuesFile=tmp/charts/helloworld-values/values.yaml
```

You can optionally skip tests in the templated output with `skipTests`.

```shell
$ kpt fn eval --image gcr.io/kpt-fn/render-helm-chart:unstable \
--mount type=bind,src=$(pwd),dst=/tmp/charts -- \
name=helloworld-chart \
releaseName=test \
valuesFile=tmp/charts/helloworld-values/values.yaml \
skipTests=true
```

### Expected result

You can run the following command to see the new files you have:
Expand All @@ -52,3 +63,6 @@ $ kpt pkg tree
You should be able to find `replicas: 5` in
file `deployment_test-helloworld-chart.yaml`, which demonstrates that
the correct values file provided by --valuesFile was used.

If you provided the `skipTests` option, `pod_test-helloworld-chart-test-connection.yaml`
will not appear in your files.
12 changes: 0 additions & 12 deletions functions/go/render-helm-chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ data:
repo: string
releaseName: string
namespace: string
createNamespace: string
description: string
nameTemplate: string
includeCRDs: string
skipCRDs: string
skipTests: string
valuesFile: string
```
Expand All @@ -79,11 +76,8 @@ data:
`repo` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts
`releaseName` | Replaces RELEASE_NAME in the chart template output | test
`namespace` | Sets the target namespace for a release (`.Release.Namespace` in the template) | my-namespace
`createNamespace` | Create the release namespace if not present | true
`description` | Add a custom description | This is a chart.
`nameTemplate` | Specify the template used to name the release | gatekeeper
`includeCRDs` | Specifies if Helm should also generate CustomResourceDefinitions. Legal values: "true", "false" (default). | "true"
`skipCRDs` | If set, no CRDs will be installed. Legal values: "true", "false" (default). | "true"
`skipTests` | If set, skip tests from templated output. Legal values: "true", "false" (default). | "true"
`valuesFile` | valuesFile is a remote or local file path to a values file to use instead of the default values that accompanied the chart. The default values are in '{chartHome}/{name}/values.yaml', where `chartHome` and `name` are the parameters defined above. | Using a local values file: path/to/your/values.yaml <br> <br> Using a remote values file: https://raw.githubusercontent.com/config-sync-examples/helm-components/main/cert-manager-values.yaml

Expand All @@ -104,11 +98,8 @@ helmCharts:
apiVersions: []string
releaseName: string
namespace: string
createNamespace: bool
description: string
nameTemplate: string
includeCRDs: bool
skipCRDs: bool
skipTests: bool
values:
valuesFiles: []string
Expand All @@ -130,11 +121,8 @@ helmCharts:
`repo` | A URL locating the chart on the internet | https://itzg.github.io/minecraft-server-charts
`releaseName` | Replaces RELEASE_NAME in the chart template output | test
`namespace` | Sets the target namespace for a release (`.Release.Namespace` in the template) | my-namespace
`createNamespace` | Create the release namespace if not present | true
`description` | Add a custom description | This is a chart.
`nameTemplate` | Specify the template used to name the release | gatekeeper
`includeCRDs` | Specifies if Helm should also generate CustomResourceDefinitions. Legal values: "true", "false" (default). | "true"
`skipCRDs` | If set, no CRDs will be installed. Legal values: "true", "false" (default). | "true"
`skipTests` | If set, skip tests from templated output. Legal values: "true", "false" (default). | "true"
`values` | Values to use instead of the default values that accompany the chart. This can be defined inline or in a file.
`valuesInline` | Values defined inline to use instead of default values that accompany the chart | global: <br> &emsp; enabled: false <br> tests: <br> &emsp; enabled: false
Expand Down
12 changes: 0 additions & 12 deletions functions/go/render-helm-chart/generated/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions functions/go/render-helm-chart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,11 @@ func (f *helmChartInflatorFunction) ConfigMapArgs(
if val, ok := m["namespace"]; ok {
p.Namespace = val
}
if val, ok := m["createNamespace"]; ok {
if val == "true" {
p.SkipTests = true
}
}
if val, ok := m["includeCRDs"]; ok {
if val == "true" {
p.IncludeCRDs = true
}
}
if val, ok := m["skipCRDs"]; ok {
if val == "true" {
p.SkipCRDs = true
}
}
if val, ok := m["skipTests"]; ok {
if val == "true" {
p.SkipTests = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,22 @@ func (p *HelmChartInflationGeneratorPlugin) createNewMergedValuesFiles(path stri
string, error) {
pValues, err := ioutil.ReadFile(path)
if err != nil {
if u, err := url.Parse(path); err == nil && (u.Scheme == "http" || u.Scheme == "https") {
var hc *http.Client
hc = &http.Client{}
resp, err := hc.Get(path)
if err != nil {
return "", err
}
defer resp.Body.Close()
pValues, err = ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
if u, urlErr := url.Parse(path); urlErr == nil {
if (u.Scheme == "http" || u.Scheme == "https") {
resp, err := http.Get(path)
if err != nil {
return "", err
}
defer resp.Body.Close()
pValues, err = ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
} else { // url scheme is not http or https
return "", fmt.Errorf("unsupported url type: %s", path)
}
} else { // invalid path and invalid URL
return "", err
}
}
if p.ValuesMerge == valuesMergeOptionMerge ||
Expand Down Expand Up @@ -191,7 +195,7 @@ func (p *HelmChartInflationGeneratorPlugin) writeValuesBytes(
}
// use a hash of the provided path to generate a unique, valid filename
hash := md5.Sum([]byte(path))
newPath := filepath.Join(p.tmpDir, p.Name+"-"+hex.EncodeToString(hash[:])+"-kustomize-values.yaml")
newPath := filepath.Join(p.tmpDir, p.Name+"-kustomize-values-"+hex.EncodeToString(hash[:])+".yaml")
return newPath, ioutil.WriteFile(newPath, b, 0644)
}

Expand Down Expand Up @@ -249,12 +253,12 @@ func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string {
if p.Namespace != "" {
args = append(args, "--namespace", p.Namespace)
}
if p.Name != "" {
args = append(args, filepath.Join(p.absChartHome(), p.Name))
}
if p.NameTemplate != "" {
args = append(args, "--name-template", p.NameTemplate)
}
if p.Name != "" {
args = append(args, filepath.Join(p.absChartHome(), p.Name))
}
for _, valuesFile := range p.ValuesFiles {
args = append(args, "-f", valuesFile)
}
Expand All @@ -267,18 +271,12 @@ func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string {
// I've tried placing the flag before and after the name argument.
args = append(args, "--generate-name")
}
if p.CreateNamespace {
args = append(args, "--create-namespace")
}
if p.Description != "" {
args = append(args, "--description", p.Description)
}
if p.IncludeCRDs {
args = append(args, "--include-crds")
}
if p.SkipCRDs {
args = append(args, "--skip-crds")
}
if p.SkipTests {
args = append(args, "--skip-tests")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ type TemplateOptions struct {
// in the helm template
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`

// CreateNamespace creates the release namespace if it is not present.
CreateNamespace bool `json:"createNamespace,omitempty" yaml:"createNamespace,omitempty"`

// Description is a custom description to add when rendering the helm chart.
Description string `json:"description,omitempty" yaml:"description,omitempty"`

Expand All @@ -81,9 +78,6 @@ type TemplateOptions struct {
// Defaults to false.
IncludeCRDs bool `json:"includeCRDs,omitempty" yaml:"includeCRDs,omitempty"`

// SkipCRDs means no CRDs will be installed. By default, CRDs are installed.
SkipCRDs bool `json:"skipCRDs,omitempty" yaml:"skipCRDs,omitempty"`

// SkipTests skips tests from templated output.
SkipTests bool `json:"skipTests,omitempty" yaml:"skipTests,omitempty"`

Expand Down

0 comments on commit 1e7e56c

Please sign in to comment.