| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,108 @@ |
| 0 |
+package describe |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "strings" |
|
| 4 |
+ "testing" |
|
| 5 |
+ |
|
| 6 |
+ kapi "k8s.io/kubernetes/pkg/api" |
|
| 7 |
+ "k8s.io/kubernetes/pkg/apis/extensions" |
|
| 8 |
+ ktestclient "k8s.io/kubernetes/pkg/client/unversioned/testclient" |
|
| 9 |
+ "k8s.io/kubernetes/pkg/runtime" |
|
| 10 |
+ |
|
| 11 |
+ "github.com/openshift/origin/pkg/client/testclient" |
|
| 12 |
+ deployapi "github.com/openshift/origin/pkg/deploy/api" |
|
| 13 |
+ deployapitest "github.com/openshift/origin/pkg/deploy/api/test" |
|
| 14 |
+ deployutil "github.com/openshift/origin/pkg/deploy/util" |
|
| 15 |
+) |
|
| 16 |
+ |
|
| 17 |
+func TestDeploymentConfigDescriber(t *testing.T) {
|
|
| 18 |
+ config := deployapitest.OkDeploymentConfig(1) |
|
| 19 |
+ deployment, _ := deployutil.MakeDeployment(config, kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion)) |
|
| 20 |
+ podList := &kapi.PodList{}
|
|
| 21 |
+ |
|
| 22 |
+ fake := &testclient.Fake{}
|
|
| 23 |
+ fake.PrependReactor("get", "deploymentconfigs", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 24 |
+ return true, config, nil |
|
| 25 |
+ }) |
|
| 26 |
+ kFake := &ktestclient.Fake{}
|
|
| 27 |
+ kFake.PrependReactor("list", "horizontalpodautoscalers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 28 |
+ return true, &extensions.HorizontalPodAutoscalerList{
|
|
| 29 |
+ Items: []extensions.HorizontalPodAutoscaler{
|
|
| 30 |
+ *deployapitest.OkHPAForDeploymentConfig(config, 1, 3), |
|
| 31 |
+ }}, nil |
|
| 32 |
+ }) |
|
| 33 |
+ kFake.PrependReactor("get", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 34 |
+ return true, deployment, nil |
|
| 35 |
+ }) |
|
| 36 |
+ kFake.PrependReactor("list", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 37 |
+ return true, &kapi.ReplicationControllerList{}, nil
|
|
| 38 |
+ }) |
|
| 39 |
+ kFake.PrependReactor("list", "pods", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 40 |
+ return true, podList, nil |
|
| 41 |
+ }) |
|
| 42 |
+ kFake.PrependReactor("list", "events", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 43 |
+ return true, &kapi.EventList{}, nil
|
|
| 44 |
+ }) |
|
| 45 |
+ |
|
| 46 |
+ d := &DeploymentConfigDescriber{
|
|
| 47 |
+ osClient: fake, |
|
| 48 |
+ kubeClient: kFake, |
|
| 49 |
+ } |
|
| 50 |
+ |
|
| 51 |
+ describe := func() string {
|
|
| 52 |
+ output, err := d.Describe("test", "deployment")
|
|
| 53 |
+ if err != nil {
|
|
| 54 |
+ t.Fatalf("unexpected error: %v", err)
|
|
| 55 |
+ return "" |
|
| 56 |
+ } |
|
| 57 |
+ t.Logf("describer output:\n%s\n", output)
|
|
| 58 |
+ return output |
|
| 59 |
+ } |
|
| 60 |
+ |
|
| 61 |
+ podList.Items = []kapi.Pod{*mkPod(kapi.PodRunning, 0)}
|
|
| 62 |
+ out := describe() |
|
| 63 |
+ substr := "Autoscaling:\tbetween 1 and 3 replicas" |
|
| 64 |
+ if !strings.Contains(out, substr) {
|
|
| 65 |
+ t.Fatalf("expected %q in output:\n%s", substr, out)
|
|
| 66 |
+ } |
|
| 67 |
+ |
|
| 68 |
+ config.Spec.Triggers = append(config.Spec.Triggers, deployapitest.OkConfigChangeTrigger()) |
|
| 69 |
+ describe() |
|
| 70 |
+ |
|
| 71 |
+ config.Spec.Strategy = deployapitest.OkCustomStrategy() |
|
| 72 |
+ describe() |
|
| 73 |
+ |
|
| 74 |
+ config.Spec.Triggers[0].ImageChangeParams.From = kapi.ObjectReference{Name: "imagestream"}
|
|
| 75 |
+ describe() |
|
| 76 |
+ |
|
| 77 |
+ config.Spec.Strategy = deployapitest.OkStrategy() |
|
| 78 |
+ config.Spec.Strategy.RecreateParams = &deployapi.RecreateDeploymentStrategyParams{
|
|
| 79 |
+ Pre: &deployapi.LifecycleHook{
|
|
| 80 |
+ FailurePolicy: deployapi.LifecycleHookFailurePolicyAbort, |
|
| 81 |
+ ExecNewPod: &deployapi.ExecNewPodHook{
|
|
| 82 |
+ ContainerName: "container", |
|
| 83 |
+ Command: []string{"/command1", "args"},
|
|
| 84 |
+ Env: []kapi.EnvVar{
|
|
| 85 |
+ {
|
|
| 86 |
+ Name: "KEY1", |
|
| 87 |
+ Value: "value1", |
|
| 88 |
+ }, |
|
| 89 |
+ }, |
|
| 90 |
+ }, |
|
| 91 |
+ }, |
|
| 92 |
+ Post: &deployapi.LifecycleHook{
|
|
| 93 |
+ FailurePolicy: deployapi.LifecycleHookFailurePolicyIgnore, |
|
| 94 |
+ ExecNewPod: &deployapi.ExecNewPodHook{
|
|
| 95 |
+ ContainerName: "container", |
|
| 96 |
+ Command: []string{"/command2", "args"},
|
|
| 97 |
+ Env: []kapi.EnvVar{
|
|
| 98 |
+ {
|
|
| 99 |
+ Name: "KEY2", |
|
| 100 |
+ Value: "value2", |
|
| 101 |
+ }, |
|
| 102 |
+ }, |
|
| 103 |
+ }, |
|
| 104 |
+ }, |
|
| 105 |
+ } |
|
| 106 |
+ describe() |
|
| 107 |
+} |
| ... | ... |
@@ -10,9 +10,9 @@ import ( |
| 10 | 10 |
"text/tabwriter" |
| 11 | 11 |
"time" |
| 12 | 12 |
|
| 13 |
+ "github.com/docker/docker/pkg/parsers" |
|
| 13 | 14 |
"github.com/docker/docker/pkg/units" |
| 14 | 15 |
|
| 15 |
- "github.com/docker/docker/pkg/parsers" |
|
| 16 | 16 |
kapi "k8s.io/kubernetes/pkg/api" |
| 17 | 17 |
kerrs "k8s.io/kubernetes/pkg/api/errors" |
| 18 | 18 |
"k8s.io/kubernetes/pkg/api/meta" |
| ... | ... |
@@ -13,7 +13,6 @@ import ( |
| 13 | 13 |
"k8s.io/kubernetes/pkg/api/unversioned" |
| 14 | 14 |
ktestclient "k8s.io/kubernetes/pkg/client/unversioned/testclient" |
| 15 | 15 |
"k8s.io/kubernetes/pkg/kubectl" |
| 16 |
- "k8s.io/kubernetes/pkg/runtime" |
|
| 17 | 16 |
|
| 18 | 17 |
api "github.com/openshift/origin/pkg/api" |
| 19 | 18 |
authorizationapi "github.com/openshift/origin/pkg/authorization/api" |
| ... | ... |
@@ -21,8 +20,6 @@ import ( |
| 21 | 21 |
"github.com/openshift/origin/pkg/client" |
| 22 | 22 |
"github.com/openshift/origin/pkg/client/testclient" |
| 23 | 23 |
deployapi "github.com/openshift/origin/pkg/deploy/api" |
| 24 |
- deployapitest "github.com/openshift/origin/pkg/deploy/api/test" |
|
| 25 |
- deployutil "github.com/openshift/origin/pkg/deploy/util" |
|
| 26 | 24 |
imageapi "github.com/openshift/origin/pkg/image/api" |
| 27 | 25 |
oauthapi "github.com/openshift/origin/pkg/oauth/api" |
| 28 | 26 |
projectapi "github.com/openshift/origin/pkg/project/api" |
| ... | ... |
@@ -143,86 +140,6 @@ func TestDescribers(t *testing.T) {
|
| 143 | 143 |
} |
| 144 | 144 |
} |
| 145 | 145 |
|
| 146 |
-func TestDeploymentConfigDescriber(t *testing.T) {
|
|
| 147 |
- config := deployapitest.OkDeploymentConfig(1) |
|
| 148 |
- deployment, _ := deployutil.MakeDeployment(config, kapi.Codecs.LegacyCodec(deployapi.SchemeGroupVersion)) |
|
| 149 |
- podList := &kapi.PodList{}
|
|
| 150 |
- |
|
| 151 |
- fake := &testclient.Fake{}
|
|
| 152 |
- fake.PrependReactor("get", "deploymentconfigs", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 153 |
- return true, config, nil |
|
| 154 |
- }) |
|
| 155 |
- kFake := &ktestclient.Fake{}
|
|
| 156 |
- kFake.PrependReactor("get", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 157 |
- return true, deployment, nil |
|
| 158 |
- }) |
|
| 159 |
- kFake.PrependReactor("list", "replicationcontrollers", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 160 |
- return true, &kapi.ReplicationControllerList{}, nil
|
|
| 161 |
- }) |
|
| 162 |
- kFake.PrependReactor("list", "pods", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 163 |
- return true, podList, nil |
|
| 164 |
- }) |
|
| 165 |
- kFake.PrependReactor("list", "events", func(action ktestclient.Action) (handled bool, ret runtime.Object, err error) {
|
|
| 166 |
- return true, &kapi.EventList{}, nil
|
|
| 167 |
- }) |
|
| 168 |
- |
|
| 169 |
- d := &DeploymentConfigDescriber{
|
|
| 170 |
- osClient: fake, |
|
| 171 |
- kubeClient: kFake, |
|
| 172 |
- } |
|
| 173 |
- |
|
| 174 |
- describe := func() {
|
|
| 175 |
- if output, err := d.Describe("test", "deployment"); err != nil {
|
|
| 176 |
- t.Fatalf("unexpected error: %v", err)
|
|
| 177 |
- } else {
|
|
| 178 |
- t.Logf("describer output:\n%s\n", output)
|
|
| 179 |
- } |
|
| 180 |
- } |
|
| 181 |
- |
|
| 182 |
- podList.Items = []kapi.Pod{*mkPod(kapi.PodRunning, 0)}
|
|
| 183 |
- describe() |
|
| 184 |
- |
|
| 185 |
- config.Spec.Triggers = append(config.Spec.Triggers, deployapitest.OkConfigChangeTrigger()) |
|
| 186 |
- describe() |
|
| 187 |
- |
|
| 188 |
- config.Spec.Strategy = deployapitest.OkCustomStrategy() |
|
| 189 |
- describe() |
|
| 190 |
- |
|
| 191 |
- config.Spec.Triggers[0].ImageChangeParams.From = kapi.ObjectReference{Name: "imageRepo"}
|
|
| 192 |
- describe() |
|
| 193 |
- |
|
| 194 |
- config.Spec.Strategy = deployapitest.OkStrategy() |
|
| 195 |
- config.Spec.Strategy.RecreateParams = &deployapi.RecreateDeploymentStrategyParams{
|
|
| 196 |
- Pre: &deployapi.LifecycleHook{
|
|
| 197 |
- FailurePolicy: deployapi.LifecycleHookFailurePolicyAbort, |
|
| 198 |
- ExecNewPod: &deployapi.ExecNewPodHook{
|
|
| 199 |
- ContainerName: "container", |
|
| 200 |
- Command: []string{"/command1", "args"},
|
|
| 201 |
- Env: []kapi.EnvVar{
|
|
| 202 |
- {
|
|
| 203 |
- Name: "KEY1", |
|
| 204 |
- Value: "value1", |
|
| 205 |
- }, |
|
| 206 |
- }, |
|
| 207 |
- }, |
|
| 208 |
- }, |
|
| 209 |
- Post: &deployapi.LifecycleHook{
|
|
| 210 |
- FailurePolicy: deployapi.LifecycleHookFailurePolicyIgnore, |
|
| 211 |
- ExecNewPod: &deployapi.ExecNewPodHook{
|
|
| 212 |
- ContainerName: "container", |
|
| 213 |
- Command: []string{"/command2", "args"},
|
|
| 214 |
- Env: []kapi.EnvVar{
|
|
| 215 |
- {
|
|
| 216 |
- Name: "KEY2", |
|
| 217 |
- Value: "value2", |
|
| 218 |
- }, |
|
| 219 |
- }, |
|
| 220 |
- }, |
|
| 221 |
- }, |
|
| 222 |
- } |
|
| 223 |
- describe() |
|
| 224 |
-} |
|
| 225 |
- |
|
| 226 | 146 |
func TestDescribeBuildDuration(t *testing.T) {
|
| 227 | 147 |
type testBuild struct {
|
| 228 | 148 |
build *buildapi.Build |
| ... | ... |
@@ -3,6 +3,7 @@ package test |
| 3 | 3 |
import ( |
| 4 | 4 |
kapi "k8s.io/kubernetes/pkg/api" |
| 5 | 5 |
"k8s.io/kubernetes/pkg/api/resource" |
| 6 |
+ "k8s.io/kubernetes/pkg/apis/extensions" |
|
| 6 | 7 |
|
| 7 | 8 |
deployapi "github.com/openshift/origin/pkg/deploy/api" |
| 8 | 9 |
imageapi "github.com/openshift/origin/pkg/image/api" |
| ... | ... |
@@ -177,3 +178,17 @@ func TestDeploymentConfig(config *deployapi.DeploymentConfig) *deployapi.Deploym |
| 177 | 177 |
config.Spec.Test = true |
| 178 | 178 |
return config |
| 179 | 179 |
} |
| 180 |
+ |
|
| 181 |
+func OkHPAForDeploymentConfig(config *deployapi.DeploymentConfig, min, max int) *extensions.HorizontalPodAutoscaler {
|
|
| 182 |
+ return &extensions.HorizontalPodAutoscaler{
|
|
| 183 |
+ ObjectMeta: kapi.ObjectMeta{Name: config.Name, Namespace: config.Namespace},
|
|
| 184 |
+ Spec: extensions.HorizontalPodAutoscalerSpec{
|
|
| 185 |
+ ScaleRef: extensions.SubresourceReference{
|
|
| 186 |
+ Name: config.Name, |
|
| 187 |
+ Kind: "DeploymentConfig", |
|
| 188 |
+ }, |
|
| 189 |
+ MinReplicas: &min, |
|
| 190 |
+ MaxReplicas: max, |
|
| 191 |
+ }, |
|
| 192 |
+ } |
|
| 193 |
+} |