diff --git a/test/common/appstest/testutil.go b/test/common/appstest/testutil.go deleted file mode 100644 index 44027d080c2c..000000000000 --- a/test/common/appstest/testutil.go +++ /dev/null @@ -1,268 +0,0 @@ -package appstest - -import ( - "testing" - - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/kubernetes/pkg/api/legacyscheme" - - appsv1 "github.com/openshift/api/apps/v1" -) - -const ( - ImageStreamName = "test-image-stream" - ImageID = "0000000000000000000000000000000000000000000000000000000000000001" - DockerImageReference = "registry:5000/openshift/test-image-stream@sha256:0000000000000000000000000000000000000000000000000000000000000001" -) - -func OkDeploymentConfig(version int64) *appsv1.DeploymentConfig { - return &appsv1.DeploymentConfig{ - ObjectMeta: metav1.ObjectMeta{ - Name: "config", - Namespace: corev1.NamespaceDefault, - SelfLink: "/apis/apps.openshift.io/v1/deploymentConfig/config", - }, - Spec: OkDeploymentConfigSpec(), - Status: OkDeploymentConfigStatus(version), - } -} - -func OkDeploymentConfigSpec() appsv1.DeploymentConfigSpec { - return appsv1.DeploymentConfigSpec{ - Replicas: 1, - Selector: OkSelector(), - Strategy: OkStrategy(), - Template: OkPodTemplate(), - Triggers: []appsv1.DeploymentTriggerPolicy{ - OkImageChangeTrigger(), - OkConfigChangeTrigger(), - }, - } -} - -func OkDeploymentConfigStatus(version int64) appsv1.DeploymentConfigStatus { - return appsv1.DeploymentConfigStatus{ - LatestVersion: version, - } -} - -func OkImageChangeDetails() *appsv1.DeploymentDetails { - return &appsv1.DeploymentDetails{ - Causes: []appsv1.DeploymentCause{{ - Type: appsv1.DeploymentTriggerOnImageChange, - ImageTrigger: &appsv1.DeploymentCauseImageTrigger{ - From: corev1.ObjectReference{ - Name: ImageStreamName + ":latest", - Kind: "ImageStreamTag", - }}}}} -} - -func OkConfigChangeDetails() *appsv1.DeploymentDetails { - return &appsv1.DeploymentDetails{ - Causes: []appsv1.DeploymentCause{{ - Type: appsv1.DeploymentTriggerOnConfigChange, - }}} -} - -func OkStrategy() appsv1.DeploymentStrategy { - return appsv1.DeploymentStrategy{ - Type: appsv1.DeploymentStrategyTypeRecreate, - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceName(corev1.ResourceCPU): resource.MustParse("10"), - corev1.ResourceName(corev1.ResourceMemory): resource.MustParse("10G"), - }, - }, - RecreateParams: &appsv1.RecreateDeploymentStrategyParams{ - TimeoutSeconds: mkintp(20), - }, - ActiveDeadlineSeconds: mkintp(21600), - } -} - -func OkCustomStrategy() appsv1.DeploymentStrategy { - return appsv1.DeploymentStrategy{ - Type: appsv1.DeploymentStrategyTypeCustom, - CustomParams: OkCustomParams(), - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceName(corev1.ResourceCPU): resource.MustParse("10"), - corev1.ResourceName(corev1.ResourceMemory): resource.MustParse("10G"), - }, - }, - } -} - -func OkCustomParams() *appsv1.CustomDeploymentStrategyParams { - return &appsv1.CustomDeploymentStrategyParams{ - Image: "openshift/origin-deployer", - Environment: []corev1.EnvVar{ - { - Name: "ENV1", - Value: "VAL1", - }, - }, - Command: []string{"/bin/echo", "hello", "world"}, - } -} - -func mkintp(i int) *int64 { - v := int64(i) - return &v -} - -func OkRollingStrategy() appsv1.DeploymentStrategy { - return appsv1.DeploymentStrategy{ - Type: appsv1.DeploymentStrategyTypeRolling, - RollingParams: &appsv1.RollingDeploymentStrategyParams{ - UpdatePeriodSeconds: mkintp(1), - IntervalSeconds: mkintp(1), - TimeoutSeconds: mkintp(20), - }, - Resources: corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceName(corev1.ResourceCPU): resource.MustParse("10"), - corev1.ResourceName(corev1.ResourceMemory): resource.MustParse("10G"), - }, - }, - } -} - -func OkSelector() map[string]string { - return map[string]string{"a": "b"} -} - -func OkPodTemplate() *corev1.PodTemplateSpec { - one := int64(1) - return &corev1.PodTemplateSpec{ - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: "container1", - Image: "registry:8080/repo1:ref1", - Env: []corev1.EnvVar{ - { - Name: "ENV1", - Value: "VAL1", - }, - }, - ImagePullPolicy: corev1.PullIfNotPresent, - TerminationMessagePath: "/dev/termination-log", - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, - { - Name: "container2", - Image: "registry:8080/repo1:ref2", - ImagePullPolicy: corev1.PullIfNotPresent, - TerminationMessagePath: "/dev/termination-log", - TerminationMessagePolicy: corev1.TerminationMessageReadFile, - }, - }, - RestartPolicy: corev1.RestartPolicyAlways, - DNSPolicy: corev1.DNSClusterFirst, - TerminationGracePeriodSeconds: &one, - SchedulerName: corev1.DefaultSchedulerName, - SecurityContext: &corev1.PodSecurityContext{}, - }, - ObjectMeta: metav1.ObjectMeta{ - Labels: OkSelector(), - }, - } -} - -func OkPodTemplateChanged() *corev1.PodTemplateSpec { - template := OkPodTemplate() - template.Spec.Containers[0].Image = DockerImageReference - return template -} - -func OkPodTemplateMissingImage(missing ...string) *corev1.PodTemplateSpec { - set := sets.NewString(missing...) - template := OkPodTemplate() - for i, c := range template.Spec.Containers { - if set.Has(c.Name) { - // remember that slices use copies, so have to ref array entry explicitly - template.Spec.Containers[i].Image = "" - } - } - return template -} - -func OkConfigChangeTrigger() appsv1.DeploymentTriggerPolicy { - return appsv1.DeploymentTriggerPolicy{ - Type: appsv1.DeploymentTriggerOnConfigChange, - } -} - -func OkImageChangeTrigger() appsv1.DeploymentTriggerPolicy { - return appsv1.DeploymentTriggerPolicy{ - Type: appsv1.DeploymentTriggerOnImageChange, - ImageChangeParams: &appsv1.DeploymentTriggerImageChangeParams{ - Automatic: true, - ContainerNames: []string{ - "container1", - }, - From: corev1.ObjectReference{ - Kind: "ImageStreamTag", - Name: ImageStreamName + ":latest", - }, - }, - } -} - -func OkTriggeredImageChange() appsv1.DeploymentTriggerPolicy { - ict := OkImageChangeTrigger() - ict.ImageChangeParams.LastTriggeredImage = DockerImageReference - return ict -} - -func OkNonAutomaticICT() appsv1.DeploymentTriggerPolicy { - ict := OkImageChangeTrigger() - ict.ImageChangeParams.Automatic = false - return ict -} - -func OkTriggeredNonAutomatic() appsv1.DeploymentTriggerPolicy { - ict := OkNonAutomaticICT() - ict.ImageChangeParams.LastTriggeredImage = DockerImageReference - return ict -} - -func TestDeploymentConfig(config *appsv1.DeploymentConfig) *appsv1.DeploymentConfig { - config.Spec.Test = true - return config -} - -func RemoveTriggerTypes(config *appsv1.DeploymentConfig, triggerTypes ...appsv1.DeploymentTriggerType) { - types := sets.NewString() - for _, triggerType := range triggerTypes { - types.Insert(string(triggerType)) - } - - remaining := []appsv1.DeploymentTriggerPolicy{} - for _, trigger := range config.Spec.Triggers { - if types.Has(string(trigger.Type)) { - continue - } - remaining = append(remaining, trigger) - } - - config.Spec.Triggers = remaining -} - -func RoundTripConfig(t *testing.T, config *appsv1.DeploymentConfig) *appsv1.DeploymentConfig { - versioned, err := legacyscheme.Scheme.ConvertToVersion(config, appsv1.SchemeGroupVersion) - if err != nil { - t.Errorf("unexpected conversion error: %v", err) - return nil - } - defaulted, err := legacyscheme.Scheme.ConvertToVersion(versioned, appsv1.SchemeGroupVersion) - if err != nil { - t.Errorf("unexpected conversion error: %v", err) - return nil - } - return defaulted.(*appsv1.DeploymentConfig) -} diff --git a/test/integration/deploy_scale_test.go b/test/integration/deploy_scale_test.go index aa11a064ce8f..8fcabfa3786a 100644 --- a/test/integration/deploy_scale_test.go +++ b/test/integration/deploy_scale_test.go @@ -18,7 +18,6 @@ import ( appsv1 "github.com/openshift/api/apps/v1" appsclient "github.com/openshift/client-go/apps/clientset/versioned" "github.com/openshift/library-go/pkg/apps/appsutil" - "github.com/openshift/origin/test/common/appstest" testutil "github.com/openshift/origin/test/util" testserver "github.com/openshift/origin/test/util/server" ) @@ -45,7 +44,7 @@ func TestDeployScale(t *testing.T) { } adminAppsClient := appsclient.NewForConfigOrDie(adminConfig) - config := appstest.OkDeploymentConfig(0) + config := OkDeploymentConfig(0) config.Namespace = namespace config.Spec.Triggers = []appsv1.DeploymentTriggerPolicy{} config.Spec.Replicas = 1 diff --git a/test/integration/deploy_trigger_test.go b/test/integration/deploy_trigger_test.go index f18f2078d425..5b6625fb5247 100644 --- a/test/integration/deploy_trigger_test.go +++ b/test/integration/deploy_trigger_test.go @@ -18,7 +18,6 @@ import ( "github.com/openshift/library-go/pkg/apps/appsutil" "github.com/openshift/library-go/pkg/image/imageutil" - "github.com/openshift/origin/test/common/appstest" testutil "github.com/openshift/origin/test/util" testserver "github.com/openshift/origin/test/util/server" ) @@ -47,7 +46,7 @@ func TestTriggers_manual(t *testing.T) { } adminAppsClient := appsclient.NewForConfigOrDie(adminConfig).AppsV1() - config := appstest.OkDeploymentConfig(0) + config := OkDeploymentConfig(0) config.Namespace = namespace config.Spec.Triggers = []appsv1.DeploymentTriggerPolicy{{Type: "Manual"}} @@ -123,11 +122,11 @@ func TestTriggers_imageChange(t *testing.T) { projectAdminAppsClient := appsclient.NewForConfigOrDie(projectAdminClientConfig).AppsV1() projectAdminImageClient := imagev1client.NewForConfigOrDie(projectAdminClientConfig).ImageV1() - imageStream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: appstest.ImageStreamName}} + imageStream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: ImageStreamName}} - config := appstest.OkDeploymentConfig(0) + config := OkDeploymentConfig(0) config.Namespace = testutil.Namespace() - config.Spec.Triggers = []appsv1.DeploymentTriggerPolicy{appstest.OkImageChangeTrigger()} + config.Spec.Triggers = []appsv1.DeploymentTriggerPolicy{OkImageChangeTrigger()} configWatch, err := projectAdminAppsClient.DeploymentConfigs(testutil.Namespace()).Watch(metav1.ListOptions{}) if err != nil { @@ -145,8 +144,8 @@ func TestTriggers_imageChange(t *testing.T) { } defer imageWatch.Stop() - updatedImage := fmt.Sprintf("sha256:%s", appstest.ImageID) - updatedPullSpec := fmt.Sprintf("%s/%s/%s@%s", registryHostname, testutil.Namespace(), appstest.ImageStreamName, updatedImage) + updatedImage := fmt.Sprintf("sha256:%s", ImageID) + updatedPullSpec := fmt.Sprintf("%s/%s/%s@%s", registryHostname, testutil.Namespace(), ImageStreamName, updatedImage) // Make a function which can create a new tag event for the image stream and // then wait for the stream status to be asynchronously updated. createTagEvent := func() { @@ -228,7 +227,7 @@ func TestTriggers_imageChange_nonAutomatic(t *testing.T) { adminAppsClient := appsclient.NewForConfigOrDie(adminConfig).AppsV1() adminImageClient := imagev1client.NewForConfigOrDie(adminConfig).ImageV1() - imageStream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: appstest.ImageStreamName}} + imageStream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: ImageStreamName}} if imageStream, err = adminImageClient.ImageStreams(testutil.Namespace()).Create(imageStream); err != nil { t.Fatalf("Couldn't create imagestream: %v", err) @@ -240,8 +239,8 @@ func TestTriggers_imageChange_nonAutomatic(t *testing.T) { } defer imageWatch.Stop() - image := fmt.Sprintf("sha256:%s", appstest.ImageID) - pullSpec := fmt.Sprintf("registry:5000/%s/%s@%s", testutil.Namespace(), appstest.ImageStreamName, image) + image := fmt.Sprintf("sha256:%s", ImageID) + pullSpec := fmt.Sprintf("registry:5000/%s/%s@%s", testutil.Namespace(), ImageStreamName, image) // Make a function which can create a new tag event for the image stream and // then wait for the stream status to be asynchronously updated. mapping := &imagev1.ImageStreamMapping{ @@ -289,9 +288,9 @@ func TestTriggers_imageChange_nonAutomatic(t *testing.T) { } defer configWatch.Stop() - config := appstest.OkDeploymentConfig(0) + config := OkDeploymentConfig(0) config.Namespace = testutil.Namespace() - config.Spec.Triggers = []appsv1.DeploymentTriggerPolicy{appstest.OkImageChangeTrigger()} + config.Spec.Triggers = []appsv1.DeploymentTriggerPolicy{OkImageChangeTrigger()} config.Spec.Triggers[0].ImageChangeParams.Automatic = false if config, err = adminAppsClient.DeploymentConfigs(testutil.Namespace()).Create(config); err != nil { t.Fatalf("Couldn't create deploymentconfig: %v", err) @@ -330,7 +329,7 @@ out: // Subsequent updates to the image shouldn't update the pod template image mapping.Image.Name = "sha256:0000000000000000000000000000000000000000000000000000000000000321" - mapping.Image.DockerImageReference = fmt.Sprintf("%s/%s/%s@%s", registryHostname, testutil.Namespace(), appstest.ImageStreamName, mapping.Image.Name) + mapping.Image.DockerImageReference = fmt.Sprintf("%s/%s/%s@%s", registryHostname, testutil.Namespace(), ImageStreamName, mapping.Image.Name) createTagEvent(mapping) timeout = time.After(20 * time.Second) @@ -407,13 +406,13 @@ func TestTriggers_MultipleICTs(t *testing.T) { adminAppsClient := appsclient.NewForConfigOrDie(adminConfig).AppsV1() adminImageClient := imagev1client.NewForConfigOrDie(adminConfig).ImageV1() - imageStream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: appstest.ImageStreamName}} + imageStream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: ImageStreamName}} secondImageStream := &imagev1.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: "sample"}} - config := appstest.OkDeploymentConfig(0) + config := OkDeploymentConfig(0) config.Namespace = testutil.Namespace() - firstTrigger := appstest.OkImageChangeTrigger() - secondTrigger := appstest.OkImageChangeTrigger() + firstTrigger := OkImageChangeTrigger() + secondTrigger := OkImageChangeTrigger() secondTrigger.ImageChangeParams.ContainerNames = []string{"container2"} secondTrigger.ImageChangeParams.From.Name = imageutil.JoinImageStreamTag("sample", imagev1.DefaultImageTag) config.Spec.Triggers = []appsv1.DeploymentTriggerPolicy{firstTrigger, secondTrigger} @@ -437,8 +436,8 @@ func TestTriggers_MultipleICTs(t *testing.T) { } defer imageWatch.Stop() - updatedImage := fmt.Sprintf("sha256:%s", appstest.ImageID) - updatedPullSpec := fmt.Sprintf("%s/%s/%s@%s", registryHostname, testutil.Namespace(), appstest.ImageStreamName, updatedImage) + updatedImage := fmt.Sprintf("sha256:%s", ImageID) + updatedPullSpec := fmt.Sprintf("%s/%s/%s@%s", registryHostname, testutil.Namespace(), ImageStreamName, updatedImage) // Make a function which can create a new tag event for the image stream and // then wait for the stream status to be asynchronously updated. @@ -572,9 +571,9 @@ func TestTriggers_configChange(t *testing.T) { } adminAppsClient := appsclient.NewForConfigOrDie(adminConfig).AppsV1() - config := appstest.OkDeploymentConfig(0) + config := OkDeploymentConfig(0) config.Namespace = namespace - config.Spec.Triggers = []appsv1.DeploymentTriggerPolicy{appstest.OkConfigChangeTrigger()} + config.Spec.Triggers = []appsv1.DeploymentTriggerPolicy{{Type: appsv1.DeploymentTriggerOnConfigChange}} rcWatch, err := kc.CoreV1().ReplicationControllers(namespace).Watch(metav1.ListOptions{}) if err != nil { diff --git a/test/integration/deployment_mock.go b/test/integration/deployment_mock.go new file mode 100644 index 000000000000..5ca5d9446ae8 --- /dev/null +++ b/test/integration/deployment_mock.go @@ -0,0 +1,105 @@ +package integration + +import ( + appsv1 "github.com/openshift/api/apps/v1" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const ( + ImageStreamName = "test-image-stream" + ImageID = "0000000000000000000000000000000000000000000000000000000000000001" +) + +func OkDeploymentConfig(version int64) *appsv1.DeploymentConfig { + one := int64(1) + return &appsv1.DeploymentConfig{ + ObjectMeta: metav1.ObjectMeta{ + Name: "config", + Namespace: corev1.NamespaceDefault, + SelfLink: "/apis/apps.openshift.io/v1/deploymentConfig/config", + }, + Spec: appsv1.DeploymentConfigSpec{ + Replicas: 1, + Selector: map[string]string{"a": "b"}, + Strategy: appsv1.DeploymentStrategy{ + Type: appsv1.DeploymentStrategyTypeRecreate, + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceName(corev1.ResourceCPU): resource.MustParse("10"), + corev1.ResourceName(corev1.ResourceMemory): resource.MustParse("10G"), + }, + }, + RecreateParams: &appsv1.RecreateDeploymentStrategyParams{ + TimeoutSeconds: mkintp(20), + }, + ActiveDeadlineSeconds: mkintp(21600), + }, + Template: &corev1.PodTemplateSpec{ + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "container1", + Image: "registry:8080/repo1:ref1", + Env: []corev1.EnvVar{ + { + Name: "ENV1", + Value: "VAL1", + }, + }, + ImagePullPolicy: corev1.PullIfNotPresent, + TerminationMessagePath: "/dev/termination-log", + TerminationMessagePolicy: corev1.TerminationMessageReadFile, + }, + { + Name: "container2", + Image: "registry:8080/repo1:ref2", + ImagePullPolicy: corev1.PullIfNotPresent, + TerminationMessagePath: "/dev/termination-log", + TerminationMessagePolicy: corev1.TerminationMessageReadFile, + }, + }, + RestartPolicy: corev1.RestartPolicyAlways, + DNSPolicy: corev1.DNSClusterFirst, + TerminationGracePeriodSeconds: &one, + SchedulerName: corev1.DefaultSchedulerName, + SecurityContext: &corev1.PodSecurityContext{}, + }, + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{"a": "b"}, + }, + }, + Triggers: []appsv1.DeploymentTriggerPolicy{ + OkImageChangeTrigger(), + { + Type: appsv1.DeploymentTriggerOnConfigChange, + }, + }, + }, + Status: appsv1.DeploymentConfigStatus{ + LatestVersion: version, + }, + } +} + +func mkintp(i int) *int64 { + v := int64(i) + return &v +} + +func OkImageChangeTrigger() appsv1.DeploymentTriggerPolicy { + return appsv1.DeploymentTriggerPolicy{ + Type: appsv1.DeploymentTriggerOnImageChange, + ImageChangeParams: &appsv1.DeploymentTriggerImageChangeParams{ + Automatic: true, + ContainerNames: []string{ + "container1", + }, + From: corev1.ObjectReference{ + Kind: "ImageStreamTag", + Name: ImageStreamName + ":latest", + }, + }, + } +}