-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Helm integration test framework #237
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d692222
Framework for helm integration tests
yorinasub17 cea9c18
Fix goimports
yorinasub17 e73603a
Deploy Tiller
yorinasub17 bff3ddd
Additional pod functions
yorinasub17 c71884b
kube resource names must start with a letter
yorinasub17 a870c5f
Fix formatting
yorinasub17 2993c07
Support creating port forwards
yorinasub17 4ca91d4
Rename resource types
yorinasub17 649031e
TEMP DELETE mE
yorinasub17 f4e2c32
Add list services
yorinasub17 d3e7e96
Use build tags to further separate helm tests
yorinasub17 ad4d27a
Fix the test runner
yorinasub17 7a2893f
Only install helm in helm_test
yorinasub17 8cd84d8
[skip ci] Add comments to helm.Install and helm.Delete
yorinasub17 bffe32b
Update boilerplate text on test overloading
yorinasub17 1a8c4e0
Fix copy pasta
yorinasub17 8ad1927
Address PR comments
yorinasub17 7440db7
Resolve race condition
yorinasub17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ include "helm-basic-example.fullname" . }} | ||
labels: | ||
# These labels are required by helm. You can read more about required labels in the chart best pracices guide: | ||
# https://docs.helm.sh/chart_best_practices/#standard-labels | ||
helm.sh/chart: {{ include "helm-basic-example.chart" . }} | ||
app.kubernetes.io/name: {{ include "helm-basic-example.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
spec: | ||
selector: | ||
app.kubernetes.io/name: {{ include "helm-basic-example.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
type: NodePort | ||
ports: | ||
- protocol: TCP | ||
targetPort: 80 | ||
port: 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,9 @@ import ( | |
"github.com/gruntwork-io/terratest/modules/shell" | ||
) | ||
|
||
// GetCommonArgs extracts common helm options. In this case, these are: | ||
// getCommonArgs extracts common helm options. In this case, these are: | ||
// - kubeconfig path | ||
// - kubeconfig context | ||
// - namespace | ||
// - helm home path | ||
func getCommonArgs(options *Options, args ...string) []string { | ||
if options.KubectlOptions != nil && options.KubectlOptions.ContextName != "" { | ||
|
@@ -19,34 +18,34 @@ func getCommonArgs(options *Options, args ...string) []string { | |
if options.KubectlOptions != nil && options.KubectlOptions.ConfigPath != "" { | ||
args = append(args, "--kubeconfig", options.KubectlOptions.ConfigPath) | ||
} | ||
if options.KubectlOptions != nil && options.KubectlOptions.Namespace != "" { | ||
args = append(args, "--namespace", options.KubectlOptions.Namespace) | ||
} | ||
if options.HomePath != "" { | ||
args = append(args, "--home", options.HomePath) | ||
} | ||
return args | ||
} | ||
|
||
// RunHelmCommandAndGetOutputE runs helm with the given arguments and options and returns stdout/stderr. | ||
func RunHelmCommandAndGetOutputE(t *testing.T, options *Options, cmd string, additionalArgs ...string) (string, error) { | ||
args := []string{cmd} | ||
args = getCommonArgs(options, args...) | ||
|
||
// getValuesArgsE computes the args to pass in for setting values | ||
func getValuesArgsE(t *testing.T, options *Options, args ...string) ([]string, error) { | ||
args = append(args, formatSetValuesAsArgs(options.SetValues)...) | ||
|
||
valuesFilesArgs, err := formatValuesFilesAsArgsE(t, options.ValuesFiles) | ||
if err != nil { | ||
return "", errors.WithStackTrace(err) | ||
return args, errors.WithStackTrace(err) | ||
} | ||
args = append(args, valuesFilesArgs...) | ||
|
||
setFilesArgs, err := formatSetFilesAsArgsE(t, options.SetFiles) | ||
if err != nil { | ||
return "", errors.WithStackTrace(err) | ||
return args, errors.WithStackTrace(err) | ||
} | ||
args = append(args, setFilesArgs...) | ||
return args, nil | ||
} | ||
|
||
// RunHelmCommandAndGetOutputE runs helm with the given arguments and options and returns stdout/stderr. | ||
func RunHelmCommandAndGetOutputE(t *testing.T, options *Options, cmd string, additionalArgs ...string) (string, error) { | ||
args := []string{cmd} | ||
args = getCommonArgs(options, args...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refactor was necessary because only |
||
args = append(args, additionalArgs...) | ||
|
||
helmCmd := shell.Command{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package helm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// Delete will delete the provided release from Tiller. If you set purge to true, Tiller will delete the release object | ||
// as well so that the release name can be reused. This will fail the test if there is an error. | ||
func Delete(t *testing.T, options *Options, releaseName string, purge bool) { | ||
require.NoError(t, DeleteE(t, options, releaseName, purge)) | ||
} | ||
|
||
// DeleteE will delete the provided release from Tiller. If you set purge to true, Tiller will delete the release object | ||
// as well so that the release name can be reused. | ||
func DeleteE(t *testing.T, options *Options, releaseName string, purge bool) error { | ||
args := []string{} | ||
if purge { | ||
args = append(args, "--purge") | ||
} | ||
args = append(args, releaseName) | ||
_, err := RunHelmCommandAndGetOutputE(t, options, "delete", args...) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this run in parallel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. See https://circleci.com/workflow-run/3daf8d7f-f7fe-4daa-a1a7-0679026b0a7e