Remove Helm charts from this repo
This commit is contained in:
219
test/kubernetes/Gopkg.lock
generated
219
test/kubernetes/Gopkg.lock
generated
@@ -1,219 +0,0 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/PuerkitoBio/purell"
|
||||
packages = ["."]
|
||||
revision = "0bcb03f4b4d0a9428594752bd2a3b9aa0a9d4bd4"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/PuerkitoBio/urlesc"
|
||||
packages = ["."]
|
||||
revision = "de5bf2ad457846296e2031421a34e2568e304e35"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/asaskevich/govalidator"
|
||||
packages = ["."]
|
||||
revision = "73945b6115bfbbcc57d89b7316e28109364124e1"
|
||||
version = "v7"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/davecgh/go-spew"
|
||||
packages = ["spew"]
|
||||
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/docker/distribution"
|
||||
packages = ["digest","reference"]
|
||||
revision = "48294d928ced5dd9b378f7fd7c6f5da3ff3f2c89"
|
||||
version = "v2.6.2"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/emicklei/go-restful"
|
||||
packages = [".","log"]
|
||||
revision = "68c9750c36bb8cb433f1b88c807b4b30df4acc40"
|
||||
version = "v2.2.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/emicklei/go-restful-swagger12"
|
||||
packages = ["."]
|
||||
revision = "dcef7f55730566d41eae5db10e7d6981829720f6"
|
||||
version = "1.0.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/ghodss/yaml"
|
||||
packages = ["."]
|
||||
revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-openapi/analysis"
|
||||
packages = ["."]
|
||||
revision = "8ed83f2ea9f00f945516462951a288eaa68bf0d6"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-openapi/errors"
|
||||
packages = ["."]
|
||||
revision = "03cfca65330da08a5a440053faf994a3c682b5bf"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-openapi/jsonpointer"
|
||||
packages = ["."]
|
||||
revision = "779f45308c19820f1a69e9a4cd965f496e0da10f"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-openapi/jsonreference"
|
||||
packages = ["."]
|
||||
revision = "36d33bfe519efae5632669801b180bf1a245da3b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-openapi/loads"
|
||||
packages = ["."]
|
||||
revision = "a80dea3052f00e5f032e860dd7355cd0cc67e24d"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-openapi/spec"
|
||||
packages = ["."]
|
||||
revision = "3faa0055dbbf2110abc1f3b4e3adbb22721e96e7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-openapi/strfmt"
|
||||
packages = ["."]
|
||||
revision = "610b6cacdcde6852f4de68998bd20ce1dac85b22"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-openapi/swag"
|
||||
packages = ["."]
|
||||
revision = "f3f9494671f93fcff853e3c6e9e948b3eb71e590"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/gogo/protobuf"
|
||||
packages = ["proto","sortkeys"]
|
||||
revision = "100ba4e885062801d56799d78530b73b178a78f3"
|
||||
version = "v0.4"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/golang/glog"
|
||||
packages = ["."]
|
||||
revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/google/gofuzz"
|
||||
packages = ["."]
|
||||
revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/howeyc/gopass"
|
||||
packages = ["."]
|
||||
revision = "bf9dde6d0d2c004a008c27aaee91170c786f6db8"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/imdario/mergo"
|
||||
packages = ["."]
|
||||
revision = "3e95a51e0639b4cf372f2ccf74c86749d747fbdc"
|
||||
version = "0.2.2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/juju/ratelimit"
|
||||
packages = ["."]
|
||||
revision = "5b9ff866471762aa2ab2dced63c9fb6f53921342"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mailru/easyjson"
|
||||
packages = ["buffer","jlexer","jwriter"]
|
||||
revision = "2a92e673c9a6302dd05c3a691ae1f24aef46457d"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mitchellh/mapstructure"
|
||||
packages = ["."]
|
||||
revision = "d0303fe809921458f417bcf828397a65db30a7e4"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/spf13/pflag"
|
||||
packages = ["."]
|
||||
revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ugorji/go"
|
||||
packages = ["codec"]
|
||||
revision = "8c0409fcbb70099c748d71f714529204975f6c3f"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
packages = ["ssh/terminal"]
|
||||
revision = "81e90905daefcd6fd217b62423c0908922eadb30"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/net"
|
||||
packages = ["http2","http2/hpack","idna","lex/httplex"]
|
||||
revision = "66aacef3dd8a676686c7ae3716979581e8b03c47"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
packages = ["unix","windows"]
|
||||
revision = "9aade4d3a3b7e6d876cd3823ad20ec45fc035402"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/text"
|
||||
packages = ["internal/gen","internal/triegen","internal/ucd","secure/bidirule","transform","unicode/bidi","unicode/cldr","unicode/norm","unicode/rangetable","width"]
|
||||
revision = "bd91bbf73e9a4a801adbfb97133c992678533126"
|
||||
|
||||
[[projects]]
|
||||
name = "gopkg.in/inf.v0"
|
||||
packages = ["."]
|
||||
revision = "3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4"
|
||||
version = "v0.9.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
name = "gopkg.in/mgo.v2"
|
||||
packages = ["bson","internal/json"]
|
||||
revision = "3f83fa5005286a7fe593b055f0d7771a7dce4655"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
name = "gopkg.in/yaml.v2"
|
||||
packages = ["."]
|
||||
revision = "eb3733d160e74a9c7e442f435eb3bea458e1d19f"
|
||||
|
||||
[[projects]]
|
||||
branch = "release-1.7"
|
||||
name = "k8s.io/apimachinery"
|
||||
packages = ["pkg/api/equality","pkg/api/errors","pkg/api/meta","pkg/api/resource","pkg/apimachinery","pkg/apimachinery/announced","pkg/apimachinery/registered","pkg/apis/meta/v1","pkg/apis/meta/v1/unstructured","pkg/apis/meta/v1alpha1","pkg/conversion","pkg/conversion/queryparams","pkg/conversion/unstructured","pkg/fields","pkg/labels","pkg/openapi","pkg/runtime","pkg/runtime/schema","pkg/runtime/serializer","pkg/runtime/serializer/json","pkg/runtime/serializer/protobuf","pkg/runtime/serializer/recognizer","pkg/runtime/serializer/streaming","pkg/runtime/serializer/versioning","pkg/selection","pkg/types","pkg/util/clock","pkg/util/diff","pkg/util/errors","pkg/util/framer","pkg/util/intstr","pkg/util/json","pkg/util/net","pkg/util/rand","pkg/util/runtime","pkg/util/sets","pkg/util/validation","pkg/util/validation/field","pkg/util/wait","pkg/util/yaml","pkg/version","pkg/watch","third_party/forked/golang/reflect"]
|
||||
revision = "8ab5f3d8a330c2e9baaf84e39042db8d49034ae2"
|
||||
|
||||
[[projects]]
|
||||
name = "k8s.io/client-go"
|
||||
packages = ["discovery","kubernetes","kubernetes/scheme","kubernetes/typed/admissionregistration/v1alpha1","kubernetes/typed/apps/v1beta1","kubernetes/typed/authentication/v1","kubernetes/typed/authentication/v1beta1","kubernetes/typed/authorization/v1","kubernetes/typed/authorization/v1beta1","kubernetes/typed/autoscaling/v1","kubernetes/typed/autoscaling/v2alpha1","kubernetes/typed/batch/v1","kubernetes/typed/batch/v2alpha1","kubernetes/typed/certificates/v1beta1","kubernetes/typed/core/v1","kubernetes/typed/extensions/v1beta1","kubernetes/typed/networking/v1","kubernetes/typed/policy/v1beta1","kubernetes/typed/rbac/v1alpha1","kubernetes/typed/rbac/v1beta1","kubernetes/typed/settings/v1alpha1","kubernetes/typed/storage/v1","kubernetes/typed/storage/v1beta1","pkg/api","pkg/api/v1","pkg/api/v1/ref","pkg/apis/admissionregistration","pkg/apis/admissionregistration/v1alpha1","pkg/apis/apps","pkg/apis/apps/v1beta1","pkg/apis/authentication","pkg/apis/authentication/v1","pkg/apis/authentication/v1beta1","pkg/apis/authorization","pkg/apis/authorization/v1","pkg/apis/authorization/v1beta1","pkg/apis/autoscaling","pkg/apis/autoscaling/v1","pkg/apis/autoscaling/v2alpha1","pkg/apis/batch","pkg/apis/batch/v1","pkg/apis/batch/v2alpha1","pkg/apis/certificates","pkg/apis/certificates/v1beta1","pkg/apis/extensions","pkg/apis/extensions/v1beta1","pkg/apis/networking","pkg/apis/networking/v1","pkg/apis/policy","pkg/apis/policy/v1beta1","pkg/apis/rbac","pkg/apis/rbac/v1alpha1","pkg/apis/rbac/v1beta1","pkg/apis/settings","pkg/apis/settings/v1alpha1","pkg/apis/storage","pkg/apis/storage/v1","pkg/apis/storage/v1beta1","pkg/util","pkg/util/parsers","pkg/version","rest","rest/watch","tools/auth","tools/clientcmd","tools/clientcmd/api","tools/clientcmd/api/latest","tools/clientcmd/api/v1","tools/metrics","transport","util/cert","util/flowcontrol","util/homedir","util/integer"]
|
||||
revision = "d92e8497f71b7b4e0494e5bd204b48d34bd6f254"
|
||||
version = "v4.0.0"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "caae962961e20347a5f6f9001a55d7baa94307f6bf6aecc001165a28a51e3919"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
@@ -1,33 +0,0 @@
|
||||
# © Copyright IBM Corporation 2017, 2018
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
|
||||
# The version of client-go corresponds to a specific Kubernetes version
|
||||
# (e.g. client-go 4.0.0 is for kubernetes 1.7)
|
||||
# If you change this version, you also need to update the corresponding
|
||||
# branch for k8s.io/apimachinery (below)
|
||||
[[constraint]]
|
||||
name = "k8s.io/client-go"
|
||||
version = "4.0.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "k8s.io/apimachinery"
|
||||
branch = "release-1.7"
|
||||
|
||||
[prune]
|
||||
unused-packages = true
|
||||
go-tests = true
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
© Copyright IBM Corporation 2017
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
var namespace = "default"
|
||||
|
||||
// Prior to running this test, a Persistent Volume must be created
|
||||
func TestHelmPredefinedVolume(t *testing.T) {
|
||||
cs := kubeLogin(t)
|
||||
release := strings.ToLower(t.Name())
|
||||
if !volumesAvailable(t, cs) {
|
||||
t.Skipf("Skipping test because no persistent volumes were found")
|
||||
}
|
||||
helmInstall(t, cs, release, "license=accept", "persistence.useDynamicProvisioning=false")
|
||||
defer helmDelete(t, cs, release)
|
||||
defer helmDeletePVC(t, cs, release)
|
||||
waitForReady(t, cs, release)
|
||||
}
|
||||
|
||||
func TestHelmStorageClass(t *testing.T) {
|
||||
cs := kubeLogin(t)
|
||||
release := strings.ToLower(t.Name())
|
||||
assertKubeVersion(t, cs, 1, 6)
|
||||
if !storageClassesDefined(t, cs) {
|
||||
t.Skipf("Skipping test because no storage classes were found")
|
||||
}
|
||||
helmInstall(t, cs, release, "license=accept", "persistence.useDynamicProvisioning=true")
|
||||
defer helmDelete(t, cs, release)
|
||||
defer helmDeletePVC(t, cs, release)
|
||||
waitForReady(t, cs, release)
|
||||
}
|
||||
|
||||
func TestPersistenceDisabled(t *testing.T) {
|
||||
cs := kubeLogin(t)
|
||||
release := strings.ToLower(t.Name())
|
||||
helmInstall(t, cs, release, "license=accept", "persistence.enabled=false")
|
||||
defer helmDelete(t, cs, release)
|
||||
waitForReady(t, cs, release)
|
||||
|
||||
// Check that no PVCs were created
|
||||
pvcs, err := cs.CoreV1().PersistentVolumeClaims(namespace).List(metav1.ListOptions{
|
||||
LabelSelector: "release=" + release,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(pvcs.Items) > 0 {
|
||||
t.Errorf("Expected no PVC, found %v (%+v)", len(pvcs.Items), pvcs.Items)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPassThroughValues tests several values which are set when installing
|
||||
// the Helm chart, and should be passed straight through to Kubernetes
|
||||
func TestPassThroughValues(t *testing.T) {
|
||||
cs := kubeLogin(t)
|
||||
release := strings.ToLower(t.Name())
|
||||
queueManagerName := "foo"
|
||||
requestCPU := "501m"
|
||||
requestMem := "501Mi"
|
||||
limitCPU := "502m"
|
||||
limitMem := "502Mi"
|
||||
helmInstall(t, cs, release,
|
||||
"license=accept",
|
||||
"persistence.enabled=false",
|
||||
"resources.requests.cpu="+requestCPU,
|
||||
"resources.requests.memory="+requestMem,
|
||||
"resources.limits.cpu="+limitCPU,
|
||||
"resources.limits.memory="+limitMem,
|
||||
"queueManager.name="+queueManagerName,
|
||||
)
|
||||
defer helmDelete(t, cs, release)
|
||||
waitForReady(t, cs, release)
|
||||
pods := getPodsForHelmRelease(t, cs, release)
|
||||
pod := pods.Items[0]
|
||||
|
||||
t.Run("resources.requests.cpu", func(t *testing.T) {
|
||||
cpu := pod.Spec.Containers[0].Resources.Requests.Cpu()
|
||||
if cpu.String() != requestCPU {
|
||||
t.Errorf("Expected requested CPU to be %v, got %v", requestCPU, cpu.String())
|
||||
}
|
||||
})
|
||||
t.Run("resources.requests.memory", func(t *testing.T) {
|
||||
mem := pod.Spec.Containers[0].Resources.Requests.Memory()
|
||||
if mem.String() != requestMem {
|
||||
t.Errorf("Expected requested memory to be %v, got %v", requestMem, mem.String())
|
||||
}
|
||||
})
|
||||
t.Run("resources.limits.cpu", func(t *testing.T) {
|
||||
cpu := pod.Spec.Containers[0].Resources.Limits.Cpu()
|
||||
if cpu.String() != limitCPU {
|
||||
t.Errorf("Expected CPU limits to be %v, got %v", limitCPU, cpu.String())
|
||||
}
|
||||
})
|
||||
t.Run("resources.limits.memory", func(t *testing.T) {
|
||||
mem := pod.Spec.Containers[0].Resources.Limits.Memory()
|
||||
if mem.String() != limitMem {
|
||||
t.Errorf("Expected memory to be %v, got %v", limitMem, mem.String())
|
||||
}
|
||||
})
|
||||
t.Run("queueManager.name", func(t *testing.T) {
|
||||
out, _, err := kubeExec(t, pod.Name, "dspmq", "-n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Example output of `dspmq -n`:
|
||||
// QMNAME(qm1) STATUS(RUNNING)
|
||||
n := strings.Fields(out)[0]
|
||||
n = strings.Split(n, "(")[1]
|
||||
n = strings.Trim(n, "() ")
|
||||
t.Logf("Queue manager name detected: %v", n)
|
||||
if n != queueManagerName {
|
||||
t.Errorf("Expected queue manager name to be %v, got %v", queueManagerName, n)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,270 +0,0 @@
|
||||
/*
|
||||
© Copyright IBM Corporation 2017
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/ibm-messaging/mq-container/internal/command"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
func image(t *testing.T) string {
|
||||
v, ok := os.LookupEnv("TEST_IMAGE")
|
||||
if !ok {
|
||||
t.Fatal("TEST_IMAGE environment variable not set")
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func imageName(t *testing.T) string {
|
||||
return strings.Fields(strings.Replace(image(t), ":", " ", -1))[0]
|
||||
}
|
||||
|
||||
func imageTag(t *testing.T) string {
|
||||
return strings.Fields(strings.Replace(image(t), ":", " ", -1))[1]
|
||||
}
|
||||
|
||||
func chartName() string {
|
||||
v, ok := os.LookupEnv("TEST_CHART")
|
||||
if !ok {
|
||||
v = "../../charts/ibm-mqadvanced-server-dev"
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func inspectLogs(t *testing.T, cs *kubernetes.Clientset, release string) string {
|
||||
pods := getPodsForHelmRelease(t, cs, release)
|
||||
opt := v1.PodLogOptions{}
|
||||
r := cs.CoreV1().Pods(namespace).GetLogs(pods.Items[0].Name, &opt)
|
||||
buf := new(bytes.Buffer)
|
||||
rc, err := r.Stream()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buf.ReadFrom(rc)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func helmInstall(t *testing.T, cs *kubernetes.Clientset, release string, values ...string) {
|
||||
chart := chartName()
|
||||
tag := imageTag(t)
|
||||
arg := []string{
|
||||
"install",
|
||||
"--debug",
|
||||
chart,
|
||||
"--name",
|
||||
release,
|
||||
"--set",
|
||||
"image.repository=" + imageName(t),
|
||||
"--set",
|
||||
"image.tag=" + tag,
|
||||
"--set",
|
||||
"image.pullSecret=admin.registrykey",
|
||||
}
|
||||
// Add any extra values to the Helm command
|
||||
for _, value := range values {
|
||||
arg = append(arg, "--set", value)
|
||||
}
|
||||
out, _, err := command.Run("helm", arg...)
|
||||
t.Log(out)
|
||||
if err != nil {
|
||||
t.Error(out)
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func helmDelete(t *testing.T, cs *kubernetes.Clientset, release string) {
|
||||
t.Log("Deleting Helm release")
|
||||
t.Log(inspectLogs(t, cs, release))
|
||||
out, _, err := command.Run("helm", "delete", "--purge", release)
|
||||
if err != nil {
|
||||
t.Error(out)
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func helmDeletePVC(t *testing.T, cs *kubernetes.Clientset, release string) {
|
||||
pvcs, err := cs.CoreV1().PersistentVolumeClaims(namespace).List(metav1.ListOptions{
|
||||
LabelSelector: "release=" + release,
|
||||
})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
for _, pvc := range pvcs.Items {
|
||||
t.Logf("Deleting persistent volume claim: %v", pvc.Name)
|
||||
err := cs.CoreV1().PersistentVolumeClaims(namespace).Delete(pvc.Name, &metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func kubeLogin(t *testing.T) *kubernetes.Clientset {
|
||||
kc := os.Getenv("KUBECONFIG")
|
||||
if kc == "" {
|
||||
kc = os.Getenv("HOME") + "/.kube/config"
|
||||
}
|
||||
c, err := clientcmd.BuildConfigFromFlags("", kc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cs, err := kubernetes.NewForConfig(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return cs
|
||||
}
|
||||
|
||||
func kubeExec(t *testing.T, podName string, name string, arg ...string) (string, int, error) {
|
||||
// Current version of Kubernetes Go client doesn't support "exec", so run this via the command line
|
||||
param := []string{"exec", podName, "--", name}
|
||||
param = append(param, arg...)
|
||||
return command.Run("kubectl", param...)
|
||||
}
|
||||
|
||||
func waitForReady(t *testing.T, cs *kubernetes.Clientset, release string) {
|
||||
pods := getPodsForHelmRelease(t, cs, release)
|
||||
if len(pods.Items) != 1 {
|
||||
t.Fatalf("Expected 1 pod, found %v", len(pods.Items))
|
||||
}
|
||||
pod := pods.Items[0]
|
||||
podName := pod.Name
|
||||
// Wait for the queue manager container to be started
|
||||
running := false
|
||||
for !running {
|
||||
pod, err := cs.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(pod.Status.ContainerStatuses) > 0 {
|
||||
state := pod.Status.ContainerStatuses[0].State
|
||||
switch {
|
||||
case state.Waiting != nil:
|
||||
t.Logf("Waiting for container")
|
||||
time.Sleep(1 * time.Second)
|
||||
case state.Running != nil:
|
||||
running = true
|
||||
}
|
||||
}
|
||||
}
|
||||
// Exec into the container to check if it's ready
|
||||
for {
|
||||
// Current version of Kubernetes Go client doesn't support "exec", so run this via the command line
|
||||
// TODO: If we run "chkmqready" here, it doesn't seem to work
|
||||
//out, _, err := command.Run(t, "kubectl", "exec", podName, "--", "dspmq")
|
||||
out, _, err := kubeExec(t, podName, "dspmq")
|
||||
//out, rc, err := command.Run(t, "kubectl", "exec", podName, "--", "chkmqready")
|
||||
if err != nil {
|
||||
t.Error(out)
|
||||
out2, _, err2 := command.Run("kubectl", "describe", "pod", podName)
|
||||
if err2 == nil {
|
||||
t.Log(out2)
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(out, "Running") {
|
||||
t.Log("MQ is ready")
|
||||
return
|
||||
}
|
||||
// if rc == 0 {
|
||||
// return
|
||||
// }
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func getPodsForHelmRelease(t *testing.T, cs *kubernetes.Clientset, release string) *v1.PodList {
|
||||
pods, err := cs.CoreV1().Pods(namespace).List(metav1.ListOptions{
|
||||
LabelSelector: "release=" + release,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return pods
|
||||
}
|
||||
|
||||
func storageClassesDefined(t *testing.T, cs *kubernetes.Clientset) bool {
|
||||
c, err := cs.Storage().StorageClasses().List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(c.Items) > 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// volumesAvailable checks to see if any persistent volumes are available.
|
||||
// On some Kubernetes clusters, only storage classes are used, so there won't
|
||||
// be any volumes pre-created.
|
||||
func volumesAvailable(t *testing.T, cs *kubernetes.Clientset) bool {
|
||||
pvs, err := cs.CoreV1().PersistentVolumes().List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, pv := range pvs.Items {
|
||||
if pv.Status.Phase == v1.VolumeAvailable {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// digitsOnly returns only the digits from the supplied string
|
||||
func digitsOnly(s string) string {
|
||||
return strings.Map(
|
||||
func(r rune) rune {
|
||||
if unicode.IsDigit(r) {
|
||||
return r
|
||||
}
|
||||
return -1
|
||||
},
|
||||
s,
|
||||
)
|
||||
}
|
||||
|
||||
// assertKubeVersion is used to assert that a test requires a specific version of Kubernetes
|
||||
func assertKubeVersion(t *testing.T, cs *kubernetes.Clientset, major int, minor int) {
|
||||
v, err := cs.Discovery().ServerVersion()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Make sure we use only the digits from the version, to account for things like "1.8+"
|
||||
maj, err := strconv.Atoi(digitsOnly(v.Major))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Make sure we use only the digits from the version, to account for things like "1.8+"
|
||||
min, err := strconv.Atoi(digitsOnly(v.Minor))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if maj <= major && min < minor {
|
||||
t.Skipf("Skipping test because it's not suitable for Kubernetes %v.%v", v.Major, v.Minor)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: On Minikube, need to make sure Helm is initialized first
|
||||
Reference in New Issue
Block a user