Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into update-lpp
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanato committed Jun 17, 2019
2 parents 987a935 + f53c402 commit 0636a9d
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
./e2e-kind.sh
build:
docker:
- image: golang:1.11.5-alpine3.9
- image: golang:1.12.4-alpine3.9
working_directory: /go/src/github.com/helm/chart-testing
steps:
- setup_remote_docker
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ARG YAMALE_VERSION=1.8.0
RUN pip install "yamale==$YAMALE_VERSION"

# Install kubectl
ARG KUBECTL_VERSION=v1.13.2
ARG KUBECTL_VERSION=v1.14.1
RUN curl -LO "https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl" && \
chmod +x kubectl && \
mv kubectl /usr/local/bin/
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ available tags [here](https://quay.io/repository/helmpack/chart-testing?tab=tags

### From Source

To install from head with [Go](https://golang.org) v1.10.1 or higher:
To install from head with [Go](https://golang.org) 1.12.4 or higher:

```cli
go get github.com/helm/chart-testing/ct
Expand Down Expand Up @@ -132,7 +132,7 @@ helm-repo-extra-args:

## Building from Source

`ct` is built using Go 1.11. Older versions may work but have not been tested.
`ct` is built using Go 1.12.4. Older versions may work but have not been tested.

`build.sh` is used to build and release the tool. It uses [Goreleaser](https://goreleaser.com/) under the covers.

Expand Down Expand Up @@ -199,7 +199,7 @@ Run the script specifying the version for the new release.
./tag.sh --tag <release_version>
```

Versions must start with a lower-case `v`, e. g. `v2.2.0`.
Versions must start with a lower-case `v`, e. g. `v2.3.3`.


## Supported versions
Expand Down
2 changes: 1 addition & 1 deletion examples/docker-for-mac/my_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set -o errexit
set -o nounset
set -o pipefail

readonly IMAGE_TAG=v2.2.0
readonly IMAGE_TAG=v2.3.3
readonly IMAGE_REPOSITORY="quay.io/helmpack/chart-testing"

main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/gke/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM quay.io/helmpack/chart-testing:v2.2.0
FROM quay.io/helmpack/chart-testing:v2.3.3

ENV PATH /google-cloud-sdk/bin:$PATH
ARG CLOUD_SDK_VERSION=221.0.0
Expand Down
2 changes: 1 addition & 1 deletion examples/kind/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

lint-charts:
docker:
- image: quay.io/helmpack/chart-testing:v2.2.0
- image: quay.io/helmpack/chart-testing:v2.3.3
steps:
- checkout
- run:
Expand Down
2 changes: 1 addition & 1 deletion examples/kind/test/e2e-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -o errexit
set -o nounset
set -o pipefail

readonly CT_VERSION=v2.2.0
readonly CT_VERSION=v2.3.3
readonly KIND_VERSION=0.2.1
readonly CLUSTER_NAME=chart-testing
readonly K8S_VERSION=v1.14.1
Expand Down
27 changes: 17 additions & 10 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ type Helm interface {
//
// GetPods gets pods for the given args
//
// GetEvents prints all events for namespace
//
// DescribePod prints the pod's description
//
// Logs prints the logs of container
Expand All @@ -111,6 +113,7 @@ type Kubectl interface {
WaitForDeployments(namespace string, selector string) error
GetPodsforDeployment(namespace string, deployment string) ([]string, error)
GetPods(args ...string) ([]string, error)
GetEvents(namespace string) error
DescribePod(namespace string, pod string) error
Logs(namespace string, pod string, container string) error
GetInitContainers(namespace string, pod string) ([]string, error)
Expand Down Expand Up @@ -269,7 +272,7 @@ func (t *Testing) processCharts(action func(chart *Chart) TestResult) ([]TestRes
return results, nil
}

charts := []*Chart{}
var charts []*Chart
for _, dir := range chartDirs {
chart, err := NewChart(dir)
if err != nil {
Expand Down Expand Up @@ -608,13 +611,13 @@ func (t *Testing) generateInstallConfig(chart *Chart) (namespace, release, relea
release, _ = chart.CreateInstallParams(t.config.BuildId)
releaseSelector = fmt.Sprintf("%s=%s", t.config.ReleaseLabel, release)
cleanup = func() {
t.PrintPodDetailsAndLogs(namespace, releaseSelector)
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
t.helm.DeleteRelease(release)
}
} else {
release, namespace = chart.CreateInstallParams(t.config.BuildId)
cleanup = func() {
t.PrintPodDetailsAndLogs(namespace, releaseSelector)
t.PrintEventsPodDetailsAndLogs(namespace, releaseSelector)
t.helm.DeleteRelease(release)
t.kubectl.DeleteNamespace(namespace)
}
Expand Down Expand Up @@ -647,7 +650,7 @@ func (t *Testing) FindChartDirsToBeProcessed() ([]string, error) {
func (t *Testing) computeMergeBase() (string, error) {
err := t.git.ValidateRepository()
if err != nil {
return "", fmt.Errorf("Must be in a git repository")
return "", errors.New("Must be in a git repository")
}
return t.git.MergeBase(fmt.Sprintf("%s/%s", t.config.Remote, t.config.TargetBranch), "HEAD")
}
Expand Down Expand Up @@ -812,7 +815,13 @@ func (t *Testing) ValidateMaintainers(chart *Chart) error {
return nil
}

func (t *Testing) PrintPodDetailsAndLogs(namespace string, selector string) {
func (t *Testing) PrintEventsPodDetailsAndLogs(namespace string, selector string) {
util.PrintDelimiterLine("=")

printDetails(namespace, "Events of namespace", ".", func(item string) error {
return t.kubectl.GetEvents(namespace)
}, namespace)

pods, err := t.kubectl.GetPods(
"--no-headers",
"--namespace",
Expand All @@ -827,8 +836,6 @@ func (t *Testing) PrintPodDetailsAndLogs(namespace string, selector string) {
return
}

util.PrintDelimiterLine("=")

for _, pod := range pods {
printDetails(pod, "Description of pod", "~", func(item string) error {
return t.kubectl.DescribePod(namespace, pod)
Expand Down Expand Up @@ -861,12 +868,12 @@ func (t *Testing) PrintPodDetailsAndLogs(namespace string, selector string) {
util.PrintDelimiterLine("=")
}

func printDetails(pod string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
func printDetails(resource string, text string, delimiterChar string, printFunc func(item string) error, items ...string) {
for _, item := range items {
item = strings.Trim(item, "'")

util.PrintDelimiterLine(delimiterChar)
fmt.Printf("==> %s %s\n", text, pod)
fmt.Printf("==> %s %s\n", text, resource)
util.PrintDelimiterLine(delimiterChar)

if err := printFunc(item); err != nil {
Expand All @@ -875,7 +882,7 @@ func printDetails(pod string, text string, delimiterChar string, printFunc func(
}

util.PrintDelimiterLine(delimiterChar)
fmt.Printf("<== %s %s\n", text, pod)
fmt.Printf("<== %s %s\n", text, resource)
util.PrintDelimiterLine(delimiterChar)
}
}
3 changes: 2 additions & 1 deletion pkg/tool/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ func (g Git) GetUrlForRemote(remote string) (string, error) {
}

func (g Git) ValidateRepository() error {
return g.exec.RunProcess("git", "rev-parse", "--is-inside-work-tree")
_, err := g.exec.RunProcessAndCaptureOutput("git", "rev-parse", "--is-inside-work-tree")
return err
}
54 changes: 26 additions & 28 deletions pkg/tool/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,26 @@ func NewKubectl(exec exec.ProcessExecutor) Kubectl {
// namespace and, eventually, the namespace itself are force-deleted.
func (k Kubectl) DeleteNamespace(namespace string) {
fmt.Printf("Deleting namespace '%s'...\n", namespace)
timeoutSec := "120s"
timeoutSec := "180s"
if err := k.exec.RunProcess("kubectl", "delete", "namespace", namespace, "--timeout", timeoutSec); err != nil {
fmt.Printf("Namespace '%s' did not terminate after %s.\n", namespace, timeoutSec)
}

if _, err := k.exec.RunProcessAndCaptureOutput("kubectl", "get", "namespace", namespace); err != nil {
fmt.Printf("Namespace '%s' terminated.\n", namespace)
return
}

fmt.Printf("Namespace '%s' did not terminate after %s.\n", namespace, timeoutSec)

fmt.Println("Force-deleting pods...")
if err := k.exec.RunProcess("kubectl", "delete", "pods", "--namespace", namespace, "--all", "--force", "--grace-period=0"); err != nil {
fmt.Println("Error deleting pods:", err)
}
if k.getNamespace(namespace) {
fmt.Printf("Namespace '%s' did not terminate after %s.\n", namespace, timeoutSec)

fmt.Println("Force-deleting pvcs...")
if err := k.exec.RunProcess("kubectl", "delete", "pvc", "--namespace", namespace, "--all", "--force", "--grace-period=0"); err != nil {
fmt.Println("Error deleting pvc(s):", err)
}
fmt.Println("Force-deleting everything...")
if err := k.exec.RunProcess("kubectl", "delete", "all", "--namespace", namespace, "--all", "--force", "--grace-period=0"); err != nil {
fmt.Printf("Error deleting everything in the namespace %v: %v", namespace, err)
}

fmt.Println("Force-deleting pvs...")
if err := k.exec.RunProcess("kubectl", "delete", "pv", "--namespace", namespace, "--all", "--force", "--grace-period=0"); err != nil {
fmt.Println("Error deleting pv(s):", err)
}
// Give it some more time to be deleted by K8s
time.Sleep(5 * time.Second)

// Give it some more time to be deleted by K8s
time.Sleep(5 * time.Second)

if _, err := k.exec.RunProcessAndCaptureOutput("kubectl", "get", "namespace", namespace); err != nil {
fmt.Printf("Namespace '%s' terminated.\n", namespace)
} else {
if err := k.forceNamespaceDeletion(namespace); err != nil {
fmt.Println("Error force deleting namespace:", err)
if k.getNamespace(namespace) {
if err := k.forceNamespaceDeletion(namespace); err != nil {
fmt.Println("Error force deleting namespace:", err)
}
}
}
}
Expand Down Expand Up @@ -199,6 +184,10 @@ func (k Kubectl) GetPods(args ...string) ([]string, error) {
return strings.Fields(pods), nil
}

func (k Kubectl) GetEvents(namespace string) error {
return k.exec.RunProcess("kubectl", "get", "events", "--output", "wide", "--namespace", namespace)
}

func (k Kubectl) DescribePod(namespace string, pod string) error {
return k.exec.RunProcess("kubectl", "describe", "pod", pod, "--namespace", namespace)
}
Expand All @@ -214,3 +203,12 @@ func (k Kubectl) GetInitContainers(namespace string, pod string) ([]string, erro
func (k Kubectl) GetContainers(namespace string, pod string) ([]string, error) {
return k.GetPods(pod, "--no-headers", "--namespace", namespace, "--output", "jsonpath={.spec.containers[*].name}")
}

func (k Kubectl) getNamespace(namespace string) bool {
if _, err := k.exec.RunProcessAndCaptureOutput("kubectl", "get", "namespace", namespace); err != nil {
fmt.Printf("Namespace '%s' terminated.\n", namespace)
return false
}

return true
}
8 changes: 4 additions & 4 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ func PrintDelimiterLine(delimiterChar string) {

func SanitizeName(s string, maxLength int) string {
reg := regexp.MustCompile("^[^a-zA-Z0-9]+")
processed := reg.ReplaceAllString(s, "")

excess := len(processed) - maxLength
excess := len(s) - maxLength
result := s
if excess > 0 {
return processed[excess:]
result = s[excess:]
}
return processed
return reg.ReplaceAllString(result, "")
}

func GetRandomPort() (int, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestSanitizeName(t *testing.T) {
{"way-longer-than-max-length", 10, "max-length"},
{"one-shorter-than-max-length", len("one-shorter-than-max-length") + 1, "one-shorter-than-max-length"},
{"oone-longer-than-max-length", len("oone-longer-than-max-length") - 1, "one-longer-than-max-length"},
{"-starts-with-invalid-char", 63, "starts-with-invalid-char"},
{"foo-would-start-with-hyphen-after-trimming", len("foo-would-start-with-hyphen-after-trimming") - 3, "would-start-with-hyphen-after-trimming"},
}

for index, testData := range testDataSlice {
Expand Down
3 changes: 2 additions & 1 deletion tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ main() {

pushd "$SCRIPT_DIR" > /dev/null

git tag -a -m "Release $tag" "$tag" "${force[@]}"
git fetch "$remote"
git tag -a -m "Release $tag" "$tag" "$remote/master" "${force[@]}"

if [[ -z "$skip_push" ]]; then
git push "$remote" "refs/tags/$tag" "${force[@]}"
Expand Down

0 comments on commit 0636a9d

Please sign in to comment.