Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
+method to extract correct image from yaml (#21)
Browse files Browse the repository at this point in the history
* +method to extract correct image from yaml
  • Loading branch information
rhmkrutov authored Feb 22, 2022
1 parent d9f278b commit faf61a7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
17 changes: 17 additions & 0 deletions test/helper_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package test

import (
"index/suffixarray"
"io/ioutil"
"regexp"
"strings"
"time"

"github.com/ghodss/yaml"
"github.com/onsi/gomega"
"github.com/rh-messaging/shipshape/pkg/framework/log"
v1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)

func FormUrl(protocol, DeployName, number, subdomain, namespace, domain, address, port string) string {
Expand Down Expand Up @@ -47,3 +51,16 @@ func WaitForDrainerRemovalSlow(sw *SetupWrapper, count int, timeout time.Duratio
func WaitForDrainerRemoval(sw *SetupWrapper, count int) bool {
return WaitForDrainerRemovalSlow(sw, count, time.Second*time.Duration(10), count*6)
}

func GetImages() []corev1.EnvVar {
filePath := Config.RepositoryPath + "/operator.yaml"
yamlFile, err := ioutil.ReadFile(filePath)
if err != nil {
log.Logf("yaml load err: #%v:, err")
return nil
} else {
deployment := &v1.Deployment{}
err = yaml.Unmarshal(yamlFile, deployment)
return deployment.Spec.Template.Spec.Containers[0].Env
}
}
45 changes: 42 additions & 3 deletions test/smoke/basic/basic_update_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package basic

import (
"strings"

"github.com/artemiscloud/activemq-artemis-operator-test-suite/pkg/bdw"
"github.com/artemiscloud/activemq-artemis-operator-test-suite/test"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"github.com/rh-messaging/shipshape/pkg/framework"
Expand All @@ -10,7 +13,8 @@ import (
)

const (
CustomImage = "registry.redhat.io/amq7/amq-broker-rhel8@sha256:c5f4c08e068b9721967cf7c7cbd9a9e93fb5e39b264dd13b653e99d8f3fa9e0e"
PPC = "_ppc64le"
IBMZ = "_s390x"
)

var _ = ginkgo.Describe("DeploymentUpdateTests", func() {
Expand All @@ -29,11 +33,26 @@ var _ = ginkgo.Describe("DeploymentUpdateTests", func() {
})

ginkgo.It("CustomImageOverrideTest", func() {
images := test.GetImages()
imageName := decideImageName()
imageArch := decideImageArch()
CustomImage := ""
for _, item := range images {
if strings.HasPrefix(item.Name, imageName) && strings.HasSuffix(item.Name, imageArch) {
if imageArch == "" { // Also check lack of other architectures..
if !strings.HasSuffix(item.Name, PPC) && !strings.HasSuffix(item.Name, IBMZ) {
CustomImage = item.Value
break
}
} else {
CustomImage = item.Value
break
}
}
}
brokerDeployer.WithCustomImage(CustomImage)
// TODO: extract this from operator.yaml
err := brokerDeployer.DeployBrokers(1)
gomega.Expect(err).To(gomega.BeNil(), "Broker deployment failed")
//TODO // Also verify image from the ""broker"" instance
pod := getPod(ctx1)
actualImage := pod.Spec.Containers[0].Image
gomega.Expect(actualImage).To(gomega.Equal(CustomImage), "Image not updated after CR update")
Expand All @@ -42,6 +61,26 @@ var _ = ginkgo.Describe("DeploymentUpdateTests", func() {

})

func decideImageArch() string {
name := ""
if test.Config.PPC {
name = PPC
} else if test.Config.IBMz {
name = IBMZ
} else {
//Problem: _s390x and _ppc here would still work.. Need an elegant solution
}
return name
}

func decideImageName() string {
name := "RELATED_IMAGE_ActiveMQ_Artemis_Broker_Kubernetes"
if test.Config.BrokerName != "amq-broker" {
name = "RELATED_IMAGE_ActiveMQ_Artemis_Broker_Kubernetes"
}
return name
}

func getPod(ctx1 *framework.ContextData) *v1.Pod {
kubeclient := ctx1.Clients.KubeClient
podName := DeployName + PodNameSuffix
Expand Down

0 comments on commit faf61a7

Please sign in to comment.