Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 9 additions & 42 deletions test/extended/image_ecosystem/s2i_perl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package image_ecosystem
import (
"context"
"fmt"
"strings"
"os"
"time"

g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
e2e "k8s.io/kubernetes/test/e2e/framework"

exutil "github.com/openshift/origin/test/extended/util"
Expand Down Expand Up @@ -45,9 +44,7 @@ var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][perl][Slow] hot deploy f
modifyCommand = []string{"sed", "-ie", `s/initial value/modified value/`, "lib/My/Test.pm"}
dcName = "perl"
rcNameOne = fmt.Sprintf("%s-1", dcName)
rcNameTwo = fmt.Sprintf("%s-2", dcName)
dcLabelOne = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", rcNameOne))
dcLabelTwo = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", rcNameTwo))
)

g.Context("", func() {
Expand All @@ -69,9 +66,14 @@ var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][perl][Slow] hot deploy f
if !archHasModPerl(oc) {
g.Skip("mod_perl based builder image is not available on arm64")
}
// Make sure the index.pl is executable in the fixture assets as it is in the sources.
// (FixturePath resets the perms on the files)
err := os.Chmod(exutil.FixturePath("testdata", "image_ecosystem", "perl-hotdeploy", "index.pl"), os.FileMode(0o755))
o.Expect(err).NotTo(o.HaveOccurred())

exutil.WaitForOpenShiftNamespaceImageStreams(oc)
g.By(fmt.Sprintf("calling oc new-app -f %q", perlTemplate))
err := oc.Run("new-app").Args("-f", perlTemplate, "-e", "HTTPD_START_SERVERS=1", "-e", "HTTPD_MAX_SPARE_SERVERS=1", "-e", "HTTPD_MAX_REQUEST_WORKERS=1").Execute()
err = oc.Run("new-app").Args("-f", perlTemplate, "-e", "HTTPD_START_SERVERS=1", "-e", "HTTPD_MAX_SPARE_SERVERS=1", "-e", "HTTPD_MAX_REQUEST_WORKERS=1").Execute()
o.Expect(err).NotTo(o.HaveOccurred())

br, err := exutil.StartBuildAndWait(oc, "perl", fmt.Sprintf("--from-dir=%s", appSource))
Expand All @@ -91,8 +93,6 @@ var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][perl][Slow] hot deploy f
g.By("waiting for endpoint")
err = exutil.WaitForEndpoint(oc.KubeFramework().ClientSet, oc.Namespace(), dcName)
o.Expect(err).NotTo(o.HaveOccurred())
oldEndpoint, err := oc.KubeFramework().ClientSet.CoreV1().Endpoints(oc.Namespace()).Get(context.Background(), dcName, metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred())

checkPage := func(expected string, dcLabel labels.Selector) {
_, err := exutil.WaitForPods(oc.KubeClient().CoreV1().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunning, 1, 4*time.Minute)
Expand All @@ -104,45 +104,12 @@ var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][perl][Slow] hot deploy f

checkPage("initial value", dcLabelOne)

g.By("modifying the source code with disabled hot deploy")
g.By("modifying the source code")
err = RunInPodContainer(oc, dcLabelOne, modifyCommand)
o.Expect(err).NotTo(o.HaveOccurred())
checkPage("initial value", dcLabelOne)

g.By("turning on hot-deploy")
err = oc.Run("set", "env").Args("dc", dcName, "PERL_APACHE2_RELOAD=true").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().AppsV1(), oc.Namespace(), dcName, 2, true, oc)
o.Expect(err).NotTo(o.HaveOccurred())

g.By("waiting for a new endpoint")
err = exutil.WaitForEndpoint(oc.KubeFramework().ClientSet, oc.Namespace(), dcName)
o.Expect(err).NotTo(o.HaveOccurred())

// Ran into an issue where we'd try to hit the endpoint before it was updated, resulting in
// request timeouts against the previous pod's ip. So make sure the endpoint is pointing to the
// new pod before hitting it.
err = wait.Poll(1*time.Second, 1*time.Minute, func() (bool, error) {
newEndpoint, err := oc.KubeFramework().ClientSet.CoreV1().Endpoints(oc.Namespace()).Get(context.Background(), dcName, metav1.GetOptions{})
if err != nil {
return false, err
}
if !strings.Contains(newEndpoint.Subsets[0].Addresses[0].TargetRef.Name, rcNameTwo) {
e2e.Logf("waiting on endpoint address ref %s to contain %s", newEndpoint.Subsets[0].Addresses[0].TargetRef.Name, rcNameTwo)
return false, nil
}
e2e.Logf("old endpoint was %#v, new endpoint is %#v", oldEndpoint, newEndpoint)
return true, nil
})
o.Expect(err).NotTo(o.HaveOccurred())

g.By("modifying the source code with enabled hot deploy")
checkPage("initial value", dcLabelTwo)
err = RunInPodContainer(oc, dcLabelTwo, modifyCommand)
o.Expect(err).NotTo(o.HaveOccurred())
checkPage("modified value", dcLabelTwo)
checkPage("modified value", dcLabelOne)
})
})

})
})
104 changes: 45 additions & 59 deletions test/extended/image_ecosystem/s2i_ruby.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
package image_ecosystem

import (
"context"
"fmt"
"strings"
"time"

g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/wait"
e2e "k8s.io/kubernetes/test/e2e/framework"

exutil "github.com/openshift/origin/test/extended/util"
)

var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][ruby][Slow] hot deploy for openshift ruby image", func() {
defer g.GinkgoRecover()
var (
railsTemplate = "rails-postgresql-example"
oc = exutil.NewCLI("s2i-ruby")
modifyCommand = []string{"sed", "-ie", `s%render :file => 'public/index.html'%%`, "app/controllers/welcome_controller.rb"}
removeCommand = []string{"rm", "-f", "public/index.html"}
dcName = "rails-postgresql-example"
rcNameOne = fmt.Sprintf("%s-1", dcName)
rcNameTwo = fmt.Sprintf("%s-2", dcName)
dcLabelOne = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", rcNameOne))
dcLabelTwo = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", rcNameTwo))
railsTemplate = "rails-postgresql-example"
oc = exutil.NewCLI("s2i-ruby")
modifyCommand = []string{"sed", "-ie", `s%render :file => 'public/index.html'%%`, "app/controllers/welcome_controller.rb"}
removeCommand = []string{"rm", "-f", "public/index.html"}
deploymentName = "rails-postgresql-example"
podLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("name=%s", deploymentName))
)

g.Context("", func() {
Expand All @@ -45,90 +35,86 @@ var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][ruby][Slow] hot deploy f

g.Describe("Rails example", func() {
g.It(fmt.Sprintf("should work with hot deploy [apigroup:image.openshift.io][apigroup:operator.openshift.io][apigroup:config.openshift.io][apigroup:build.openshift.io]"), func() {
// The rails sample is not supported in the Samples operator and has bitrotten. Let's skip the test but keep the test code around
// just in case the sample gets resurrected in the future.
g.Skip("The rails-postgresql-example is not working anymore and is not supported by the samples operator (since OCP 4.16) so let's not use it for tests.")

exutil.WaitForOpenShiftNamespaceImageStreams(oc)
g.By(fmt.Sprintf("calling oc new-app %q", railsTemplate))
err := oc.Run("new-app").Args(railsTemplate).Execute()
o.Expect(err).NotTo(o.HaveOccurred())

g.By("waiting for build to finish")
err = exutil.WaitForABuild(oc.BuildClient().BuildV1().Builds(oc.Namespace()), rcNameOne, nil, nil, nil)
// This example seems to be taking quite some time, so let's use custom timeouts
err = exutil.WaitForABuildWithTimeout(oc.BuildClient().BuildV1().Builds(oc.Namespace()), deploymentName+"-1", 5*time.Minute, 15*time.Minute, nil, nil, nil)
if err != nil {
exutil.DumpBuildLogs(dcName, oc)
exutil.DumpBuildLogs(deploymentName, oc)
}

o.Expect(err).NotTo(o.HaveOccurred())

err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().AppsV1(), oc.Namespace(), dcName, 1, true, oc)
err = exutil.WaitForDeploymentReadyWithTimeout(oc, deploymentName, oc.Namespace(), 15*time.Minute)
o.Expect(err).NotTo(o.HaveOccurred())

g.By("waiting for endpoint")
err = exutil.WaitForEndpoint(oc.KubeFramework().ClientSet, oc.Namespace(), dcName)
o.Expect(err).NotTo(o.HaveOccurred())
oldEndpoint, err := oc.KubeFramework().ClientSet.CoreV1().Endpoints(oc.Namespace()).Get(context.Background(), dcName, metav1.GetOptions{})
err = exutil.WaitForEndpoint(oc.KubeFramework().ClientSet, oc.Namespace(), deploymentName)
o.Expect(err).NotTo(o.HaveOccurred())

assertPageContent := func(content string, dcLabel labels.Selector) {
_, err := exutil.WaitForPods(oc.KubeClient().CoreV1().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunning, 1, 4*time.Minute)
assertPageContent := func(content string) {
_, err := exutil.WaitForPods(oc.KubeClient().CoreV1().Pods(oc.Namespace()), podLabel, exutil.CheckPodIsRunning, 1, 4*time.Minute)
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())

result, err := CheckPageContains(oc, dcName, "", content)
result, err := CheckPageContains(oc, deploymentName, "", content)
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
o.ExpectWithOffset(1, result).To(o.BeTrue())
}

// with hot deploy disabled, making a change to
// welcome_controller.rb should not affect the app
g.By("testing application content")
assertPageContent("Welcome to your Rails application on OpenShift", dcLabelOne)
assertPageContent("Welcome to your Rails application on OpenShift")
g.By("modifying the source code with disabled hot deploy")
err = RunInPodContainer(oc, dcLabelOne, modifyCommand)
err = RunInPodContainer(oc, podLabel, modifyCommand)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("testing application content source modification")
assertPageContent("Welcome to your Rails application on OpenShift", dcLabelOne)

pods, err := oc.KubeClient().CoreV1().Pods(oc.Namespace()).List(context.Background(), metav1.ListOptions{LabelSelector: dcLabelOne.String()})
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(len(pods.Items)).To(o.Equal(1))
assertPageContent("Welcome to your Rails application on OpenShift")

g.By("turning on hot-deploy")
err = oc.Run("set", "env").Args("dc", dcName, "RAILS_ENV=development").Execute()
err = oc.Run("set", "env").Args("deployment", deploymentName, "RAILS_ENV=development").Execute()
o.Expect(err).NotTo(o.HaveOccurred())
err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().AppsV1(), oc.Namespace(), dcName, 2, true, oc)
err = exutil.WaitForDeploymentReady(oc, deploymentName, oc.Namespace())
o.Expect(err).NotTo(o.HaveOccurred())

g.By("waiting for a new endpoint")
err = exutil.WaitForEndpoint(oc.KubeFramework().ClientSet, oc.Namespace(), dcName)
err = exutil.WaitForEndpoint(oc.KubeFramework().ClientSet, oc.Namespace(), deploymentName)
o.Expect(err).NotTo(o.HaveOccurred())

// Ran into an issue where we'd try to hit the endpoint before it was updated, resulting in
// request timeouts against the previous pod's ip. So make sure the endpoint is pointing to the
// new pod before hitting it.
err = wait.Poll(1*time.Second, 1*time.Minute, func() (bool, error) {
newEndpoint, err := oc.KubeFramework().ClientSet.CoreV1().Endpoints(oc.Namespace()).Get(context.Background(), dcName, metav1.GetOptions{})
if err != nil {
return false, err
}
if !strings.Contains(newEndpoint.Subsets[0].Addresses[0].TargetRef.Name, rcNameTwo) {
e2e.Logf("waiting on endpoint address ref %s to contain %s", newEndpoint.Subsets[0].Addresses[0].TargetRef.Name, rcNameTwo)
return false, nil
}
e2e.Logf("old endpoint was %#v, new endpoint is %#v", oldEndpoint, newEndpoint)
return true, nil
})
o.Expect(err).NotTo(o.HaveOccurred())
// NOTE: The code below was here when the test was based on DeploymentConfig. The deployments seem to exhibit a different behavior
// where the deployment is not ready until the pods and endpoints have transitioned to the new replica set. Therefore, I'm commenting this
// out. If we ever encounter spurious errors here, we can learn from how the situation was handled with the DeploymentConfigs.
//
// // Ran into an issue where we'd try to hit the endpoint before it was updated, resulting in
// // request timeouts against the previous pod's ip. So make sure the endpoint is pointing to the
// // new pod before hitting it.
// err = wait.Poll(1*time.Second, 1*time.Minute, func() (bool, error) {
// newEndpoint, err := oc.KubeFramework().ClientSet.CoreV1().Endpoints(oc.Namespace()).Get(context.Background(), dcName, metav1.GetOptions{})
// if err != nil {
// return false, err
// }
// if !strings.Contains(newEndpoint.Subsets[0].Addresses[0].TargetRef.Name, rcNameTwo) {
// e2e.Logf("waiting on endpoint address ref %s to contain %s", newEndpoint.Subsets[0].Addresses[0].TargetRef.Name, rcNameTwo)
// return false, nil
// }
// e2e.Logf("old endpoint was %#v, new endpoint is %#v", oldEndpoint, newEndpoint)
// return true, nil
// })
// o.Expect(err).NotTo(o.HaveOccurred())

// now hot deploy is enabled, a change to welcome_controller.rb
// should affect the app
g.By("modifying the source code with enabled hot deploy")
assertPageContent("Welcome to your Rails application on OpenShift", dcLabelTwo)
err = RunInPodContainer(oc, dcLabelTwo, modifyCommand)
assertPageContent("Welcome to your Rails application on OpenShift")
err = RunInPodContainer(oc, podLabel, modifyCommand)
o.Expect(err).NotTo(o.HaveOccurred())
err = RunInPodContainer(oc, dcLabelTwo, removeCommand)
err = RunInPodContainer(oc, podLabel, removeCommand)
o.Expect(err).NotTo(o.HaveOccurred())
assertPageContent("Hello, Rails!", dcLabelTwo)
assertPageContent("Hello, Rails!")
})
})
})
Expand Down
46 changes: 29 additions & 17 deletions test/extended/image_ecosystem/sample_repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ type sampleRepoConfig struct {
buildConfigName string
serviceName string
deploymentConfigName string
deploymentName string
expectedString string
appPath string
dbDeploymentConfigName string
dbDeploymentName string
dbServiceName string
newAppParams string
}
Expand All @@ -36,7 +38,7 @@ type sampleRepoConfig struct {
func NewSampleRepoTest(c sampleRepoConfig) func() {
return func() {
defer g.GinkgoRecover()
var oc = exutil.NewCLI(c.repoName + "-repo-test")
oc := exutil.NewCLI(c.repoName + "-repo-test")

g.Context("", func() {
g.BeforeEach(func() {
Expand All @@ -52,7 +54,6 @@ func NewSampleRepoTest(c sampleRepoConfig) func() {

g.Describe("Building "+c.repoName+" app from new-app", func() {
g.It(fmt.Sprintf("should build a "+c.repoName+" image and run it in a pod [apigroup:build.openshift.io]"), func() {

err := exutil.WaitForOpenShiftNamespaceImageStreams(oc)
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("calling oc new-app with the " + c.repoName + " example template"))
Expand All @@ -76,12 +77,25 @@ func NewSampleRepoTest(c sampleRepoConfig) func() {
o.Expect(err).NotTo(o.HaveOccurred())

g.By("expecting the app deployment to be complete")
err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().AppsV1(), oc.Namespace(), c.deploymentConfigName, 1, true, oc)

if c.deploymentConfigName != "" {
err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().AppsV1(), oc.Namespace(), c.deploymentConfigName, 1, true, oc)
} else if c.deploymentName != "" {
err = exutil.WaitForDeploymentReadyWithTimeout(oc, c.deploymentName, oc.Namespace(), 15*time.Minute)
} else {
g.Fail("invalid test configuration: neither deploymentConfigName nor deploymentName is set")
}
o.Expect(err).NotTo(o.HaveOccurred())

if len(c.dbDeploymentConfigName) > 0 {
g.By("expecting the db deployment to be complete")
err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().AppsV1(), oc.Namespace(), c.dbDeploymentConfigName, 1, true, oc)
if c.dbDeploymentConfigName != "" {
err = exutil.WaitForDeploymentConfig(oc.KubeClient(), oc.AppsClient().AppsV1(), oc.Namespace(), c.dbDeploymentConfigName, 1, true, oc)
} else if c.dbDeploymentName != "" {
err = exutil.WaitForDeploymentReadyWithTimeout(oc, c.dbDeploymentName, oc.Namespace(), 15*time.Minute)
} else {
g.Fail("invalid test configuration: neither dbDeploymentConfigName nor dbDeploymentName is set")
}
o.Expect(err).NotTo(o.HaveOccurred())

g.By("expecting the db service is available")
Expand Down Expand Up @@ -124,19 +138,18 @@ func NewSampleRepoTest(c sampleRepoConfig) func() {
}

var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][Slow] openshift sample application repositories", func() {

g.Describe("[sig-devex][Feature:ImageEcosystem][ruby] test ruby images with rails-ex db repo", NewSampleRepoTest(
sampleRepoConfig{
repoName: "rails-postgresql",
templateURL: "rails-postgresql-example",
buildConfigName: "rails-postgresql-example",
serviceName: "rails-postgresql-example",
deploymentConfigName: "rails-postgresql-example",
expectedString: "Listing articles",
appPath: "/articles",
dbDeploymentConfigName: "postgresql",
dbServiceName: "postgresql",
newAppParams: "APPLICATION_DOMAIN=rails-%s.ocp.io",
repoName: "rails-postgresql",
templateURL: "rails-postgresql-example",
buildConfigName: "rails-postgresql-example",
serviceName: "rails-postgresql-example",
deploymentName: "rails-postgresql-example",
expectedString: "Listing articles",
appPath: "/articles",
dbDeploymentName: "postgresql",
dbServiceName: "postgresql",
newAppParams: "APPLICATION_DOMAIN=rails-%s.ocp.io",
},
))

Expand Down Expand Up @@ -170,7 +183,7 @@ var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][Slow] openshift sample a
},
))

var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][php] test php images with cakephp-ex db repo", NewSampleRepoTest(
_ = g.Describe("[sig-devex][Feature:ImageEcosystem][php] test php images with cakephp-ex db repo", NewSampleRepoTest(
sampleRepoConfig{
repoName: "cakephp-mysql",
templateURL: "cakephp-mysql-example",
Expand Down Expand Up @@ -214,5 +227,4 @@ var _ = g.Describe("[sig-devex][Feature:ImageEcosystem][Slow] openshift sample a
dbServiceName: "",
},
))*/

})
2 changes: 1 addition & 1 deletion test/extended/testdata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"from": {
"kind": "ImageStreamTag",
"namespace": "openshift",
"name": "perl:5.30-el7"
"name": "perl:5.32-ubi8"
}
}
},
Expand Down
Loading