Skip to content
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

Add support for Helm 3 #184

Merged
merged 1 commit into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ jobs:
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

curl https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash
helm_version=v3.0.0
curl -sSLO "https://get.helm.sh/helm-$helm_version-linux-amd64.tar.gz"
sudo mkdir -p "/usr/local/helm-$helm_version"
sudo tar -xzf "helm-$helm_version-linux-amd64.tar.gz" -C "/usr/local/helm-$helm_version"
sudo ln -s "/usr/local/helm-$helm_version/linux-amd64/helm" /usr/local/bin/helm

curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/v0.5.1/kind-linux-amd64"
chmod +x kind
sudo mv kind /usr/local/bin/kind
- run:
name: Test
command: |
go mod download
./e2e-kind.sh
build:
docker:
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ ARG YAMALE_VERSION=1.8.0
RUN pip install "yamale==$YAMALE_VERSION"

# Install kubectl
ARG KUBECTL_VERSION=v1.16.0
ARG KUBECTL_VERSION=v1.16.2
RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl" && \
chmod +x kubectl && \
mv kubectl /usr/local/bin/

# Install Helm
ARG HELM_VERSION=v2.15.2
RUN curl -LO "https://kubernetes-helm.storage.googleapis.com/helm-$HELM_VERSION-linux-amd64.tar.gz" && \
ARG HELM_VERSION=v3.0.0
RUN curl -LO "https://get.helm.sh/helm-$HELM_VERSION-linux-amd64.tar.gz" && \
mkdir -p "/usr/local/helm-$HELM_VERSION" && \
tar -xzf "helm-$HELM_VERSION-linux-amd64.tar.gz" -C "/usr/local/helm-$HELM_VERSION" && \
ln -s "/usr/local/helm-$HELM_VERSION/linux-amd64/helm" /usr/local/bin/helm && \
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ set -o errexit
set -o nounset
set -o pipefail

readonly SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
SCRIPT_DIR=$(dirname -- "$(readlink -e "${BASH_SOURCE[0]}" || realpath "${BASH_SOURCE[0]}")")
readonly SCRIPT_DIR

show_help() {
cat << EOF
Expand Down Expand Up @@ -71,7 +72,6 @@ main() {

pushd "$SCRIPT_DIR" > /dev/null

go mod download
go test ./...
goreleaser "${goreleaser_args[@]}"

Expand Down
10 changes: 4 additions & 6 deletions ct/cmd/docGen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package cmd

import (
"fmt"
"os"

"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
Expand All @@ -31,18 +29,18 @@ func newGenerateDocsCmd() *cobra.Command {
Generate documentation for all commands
to the 'docs' directory.`),
Hidden: true,
Run: generateDocs,
RunE: generateDocs,
}
}

func generateDocs(cmd *cobra.Command, args []string) {
func generateDocs(cmd *cobra.Command, args []string) error {
fmt.Println("Generating docs...")

err := doc.GenMarkdownTree(NewRootCmd(), "doc")
if err != nil {
fmt.Println(err)
os.Exit(1)
return err
}

fmt.Println("Done.")
return nil
}
24 changes: 10 additions & 14 deletions ct/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package cmd

import (
"fmt"
"os"

"github.com/MakeNowJust/heredoc"
"github.com/helm/chart-testing/v3/pkg/chart"
"github.com/helm/chart-testing/v3/pkg/config"
Expand Down Expand Up @@ -48,7 +46,7 @@ func newInstallCmd() *cobra.Command {
directory. The chart is installed and tested for each of these files.
If no custom values file is present, the chart is installed and
tested with defaults.`),
Run: install,
RunE: install,
}

flags := cmd.Flags()
Expand Down Expand Up @@ -80,26 +78,24 @@ func addInstallFlags(flags *flag.FlagSet) {
This is only used if namespace is specified`))
}

func install(cmd *cobra.Command, args []string) {
func install(cmd *cobra.Command, args []string) error {
fmt.Println("Installing charts...")

configuration, err := config.LoadConfiguration(cfgFile, cmd, true)
if err != nil {
fmt.Printf("Error loading configuration: %s\n", err)
os.Exit(1)
return fmt.Errorf("Error loading configuration: %s", err)
}

testing := chart.NewTesting(*configuration)
testing, err := chart.NewTesting(*configuration)
if err != nil {
fmt.Println(err)
}
results, err := testing.InstallCharts()
if err != nil {
fmt.Printf("Error installing charts: %s\n", err)
} else {
fmt.Println("All charts installed successfully")
return fmt.Errorf("Error installing charts: %s", err)
}

fmt.Println("All charts installed successfully")
testing.PrintResults(results)

if err != nil {
os.Exit(1)
}
return nil
}
24 changes: 10 additions & 14 deletions ct/cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package cmd

import (
"fmt"
"os"

"github.com/MakeNowJust/heredoc"
"github.com/helm/chart-testing/v3/pkg/chart"
"github.com/helm/chart-testing/v3/pkg/config"
Expand All @@ -44,7 +42,7 @@ func newLintCmd() *cobra.Command {
'*-values.yaml' in a directory named 'ci' in the root of the chart's
directory. The chart is linted for each of these files. If no custom
values file is present, the chart is linted with defaults.`),
Run: lint,
RunE: lint,
}

flags := cmd.Flags()
Expand Down Expand Up @@ -72,26 +70,24 @@ func addLintFlags(flags *flag.FlagSet) {
Enable linting of 'Chart.yaml' and values files (default: true)`))
}

func lint(cmd *cobra.Command, args []string) {
func lint(cmd *cobra.Command, args []string) error {
fmt.Println("Linting charts...")

configuration, err := config.LoadConfiguration(cfgFile, cmd, true)
if err != nil {
fmt.Printf("Error loading configuration: %s\n", err)
os.Exit(1)
return fmt.Errorf("Error loading configuration: %s", err)
}

testing := chart.NewTesting(*configuration)
testing, err := chart.NewTesting(*configuration)
if err != nil {
return err
}
results, err := testing.LintCharts()
if err != nil {
fmt.Printf("Error linting charts: %s\n", err)
} else {
fmt.Println("All charts linted successfully")
return fmt.Errorf("Error linting charts: %s", err)
}

fmt.Println("All charts linted successfully")
testing.PrintResults(results)

if err != nil {
os.Exit(1)
}
return nil
}
24 changes: 10 additions & 14 deletions ct/cmd/lintAndInstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package cmd

import (
"fmt"
"os"

"github.com/helm/chart-testing/v3/pkg/chart"
"github.com/helm/chart-testing/v3/pkg/config"

Expand All @@ -30,7 +28,7 @@ func newLintAndInstallCmd() *cobra.Command {
Aliases: []string{"li"},
Short: "Lint, install, and test a chart",
Long: "Combines 'lint' and 'install' commands.",
Run: lintAndInstall,
RunE: lintAndInstall,
}

flags := cmd.Flags()
Expand All @@ -40,26 +38,24 @@ func newLintAndInstallCmd() *cobra.Command {
return cmd
}

func lintAndInstall(cmd *cobra.Command, args []string) {
func lintAndInstall(cmd *cobra.Command, args []string) error {
fmt.Println("Linting and installing charts...")

configuration, err := config.LoadConfiguration(cfgFile, cmd, true)
if err != nil {
fmt.Printf("Error loading configuration: %s\n", err)
os.Exit(1)
return fmt.Errorf("Error loading configuration: %s", err)
}

testing := chart.NewTesting(*configuration)
testing, err := chart.NewTesting(*configuration)
if err != nil {
return err
}
results, err := testing.LintAndInstallCharts()
if err != nil {
fmt.Printf("Error linting and installing charts: %s\n", err)
} else {
fmt.Println("All charts linted and installed successfully")
return fmt.Errorf("Error linting and installing charts: %s", err)
}

fmt.Println("All charts linted and installed successfully")
testing.PrintResults(results)

if err != nil {
os.Exit(1)
}
return nil
}
17 changes: 9 additions & 8 deletions ct/cmd/listChanged.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package cmd

import (
"fmt"
"os"

"github.com/MakeNowJust/heredoc"

"github.com/helm/chart-testing/v3/pkg/chart"
Expand All @@ -33,28 +31,31 @@ func newListChangedCmd() *cobra.Command {
Long: heredoc.Doc(`
"List changed charts based on configured charts directories,
"remote, and target branch`),
Run: listChanged,
RunE: listChanged,
}

flags := cmd.Flags()
addCommonFlags(flags)
return cmd
}

func listChanged(cmd *cobra.Command, args []string) {
func listChanged(cmd *cobra.Command, args []string) error {
configuration, err := config.LoadConfiguration(cfgFile, cmd, false)
if err != nil {
fmt.Printf("Error loading configuration: %s\n", err)
os.Exit(1)
return fmt.Errorf("Error loading configuration: %s", err)
}

testing := chart.NewTesting(*configuration)
testing, err := chart.NewTesting(*configuration)
if err != nil {
return err
}
chartDirs, err := testing.ComputeChangedChartDirectories()
if err != nil {
os.Exit(1)
return err
}

for _, dir := range chartDirs {
fmt.Println(dir)
}
return nil
}
16 changes: 5 additions & 11 deletions e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ set -o errexit
set -o nounset
set -o pipefail

readonly CLUSTER_NAME=chart-testing
readonly K8S_VERSION=v1.15.3
CLUSTER_NAME=chart-testing
readonly CLUSTER_NAME

K8S_VERSION=v1.15.3
readonly K8S_VERSION

create_kind_cluster() {
kind create cluster --name "$CLUSTER_NAME" --image "kindest/node:$K8S_VERSION" --wait 60s
Expand All @@ -22,14 +25,6 @@ create_kind_cluster() {
echo
}

install_tiller() {
echo 'Installing Tiller...'
kubectl --namespace kube-system --output yaml create serviceaccount tiller --dry-run | kubectl apply -f -
kubectl create --output yaml clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller --dry-run | kubectl apply -f -
helm init --service-account tiller --upgrade --wait
echo
}

install_local-path-provisioner() {
# kind doesn't support Dynamic PVC provisioning yet, this is one way to get it working
# https://github.com/rancher/local-path-provisioner
Expand Down Expand Up @@ -57,7 +52,6 @@ main() {

create_kind_cluster
install_local-path-provisioner
install_tiller
test_e2e
}

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Loading