|
|
@ -22,6 +22,7 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ghodss/yaml"
|
|
|
|
"github.com/ghodss/yaml"
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
|
|
|
|
"k8s.io/kubernetes/pkg/api/errors"
|
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
|
|
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
|
|
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
|
|
|
testcore "k8s.io/kubernetes/pkg/client/testing/core"
|
|
|
|
testcore "k8s.io/kubernetes/pkg/client/testing/core"
|
|
|
@ -64,6 +65,21 @@ func TestDeploymentManifest(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestServiceManifest(t *testing.T) {
|
|
|
|
|
|
|
|
o, err := ServiceManifest(api.NamespaceDefault)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Fatalf("error %q", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var svc api.Service
|
|
|
|
|
|
|
|
if err := yaml.Unmarshal([]byte(o), &svc); err != nil {
|
|
|
|
|
|
|
|
t.Fatalf("error %q", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if got := svc.ObjectMeta.Namespace; got != api.NamespaceDefault {
|
|
|
|
|
|
|
|
t.Errorf("expected namespace %s, got %s", api.NamespaceDefault, got)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestInstall(t *testing.T) {
|
|
|
|
func TestInstall(t *testing.T) {
|
|
|
|
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
|
|
|
|
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
|
|
|
|
|
|
|
|
|
|
|
@ -80,13 +96,25 @@ func TestInstall(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true, obj, nil
|
|
|
|
return true, obj, nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
fc.AddReactor("create", "services", func(action testcore.Action) (bool, runtime.Object, error) {
|
|
|
|
|
|
|
|
obj := action.(testcore.CreateAction).GetObject().(*api.Service)
|
|
|
|
|
|
|
|
l := obj.GetLabels()
|
|
|
|
|
|
|
|
if reflect.DeepEqual(l, map[string]string{"app": "helm"}) {
|
|
|
|
|
|
|
|
t.Errorf("expected labels = '', got '%s'", l)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
n := obj.ObjectMeta.Namespace
|
|
|
|
|
|
|
|
if n != api.NamespaceDefault {
|
|
|
|
|
|
|
|
t.Errorf("expected namespace = '%s', got '%s'", api.NamespaceDefault, n)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, obj, nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if err := Install(fc.Extensions(), api.NamespaceDefault, image, false, false); err != nil {
|
|
|
|
if err := Install(fc, api.NamespaceDefault, image, false, false); err != nil {
|
|
|
|
t.Errorf("unexpected error: %#+v", err)
|
|
|
|
t.Errorf("unexpected error: %#+v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if actions := fc.Actions(); len(actions) != 1 {
|
|
|
|
if actions := fc.Actions(); len(actions) != 2 {
|
|
|
|
t.Errorf("unexpected actions: %v, expected 1 actions got %d", actions, len(actions))
|
|
|
|
t.Errorf("unexpected actions: %v, expected 2 actions got %d", actions, len(actions))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -100,13 +128,17 @@ func TestInstall_canary(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true, obj, nil
|
|
|
|
return true, obj, nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
fc.AddReactor("create", "services", func(action testcore.Action) (bool, runtime.Object, error) {
|
|
|
|
|
|
|
|
obj := action.(testcore.CreateAction).GetObject().(*api.Service)
|
|
|
|
|
|
|
|
return true, obj, nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if err := Install(fc.Extensions(), api.NamespaceDefault, "", true, false); err != nil {
|
|
|
|
if err := Install(fc, api.NamespaceDefault, "", true, false); err != nil {
|
|
|
|
t.Errorf("unexpected error: %#+v", err)
|
|
|
|
t.Errorf("unexpected error: %#+v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if actions := fc.Actions(); len(actions) != 1 {
|
|
|
|
if actions := fc.Actions(); len(actions) != 2 {
|
|
|
|
t.Errorf("unexpected actions: %v, expected 1 actions got %d", actions, len(actions))
|
|
|
|
t.Errorf("unexpected actions: %v, expected 2 actions got %d", actions, len(actions))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -114,6 +146,7 @@ func TestUpgrade(t *testing.T) {
|
|
|
|
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
|
|
|
|
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
|
|
|
|
|
|
|
|
|
|
|
|
existingDeployment := deployment(api.NamespaceDefault, "imageToReplace", false)
|
|
|
|
existingDeployment := deployment(api.NamespaceDefault, "imageToReplace", false)
|
|
|
|
|
|
|
|
existingService := service(api.NamespaceDefault)
|
|
|
|
|
|
|
|
|
|
|
|
fc := &fake.Clientset{}
|
|
|
|
fc := &fake.Clientset{}
|
|
|
|
fc.AddReactor("get", "deployments", func(action testcore.Action) (bool, runtime.Object, error) {
|
|
|
|
fc.AddReactor("get", "deployments", func(action testcore.Action) (bool, runtime.Object, error) {
|
|
|
@ -127,12 +160,53 @@ func TestUpgrade(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true, obj, nil
|
|
|
|
return true, obj, nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
fc.AddReactor("get", "services", func(action testcore.Action) (bool, runtime.Object, error) {
|
|
|
|
|
|
|
|
return true, existingService, nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if err := Upgrade(fc.Extensions(), api.NamespaceDefault, image, false); err != nil {
|
|
|
|
if err := Upgrade(fc, api.NamespaceDefault, image, false); err != nil {
|
|
|
|
t.Errorf("unexpected error: %#+v", err)
|
|
|
|
t.Errorf("unexpected error: %#+v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if actions := fc.Actions(); len(actions) != 2 {
|
|
|
|
if actions := fc.Actions(); len(actions) != 3 {
|
|
|
|
t.Errorf("unexpected actions: %v, expected 2 actions got %d", actions, len(actions))
|
|
|
|
t.Errorf("unexpected actions: %v, expected 3 actions got %d", actions, len(actions))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestUpgrade_serviceNotFound(t *testing.T) {
|
|
|
|
|
|
|
|
image := "gcr.io/kubernetes-helm/tiller:v2.0.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
existingDeployment := deployment(api.NamespaceDefault, "imageToReplace", false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fc := &fake.Clientset{}
|
|
|
|
|
|
|
|
fc.AddReactor("get", "deployments", func(action testcore.Action) (bool, runtime.Object, error) {
|
|
|
|
|
|
|
|
return true, existingDeployment, nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
fc.AddReactor("update", "deployments", func(action testcore.Action) (bool, runtime.Object, error) {
|
|
|
|
|
|
|
|
obj := action.(testcore.UpdateAction).GetObject().(*extensions.Deployment)
|
|
|
|
|
|
|
|
i := obj.Spec.Template.Spec.Containers[0].Image
|
|
|
|
|
|
|
|
if i != image {
|
|
|
|
|
|
|
|
t.Errorf("expected image = '%s', got '%s'", image, i)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, obj, nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
fc.AddReactor("get", "services", func(action testcore.Action) (bool, runtime.Object, error) {
|
|
|
|
|
|
|
|
return true, nil, errors.NewNotFound(api.Resource("services"), "1")
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
fc.AddReactor("create", "services", func(action testcore.Action) (bool, runtime.Object, error) {
|
|
|
|
|
|
|
|
obj := action.(testcore.CreateAction).GetObject().(*api.Service)
|
|
|
|
|
|
|
|
n := obj.ObjectMeta.Namespace
|
|
|
|
|
|
|
|
if n != api.NamespaceDefault {
|
|
|
|
|
|
|
|
t.Errorf("expected namespace = '%s', got '%s'", api.NamespaceDefault, n)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, obj, nil
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := Upgrade(fc, api.NamespaceDefault, image, false); err != nil {
|
|
|
|
|
|
|
|
t.Errorf("unexpected error: %#+v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if actions := fc.Actions(); len(actions) != 4 {
|
|
|
|
|
|
|
|
t.Errorf("unexpected actions: %v, expected 4 actions got %d", actions, len(actions))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|