element_type
stringclasses
4 values
project_name
stringclasses
1 value
uuid
stringlengths
36
36
name
stringlengths
0
346
imports
stringlengths
0
2.67k
structs
stringclasses
761 values
interfaces
stringclasses
22 values
file_location
stringclasses
545 values
code
stringlengths
26
8.07M
global_vars
stringclasses
7 values
package
stringclasses
124 values
tags
stringclasses
1 value
test
openshift/openshift-tests-private
85d8e9cb-6abd-4335-94d9-69e82f53b87a
imageregistry_optional
import ( "encoding/base64" "strings" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" e2e "k8s.io/kubernetes/test/e2e/framework" )
github.com/openshift/openshift-tests-private/test/extended/image_registry/imageregistry_optional.go
package imageregistry import ( "encoding/base64" "strings" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" e2e "k8s.io/kubernetes/test/e2e/framework" ) var _ = g.Describe("[sig-imageregistry] Image_Registry", func() { defer g.GinkgoRecover() var oc = exutil.NewCLI("imageregistry-optional", exutil.KubeConfigPath()) g.It("NonHyperShiftHOST-Author:xiuwang-High-66514-Disable Image Registry operator", func() { if checkOptionalOperatorInstalled(oc, "ImageRegistry") { g.Skip("Skip for the test when registry is installed") } g.By("All registry related resources are not installed") var object imageObject resources := map[string]string{ "co/image-registry": `clusteroperators.config.openshift.io "image-registry" not found`, "config.image/cluster": `configs.imageregistry.operator.openshift.io "cluster" not found`, "ns/openshift-image-registry": `namespaces "openshift-image-registry" not found`, "imagepruner/cluster": `imagepruners.imageregistry.operator.openshift.io "cluster" not found`, } for key := range resources { output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args(key).Output() o.Expect(err).To(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring(resources[key])) } g.By("Created imagestream only could be source policy") err := oc.AsAdmin().WithoutNamespace().Run("tag").Args("quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", "66514:latest", "--import-mode=PreserveOriginal", "--reference-policy=local", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = waitForAnImageStreamTag(oc, oc.Namespace(), "66514", "latest") o.Expect(err).NotTo(o.HaveOccurred()) object.getManifestObject(oc, "imagestreamtag", "66514:latest", oc.Namespace()) if len(object.architecture) == 1 && len(object.digest) == 1 { e2e.Failf("Only one arch image imported") } imageRepo, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("is", "66514", "-n", oc.Namespace(), "-ojsonpath={.status.dockerImageRepository}").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(imageRepo).To(o.BeEmpty()) g.By("Check additional ca could be merged by mco") trustCAName, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("image.config", "-o=jsonpath={..spec.additionalTrustedCA.name}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if trustCAName != "" { g.By("additionalTrustedCA is set") addTrustCA, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("configmap", trustCAName, "-o=jsonpath={.data}", "-n", "openshift-config").Output() o.Expect(err).NotTo(o.HaveOccurred()) addTrustCA = strings.TrimSuffix(string(addTrustCA), "}") addTrustCA = strings.TrimPrefix(string(addTrustCA), "{") regCerts, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("configmap", "merged-trusted-image-registry-ca", "-o=jsonpath={.data}", "-n", "openshift-config-managed").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(regCerts, addTrustCA) { e2e.Failf("The additional ca can't be merged by mco") } } }) g.It("NonHyperShiftHOST-Author:xiuwang-High-66516-Image registry pruner job should pass when cluster was installed without DeploymentConfig capability [Serial]", func() { if checkOptionalOperatorInstalled(oc, "DeploymentConfig") || !checkOptionalOperatorInstalled(oc, "ImageRegistry") { g.Skip("Skip for the test when DeploymentConfig is installed or ImageRegistry is not installed") } g.By("Set imagepruner cronjob started every 1 minutes") expectedStatus := map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} err := waitCoBecomes(oc, "image-registry", 240, expectedStatus) o.Expect(err).NotTo(o.HaveOccurred()) defer oc.AsAdmin().Run("patch").Args("imagepruner/cluster", "-p", `{"spec":{"schedule":""}}`, "--type=merge").Execute() err = oc.AsAdmin().Run("patch").Args("imagepruner/cluster", "-p", `{"spec":{"schedule":"* * * * *"}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) imagePruneLog(oc, "", "the server could not find the requested resource (get deploymentconfigs.apps.openshift.io)") }) g.It("NonHyperShiftHOST-Author:wewang-High-66667-Install Image Registry operator after cluster install successfully", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } g.By("Check image registry operator installed optionally") if !checkOptionalOperatorInstalled(oc, "ImageRegistry") { g.Skip("Skip for the test due to image registry not installed") } else { baseCapSet, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("clusterversion", "-o=jsonpath={.items[*].spec.capabilities.baselineCapabilitySet}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if baseCapSet != "None" { g.Skip("Skip for the test when registry is installed in default") } } g.By("Check serviceaccount and pull secret created after the project created") oc.SetupProject() secretName, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("sa/builder", "-o=jsonpath={.imagePullSecrets[0].name}", "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) dockerCfg, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("secret/"+secretName, "-o=jsonpath={.data.\\.dockercfg}", "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) credsTXT, err := base64.StdEncoding.DecodeString(dockerCfg) o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(strings.Contains(string(credsTXT), "image-registry.openshift-image-registry.svc:5000")).To(o.BeTrue()) g.By("Create a imagestream with pullthrough") err = oc.AsAdmin().WithoutNamespace().Run("tag").Args("registry.redhat.io/ubi8/httpd-24:latest", "httpd:latest", "--reference-policy=local", "--insecure", "--import-mode=PreserveOriginal", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = waitForAnImageStreamTag(oc, oc.Namespace(), "httpd", "latest") o.Expect(err).NotTo(o.HaveOccurred()) err = oc.AsAdmin().WithoutNamespace().Run("create").Args("deployment", "pull-test", "--image", "image-registry.openshift-image-registry.svc:5000/"+oc.Namespace()+"/httpd:latest", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) checkPodsRunningWithLabel(oc, oc.Namespace(), "app=pull-test", 1) }) })
package imageregistry
test case
openshift/openshift-tests-private
6828a980-2b0f-4319-a1d5-cd35621e0a7e
NonHyperShiftHOST-Author:xiuwang-High-66514-Disable Image Registry operator
['"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/imageregistry_optional.go
g.It("NonHyperShiftHOST-Author:xiuwang-High-66514-Disable Image Registry operator", func() { if checkOptionalOperatorInstalled(oc, "ImageRegistry") { g.Skip("Skip for the test when registry is installed") } g.By("All registry related resources are not installed") var object imageObject resources := map[string]string{ "co/image-registry": `clusteroperators.config.openshift.io "image-registry" not found`, "config.image/cluster": `configs.imageregistry.operator.openshift.io "cluster" not found`, "ns/openshift-image-registry": `namespaces "openshift-image-registry" not found`, "imagepruner/cluster": `imagepruners.imageregistry.operator.openshift.io "cluster" not found`, } for key := range resources { output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args(key).Output() o.Expect(err).To(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring(resources[key])) } g.By("Created imagestream only could be source policy") err := oc.AsAdmin().WithoutNamespace().Run("tag").Args("quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", "66514:latest", "--import-mode=PreserveOriginal", "--reference-policy=local", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = waitForAnImageStreamTag(oc, oc.Namespace(), "66514", "latest") o.Expect(err).NotTo(o.HaveOccurred()) object.getManifestObject(oc, "imagestreamtag", "66514:latest", oc.Namespace()) if len(object.architecture) == 1 && len(object.digest) == 1 { e2e.Failf("Only one arch image imported") } imageRepo, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("is", "66514", "-n", oc.Namespace(), "-ojsonpath={.status.dockerImageRepository}").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(imageRepo).To(o.BeEmpty()) g.By("Check additional ca could be merged by mco") trustCAName, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("image.config", "-o=jsonpath={..spec.additionalTrustedCA.name}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if trustCAName != "" { g.By("additionalTrustedCA is set") addTrustCA, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("configmap", trustCAName, "-o=jsonpath={.data}", "-n", "openshift-config").Output() o.Expect(err).NotTo(o.HaveOccurred()) addTrustCA = strings.TrimSuffix(string(addTrustCA), "}") addTrustCA = strings.TrimPrefix(string(addTrustCA), "{") regCerts, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("configmap", "merged-trusted-image-registry-ca", "-o=jsonpath={.data}", "-n", "openshift-config-managed").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(regCerts, addTrustCA) { e2e.Failf("The additional ca can't be merged by mco") } } })
test case
openshift/openshift-tests-private
ce0433c3-6085-4d2f-8633-aab9cc030386
NonHyperShiftHOST-Author:xiuwang-High-66516-Image registry pruner job should pass when cluster was installed without DeploymentConfig capability [Serial]
github.com/openshift/openshift-tests-private/test/extended/image_registry/imageregistry_optional.go
g.It("NonHyperShiftHOST-Author:xiuwang-High-66516-Image registry pruner job should pass when cluster was installed without DeploymentConfig capability [Serial]", func() { if checkOptionalOperatorInstalled(oc, "DeploymentConfig") || !checkOptionalOperatorInstalled(oc, "ImageRegistry") { g.Skip("Skip for the test when DeploymentConfig is installed or ImageRegistry is not installed") } g.By("Set imagepruner cronjob started every 1 minutes") expectedStatus := map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} err := waitCoBecomes(oc, "image-registry", 240, expectedStatus) o.Expect(err).NotTo(o.HaveOccurred()) defer oc.AsAdmin().Run("patch").Args("imagepruner/cluster", "-p", `{"spec":{"schedule":""}}`, "--type=merge").Execute() err = oc.AsAdmin().Run("patch").Args("imagepruner/cluster", "-p", `{"spec":{"schedule":"* * * * *"}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) imagePruneLog(oc, "", "the server could not find the requested resource (get deploymentconfigs.apps.openshift.io)") })
test case
openshift/openshift-tests-private
200da46f-95bc-4c48-b02e-bd4e84f11366
NonHyperShiftHOST-Author:wewang-High-66667-Install Image Registry operator after cluster install successfully
['"encoding/base64"', '"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/imageregistry_optional.go
g.It("NonHyperShiftHOST-Author:wewang-High-66667-Install Image Registry operator after cluster install successfully", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } g.By("Check image registry operator installed optionally") if !checkOptionalOperatorInstalled(oc, "ImageRegistry") { g.Skip("Skip for the test due to image registry not installed") } else { baseCapSet, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("clusterversion", "-o=jsonpath={.items[*].spec.capabilities.baselineCapabilitySet}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if baseCapSet != "None" { g.Skip("Skip for the test when registry is installed in default") } } g.By("Check serviceaccount and pull secret created after the project created") oc.SetupProject() secretName, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("sa/builder", "-o=jsonpath={.imagePullSecrets[0].name}", "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) dockerCfg, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("secret/"+secretName, "-o=jsonpath={.data.\\.dockercfg}", "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) credsTXT, err := base64.StdEncoding.DecodeString(dockerCfg) o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(strings.Contains(string(credsTXT), "image-registry.openshift-image-registry.svc:5000")).To(o.BeTrue()) g.By("Create a imagestream with pullthrough") err = oc.AsAdmin().WithoutNamespace().Run("tag").Args("registry.redhat.io/ubi8/httpd-24:latest", "httpd:latest", "--reference-policy=local", "--insecure", "--import-mode=PreserveOriginal", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = waitForAnImageStreamTag(oc, oc.Namespace(), "httpd", "latest") o.Expect(err).NotTo(o.HaveOccurred()) err = oc.AsAdmin().WithoutNamespace().Run("create").Args("deployment", "pull-test", "--image", "image-registry.openshift-image-registry.svc:5000/"+oc.Namespace()+"/httpd:latest", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) checkPodsRunningWithLabel(oc, oc.Namespace(), "app=pull-test", 1) })
test
openshift/openshift-tests-private
235e6661-1138-4dab-a950-b3cc0710ef2e
ociimage
import ( "os" "strings" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" container "github.com/openshift/openshift-tests-private/test/extended/util/container" e2e "k8s.io/kubernetes/test/e2e/framework" )
github.com/openshift/openshift-tests-private/test/extended/image_registry/ociimage.go
package imageregistry import ( "os" "strings" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" container "github.com/openshift/openshift-tests-private/test/extended/util/container" e2e "k8s.io/kubernetes/test/e2e/framework" ) var _ = g.Describe("[sig-imageregistry] Image_Registry", func() { defer g.GinkgoRecover() var ( oc = exutil.NewCLI("default-image-oci", exutil.KubeConfigPath()) manifestType = "application/vnd.oci.image.manifest.v1+json" ) g.BeforeEach(func() { if !checkOptionalOperatorInstalled(oc, "ImageRegistry") { g.Skip("Skip for the test due to image registry not installed") } }) // author: [email protected] g.It("ROSA-OSD_CCS-ARO-Author:wewang-VMonly-ConnectedOnly-High-36291-OCI image is supported by API server and image registry", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } var containerCLI = container.NewPodmanCLI() oc.SetupProject() g.By("Import an OCI image to internal registry") err := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("myimage", "--from", "quay.io/openshifttest/ociimage:multiarch", "--confirm", "--reference-policy=local", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = waitForAnImageStreamTag(oc, oc.Namespace(), "myimage", "latest") o.Expect(err).NotTo(o.HaveOccurred()) g.By("Expose route of internal registry") routeName := getRandomString() defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("route", routeName, "-n", "openshift-image-registry").Execute() regRoute := exposeRouteFromSVC(oc, "reencrypt", "openshift-image-registry", routeName, "image-registry") waitRouteReady(regRoute) g.By("Save the external registry auth with the specific token") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, oc.Namespace()) defer os.RemoveAll(authFile) o.Expect(err).NotTo(o.HaveOccurred()) imageInfo := regRoute + "/" + oc.Namespace() + "/myimage:latest" _, err = containerCLI.Run("pull").Args(imageInfo, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Display oci image info") output, err := containerCLI.Run("inspect").Args(imageInfo).Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(output, manifestType) { e2e.Failf("The internal registry image is not oci image") } }) }) var _ = g.Describe("[sig-imageregistry] Image_Registry Vmonly", func() { defer g.GinkgoRecover() var ( oc = exutil.NewCLI("default-image-oci-vm", exutil.KubeConfigPath()) ) // author: [email protected] g.It("ROSA-OSD_CCS-ARO-Author:wewang-ConnectedOnly-VMonly-High-37498-Push image with OCI format directly to the internal registry", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } var podmanCLI = container.NewPodmanCLI() containerCLI := podmanCLI ociImage := "quay.io/openshifttest/ociimage:multiarch" g.By("Expose route of internal registry") routeName := getRandomString() defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("route", routeName, "-n", "openshift-image-registry").Execute() regRoute := exposeRouteFromSVC(oc, "reencrypt", "openshift-image-registry", routeName, "image-registry") waitRouteReady(regRoute) oc.SetupProject() g.By("Save the external registry auth with the specific token") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, oc.Namespace()) defer os.RemoveAll(authFile) o.Expect(err).NotTo(o.HaveOccurred()) g.By("podman tag an image") output, err := containerCLI.Run("pull").Args(ociImage, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } defer containerCLI.RemoveImage(ociImage) output, err = containerCLI.Run("tag").Args(ociImage, regRoute+"/"+oc.Namespace()+"/myimage:latest").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } g.By(" Push it with oci format") out := regRoute + "/" + oc.Namespace() + "/myimage:latest" output, err = containerCLI.Run("push").Args("--format=oci", out, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } g.By("Check the manifest type") output, err = containerCLI.Run("inspect").Args(out).Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } defer containerCLI.RemoveImage(out) o.Expect(output).To(o.ContainSubstring("application/vnd.oci.image.manifest.v1+json")) }) // author: [email protected] g.It("ROSA-OSD_CCS-ARO-Author:wewang-ConnectedOnly-VMonly-Critical-35998-OCI images layers configs can be pruned completely", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } var podmanCLI = container.NewPodmanCLI() containerCLI := podmanCLI ociImage := "quay.io/openshifttest/ociimage:multiarch" g.By("Tag the image to internal registry") oc.SetupProject() err := oc.AsAdmin().WithoutNamespace().Run("tag").Args("--import-mode=PreserveOriginal", "--source=docker", ociImage, "35998-image:latest", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Check if new imagestreamtag created") err = waitForAnImageStreamTag(oc, oc.Namespace(), "35998-image", "latest") o.Expect(err).NotTo(o.HaveOccurred()) g.By("Log into the default route") routeName := getRandomString() defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("route", routeName, "-n", "openshift-image-registry").Execute() regRoute := exposeRouteFromSVC(oc, "reencrypt", "openshift-image-registry", routeName, "image-registry") waitRouteReady(regRoute) g.By("Save the external registry auth with the specific token") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, oc.Namespace()) defer os.RemoveAll(authFile) o.Expect(err).NotTo(o.HaveOccurred()) e2e.Logf("the file is %s", authFile) g.By("Pull internal image locally") imageInfo := regRoute + "/" + oc.Namespace() + "/35998-image:latest" output, err := containerCLI.Run("pull").Args(imageInfo, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } defer containerCLI.RemoveImage(imageInfo) g.By("Mark down the config/layer info of oci image") output, err = oc.WithoutNamespace().AsAdmin().Run("image").Args("info", ociImage, "--filter-by-os=linux/amd64").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } o.Expect(output).To(o.ContainSubstring("application/vnd.oci.image.manifest.v1+json")) o.Expect(output).To(o.ContainSubstring("Layers")) err = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-n", oc.Namespace(), "all", "--all").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Prune image") token, err := oc.Run("whoami").Args("-t").Output() o.Expect(err).NotTo(o.HaveOccurred()) output, err = oc.WithoutNamespace().AsAdmin().Run("adm").Args("prune", "images", "--keep-tag-revisions=0", "--keep-younger-than=0m", "--token="+token).Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring("Deleting layer link")) o.Expect(output).To(o.ContainSubstring("Deleting blob")) o.Expect(output).To(o.ContainSubstring("Deleting image")) }) })
package imageregistry
test case
openshift/openshift-tests-private
7682b7f1-1730-4400-b21b-e34eca574c8f
ROSA-OSD_CCS-ARO-Author:wewang-VMonly-ConnectedOnly-High-36291-OCI image is supported by API server and image registry
['"os"', '"strings"', 'container "github.com/openshift/openshift-tests-private/test/extended/util/container"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/ociimage.go
g.It("ROSA-OSD_CCS-ARO-Author:wewang-VMonly-ConnectedOnly-High-36291-OCI image is supported by API server and image registry", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } var containerCLI = container.NewPodmanCLI() oc.SetupProject() g.By("Import an OCI image to internal registry") err := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("myimage", "--from", "quay.io/openshifttest/ociimage:multiarch", "--confirm", "--reference-policy=local", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = waitForAnImageStreamTag(oc, oc.Namespace(), "myimage", "latest") o.Expect(err).NotTo(o.HaveOccurred()) g.By("Expose route of internal registry") routeName := getRandomString() defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("route", routeName, "-n", "openshift-image-registry").Execute() regRoute := exposeRouteFromSVC(oc, "reencrypt", "openshift-image-registry", routeName, "image-registry") waitRouteReady(regRoute) g.By("Save the external registry auth with the specific token") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, oc.Namespace()) defer os.RemoveAll(authFile) o.Expect(err).NotTo(o.HaveOccurred()) imageInfo := regRoute + "/" + oc.Namespace() + "/myimage:latest" _, err = containerCLI.Run("pull").Args(imageInfo, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Display oci image info") output, err := containerCLI.Run("inspect").Args(imageInfo).Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(output, manifestType) { e2e.Failf("The internal registry image is not oci image") } })
test case
openshift/openshift-tests-private
8e63b0c7-4016-42d4-bad1-226332ffeb5e
ROSA-OSD_CCS-ARO-Author:wewang-ConnectedOnly-VMonly-High-37498-Push image with OCI format directly to the internal registry
['"os"', 'container "github.com/openshift/openshift-tests-private/test/extended/util/container"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/ociimage.go
g.It("ROSA-OSD_CCS-ARO-Author:wewang-ConnectedOnly-VMonly-High-37498-Push image with OCI format directly to the internal registry", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } var podmanCLI = container.NewPodmanCLI() containerCLI := podmanCLI ociImage := "quay.io/openshifttest/ociimage:multiarch" g.By("Expose route of internal registry") routeName := getRandomString() defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("route", routeName, "-n", "openshift-image-registry").Execute() regRoute := exposeRouteFromSVC(oc, "reencrypt", "openshift-image-registry", routeName, "image-registry") waitRouteReady(regRoute) oc.SetupProject() g.By("Save the external registry auth with the specific token") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, oc.Namespace()) defer os.RemoveAll(authFile) o.Expect(err).NotTo(o.HaveOccurred()) g.By("podman tag an image") output, err := containerCLI.Run("pull").Args(ociImage, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } defer containerCLI.RemoveImage(ociImage) output, err = containerCLI.Run("tag").Args(ociImage, regRoute+"/"+oc.Namespace()+"/myimage:latest").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } g.By(" Push it with oci format") out := regRoute + "/" + oc.Namespace() + "/myimage:latest" output, err = containerCLI.Run("push").Args("--format=oci", out, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } g.By("Check the manifest type") output, err = containerCLI.Run("inspect").Args(out).Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } defer containerCLI.RemoveImage(out) o.Expect(output).To(o.ContainSubstring("application/vnd.oci.image.manifest.v1+json")) })
test case
openshift/openshift-tests-private
f942ce7f-2dd8-4c8d-9db9-154a5bf37931
ROSA-OSD_CCS-ARO-Author:wewang-ConnectedOnly-VMonly-Critical-35998-OCI images layers configs can be pruned completely
['"os"', 'container "github.com/openshift/openshift-tests-private/test/extended/util/container"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/ociimage.go
g.It("ROSA-OSD_CCS-ARO-Author:wewang-ConnectedOnly-VMonly-Critical-35998-OCI images layers configs can be pruned completely", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } var podmanCLI = container.NewPodmanCLI() containerCLI := podmanCLI ociImage := "quay.io/openshifttest/ociimage:multiarch" g.By("Tag the image to internal registry") oc.SetupProject() err := oc.AsAdmin().WithoutNamespace().Run("tag").Args("--import-mode=PreserveOriginal", "--source=docker", ociImage, "35998-image:latest", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Check if new imagestreamtag created") err = waitForAnImageStreamTag(oc, oc.Namespace(), "35998-image", "latest") o.Expect(err).NotTo(o.HaveOccurred()) g.By("Log into the default route") routeName := getRandomString() defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("route", routeName, "-n", "openshift-image-registry").Execute() regRoute := exposeRouteFromSVC(oc, "reencrypt", "openshift-image-registry", routeName, "image-registry") waitRouteReady(regRoute) g.By("Save the external registry auth with the specific token") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, oc.Namespace()) defer os.RemoveAll(authFile) o.Expect(err).NotTo(o.HaveOccurred()) e2e.Logf("the file is %s", authFile) g.By("Pull internal image locally") imageInfo := regRoute + "/" + oc.Namespace() + "/35998-image:latest" output, err := containerCLI.Run("pull").Args(imageInfo, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } defer containerCLI.RemoveImage(imageInfo) g.By("Mark down the config/layer info of oci image") output, err = oc.WithoutNamespace().AsAdmin().Run("image").Args("info", ociImage, "--filter-by-os=linux/amd64").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } o.Expect(output).To(o.ContainSubstring("application/vnd.oci.image.manifest.v1+json")) o.Expect(output).To(o.ContainSubstring("Layers")) err = oc.AsAdmin().WithoutNamespace().Run("delete").Args("-n", oc.Namespace(), "all", "--all").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Prune image") token, err := oc.Run("whoami").Args("-t").Output() o.Expect(err).NotTo(o.HaveOccurred()) output, err = oc.WithoutNamespace().AsAdmin().Run("adm").Args("prune", "images", "--keep-tag-revisions=0", "--keep-younger-than=0m", "--token="+token).Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring("Deleting layer link")) o.Expect(output).To(o.ContainSubstring("Deleting blob")) o.Expect(output).To(o.ContainSubstring("Deleting image")) })
test
openshift/openshift-tests-private
5054f51c-f691-4150-a946-2eea692c9974
registry_upgrade
import ( "context" "os" "strings" "time" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" container "github.com/openshift/openshift-tests-private/test/extended/util/container" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" e2e "k8s.io/kubernetes/test/e2e/framework" )
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
package imageregistry import ( "context" "os" "strings" "time" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" container "github.com/openshift/openshift-tests-private/test/extended/util/container" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" e2e "k8s.io/kubernetes/test/e2e/framework" ) var _ = g.Describe("[sig-imageregistry] Image_Registry", func() { defer g.GinkgoRecover() var ( oc = exutil.NewCLI("default-registry-upgrade", exutil.KubeConfigPath()) ) g.BeforeEach(func() { if !checkOptionalOperatorInstalled(oc, "ImageRegistry") { g.Skip("Skip for the test due to image registry not installed") } }) // author: [email protected] g.It("NonHyperShiftHOST-NonPreRelease-PreChkUpgrade-Author:wewang-High-26401-Upgrade cluster with insecureRegistries and blockedRegistries defined prepare [Disruptive]", func() { SkipDnsFailure(oc) var ( ns = "26401-upgrade-ns" mc = machineConfig{ name: "", pool: "worker", source: "", path: "", template: "", } ) g.By("Create two registries") err := oc.AsAdmin().WithoutNamespace().Run("create").Args("namespace", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) blockedRoute := setSecureRegistryWithoutAuth(oc, ns, "blockedreg", "quay.io/openshifttest/registry@sha256:1106aedc1b2e386520bc2fb797d9a7af47d651db31d8e7ab472f2352da37d1b3", "5000") insecuredRoute := setSecureRegistryWithoutAuth(oc, ns, "insecuredreg", "quay.io/openshifttest/registry@sha256:1106aedc1b2e386520bc2fb797d9a7af47d651db31d8e7ab472f2352da37d1b3", "5000") blockedImage := blockedRoute + "/" + ns + "/blockedimage:latest" insecuredImage := insecuredRoute + "/" + ns + "/insecuredimage:latest" g.By("Push image to insecured registries") checkDnsCO(oc) waitRouteReady(insecuredImage) err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", insecuredImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Without --insecure the imagestream will import fail") insecuredOut, _ := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("insecured-firstis:latest", "--from="+insecuredImage, "--confirm", "-n", ns).Output() o.Expect(insecuredOut).To(o.ContainSubstring("x509")) g.By("Add insecureRegistries and blockedRegistries to image.config") err = oc.AsAdmin().Run("patch").Args("images.config.openshift.io/cluster", "-p", `{"spec":{"registrySources":{"blockedRegistries": ["`+blockedRoute+`"],"insecureRegistries": ["`+insecuredRoute+`"]}}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) // image.conf.spec.registrySources will restart crio to apply change to every node // Need ensure master and worker update completed mc.waitForMCPComplete(oc) mc.pool = "master" mc.waitForMCPComplete(oc) g.By("Push images to two registries") checkDnsCO(oc) waitRouteReady(blockedImage) err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", blockedImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) // worker restart, data is removed, need mirror again err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", insecuredImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Can't import image from blocked registry") blockedOut, _ := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("blocked-firstis:latest", "--from="+blockedImage, "--reference-policy=local", "--import-mode=PreserveOriginal", "--insecure", "--confirm", "-n", ns).Output() o.Expect(blockedOut).To(o.ContainSubstring(blockedRoute + " blocked")) g.By("Could import image from the insecured registry without --insecure") insecuredOut, insecuredErr := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("insecured-secondis:latest", "--from="+insecuredImage, "--import-mode=PreserveOriginal", "--confirm", "-n", ns).Output() o.Expect(insecuredErr).NotTo(o.HaveOccurred()) o.Expect(insecuredOut).NotTo(o.ContainSubstring("x509")) }) // author: [email protected] g.It("NonHyperShiftHOST-NonPreRelease-PstChkUpgrade-Author:wewang-High-26401-Upgrade cluster with insecureRegistries and blockedRegistries defined after upgrade [Disruptive]", func() { g.By("Setup upgrade info") ns := "26401-upgrade-ns" defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("namespace", ns, "--ignore-not-found").Execute() blockedRoute, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("route", "blockedreg", "-n", ns, "-o=jsonpath={.spec.host}").Output() o.Expect(err).NotTo(o.HaveOccurred()) insecuredRoute, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("route", "insecuredreg", "-n", ns, "-o=jsonpath={.spec.host}").Output() o.Expect(err).NotTo(o.HaveOccurred()) blockedImage := blockedRoute + "/" + ns + "/blockedimage:latest" insecuredImage := insecuredRoute + "/" + ns + "/insecuredimage:latest" g.By("Push images to two registries") // After upgrade the reigstry pods restarted, the data should be lost err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", blockedImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", insecuredImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Can't import image from blocked registry") blockedOut, _ := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("blocked-secondis:latest", "--from="+blockedImage, "--reference-policy=local", "--insecure", "--confirm", "--import-mode=PreserveOriginal", "-n", ns).Output() o.Expect(blockedOut).To(o.ContainSubstring(blockedRoute + " blocked")) g.By("Could import image from the insecured registry without --insecure") insecuredOut, insecuredErr := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("insecured-thirdis:latest", "--from="+insecuredImage, "--confirm", "--import-mode=PreserveOriginal", "-n", ns).Output() o.Expect(insecuredErr).NotTo(o.HaveOccurred()) o.Expect(insecuredOut).NotTo(o.ContainSubstring("x509")) }) // author: [email protected] g.It("NonHyperShiftHOST-NonPreRelease-PstChkUpgrade-Author:wewang-High-41400- Users providing custom AWS tags are set with bucket creation after upgrade", func() { g.By("Check platforms") exutil.SkipIfPlatformTypeNot(oc, "AWS") g.By("Check the cluster is with resourceTags") output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("infrastructure.config.openshift.io", "-o=jsonpath={..status.platformStatus.aws}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(output, "resourceTags") { g.Skip("Skip for no resourceTags") } g.By("Get bucket name") bucket, _ := oc.AsAdmin().Run("get").Args("config.image", "-o=jsonpath={..spec.storage.s3.bucket}").Output() o.Expect(bucket).NotTo(o.BeEmpty()) g.By("Check the tags") aws := getAWSClient(oc) tag, err := awsGetBucketTagging(aws, bucket) o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(tag).To(o.ContainSubstring("customTag")) o.Expect(tag).To(o.ContainSubstring("installer-qe")) }) // author: [email protected] g.It("NonPreRelease-PstChkUpgrade-Author:xiuwang-Medium-45346-Payload imagestream new tags should properly updated during cluster upgrade prepare", func() { g.By("Check payload imagestream") output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("is", "-n", "openshift", "-l", "samples.operator.openshift.io/managed!=true", "-o=jsonpath={.items[*].metadata.name}").Output() o.Expect(err).NotTo(o.HaveOccurred()) plimage := strings.Split(output, " ") for _, isname := range plimage { output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("is", isname, "-n", "openshift", "-o=jsonpath={.spec.tags[*].name}").Output() o.Expect(err).NotTo(o.HaveOccurred()) tagname := strings.Split(output, " ") for _, tname := range tagname { e2e.Logf("tag is %s", tname) if tname == "" { e2e.Failf("The imagestream %s is broken after upgrade", isname) } } } }) // author: [email protected] g.It("NonHyperShiftHOST-NonPreRelease-PreChkUpgrade-Author:xiuwang-Critical-24345-Set proxy in Image-registry-operator before upgrade", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } g.By("Check if it's a proxy cluster") httpProxy, httpsProxy, noProxy := saveGlobalProxy(oc) if !strings.Contains(httpProxy, "http") { g.Skip("Skip for non-proxy platform") } g.By("Check if registry operator degraded") registryDegrade := checkRegistryDegraded(oc) if registryDegrade { e2e.Failf("Image registry is degraded") } g.By("Set image-registry proxy setting") err := oc.WithoutNamespace().AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"proxy":{"http": "`+httpProxy+`","https":"`+httpsProxy+`","noProxy":"`+noProxy+`"}}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.PollImmediate(10*time.Second, 2*time.Minute, func() (bool, error) { registryDegrade := checkRegistryDegraded(oc) if registryDegrade { e2e.Logf("wait for next round") return false, nil } return true, nil }) exutil.AssertWaitPollNoErr(err, "Image registry is degraded") oc.SetupProject() err = oc.AsAdmin().WithoutNamespace().Run("new-build").Args("-D", "FROM quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", "--to=prepare-24345", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = exutil.WaitForABuild(oc.BuildClient().BuildV1().Builds(oc.Namespace()), "prepare-24345-1", nil, nil, nil) exutil.AssertWaitPollNoErr(err, "build is not complete") err = waitForAnImageStreamTag(oc, oc.Namespace(), "prepare-24345", "latest") o.Expect(err).NotTo(o.HaveOccurred()) imagename := "image-registry.openshift-image-registry.svc:5000/" + oc.Namespace() + "/prepare-24345:latest" err = oc.AsAdmin().WithoutNamespace().Run("run").Args("prepare-24345", "--image", imagename, `--overrides={"spec":{"securityContext":{"runAsNonRoot":true,"seccompProfile":{"type":"RuntimeDefault"}}}}`, "-n", oc.Namespace(), "--command", "--", "/bin/sleep", "120").Execute() o.Expect(err).NotTo(o.HaveOccurred()) errWait := wait.Poll(30*time.Second, 6*time.Minute, func() (bool, error) { podList, _ := oc.AdminKubeClient().CoreV1().Pods(oc.Namespace()).List(context.Background(), metav1.ListOptions{LabelSelector: "run=prepare-24345"}) for _, pod := range podList.Items { if pod.Status.Phase != corev1.PodRunning { e2e.Logf("Continue to next round") return false, nil } } return true, nil }) exutil.AssertWaitPollNoErr(errWait, "Pod can't be running") }) // author: [email protected] g.It("NonHyperShiftHOST-NonPreRelease-PstChkUpgrade-Author:xiuwang-Critical-24345-Set proxy in Image-registry-operator after upgrade", func() { g.By("Check if it's a proxy cluster") httpProxy, httpsProxy, noProxy := saveGlobalProxy(oc) if !strings.Contains(httpProxy, "http") { g.Skip("Skip for non-proxy platform") } g.By("Check if registry operator degraded") registryDegrade := checkRegistryDegraded(oc) if registryDegrade { e2e.Failf("Image registry is degraded") } g.By("Check image-registry proxy setting") Output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("configs.imageregistry/cluster", "-o=jsonpath={.spec.proxy}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(Output, httpProxy) || !strings.Contains(Output, httpsProxy) || !strings.Contains(Output, noProxy) { e2e.Failf("http proxy is not same") } oc.SetupProject() checkRegistryFunctionFine(oc, "check-24345", oc.Namespace()) }) g.It("NonPreRelease-PreChkUpgrade-PstChkUpgrade-Author:xiuwang-Medium-22678-Check image-registry operator upgrade", func() { g.By("image-registry operator should be avaliable") expectedStatus1 := map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} err := waitCoBecomes(oc, "image-registry", 240, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) }) // author: [email protected] g.It("NonHyperShiftHOST-NonPreRelease-Longduration-VMonly-PreChkUpgrade-Author:wewang-High-71533-Upgrade cluster with pull Internal Registry custom images successfully prepare[Disruptive]", func() { SkipDnsFailure(oc) var ( podmanCLI = container.NewPodmanCLI() ns = "71533-upgrade-ns" expectedStatus1 = map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} ) containerCLI := podmanCLI oriImage := "quay.io/openshifttest/ociimage:multiarch" err := oc.AsAdmin().WithoutNamespace().Run("create").Args("namespace", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("set default route of registry") defroute, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("route", "-n", "openshift-image-registry").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(defroute, "No resources found") { defer func() { restoreRouteExposeRegistry(oc) err := waitCoBecomes(oc, "image-registry", 60, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "openshift-apiserver", 480, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "kube-apiserver", 600, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) }() createRouteExposeRegistry(oc) err = waitCoBecomes(oc, "image-registry", 60, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "openshift-apiserver", 480, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "kube-apiserver", 600, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) } regRoute := getRegistryDefaultRoute(oc) checkDnsCO(oc) waitRouteReady(regRoute) g.By("get authfile") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, ns) o.Expect(err).NotTo(o.HaveOccurred()) defer os.RemoveAll(authFile) g.By("podman tag an image") output, err := containerCLI.Run("pull").Args(oriImage, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } out := regRoute + "/" + ns + "/myimage:latest" output, err = containerCLI.Run("tag").Args(oriImage, out).Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } g.By(" Push the image to internal registry") output, err = containerCLI.Run("push").Args(out, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } o.Expect(output).To(o.ContainSubstring("Writing manifest to image destination")) containerCLI.RemoveImage(out) g.By("Pull the image from internal registry") output, err = containerCLI.Run("pull").Args(out, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } o.Expect(output).To(o.ContainSubstring("Writing manifest to image destination")) g.By("Check the image is in local") defer containerCLI.RemoveImage(out) output, err = containerCLI.Run("images").Args("-n").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring(strings.Replace(out, ":latest", "", -1))) }) // author: [email protected] g.It("NonHyperShiftHOST-NonPreRelease-VMonly-PstChkUpgrade-Author:wewang-Critical-71533-Upgrade cluster with pull Internal Registry custom images successfully after upgrade[Disruptive]", func() { SkipDnsFailure(oc) var ( podmanCLI = container.NewPodmanCLI() ns = "71533-upgrade-ns" expectedStatus1 = map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} ) _, err := oc.AdminKubeClient().CoreV1().Namespaces().Get(context.Background(), "71533-upgrade-ns", metav1.GetOptions{}) if err != nil { if apierrors.IsNotFound(err) { g.Skip("The project 71533-upgrade-ns is not found, skip test") } else { o.Expect(err).NotTo(o.HaveOccurred()) } } defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("namespace", ns, "--ignore-not-found").Execute() containerCLI := podmanCLI g.By("set default route of registry") defroute, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("route", "-n", "openshift-image-registry").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(defroute, "No resources found") { defer func() { restoreRouteExposeRegistry(oc) err := waitCoBecomes(oc, "image-registry", 60, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "openshift-apiserver", 480, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "kube-apiserver", 600, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) }() createRouteExposeRegistry(oc) err = waitCoBecomes(oc, "image-registry", 60, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "openshift-apiserver", 480, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "kube-apiserver", 600, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) } regRoute := getRegistryDefaultRoute(oc) checkDnsCO(oc) waitRouteReady(regRoute) g.By("get authfile") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, ns) o.Expect(err).NotTo(o.HaveOccurred()) defer os.RemoveAll(authFile) g.By(" Pull existed images from internal registry") out := regRoute + "/" + ns + "/myimage:latest" output, err := containerCLI.Run("pull").Args(out, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } g.By("Check the image is in local") defer containerCLI.RemoveImage(out) output, err = containerCLI.Run("images").Args("-n").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring(strings.Replace(out, ":latest", "", -1))) }) })
package imageregistry
test case
openshift/openshift-tests-private
b00e4300-f486-4748-a209-49ba275e43be
NonHyperShiftHOST-NonPreRelease-PreChkUpgrade-Author:wewang-High-26401-Upgrade cluster with insecureRegistries and blockedRegistries defined prepare [Disruptive]
['"os"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
g.It("NonHyperShiftHOST-NonPreRelease-PreChkUpgrade-Author:wewang-High-26401-Upgrade cluster with insecureRegistries and blockedRegistries defined prepare [Disruptive]", func() { SkipDnsFailure(oc) var ( ns = "26401-upgrade-ns" mc = machineConfig{ name: "", pool: "worker", source: "", path: "", template: "", } ) g.By("Create two registries") err := oc.AsAdmin().WithoutNamespace().Run("create").Args("namespace", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) blockedRoute := setSecureRegistryWithoutAuth(oc, ns, "blockedreg", "quay.io/openshifttest/registry@sha256:1106aedc1b2e386520bc2fb797d9a7af47d651db31d8e7ab472f2352da37d1b3", "5000") insecuredRoute := setSecureRegistryWithoutAuth(oc, ns, "insecuredreg", "quay.io/openshifttest/registry@sha256:1106aedc1b2e386520bc2fb797d9a7af47d651db31d8e7ab472f2352da37d1b3", "5000") blockedImage := blockedRoute + "/" + ns + "/blockedimage:latest" insecuredImage := insecuredRoute + "/" + ns + "/insecuredimage:latest" g.By("Push image to insecured registries") checkDnsCO(oc) waitRouteReady(insecuredImage) err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", insecuredImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Without --insecure the imagestream will import fail") insecuredOut, _ := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("insecured-firstis:latest", "--from="+insecuredImage, "--confirm", "-n", ns).Output() o.Expect(insecuredOut).To(o.ContainSubstring("x509")) g.By("Add insecureRegistries and blockedRegistries to image.config") err = oc.AsAdmin().Run("patch").Args("images.config.openshift.io/cluster", "-p", `{"spec":{"registrySources":{"blockedRegistries": ["`+blockedRoute+`"],"insecureRegistries": ["`+insecuredRoute+`"]}}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) // image.conf.spec.registrySources will restart crio to apply change to every node // Need ensure master and worker update completed mc.waitForMCPComplete(oc) mc.pool = "master" mc.waitForMCPComplete(oc) g.By("Push images to two registries") checkDnsCO(oc) waitRouteReady(blockedImage) err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", blockedImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) // worker restart, data is removed, need mirror again err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", insecuredImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Can't import image from blocked registry") blockedOut, _ := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("blocked-firstis:latest", "--from="+blockedImage, "--reference-policy=local", "--import-mode=PreserveOriginal", "--insecure", "--confirm", "-n", ns).Output() o.Expect(blockedOut).To(o.ContainSubstring(blockedRoute + " blocked")) g.By("Could import image from the insecured registry without --insecure") insecuredOut, insecuredErr := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("insecured-secondis:latest", "--from="+insecuredImage, "--import-mode=PreserveOriginal", "--confirm", "-n", ns).Output() o.Expect(insecuredErr).NotTo(o.HaveOccurred()) o.Expect(insecuredOut).NotTo(o.ContainSubstring("x509")) })
test case
openshift/openshift-tests-private
4336c209-7fa7-4cf1-934c-f96e72d72069
NonHyperShiftHOST-NonPreRelease-PstChkUpgrade-Author:wewang-High-26401-Upgrade cluster with insecureRegistries and blockedRegistries defined after upgrade [Disruptive]
['"os"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
g.It("NonHyperShiftHOST-NonPreRelease-PstChkUpgrade-Author:wewang-High-26401-Upgrade cluster with insecureRegistries and blockedRegistries defined after upgrade [Disruptive]", func() { g.By("Setup upgrade info") ns := "26401-upgrade-ns" defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("namespace", ns, "--ignore-not-found").Execute() blockedRoute, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("route", "blockedreg", "-n", ns, "-o=jsonpath={.spec.host}").Output() o.Expect(err).NotTo(o.HaveOccurred()) insecuredRoute, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("route", "insecuredreg", "-n", ns, "-o=jsonpath={.spec.host}").Output() o.Expect(err).NotTo(o.HaveOccurred()) blockedImage := blockedRoute + "/" + ns + "/blockedimage:latest" insecuredImage := insecuredRoute + "/" + ns + "/insecuredimage:latest" g.By("Push images to two registries") // After upgrade the reigstry pods restarted, the data should be lost err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", blockedImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = oc.AsAdmin().WithoutNamespace().Run("image").Args("mirror", "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", insecuredImage, "--insecure", "--keep-manifest-list=true", "--filter-by-os=.*").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Can't import image from blocked registry") blockedOut, _ := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("blocked-secondis:latest", "--from="+blockedImage, "--reference-policy=local", "--insecure", "--confirm", "--import-mode=PreserveOriginal", "-n", ns).Output() o.Expect(blockedOut).To(o.ContainSubstring(blockedRoute + " blocked")) g.By("Could import image from the insecured registry without --insecure") insecuredOut, insecuredErr := oc.AsAdmin().WithoutNamespace().Run("import-image").Args("insecured-thirdis:latest", "--from="+insecuredImage, "--confirm", "--import-mode=PreserveOriginal", "-n", ns).Output() o.Expect(insecuredErr).NotTo(o.HaveOccurred()) o.Expect(insecuredOut).NotTo(o.ContainSubstring("x509")) })
test case
openshift/openshift-tests-private
f57863d2-dfd0-4dc1-8209-e0c21eccf882
NonHyperShiftHOST-NonPreRelease-PstChkUpgrade-Author:wewang-High-41400- Users providing custom AWS tags are set with bucket creation after upgrade
['"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
g.It("NonHyperShiftHOST-NonPreRelease-PstChkUpgrade-Author:wewang-High-41400- Users providing custom AWS tags are set with bucket creation after upgrade", func() { g.By("Check platforms") exutil.SkipIfPlatformTypeNot(oc, "AWS") g.By("Check the cluster is with resourceTags") output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("infrastructure.config.openshift.io", "-o=jsonpath={..status.platformStatus.aws}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(output, "resourceTags") { g.Skip("Skip for no resourceTags") } g.By("Get bucket name") bucket, _ := oc.AsAdmin().Run("get").Args("config.image", "-o=jsonpath={..spec.storage.s3.bucket}").Output() o.Expect(bucket).NotTo(o.BeEmpty()) g.By("Check the tags") aws := getAWSClient(oc) tag, err := awsGetBucketTagging(aws, bucket) o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(tag).To(o.ContainSubstring("customTag")) o.Expect(tag).To(o.ContainSubstring("installer-qe")) })
test case
openshift/openshift-tests-private
a28b38ac-8b62-43cb-a152-d888d61e5097
NonPreRelease-PstChkUpgrade-Author:xiuwang-Medium-45346-Payload imagestream new tags should properly updated during cluster upgrade prepare
['"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
g.It("NonPreRelease-PstChkUpgrade-Author:xiuwang-Medium-45346-Payload imagestream new tags should properly updated during cluster upgrade prepare", func() { g.By("Check payload imagestream") output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("is", "-n", "openshift", "-l", "samples.operator.openshift.io/managed!=true", "-o=jsonpath={.items[*].metadata.name}").Output() o.Expect(err).NotTo(o.HaveOccurred()) plimage := strings.Split(output, " ") for _, isname := range plimage { output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("is", isname, "-n", "openshift", "-o=jsonpath={.spec.tags[*].name}").Output() o.Expect(err).NotTo(o.HaveOccurred()) tagname := strings.Split(output, " ") for _, tname := range tagname { e2e.Logf("tag is %s", tname) if tname == "" { e2e.Failf("The imagestream %s is broken after upgrade", isname) } } } })
test case
openshift/openshift-tests-private
8127bc78-7169-446e-aafe-7042b2e747a6
NonHyperShiftHOST-NonPreRelease-PreChkUpgrade-Author:xiuwang-Critical-24345-Set proxy in Image-registry-operator before upgrade
['"context"', '"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
g.It("NonHyperShiftHOST-NonPreRelease-PreChkUpgrade-Author:xiuwang-Critical-24345-Set proxy in Image-registry-operator before upgrade", func() { if !checkOptionalOperatorInstalled(oc, "Build") { g.Skip("Skip for the test due to Build not installed") } g.By("Check if it's a proxy cluster") httpProxy, httpsProxy, noProxy := saveGlobalProxy(oc) if !strings.Contains(httpProxy, "http") { g.Skip("Skip for non-proxy platform") } g.By("Check if registry operator degraded") registryDegrade := checkRegistryDegraded(oc) if registryDegrade { e2e.Failf("Image registry is degraded") } g.By("Set image-registry proxy setting") err := oc.WithoutNamespace().AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"proxy":{"http": "`+httpProxy+`","https":"`+httpsProxy+`","noProxy":"`+noProxy+`"}}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.PollImmediate(10*time.Second, 2*time.Minute, func() (bool, error) { registryDegrade := checkRegistryDegraded(oc) if registryDegrade { e2e.Logf("wait for next round") return false, nil } return true, nil }) exutil.AssertWaitPollNoErr(err, "Image registry is degraded") oc.SetupProject() err = oc.AsAdmin().WithoutNamespace().Run("new-build").Args("-D", "FROM quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", "--to=prepare-24345", "-n", oc.Namespace()).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = exutil.WaitForABuild(oc.BuildClient().BuildV1().Builds(oc.Namespace()), "prepare-24345-1", nil, nil, nil) exutil.AssertWaitPollNoErr(err, "build is not complete") err = waitForAnImageStreamTag(oc, oc.Namespace(), "prepare-24345", "latest") o.Expect(err).NotTo(o.HaveOccurred()) imagename := "image-registry.openshift-image-registry.svc:5000/" + oc.Namespace() + "/prepare-24345:latest" err = oc.AsAdmin().WithoutNamespace().Run("run").Args("prepare-24345", "--image", imagename, `--overrides={"spec":{"securityContext":{"runAsNonRoot":true,"seccompProfile":{"type":"RuntimeDefault"}}}}`, "-n", oc.Namespace(), "--command", "--", "/bin/sleep", "120").Execute() o.Expect(err).NotTo(o.HaveOccurred()) errWait := wait.Poll(30*time.Second, 6*time.Minute, func() (bool, error) { podList, _ := oc.AdminKubeClient().CoreV1().Pods(oc.Namespace()).List(context.Background(), metav1.ListOptions{LabelSelector: "run=prepare-24345"}) for _, pod := range podList.Items { if pod.Status.Phase != corev1.PodRunning { e2e.Logf("Continue to next round") return false, nil } } return true, nil }) exutil.AssertWaitPollNoErr(errWait, "Pod can't be running") })
test case
openshift/openshift-tests-private
25c07526-97e8-4314-8706-79a0a5806deb
NonHyperShiftHOST-NonPreRelease-PstChkUpgrade-Author:xiuwang-Critical-24345-Set proxy in Image-registry-operator after upgrade
['"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
g.It("NonHyperShiftHOST-NonPreRelease-PstChkUpgrade-Author:xiuwang-Critical-24345-Set proxy in Image-registry-operator after upgrade", func() { g.By("Check if it's a proxy cluster") httpProxy, httpsProxy, noProxy := saveGlobalProxy(oc) if !strings.Contains(httpProxy, "http") { g.Skip("Skip for non-proxy platform") } g.By("Check if registry operator degraded") registryDegrade := checkRegistryDegraded(oc) if registryDegrade { e2e.Failf("Image registry is degraded") } g.By("Check image-registry proxy setting") Output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("configs.imageregistry/cluster", "-o=jsonpath={.spec.proxy}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(Output, httpProxy) || !strings.Contains(Output, httpsProxy) || !strings.Contains(Output, noProxy) { e2e.Failf("http proxy is not same") } oc.SetupProject() checkRegistryFunctionFine(oc, "check-24345", oc.Namespace()) })
test case
openshift/openshift-tests-private
10ae8136-df68-4beb-8a15-e038f6041611
NonPreRelease-PreChkUpgrade-PstChkUpgrade-Author:xiuwang-Medium-22678-Check image-registry operator upgrade
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
g.It("NonPreRelease-PreChkUpgrade-PstChkUpgrade-Author:xiuwang-Medium-22678-Check image-registry operator upgrade", func() { g.By("image-registry operator should be avaliable") expectedStatus1 := map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} err := waitCoBecomes(oc, "image-registry", 240, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) })
test case
openshift/openshift-tests-private
d17f0660-98d9-41f4-a9d0-7bce1b7accf1
NonHyperShiftHOST-NonPreRelease-Longduration-VMonly-PreChkUpgrade-Author:wewang-High-71533-Upgrade cluster with pull Internal Registry custom images successfully prepare[Disruptive]
['"os"', '"strings"', 'container "github.com/openshift/openshift-tests-private/test/extended/util/container"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
g.It("NonHyperShiftHOST-NonPreRelease-Longduration-VMonly-PreChkUpgrade-Author:wewang-High-71533-Upgrade cluster with pull Internal Registry custom images successfully prepare[Disruptive]", func() { SkipDnsFailure(oc) var ( podmanCLI = container.NewPodmanCLI() ns = "71533-upgrade-ns" expectedStatus1 = map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} ) containerCLI := podmanCLI oriImage := "quay.io/openshifttest/ociimage:multiarch" err := oc.AsAdmin().WithoutNamespace().Run("create").Args("namespace", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("set default route of registry") defroute, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("route", "-n", "openshift-image-registry").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(defroute, "No resources found") { defer func() { restoreRouteExposeRegistry(oc) err := waitCoBecomes(oc, "image-registry", 60, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "openshift-apiserver", 480, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "kube-apiserver", 600, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) }() createRouteExposeRegistry(oc) err = waitCoBecomes(oc, "image-registry", 60, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "openshift-apiserver", 480, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "kube-apiserver", 600, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) } regRoute := getRegistryDefaultRoute(oc) checkDnsCO(oc) waitRouteReady(regRoute) g.By("get authfile") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, ns) o.Expect(err).NotTo(o.HaveOccurred()) defer os.RemoveAll(authFile) g.By("podman tag an image") output, err := containerCLI.Run("pull").Args(oriImage, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } out := regRoute + "/" + ns + "/myimage:latest" output, err = containerCLI.Run("tag").Args(oriImage, out).Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } g.By(" Push the image to internal registry") output, err = containerCLI.Run("push").Args(out, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } o.Expect(output).To(o.ContainSubstring("Writing manifest to image destination")) containerCLI.RemoveImage(out) g.By("Pull the image from internal registry") output, err = containerCLI.Run("pull").Args(out, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } o.Expect(output).To(o.ContainSubstring("Writing manifest to image destination")) g.By("Check the image is in local") defer containerCLI.RemoveImage(out) output, err = containerCLI.Run("images").Args("-n").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring(strings.Replace(out, ":latest", "", -1))) })
test case
openshift/openshift-tests-private
d4baac75-3dc7-40fe-a6d4-fdf772bfa76d
NonHyperShiftHOST-NonPreRelease-VMonly-PstChkUpgrade-Author:wewang-Critical-71533-Upgrade cluster with pull Internal Registry custom images successfully after upgrade[Disruptive]
['"context"', '"os"', '"strings"', 'container "github.com/openshift/openshift-tests-private/test/extended/util/container"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/registry_upgrade.go
g.It("NonHyperShiftHOST-NonPreRelease-VMonly-PstChkUpgrade-Author:wewang-Critical-71533-Upgrade cluster with pull Internal Registry custom images successfully after upgrade[Disruptive]", func() { SkipDnsFailure(oc) var ( podmanCLI = container.NewPodmanCLI() ns = "71533-upgrade-ns" expectedStatus1 = map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} ) _, err := oc.AdminKubeClient().CoreV1().Namespaces().Get(context.Background(), "71533-upgrade-ns", metav1.GetOptions{}) if err != nil { if apierrors.IsNotFound(err) { g.Skip("The project 71533-upgrade-ns is not found, skip test") } else { o.Expect(err).NotTo(o.HaveOccurred()) } } defer oc.AsAdmin().WithoutNamespace().Run("delete").Args("namespace", ns, "--ignore-not-found").Execute() containerCLI := podmanCLI g.By("set default route of registry") defroute, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("route", "-n", "openshift-image-registry").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(defroute, "No resources found") { defer func() { restoreRouteExposeRegistry(oc) err := waitCoBecomes(oc, "image-registry", 60, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "openshift-apiserver", 480, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "kube-apiserver", 600, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) }() createRouteExposeRegistry(oc) err = waitCoBecomes(oc, "image-registry", 60, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "openshift-apiserver", 480, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "kube-apiserver", 600, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) } regRoute := getRegistryDefaultRoute(oc) checkDnsCO(oc) waitRouteReady(regRoute) g.By("get authfile") authFile, err := saveImageRegistryAuth(oc, "builder", regRoute, ns) o.Expect(err).NotTo(o.HaveOccurred()) defer os.RemoveAll(authFile) g.By(" Pull existed images from internal registry") out := regRoute + "/" + ns + "/myimage:latest" output, err := containerCLI.Run("pull").Args(out, "--authfile="+authFile, "--tls-verify=false").Output() o.Expect(err).NotTo(o.HaveOccurred()) if err != nil { e2e.Logf(output) } g.By("Check the image is in local") defer containerCLI.RemoveImage(out) output, err = containerCLI.Run("images").Args("-n").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring(strings.Replace(out, ":latest", "", -1))) })
file
openshift/openshift-tests-private
bcf469e9-f3ec-4ea4-ad80-d8a97f00fcaf
util
import ( "context" "encoding/base64" "encoding/json" "fmt" "io/ioutil" "math/rand" "os" "os/exec" "path/filepath" "reflect" "regexp" "strconv" "strings" "time" "github.com/tidwall/gjson" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/s3" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" "github.com/prometheus/common/model" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" e2e "k8s.io/kubernetes/test/e2e/framework" e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output" )
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
package imageregistry import ( "context" "encoding/base64" "encoding/json" "fmt" "io/ioutil" "math/rand" "os" "os/exec" "path/filepath" "reflect" "regexp" "strconv" "strings" "time" "github.com/tidwall/gjson" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/s3" g "github.com/onsi/ginkgo/v2" o "github.com/onsi/gomega" exutil "github.com/openshift/openshift-tests-private/test/extended/util" "github.com/prometheus/common/model" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" e2e "k8s.io/kubernetes/test/e2e/framework" e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output" ) const ( asAdmin = true withoutNamespace = true contain = false ok = true pvcType = "pvc" swiftType = "swift" emptyDir = "emptyDir" ) type prometheusResponse struct { Status string `json:"status"` Error string `json:"error"` Data prometheusResponseData `json:"data"` } type prometheusResponseData struct { ResultType string `json:"resultType"` Result model.Vector `json:"result"` } // [email protected] for OCP-22056 type prometheusImageregistryQueryHTTP struct { Data struct { Result []struct { Metric struct { Name string `json:"__name__"` Container string `json:"container"` Endpoint string `json:"endpoint"` Instance string `json:"instance"` Job string `json:"job"` Namespace string `json:"namespace"` Pod string `json:"pod"` Service string `json:"service"` } `json:"metric"` Value []interface{} `json:"value"` } `json:"result"` ResultType string `json:"resultType"` } `json:"data"` Status string `json:"status"` } func gatherMetricsResult(oc *exutil.CLI, token, prometheusURL string, metrics []string) map[string]int { var ( data prometheusImageregistryQueryHTTP err error l int msg string result = make(map[string]int) ) for _, query := range metrics { prometheusURLQuery := fmt.Sprintf("%v/query?query=%v", prometheusURL, query) err = wait.PollUntilContextTimeout(context.TODO(), 10*time.Second, 30*time.Second, false, func(ctx context.Context) (bool, error) { msg, _, err = oc.AsAdmin().WithoutNamespace().Run("exec").Args("-n", "openshift-monitoring", "-c", "prometheus", "prometheus-k8s-0", "-i", "--", "curl", "-k", "-H", fmt.Sprintf("Authorization: Bearer %v", token), prometheusURLQuery).Outputs() if err != nil || msg == "" { return false, nil } return true, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("the query %v is getting failed", query)) json.Unmarshal([]byte(msg), &data) l = len(data.Data.Result) - 1 result[query], _ = strconv.Atoi(data.Data.Result[l].Value[1].(string)) e2e.Logf("The query %v result == %v", query, result[query]) } return result } func listPodStartingWith(prefix string, oc *exutil.CLI, namespace string) (pod []corev1.Pod) { podsToAll := []corev1.Pod{} podList, err := oc.AdminKubeClient().CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{}) if err != nil { e2e.Logf("Error listing pods: %v", err) return nil } for _, pod := range podList.Items { if strings.HasPrefix(pod.Name, prefix) { podsToAll = append(podsToAll, pod) } } return podsToAll } func dePodLogs(pods []corev1.Pod, oc *exutil.CLI, matchlogs string) bool { for _, pod := range pods { depOutput, err := oc.AsAdmin().WithoutNamespace().Run("logs").Args("pod/"+pod.Name, "-n", pod.Namespace).Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(depOutput, matchlogs) { return true } } return false } func getBearerTokenURLViaPod(ns, execPodName, url, bearer string) (string, error) { g.By("Get token via pod") cmd := fmt.Sprintf("curl --retry 15 --max-time 4 --retry-delay 1 -s -k -H 'Authorization: Bearer %s' %s", bearer, url) output, err := e2eoutput.RunHostCmd(ns, execPodName, cmd) if err != nil { return "", fmt.Errorf("host command failed: %v\n%s", err, output) } return output, nil } type bcSource struct { outname string name string namespace string template string } type authRole struct { namespace string rolename string template string } func (bcsrc *bcSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", bcsrc.template, "-p", "OUTNAME="+bcsrc.outname, "NAME="+bcsrc.name, "NAMESPACE="+bcsrc.namespace) o.Expect(err).NotTo(o.HaveOccurred()) } func (authrole *authRole) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", authrole.template, "-p", "NAMESPACE="+authrole.namespace, "ROLE_NAME="+authrole.rolename) o.Expect(err).NotTo(o.HaveOccurred()) } func parseToJSON(oc *exutil.CLI, parameters []string) string { var configFile string err := wait.Poll(3*time.Second, 15*time.Second, func() (bool, error) { output, err := oc.AsAdmin().Run("process").Args(parameters...).OutputToFile(getRandomString() + "config.json") if err != nil { e2e.Logf("the err:%v, and try next round", err) return false, nil } configFile = output return true, nil }) exutil.AssertWaitPollNoErr(err, "Applying resources from template is failed") e2e.Logf("the file of resource is %s", configFile) return configFile } func createResourceFromTemplate(oc *exutil.CLI, parameters ...string) error { configFile := parseToJSON(oc, parameters) return oc.AsAdmin().WithoutNamespace().Run("create").Args("-f", configFile).Execute() } func applyResourceFromTemplate(oc *exutil.CLI, parameters ...string) error { configFile := parseToJSON(oc, parameters) return oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", configFile).Execute() } func getRandomString() string { chars := "abcdefghijklmnopqrstuvwxyz" seed := rand.New(rand.NewSource(time.Now().UnixNano())) buffer := make([]byte, 8) for index := range buffer { buffer[index] = chars[seed.Intn(len(chars))] } return string(buffer) } // the method is to get something from resource. it is "oc get xxx" actually func getResource(oc *exutil.CLI, asAdmin, withoutNamespace bool, parameters ...string) string { var result string var err error err = wait.Poll(3*time.Second, 150*time.Second, func() (bool, error) { result, err = doAction(oc, "get", asAdmin, withoutNamespace, parameters...) if err != nil { e2e.Logf("output is %v, error is %v, and try next", result, err) return false, nil } return true, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("Failed to get %v", parameters)) e2e.Logf("$oc get %v, the returned resource:%v", parameters, result) return result } // the method is to do something with oc. func doAction(oc *exutil.CLI, action string, asAdmin, withoutNamespace bool, parameters ...string) (string, error) { if asAdmin && withoutNamespace { return oc.AsAdmin().WithoutNamespace().Run(action).Args(parameters...).Output() } if asAdmin && !withoutNamespace { return oc.AsAdmin().Run(action).Args(parameters...).Output() } if !asAdmin && withoutNamespace { return oc.WithoutNamespace().Run(action).Args(parameters...).Output() } if !asAdmin && !withoutNamespace { return oc.Run(action).Args(parameters...).Output() } return "", nil } func comparePodHostIP(oc *exutil.CLI) (int, int) { var hostsIP = []string{} var numi, numj int podList, _ := oc.AdminKubeClient().CoreV1().Pods("openshift-image-registry").List(context.Background(), metav1.ListOptions{LabelSelector: "docker-registry=default"}) for _, pod := range podList.Items { hostsIP = append(hostsIP, pod.Status.HostIP) } for i := 0; i < len(hostsIP)-1; i++ { for j := i + 1; j < len(hostsIP); j++ { if hostsIP[i] == hostsIP[j] { numi++ } else { numj++ } } } return numi, numj } // Check the latest image pruner pod logs func imagePruneLog(oc *exutil.CLI, matchLogs, notMatchLogs string) { podsOfImagePrune := []corev1.Pod{} err := wait.Poll(10*time.Second, 5*time.Minute, func() (bool, error) { podsOfImagePrune = listPodStartingWith("image-pruner", oc, "openshift-image-registry") if len(podsOfImagePrune) == 0 { e2e.Logf("Can't get pruner pods, go to next round") return false, nil } pod := podsOfImagePrune[len(podsOfImagePrune)-1] e2e.Logf("the pod status is %s", pod.Status.Phase) if pod.Status.Phase != "ContainerCreating" && pod.Status.Phase != "Pending" { depOutput, _ := oc.AsAdmin().WithoutNamespace().Run("logs").Args("pod/"+pod.Name, "-n", pod.Namespace).Output() if strings.Contains(depOutput, matchLogs) && !strings.Contains(depOutput, notMatchLogs) { return true, nil } } e2e.Logf("The image pruner log doesn't contain %v or contain %v", matchLogs, notMatchLogs) return false, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("Can't get the image pruner log or image pruner log doesn't contain %v or contain %v", matchLogs, notMatchLogs)) } func configureRegistryStorageToEmptyDir(oc *exutil.CLI) { emptydirstorage, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("configs.imageregistry/cluster", "-o=jsonpath={.status.storage.emptyDir}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if emptydirstorage == "{}" { g.By("Image registry is using EmptyDir now") } else { g.By("Set registry to use EmptyDir storage") storagetype, _ := getRegistryStorageConfig(oc) err = oc.AsAdmin().WithoutNamespace().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"storage":{"`+storagetype+`":null,"emptyDir":{}}, "replicas":1}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(30*time.Second, 2*time.Minute, func() (bool, error) { podList, _ := oc.AdminKubeClient().CoreV1().Pods("openshift-image-registry").List(context.Background(), metav1.ListOptions{LabelSelector: "docker-registry=default"}) o.Expect(err).NotTo(o.HaveOccurred()) if len(podList.Items) == 1 && podList.Items[0].Status.Phase == corev1.PodRunning { return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, "Image registry pod list is not 1") err = oc.AsAdmin().WithoutNamespace().Run("wait").Args("configs.imageregistry/cluster", "--for=condition=Available").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } } func recoverRegistryStorageConfig(oc *exutil.CLI) { g.By("Set image registry storage to default value") platformtype, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.spec.platformSpec.type}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if platformtype != "VSphere" { if platformtype != "None" { err := oc.AsAdmin().WithoutNamespace().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"storage":null}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Image registry will be auto-recovered to default storage") } } } func recoverRegistryDefaultReplicas(oc *exutil.CLI) { g.By("Set image registry to default replicas") platforms := map[string]bool{ "VSphere": true, "None": true, "oVirt": true, } expectedStatus1 := map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} platformtype, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.spec.platformSpec.type}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !platforms[platformtype] { g.By("Check if cluster is sno") workerNodes, _ := exutil.GetClusterNodesBy(oc, "worker") if len(workerNodes) == 1 { err := oc.AsAdmin().WithoutNamespace().Run("patch").Args("config.imageregistry/cluster", "-p", `{"spec":{"replicas":1}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } else { err := oc.AsAdmin().WithoutNamespace().Run("patch").Args("config.imageregistry/cluster", "-p", `{"spec":{"replicas":2}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } err = waitCoBecomes(oc, "image-registry", 240, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) } } func getRegistryStorageConfig(oc *exutil.CLI) (string, string) { var storagetype, storageinfo string g.By("Get image registry storage info") platformtype, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.spec.platformSpec.type}").Output() o.Expect(err).NotTo(o.HaveOccurred()) switch platformtype { case "AWS": storagetype = "s3" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.s3.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "Azure": storagetype = "azure" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.azure.container}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "GCP": storagetype = "gcs" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.gcs.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "OpenStack": storagetype = swiftType storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.swift.container}").Output() o.Expect(err).NotTo(o.HaveOccurred()) // On disconnect & openstack, the registry configure to use persistent volume if storageinfo == "" { storagetype = pvcType storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.pvc.claim}").Output() o.Expect(err).NotTo(o.HaveOccurred()) } case "AlibabaCloud": storagetype = "oss" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.oss.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "IBMCloud": storagetype = "ibmcos" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.ibmcos.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "BareMetal", "None", "VSphere", "Nutanix", "External": storagetype = pvcType storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.pvc.claim}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if storageinfo == "" { storagetype = emptyDir storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.emptyDir}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if storageinfo == "" { storagetype = "s3" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.s3.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) } } default: e2e.Logf("Image Registry is using unknown storage type") } return storagetype, storageinfo } /* func waitRegistryDefaultPodsReady(oc *exutil.CLI) { storagetype, _ := getRegistryStorageConfig(oc) if storagetype == pvcType || storagetype == emptyDir { podNum := getImageRegistryPodNumber(oc) o.Expect(podNum).Should(o.Equal(1)) checkPodsRunningWithLabel(oc, "openshift-image-registry", "docker-registry=default", podNum) } else { podNum := getImageRegistryPodNumber(oc) o.Expect(podNum).Should(o.Equal(2)) checkPodsRunningWithLabel(oc, "openshift-image-registry", "docker-registry=default", podNum) } } */ func checkRegistrypodsRemoved(oc *exutil.CLI) { err := wait.Poll(25*time.Second, 3*time.Minute, func() (bool, error) { podList, err := oc.AdminKubeClient().CoreV1().Pods("openshift-image-registry").List(context.Background(), metav1.ListOptions{LabelSelector: "docker-registry=default"}) o.Expect(err).NotTo(o.HaveOccurred()) if len(podList.Items) == 0 { return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(err, "Image registry pods are not removed") } type staSource struct { name string namespace string image string template string } func (stafulsrc *staSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", stafulsrc.template, "-p", "NAME="+stafulsrc.name, "NAMESPACE="+stafulsrc.namespace, "IMAGE="+stafulsrc.image) o.Expect(err).NotTo(o.HaveOccurred()) } func checkPodsRunningWithLabel(oc *exutil.CLI, namespace, label string, number int) { err := wait.Poll(25*time.Second, 6*time.Minute, func() (bool, error) { podList, _ := oc.AdminKubeClient().CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{LabelSelector: label}) if len(podList.Items) != number { e2e.Logf("the pod number is not %d, Continue to next round", number) return false, nil } for _, pod := range podList.Items { if pod.Status.Phase != corev1.PodRunning { e2e.Logf("Continue to next round") return false, nil } } return true, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("pods list are not %d", number)) } type icspSource struct { name string mirrors string source string template string } func (icspsrc *icspSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", icspsrc.template, "-p", "NAME="+icspsrc.name, "MIRRORS="+icspsrc.mirrors, "SOURCE="+icspsrc.source) o.Expect(err).NotTo(o.HaveOccurred()) } func (icspsrc *icspSource) delete(oc *exutil.CLI) { e2e.Logf("deleting icsp: %s", icspsrc.name) err := oc.AsAdmin().WithoutNamespace().Run("delete").Args("imagecontentsourcepolicy", icspsrc.name, "--ignore-not-found=true").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } func getRegistryDefaultRoute(oc *exutil.CLI) (defaultroute string) { err := wait.Poll(5*time.Second, 30*time.Second, func() (bool, error) { defroute, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("route", "-n", "openshift-image-registry", "default-route", "-o=jsonpath={.spec.host}").Output() if defroute == "" || err != nil { e2e.Logf("Continue to next round") return false, nil } defaultroute = defroute return true, nil }) exutil.AssertWaitPollNoErr(err, "Did not find registry route") return defaultroute } func setImageregistryConfigs(oc *exutil.CLI, pathinfo, matchlogs string) bool { foundInfo := false defer recoverRegistrySwiftSet(oc) err := oc.WithoutNamespace().AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"storage":{"swift":{`+pathinfo+`}}}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(5*time.Second, 20*time.Second, func() (bool, error) { output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("co/image-registry").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, matchlogs) { foundInfo = true return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, "No image registry error info found") return foundInfo } func recoverRegistrySwiftSet(oc *exutil.CLI) { matchInfo := "True False False" err := oc.WithoutNamespace().AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"storage":{"swift":{"authURL":null, "regionName":null, "regionID":null, "domainID":null, "domain":null, "tenantID":null}}}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(4*time.Second, 20*time.Second, func() (bool, error) { output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("co/image-registry", "-o=jsonpath={.status.conditions[*].status}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, matchInfo) { return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, "Image registry is degrade") } type podSource struct { name string namespace string image string template string } func (podsrc *podSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", podsrc.template, "-p", "NAME="+podsrc.name, "NAMESPACE="+podsrc.namespace, "IMAGE="+podsrc.image) o.Expect(err).NotTo(o.HaveOccurred()) } func checkRegistryUsingFSVolume(oc *exutil.CLI) bool { storageinfo, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(storageinfo, pvcType) || strings.Contains(storageinfo, emptyDir) { return true } return false } func saveImageMetadataName(oc *exutil.CLI, image string) string { imagemetadata, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("images").OutputToFile("imagemetadata.txt") o.Expect(err).NotTo(o.HaveOccurred()) defer os.Remove("imagemetadata.txt") manifest, err := exec.Command("bash", "-c", "cat "+imagemetadata+" | grep "+image+" | awk '{print $1}'").Output() o.Expect(err).NotTo(o.HaveOccurred()) return strings.TrimSuffix(string(manifest), "\n") } func checkRegistryFunctionFine(oc *exutil.CLI, bcname, namespace string) { errTag := oc.AsAdmin().WithoutNamespace().Run("tag").Args("quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", "busybox:latest", "--reference-policy=local", "--import-mode=PreserveOriginal", "-n", namespace).Execute() o.Expect(errTag).NotTo(o.HaveOccurred()) errTag = waitForAnImageStreamTag(oc, namespace, "busybox", "latest") o.Expect(errTag).NotTo(o.HaveOccurred()) // Check if could push images to image registry err := oc.AsAdmin().WithoutNamespace().Run("new-build").Args("-D", "FROM quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", "--to="+bcname, "-n", namespace).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = exutil.WaitForABuild(oc.BuildClient().BuildV1().Builds(namespace), bcname+"-1", nil, nil, nil) if err != nil { exutil.DumpBuildLogs(bcname, oc) } exutil.AssertWaitPollNoErr(err, "build is not complete") err = exutil.WaitForAnImageStreamTag(oc, namespace, bcname, "latest") o.Expect(err).NotTo(o.HaveOccurred()) // Check if could pull images from image registry imagename := "image-registry.openshift-image-registry.svc:5000/" + namespace + "/" + bcname + ":latest" err = oc.AsAdmin().WithoutNamespace().Run("run").Args(bcname, "--image", imagename, `--overrides={"spec":{"securityContext":{"runAsNonRoot":true,"seccompProfile":{"type":"RuntimeDefault"}}}}`, "-n", namespace, "--command", "--", "/bin/sleep", "120").Execute() o.Expect(err).NotTo(o.HaveOccurred()) var output string errWait := wait.Poll(10*time.Second, 3*time.Minute, func() (bool, error) { output, err = oc.AsAdmin().WithoutNamespace().Run("describe").Args("pod", bcname, "-n", namespace).Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, `Successfully pulled image`) { return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(errWait, fmt.Sprintf("Image registry is broken, can't pull image. the log:\n %v", output)) } func checkRegistryDegraded(oc *exutil.CLI) bool { status := "TrueFalseFalse" output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("co/image-registry", "-o=jsonpath={.status.conditions[?(@.type==\"Available\")].status}{.status.conditions[?(@.type==\"Progressing\")].status}{.status.conditions[?(@.type==\"Degraded\")].status}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return !strings.Contains(output, status) } func getCreditFromCluster(oc *exutil.CLI) (string, string, string) { credential, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("secret/aws-creds", "-n", "kube-system", "-o", "json").Output() o.Expect(err).NotTo(o.HaveOccurred()) accessKeyIDBase64, secureKeyBase64 := gjson.Get(credential, `data.aws_access_key_id`).Str, gjson.Get(credential, `data.aws_secret_access_key`).Str accessKeyID, err1 := base64.StdEncoding.DecodeString(accessKeyIDBase64) o.Expect(err1).NotTo(o.HaveOccurred()) secureKey, err2 := base64.StdEncoding.DecodeString(secureKeyBase64) o.Expect(err2).NotTo(o.HaveOccurred()) clusterRegion, err3 := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.status.platformStatus.aws.region}").Output() o.Expect(err3).NotTo(o.HaveOccurred()) return string(accessKeyID), string(secureKey), clusterRegion } func getAWSClient(oc *exutil.CLI) *s3.Client { accessKeyID, secureKey, clusterRegion := getCreditFromCluster(oc) cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKeyID, secureKey, "")), config.WithRegion(clusterRegion)) o.Expect(err).NotTo(o.HaveOccurred()) return s3.NewFromConfig(cfg) } func awsGetBucketTagging(client *s3.Client, bucket string) (string, error) { tagOutput, err := client.GetBucketTagging(context.TODO(), &s3.GetBucketTaggingInput{Bucket: &bucket}) if err != nil { outputGetTag := fmt.Sprintf("Got an error GetBucketTagging for %s: %v", bucket, err) return outputGetTag, err } outputGetTag := "" for _, t := range tagOutput.TagSet { outputGetTag += *t.Key + " " + *t.Value + "\n" } return outputGetTag, nil } // the method is to make newCheck object. // the method parameter is expect, it will check something is expceted or not // the method parameter is present, it will check something exists or not // the executor is asAdmin, it will exectue oc with Admin // the executor is asUser, it will exectue oc with User // the inlineNamespace is withoutNamespace, it will execute oc with WithoutNamespace() // the inlineNamespace is withNamespace, it will execute oc with WithNamespace() // the expectAction take effective when method is expect, if it is contain, it will check if the strings contain substring with expectContent parameter // // if it is compare, it will check the strings is samme with expectContent parameter // // the expectContent is the content we expected // the expect is ok, contain or compare result is OK for method == expect, no error raise. if not OK, error raise // the expect is nok, contain or compare result is NOK for method == expect, no error raise. if OK, error raise // the expect is ok, resource existing is OK for method == present, no error raise. if resource not existing, error raise // the expect is nok, resource not existing is OK for method == present, no error raise. if resource existing, error raise func newCheck(method string, executor bool, inlineNamespace bool, expectAction bool, expectContent string, expect bool, resource []string) checkDescription { return checkDescription{ method: method, executor: executor, inlineNamespace: inlineNamespace, expectAction: expectAction, expectContent: expectContent, expect: expect, resource: resource, } } type checkDescription struct { method string executor bool inlineNamespace bool expectAction bool expectContent string expect bool resource []string } // the method is to check the resource per definition of the above described newCheck. func (ck checkDescription) check(oc *exutil.CLI) { switch ck.method { case "present": ok := isPresentResource(oc, ck.executor, ck.inlineNamespace, ck.expectAction, ck.resource...) o.Expect(ok).To(o.BeTrue()) case "expect": err := expectedResource(oc, ck.executor, ck.inlineNamespace, ck.expectAction, ck.expectContent, ck.expect, ck.resource...) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("expected content %s not found by %v", ck.expectContent, ck.resource)) default: err := fmt.Errorf("unknown method") o.Expect(err).NotTo(o.HaveOccurred()) } } // the method is to check the presence of the resource // asAdmin means if taking admin to check it // withoutNamespace means if take WithoutNamespace() to check it. // present means if you expect the resource presence or not. if it is ok, expect presence. if it is nok, expect not present. func isPresentResource(oc *exutil.CLI, asAdmin, withoutNamespace, present bool, parameters ...string) bool { parameters = append(parameters, "--ignore-not-found") err := wait.Poll(3*time.Second, 70*time.Second, func() (bool, error) { output, err := doAction(oc, "get", asAdmin, withoutNamespace, parameters...) if err != nil { e2e.Logf("the get error is %v, and try next", err) return false, nil } if !present && strings.Compare(output, "") == 0 { return true, nil } if present && strings.Compare(output, "") != 0 { return true, nil } return false, nil }) return err == nil } // the method is to check one resource's attribution is expected or not. // asAdmin means if taking admin to check it // withoutNamespace means if take WithoutNamespace() to check it. // isCompare means if containing or exactly comparing. if it is contain, it check result contain content. if it is compare, it compare the result with content exactly. // content is the substing to be expected // the expect is ok, contain or compare result is OK for method == expect, no error raise. if not OK, error raise // the expect is nok, contain or compare result is NOK for method == expect, no error raise. if OK, error raise func expectedResource(oc *exutil.CLI, asAdmin, withoutNamespace, isCompare bool, content string, expect bool, parameters ...string) error { expectMap := map[bool]string{ true: "do", false: "do not", } cc := func(a, b string, ic bool) bool { bs := strings.Split(b, "+2+") ret := false for _, s := range bs { if (ic && strings.Compare(a, s) == 0) || (!ic && strings.Contains(a, s)) { ret = true } } return ret } e2e.Logf("Running: oc get asAdmin(%t) withoutNamespace(%t) %s", asAdmin, withoutNamespace, strings.Join(parameters, " ")) return wait.Poll(3*time.Second, 150*time.Second, func() (bool, error) { output, err := doAction(oc, "get", asAdmin, withoutNamespace, parameters...) if err != nil { e2e.Logf("the get error is %v, and try next", err) return false, nil } e2e.Logf("---> we %v expect value: %s, in returned value: %s", expectMap[expect], content, output) if isCompare && expect && cc(output, content, isCompare) { e2e.Logf("the output %s matches one of the content %s, expected", output, content) return true, nil } if isCompare && !expect && !cc(output, content, isCompare) { e2e.Logf("the output %s does not matche the content %s, expected", output, content) return true, nil } if !isCompare && expect && cc(output, content, isCompare) { e2e.Logf("the output %s contains one of the content %s, expected", output, content) return true, nil } if !isCompare && !expect && !cc(output, content, isCompare) { e2e.Logf("the output %s does not contain the content %s, expected", output, content) return true, nil } e2e.Logf("---> Not as expected! Return false") return false, nil }) } func exposeService(oc *exutil.CLI, ns, resource, name, port string) { err := oc.AsAdmin().WithoutNamespace().Run("expose").Args(resource, "--name="+name, "--port="+port, "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) } func exposeRouteFromSVC(oc *exutil.CLI, rType, ns, route, service string) string { err := oc.AsAdmin().WithoutNamespace().Run("create").Args("route", rType, route, "--service="+service, "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) regRoute, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("route", route, "-n", ns, "-o=jsonpath={.spec.host}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return regRoute } func listRepositories(regRoute, expect string) { curlCmd := fmt.Sprintf("curl -ks https://%s/v2/_catalog | grep %s", regRoute, expect) result, err := exec.Command("bash", "-c", curlCmd).CombinedOutput() if err != nil { e2e.Logf("Command: \"%s\" returned: %v", curlCmd, string(result)) o.Expect(err).NotTo(o.HaveOccurred()) } o.Expect(string(result)).To(o.ContainSubstring(expect)) } func setSecureRegistryWithoutAuth(oc *exutil.CLI, ns, regName, image, port string) string { err := oc.AsAdmin().WithoutNamespace().Run("create").Args("deploy", regName, "--image="+image, "--port=5000", "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) checkPodsRunningWithLabel(oc, ns, "app="+regName, 1) exposeService(oc, ns, "deploy/"+regName, regName, port) regRoute := exposeRouteFromSVC(oc, "edge", ns, regName, regName) checkDnsCO(oc) waitRouteReady(regRoute) listRepositories(regRoute, "repositories") return regRoute } func setSecureRegistryEnableAuth(oc *exutil.CLI, ns, regName, htpasswdFile, image string) string { regRoute := setSecureRegistryWithoutAuth(oc, ns, regName, image, "5000") ge1 := saveGeneration(oc, ns, "deployment/"+regName) err := oc.AsAdmin().WithoutNamespace().Run("create").Args("secret", "generic", "htpasswd", "--from-file="+htpasswdFile, "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = oc.WithoutNamespace().Run("set").Args("volume", "deployment/"+regName, "--add", "--mount-path=/auth", "--type=secret", "--secret-name=htpasswd", "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = oc.WithoutNamespace().Run("set").Args("env", "deployment/"+regName, "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd", "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm", "REGISTRY_AUTH=htpasswd", "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(5*time.Second, 60*time.Second, func() (bool, error) { ge2 := saveGeneration(oc, ns, "deployment/"+regName) if ge2 == ge1 { e2e.Logf("Continue to next round") return false, nil } return true, nil }) exutil.AssertWaitPollNoErr(err, "Custom registry does not update") checkPodsRunningWithLabel(oc, ns, "app="+regName, 1) return regRoute } func generateHtpasswdFile(tempDataDir, user, pass string) (string, error) { htpasswdFile := filepath.Join(tempDataDir, "htpasswd") generateCMD := fmt.Sprintf("htpasswd -Bbn %s %s > %s", user, pass, htpasswdFile) _, err := exec.Command("bash", "-c", generateCMD).Output() if err != nil { e2e.Logf("Fail to generate htpasswd file: %v", err) return htpasswdFile, err } return htpasswdFile, nil } func extractPullSecret(oc *exutil.CLI) (string, error) { tempDataDir := filepath.Join("/tmp/", fmt.Sprintf("ir-%s", getRandomString())) err := os.Mkdir(tempDataDir, 0o755) if err != nil { e2e.Logf("Fail to create directory: %v", err) return tempDataDir, err } err = oc.AsAdmin().Run("extract").Args("secret/pull-secret", "-n", "openshift-config", "--confirm", "--to="+tempDataDir).Execute() if err != nil { e2e.Logf("Fail to extract dockerconfig: %v", err) return tempDataDir, err } return tempDataDir, nil } func appendPullSecretAuth(authFile, regRouter, newRegUser, newRegPass string) (string, error) { fieldValue := newRegUser + ":" + newRegPass regToken := base64.StdEncoding.EncodeToString([]byte(fieldValue)) authDir, _ := filepath.Split(authFile) newAuthFile := filepath.Join(authDir, fmt.Sprintf("%s.json", getRandomString())) jqCMD := fmt.Sprintf(`cat %s | jq '.auths += {"%s":{"auth":"%s"}}' > %s`, authFile, regRouter, regToken, newAuthFile) _, err := exec.Command("bash", "-c", jqCMD).Output() if err != nil { e2e.Logf("Fail to extract dockerconfig: %v", err) return newAuthFile, err } return newAuthFile, nil } func updatePullSecret(oc *exutil.CLI, authFile string) { err := oc.AsAdmin().WithoutNamespace().Run("set").Args("data", "secret/pull-secret", "-n", "openshift-config", "--from-file=.dockerconfigjson="+authFile).Execute() o.Expect(err).NotTo(o.HaveOccurred()) } func foundAffinityRules(oc *exutil.CLI, affinityRules string) bool { podList, _ := oc.AdminKubeClient().CoreV1().Pods("openshift-image-registry").List(context.Background(), metav1.ListOptions{LabelSelector: "docker-registry=default"}) for _, pod := range podList.Items { out, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("pod/"+pod.Name, "-n", pod.Namespace, "-o=jsonpath={.spec.affinity.podAntiAffinity}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(out, affinityRules) { return false } } return true } func saveGlobalProxy(oc *exutil.CLI) (string, string, string) { httpProxy := getResource(oc, asAdmin, withoutNamespace, "proxy", "cluster", "-o=jsonpath={.status.httpProxy}") httpsProxy := getResource(oc, asAdmin, withoutNamespace, "proxy", "cluster", "-o=jsonpath={.status.httpsProxy}") noProxy := getResource(oc, asAdmin, withoutNamespace, "proxy", "cluster", "-o=jsonpath={.status.noProxy}") return httpProxy, httpsProxy, noProxy } func createSimpleRunPod(oc *exutil.CLI, image, expectInfo string) { podName := getRandomString() err := oc.AsAdmin().WithoutNamespace().Run("run").Args(podName, "--image="+image, "-n", oc.Namespace(), `--overrides={"spec":{"securityContext":{"runAsNonRoot":true,"seccompProfile":{"type":"RuntimeDefault"}}}}`, "--image-pull-policy=Always", "--", "sleep", "300").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(10*time.Second, 3*time.Minute, func() (bool, error) { output, err := oc.AsAdmin().WithoutNamespace().Run("describe").Args("pod", podName, "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, expectInfo) { return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("Pod doesn't show expected log %v", expectInfo)) } func newAppUseImageStream(oc *exutil.CLI, ns, imagestream, expectInfo string) { appName := getRandomString() err := oc.AsAdmin().WithoutNamespace().Run("new-app").Args("-i", imagestream, "--name="+appName, "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(3*time.Second, 30*time.Second, func() (bool, error) { output, err := oc.AsAdmin().WithoutNamespace().Run("describe").Args("pod", "-l", "deployment="+appName, "-n", ns).Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, expectInfo) { return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, "Pod doesn't pull expected image") } // Save deployment or daemonset generation to judge if update applied func saveGeneration(oc *exutil.CLI, ns, resource string) string { num, err := oc.AsAdmin().WithoutNamespace().Run("get").Args(resource, "-n", ns, "-o=jsonpath={.metadata.generation}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return num } // Create route to expose the registry func createRouteExposeRegistry(oc *exutil.CLI) { // Don't forget to restore the environment use func restoreRouteExposeRegistry output, err := oc.AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"defaultRoute":true}}`, "--type=merge").Output() if err != nil { e2e.Logf(output) } o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring("patched")) } func restoreRouteExposeRegistry(oc *exutil.CLI) { output, err := oc.AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"defaultRoute":false}}`, "--type=merge").Output() if err != nil { e2e.Logf(output) } o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring("patched")) } func getPodNodeListByLabel(oc *exutil.CLI, namespace, labelKey string) []string { output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("pods", "-o", "wide", "-n", namespace, "-l", labelKey, "-o=jsonpath={.items[*].spec.nodeName}").Output() o.Expect(err).NotTo(o.HaveOccurred()) nodeNameList := strings.Fields(output) return nodeNameList } func getImageRegistryPodNumber(oc *exutil.CLI) int { podNum, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("config.image/cluster", "-o=jsonpath={.spec.replicas}").Output() o.Expect(err).NotTo(o.HaveOccurred()) intPodNum, _ := strconv.Atoi(podNum) return intPodNum } func saveImageRegistryAuth(oc *exutil.CLI, sa, regRoute, ns string) (string, error) { tempDataFile := filepath.Join("/tmp/", fmt.Sprintf("ir-auth-%s", getRandomString())) token, err := getSAToken(oc, sa, ns) o.Expect(err).NotTo(o.HaveOccurred()) err = oc.NotShowInfo().AsAdmin().WithoutNamespace().Run("registry").Args("login", "--registry="+regRoute, "--auth-basic=anyuser:"+token, "--to="+tempDataFile, "--insecure", "-n", ns).Execute() if err != nil { e2e.Logf("Fail to login image registry: %v", err) return tempDataFile, err } return tempDataFile, nil } func getSAToken(oc *exutil.CLI, sa, ns string) (string, error) { e2e.Logf("Getting a token assgined to specific serviceaccount from %s namespace...", ns) token, err := oc.AsAdmin().WithoutNamespace().Run("create").Args("token", sa, "-n", ns).Output() if err != nil { if strings.Contains(token, "unknown command") { // oc client is old version, create token is not supported e2e.Logf("oc create token is not supported by current client, use oc sa get-token instead") token, err = oc.AsAdmin().WithoutNamespace().Run("sa").Args("get-token", sa, "-n", ns).Output() } else { return "", err } } return token, err } type machineConfig struct { name string pool string source string path string template string parameters []string } func (mc *machineConfig) waitForMCPComplete(oc *exutil.CLI) { machineCount, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mcp", mc.pool, "-ojsonpath={.status.machineCount}").Output() e2e.Logf("machineCount: %v", machineCount) o.Expect(err).NotTo(o.HaveOccurred()) mcCount, _ := strconv.Atoi(machineCount) timeToWait := time.Duration(10*mcCount) * time.Minute e2e.Logf("Waiting %s for MCP %s to be completed.", timeToWait, mc.pool) err = wait.Poll(1*time.Minute, timeToWait, func() (bool, error) { mcpStatus, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mcp", mc.pool, `-ojsonpath={.status.conditions[?(@.type=="Updated")].status}`).Output() e2e.Logf("mcpStatus: %v", mcpStatus) if err != nil { e2e.Logf("the err:%v, and try next round", err) return false, nil } if strings.Contains(mcpStatus, "True") { // i.e. mcp updated=true, mc is applied successfully e2e.Logf("mc operation is completed on mcp %s", mc.pool) return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("mc operation is not completed on mcp %s", mc.pool)) } func (mc *machineConfig) createWithCheck(oc *exutil.CLI) { mc.name = mc.name + "-" + exutil.GetRandomString() params := []string{"--ignore-unknown-parameters=true", "-f", mc.template, "-p", "NAME=" + mc.name, "POOL=" + mc.pool, "SOURCE=" + mc.source, "PATH=" + mc.path} params = append(params, mc.parameters...) exutil.CreateClusterResourceFromTemplate(oc, params...) pollerr := wait.Poll(5*time.Second, 1*time.Minute, func() (bool, error) { stdout, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mc/"+mc.name, "-o", "jsonpath='{.metadata.name}'").Output() if err != nil { e2e.Logf("the err:%v, and try next round", err) return false, nil } if strings.Contains(stdout, mc.name) { e2e.Logf("mc %s is created successfully", mc.name) return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(pollerr, fmt.Sprintf("create machine config %v failed", mc.name)) mc.waitForMCPComplete(oc) } func (mc *machineConfig) delete(oc *exutil.CLI) { err := oc.AsAdmin().WithoutNamespace().Run("delete").Args("mc", mc.name, "--ignore-not-found=true").Execute() o.Expect(err).NotTo(o.HaveOccurred()) mc.waitForMCPComplete(oc) } type runtimeClass struct { name string handler string template string } func (rtc *runtimeClass) createWithCheck(oc *exutil.CLI) { rtc.name = rtc.name + "-" + exutil.GetRandomString() params := []string{"--ignore-unknown-parameters=true", "-f", rtc.template, "-p", "NAME=" + rtc.name, "HANDLER=" + rtc.handler} exutil.CreateClusterResourceFromTemplate(oc, params...) rtcerr := wait.Poll(5*time.Second, 1*time.Minute, func() (bool, error) { stdout, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("runtimeclass/"+rtc.name, "-o", "jsonpath='{.metadata.name}'").Output() if err != nil { e2e.Logf("the err:%v, and try next round", err) return false, nil } if strings.Contains(stdout, rtc.name) { e2e.Logf("runtimeClass %s is created successfully", rtc.name) return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(rtcerr, fmt.Sprintf("create runtimeClass %v failed", rtc.name)) } func (rtc *runtimeClass) delete(oc *exutil.CLI) { err := oc.AsAdmin().WithoutNamespace().Run("delete").Args("runtimeclass", rtc.name, "--ignore-not-found=true").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } type prometheusImageregistryOperations struct { Data struct { Result []struct { Metric []struct { Name string `json:"__name__"` Operation string `json:"operation"` Resource string `json:"resource_type"` } `json:"metric"` Value []interface{} `json:"value"` } `json:"result"` ResultType string `json:"resultType"` } `json:"data"` Status string `json:"status"` } type prometheusImageregistryStorageType struct { Data struct { Result []struct { Metric struct { Name string `json:"__name__"` Container string `json:"container"` Endpoint string `json:"endpoint"` Instance string `json:"instance"` Job string `json:"job"` Namespace string `json:"namespace"` Pod string `json:"pod"` Service string `json:"service"` Storage string `json:"storage"` } `json:"metric"` Value []interface{} `json:"value"` } `json:"result"` ResultType string `json:"resultType"` } `json:"data"` Status string `json:"status"` } type limitSource struct { name string namespace string size string template string } func (limitsrc *limitSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", limitsrc.template, "-p", "NAME="+limitsrc.name, "NAMESPACE="+limitsrc.namespace, "SIZE="+limitsrc.size) o.Expect(err).NotTo(o.HaveOccurred()) } func checkDnsCO(oc *exutil.CLI) { expectedStatus := map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} err := waitCoBecomes(oc, "ingress", 240, expectedStatus) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "dns", 240, expectedStatus) o.Expect(err).NotTo(o.HaveOccurred()) } func waitRouteReady(route string) { curlCmd := "curl -k https://" + route var output []byte var curlErr error pollErr := wait.Poll(5*time.Second, 1*time.Minute, func() (bool, error) { output, curlErr = exec.Command("bash", "-c", curlCmd).CombinedOutput() if curlErr != nil { e2e.Logf("the route is not ready, go to next round") return false, nil } return true, nil }) if pollErr != nil { e2e.Logf("output is: %v with error %v", string(output), curlErr.Error()) } exutil.AssertWaitPollNoErr(pollErr, "The route can't be used") } type signatureSource struct { name string imageid string title string content string template string } func (signsrc *signatureSource) create(oc *exutil.CLI) { err := createResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", signsrc.template, "-p", "NAME="+signsrc.name, "IMAGEID="+signsrc.imageid, "TITLE="+signsrc.title, "CONTENT="+signsrc.content) o.Expect(err).NotTo(o.HaveOccurred()) } type isSource struct { name string namespace string repo string tagname string image string template string } func (issrc *isSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", issrc.template, "-p", "NAME="+issrc.name, "REPO="+issrc.repo, "NAMESPACE="+issrc.namespace, "TAGNAME="+issrc.tagname, "IMAGE="+issrc.image) o.Expect(err).NotTo(o.HaveOccurred()) } /* func setWaitForAnImageStreamTag(oc *exutil.CLI, namespace, name, tag string, timeout time.Duration) error { return exutil.TimedWaitForAnImageStreamTag(oc, namespace, name, tag, timeout) } */ func waitForAnImageStreamTag(oc *exutil.CLI, namespace, name, tag string) error { return exutil.TimedWaitForAnImageStreamTag(oc, namespace, name, tag, time.Second*420) } func waitCoBecomes(oc *exutil.CLI, coName string, waitTime int, expectedStatus map[string]string) error { var gottenStatus map[string]string err := wait.Poll(15*time.Second, time.Duration(waitTime)*time.Second, func() (bool, error) { gottenStatus := getCoStatus(oc, coName, expectedStatus) eq := reflect.DeepEqual(expectedStatus, gottenStatus) if eq { e2e.Logf("Given operator %s becomes %s", coName, gottenStatus) return true, nil } return false, nil }) if err != nil { for key, value := range gottenStatus { e2e.Logf("\ncheck the %v status %v is %v\n", coName, key, value) } } return err } func getCoStatus(oc *exutil.CLI, coName string, statusToCompare map[string]string) map[string]string { newStatusToCompare := make(map[string]string) for key := range statusToCompare { args := fmt.Sprintf(`-o=jsonpath={.status.conditions[?(@.type == "%s")].status}`, key) status, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("co", args, coName).Output() o.Expect(err).NotTo(o.HaveOccurred()) newStatusToCompare[key] = status } return newStatusToCompare } func checkPodsRemovedWithLabel(oc *exutil.CLI, namespace, label string) { err := wait.Poll(25*time.Second, 3*time.Minute, func() (bool, error) { podList, err := oc.AdminKubeClient().CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{LabelSelector: label}) o.Expect(err).NotTo(o.HaveOccurred()) if len(podList.Items) == 0 { return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(err, "Pods are not removed") } type dsSource struct { name string namespace string image string template string } func (dssrc *dsSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", dssrc.template, "-p", "NAME="+dssrc.name, "NAMESPACE="+dssrc.namespace, "IMAGE="+dssrc.image) o.Expect(err).NotTo(o.HaveOccurred()) } type isImportSource struct { name string namespace string image string policy string mode string template string } func (issrc *isImportSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", issrc.template, "-p", "NAME="+issrc.name, "NAMESPACE="+issrc.namespace, "IMAGE="+issrc.image, "POLICY="+issrc.policy, "MODE="+issrc.mode) o.Expect(err).NotTo(o.HaveOccurred()) } func pruneImage(oc *exutil.CLI, isName, imageName, refRoute, token string, num int) { g.By("Check image object and sub-manifest created for the manifest list") isOut, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("is/"+isName, "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(strings.Contains(isOut, isName)).To(o.BeTrue()) imageOut, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("images", "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) imageCount := strings.Count(imageOut, imageName) o.Expect(imageCount).To(o.Equal(num)) g.By("Prune image") out, err := oc.AsAdmin().WithoutNamespace().Run("adm").Args("prune", "images", "--token="+token, "--registry-url="+refRoute, "--confirm").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(strings.Contains(out, "Summary: deleted")).To(o.BeTrue()) imageOut, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("images", "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) imageCount = strings.Count(imageOut, imageName) o.Expect(imageCount).To(o.Equal(num)) } func doPrometheusQuery(oc *exutil.CLI, token, url string) int { var ( data prometheusImageregistryQueryHTTP count int ) msg, _, err := oc.AsAdmin().WithoutNamespace().Run("exec").Args( "-n", "openshift-monitoring", "-c", "prometheus", "prometheus-k8s-0", "-i", "--", "curl", "-k", "-H", fmt.Sprintf("Authorization: Bearer %v", token), fmt.Sprintf("%s", url)).Outputs() if err != nil { e2e.Failf("Failed Prometheus query, error: %v", err) } o.Expect(msg).NotTo(o.BeEmpty()) json.Unmarshal([]byte(msg), &data) err = wait.Poll(60*time.Second, 120*time.Second, func() (bool, error) { if len(data.Data.Result) != 0 { return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(err, "cannot get query result") count, err = strconv.Atoi(data.Data.Result[0].Value[1].(string)) o.Expect(err).NotTo(o.HaveOccurred()) return count } func copyFile(source string, dest string) { bytesRead, err := ioutil.ReadFile(source) o.Expect(err).NotTo(o.HaveOccurred()) err = ioutil.WriteFile(dest, bytesRead, 0644) o.Expect(err).NotTo(o.HaveOccurred()) } type imageObject struct { architecture []string digest []string os []string } func (c *imageObject) getManifestObject(oc *exutil.CLI, resource, name, namespace string) *imageObject { archList, err := oc.AsAdmin().WithoutNamespace().Run("get").Args(resource, name, "-n", namespace, "-ojsonpath={..dockerImageManifests[*].architecture}").Output() o.Expect(err).NotTo(o.HaveOccurred()) c.architecture = strings.Split(archList, " ") digestList, err := oc.AsAdmin().WithoutNamespace().Run("get").Args(resource, name, "-n", namespace, "-ojsonpath={..dockerImageManifests[*].digest}").Output() o.Expect(err).NotTo(o.HaveOccurred()) c.digest = strings.Split(digestList, " ") osList, err := oc.AsAdmin().WithoutNamespace().Run("get").Args(resource, name, "-n", namespace, "-ojsonpath={..dockerImageManifests[*].os}").Output() o.Expect(err).NotTo(o.HaveOccurred()) c.os = strings.Split(osList, " ") return c } func getManifestList(oc *exutil.CLI, image, auth string) string { jqCMD := fmt.Sprintf(`oc image info %s -a %s --insecure --show-multiarch -o json| jq -r '.[0].listDigest'`, image, auth) manifestList, err := exec.Command("bash", "-c", jqCMD).Output() o.Expect(err).NotTo(o.HaveOccurred()) return strings.TrimSuffix(string(manifestList), "\n") } func checkOptionalOperatorInstalled(oc *exutil.CLI, operator string) bool { installedOperators, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("clusterversion", "version", "-o=jsonpath={.status.capabilities.enabledCapabilities}").Output() if err != nil { e2e.Failf("get enabledCapabilities failed err %v .", err) } if strings.Contains(installedOperators, operator) { e2e.Logf("The %v operator is installed", operator) return true } e2e.Logf("The %v operator is not installed", operator) return false } func checkICSP(oc *exutil.CLI) bool { icsp, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("ImageContentSourcePolicy").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(icsp, "No resources found") { e2e.Logf("there is no ImageContentSourcePolicy in this cluster") return false } return true } type idmsSource struct { name string mirrors string source string template string } func (idmssrc *idmsSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", idmssrc.template, "-p", "NAME="+idmssrc.name, "MIRRORS="+idmssrc.mirrors, "SOURCE="+idmssrc.source) o.Expect(err).NotTo(o.HaveOccurred()) } func (idmssrc *idmsSource) delete(oc *exutil.CLI) { e2e.Logf("deleting idms: %s", idmssrc.name) err := oc.AsAdmin().WithoutNamespace().Run("delete").Args("idms", idmssrc.name, "--ignore-not-found=true").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } type itmsSource struct { name string mirrors string source string template string } func (itmssrc *itmsSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", itmssrc.template, "-p", "NAME="+itmssrc.name, "MIRRORS="+itmssrc.mirrors, "SOURCE="+itmssrc.source) o.Expect(err).NotTo(o.HaveOccurred()) } func (itmssrc *itmsSource) delete(oc *exutil.CLI) { e2e.Logf("deleting itms: %s", itmssrc.name) err := oc.AsAdmin().WithoutNamespace().Run("delete").Args("itms", itmssrc.name, "--ignore-not-found=true").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } type isStruct struct { name string namespace string repo string template string } func (issrc *isStruct) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", issrc.template, "-p", "NAME="+issrc.name, "REPO="+issrc.repo, "NAMESPACE="+issrc.namespace) o.Expect(err).NotTo(o.HaveOccurred()) } // GetMirrorRegistry returns mirror registry from idms func GetMirrorRegistry(oc *exutil.CLI) (registry string) { registry, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("idms", "-o", "jsonpath={.items[0].spec.imageDigestMirrors[0].mirrors[0]}").Output() if err != nil { e2e.Failf("failed to acquire mirror registry from IDMS: %v", err) } else { registry, _, _ = strings.Cut(registry, "/") } return registry } func checkImagePruners(oc *exutil.CLI) bool { impr, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("imagepruners").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(impr, "No resources found") { e2e.Logf("there is no imagepruners in this cluster") return false } return true } func get_osp_authurl(oc *exutil.CLI) string { g.By("get authurl") var authURL string credentials, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("secret/openstack-credentials", "-n", "kube-system", "-o", `jsonpath={.data.clouds\.yaml}`).Output() o.Expect(err).NotTo(o.HaveOccurred()) credential, err := base64.StdEncoding.DecodeString(credentials) o.Expect(err).NotTo(o.HaveOccurred()) r, _ := regexp.Compile("auth_url:.*") match := r.FindAllString(string(credential), -1) if strings.Contains(match[0], "auth_url") { authURL = strings.Split(match[0], " ")[1] return authURL } return "" } func getgcloudClient(oc *exutil.CLI) *exutil.Gcloud { if exutil.CheckPlatform(oc) != "gcp" { g.Skip("it is not gcp platform!") } projectID, err := exutil.GetGcpProjectID(oc) o.Expect(err).NotTo(o.HaveOccurred()) gcloud := exutil.Gcloud{ProjectID: projectID} return gcloud.Login() } func filterTimestampFromLogs(logs string, numberOfTimestamp int) []string { return regexp.MustCompile("(?m)[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}.[0-9]{1,6}").FindAllString(logs, numberOfTimestamp) } func getTimeDifferenceInMinute(oldTimestamp, newTimestamp string) float64 { oldTimeValues := strings.Split(oldTimestamp, ":") oldTimeHour, _ := strconv.Atoi(oldTimeValues[0]) oldTimeMinute, _ := strconv.Atoi(oldTimeValues[1]) oldTimeSecond, _ := strconv.Atoi(strings.Split(oldTimeValues[2], ".")[0]) oldTimeNanoSecond, _ := strconv.Atoi(strings.Split(oldTimeValues[2], ".")[1]) newTimeValues := strings.Split(newTimestamp, ":") newTimeHour, _ := strconv.Atoi(newTimeValues[0]) newTimeMinute, _ := strconv.Atoi(newTimeValues[1]) newTimeSecond, _ := strconv.Atoi(strings.Split(newTimeValues[2], ".")[0]) newTimeNanoSecond, _ := strconv.Atoi(strings.Split(newTimeValues[2], ".")[1]) y, m, d := time.Now().Date() oldTime := time.Date(y, m, d, oldTimeHour, oldTimeMinute, oldTimeSecond, oldTimeNanoSecond, time.UTC) newTime := time.Date(y, m, d, newTimeHour, newTimeMinute, newTimeSecond, newTimeNanoSecond, time.UTC) return newTime.Sub(oldTime).Minutes() } func validateResourceEnv(oc *exutil.CLI, namespace, resource, value string) { result, err := oc.AsAdmin().WithoutNamespace().Run("set").Args("env", "-n", namespace, resource, "--list").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(strings.Contains(result, value)).To(o.BeTrue()) } func checkDiscPolicy(oc *exutil.CLI) (string, bool) { sites := [3]string{"ImageContentSourcePolicy", "idms", "itms"} for _, policy := range sites { result, err := oc.AsAdmin().WithoutNamespace().Run("get").Args(policy).Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(result, "No resources found") { return policy, true } } return "", false } func checkMirrorRegistry(oc *exutil.CLI, repo string) string { policy, dis := checkDiscPolicy(oc) switch dis { case policy == "ImageContentSourcePolicy": mirrorReg, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("ImageContentSourcePolicy/image-policy-aosqe", "-o=jsonpath={.spec.repositoryDigestMirrors[?(@.source==\""+repo+"\")].mirrors[]}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return mirrorReg case policy == "idms": mirrorReg, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("idms/image-policy-aosqe", "-o=jsonpath={.spec.imageDigestMirrors[?(@.source==\""+repo+"\")].mirrors[]}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return mirrorReg case policy == "itms": mirrorReg, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("itms/image-policy-aosqe", "-o=jsonpath={.spec.imageTagMirrors[?(@.source==\""+repo+"\")].mirrors[]}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return mirrorReg } return "" } func SkipDnsFailure(oc *exutil.CLI) { expectedStatus := map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} err := waitCoBecomes(oc, "ingress", 240, expectedStatus) if err != nil { g.Skip("Ingress is not ready, skip the case test!") } err = waitCoBecomes(oc, "dns", 240, expectedStatus) if err != nil { g.Skip("Dns is not ready, skip the case test!") } } // Upi install on azure is based on azure arm template // Ipi install on azure is based on cluster api since 4.17 func isIPIAzure(oc *exutil.CLI) bool { result, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("cm", "openshift-install", "-n", "openshift-config").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(result, "NotFound") { return true } return false } func hasDuplicate(slice []string, value string) bool { countMap := make(map[string]int) for _, v := range slice { if v == value { countMap[v]++ if countMap[v] > 1 { return true } } } return false } func configureRegistryStorageToPvc(oc *exutil.CLI, pvcName string) { err := oc.AsAdmin().WithoutNamespace().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"storage":null, "managementState":"Unmanaged"}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) patchInfo := fmt.Sprintf("{\"spec\":{\"managementState\":\"Managed\",\"replicas\":1,\"rolloutStrategy\":\"Recreate\",\"storage\":{\"managementState\":\"Managed\",\"pvc\":{\"claim\":\"%s\"}}}}", pvcName) err = oc.AsAdmin().WithoutNamespace().Run("patch").Args("configs.imageregistry/cluster", "-p", patchInfo, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) checkPodsRunningWithLabel(oc, "openshift-image-registry", "docker-registry=default", 1) } type persistentVolumeClaim struct { name string namespace string accessmode string memorysize string storageclassname string template string } func (pvc *persistentVolumeClaim) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", pvc.template, "-p", "NAME="+pvc.name, "NAMESPACE="+pvc.namespace, "MEMORYSIZE="+pvc.memorysize, "STORAGECLASSNAME="+pvc.storageclassname, "ACCESSMODE="+pvc.accessmode) o.Expect(err).NotTo(o.HaveOccurred()) } func waitForPvcStatus(oc *exutil.CLI, namespace string, pvcname string) { err := wait.Poll(10*time.Second, 180*time.Second, func() (bool, error) { pvStatus, err := oc.AsAdmin().Run("get").Args("-n", namespace, "pvc", pvcname, "-o=jsonpath='{.status.phase}'").Output() if err != nil { return false, err } if match, _ := regexp.MatchString("Bound", pvStatus); match { return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(err, "The PVC is not Bound as expected") } func checkMetric(oc *exutil.CLI, url, token, metricString string, timeout time.Duration) { var metrics string var err error getCmd := "curl -G -k -s -H \"Authorization:Bearer " + token + "\" " + url err = wait.PollUntilContextTimeout(context.TODO(), 3*time.Second, timeout*time.Second, false, func(context.Context) (bool, error) { metrics, err = exutil.RemoteShPod(oc, "openshift-monitoring", "prometheus-k8s-0", "sh", "-c", getCmd) if err != nil || !strings.Contains(metrics, metricString) { return false, nil } return true, err }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("The metrics %s failed to contain %s", metrics, metricString)) } type azureStorageSetting struct { AccountName string `json:"accountName"` CloudName string `json:"cloudName"` Container string `json:"container"` ManagementState string `json:"managementState"` NetworkAccess struct { Type string `json:"type"` } `json:"networkAccess"` } func getAzureImageRegistryStorage(oc *exutil.CLI) azureStorageSetting { var setting azureStorageSetting output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("config.image/cluster", "-o=jsonpath={.status.storage.azure}").Output() o.Expect(err).NotTo(o.HaveOccurred()) json.Unmarshal([]byte(output), &setting) return setting } func getAzureRegion(oc *exutil.CLI) string { regionSec, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("secret/installer-cloud-credentials", "-n", "openshift-image-registry", "-o=jsonpath={.data.azure_region}").Output() o.Expect(err).NotTo(o.HaveOccurred()) region, err := base64.StdEncoding.DecodeString(regionSec) o.Expect(err).NotTo(o.HaveOccurred()) return string(region) } func getResourceGroupOnAzure(oc *exutil.CLI) string { resourceGroup, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructures", "cluster", "-o=jsonpath={.status.platformStatus.azure.resourceGroupName}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return resourceGroup } func IsFeaturegateEnabled(oc *exutil.CLI, featuregate string) (bool, error) { enabledFeatureGates, err := getEnabledFeatureGates(oc) if err != nil { return false, err } for _, f := range enabledFeatureGates { if f == featuregate { return true, nil } } return false, nil } func getEnabledFeatureGates(oc *exutil.CLI) ([]string, error) { enabledFeatureGates, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("featuregate", "cluster", "-o=jsonpath={.status.featureGates[0].enabled[*].name}").Output() if err != nil { return nil, err } return strings.Split(enabledFeatureGates, " "), nil } func IsMultiArch(oc *exutil.CLI) bool { architecture, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("clusterversion/version", "-o=jsonpath={..status.desired.architecture}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return strings.ToLower(architecture) == "multi" }
package imageregistry
function
openshift/openshift-tests-private
ea15d303-ec54-4f52-9233-85558df160bc
gatherMetricsResult
['"context"', '"encoding/json"', '"fmt"', '"os/exec"', '"strconv"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
['prometheusImageregistryQueryHTTP']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func gatherMetricsResult(oc *exutil.CLI, token, prometheusURL string, metrics []string) map[string]int { var ( data prometheusImageregistryQueryHTTP err error l int msg string result = make(map[string]int) ) for _, query := range metrics { prometheusURLQuery := fmt.Sprintf("%v/query?query=%v", prometheusURL, query) err = wait.PollUntilContextTimeout(context.TODO(), 10*time.Second, 30*time.Second, false, func(ctx context.Context) (bool, error) { msg, _, err = oc.AsAdmin().WithoutNamespace().Run("exec").Args("-n", "openshift-monitoring", "-c", "prometheus", "prometheus-k8s-0", "-i", "--", "curl", "-k", "-H", fmt.Sprintf("Authorization: Bearer %v", token), prometheusURLQuery).Outputs() if err != nil || msg == "" { return false, nil } return true, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("the query %v is getting failed", query)) json.Unmarshal([]byte(msg), &data) l = len(data.Data.Result) - 1 result[query], _ = strconv.Atoi(data.Data.Result[l].Value[1].(string)) e2e.Logf("The query %v result == %v", query, result[query]) } return result }
imageregistry
function
openshift/openshift-tests-private
52d96c15-f591-4099-9dd9-149e314aa4bf
listPodStartingWith
['"context"', '"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func listPodStartingWith(prefix string, oc *exutil.CLI, namespace string) (pod []corev1.Pod) { podsToAll := []corev1.Pod{} podList, err := oc.AdminKubeClient().CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{}) if err != nil { e2e.Logf("Error listing pods: %v", err) return nil } for _, pod := range podList.Items { if strings.HasPrefix(pod.Name, prefix) { podsToAll = append(podsToAll, pod) } } return podsToAll }
imageregistry
function
openshift/openshift-tests-private
a0fb2993-a84e-438e-83ad-ee1644b997fa
dePodLogs
['"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func dePodLogs(pods []corev1.Pod, oc *exutil.CLI, matchlogs string) bool { for _, pod := range pods { depOutput, err := oc.AsAdmin().WithoutNamespace().Run("logs").Args("pod/"+pod.Name, "-n", pod.Namespace).Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(depOutput, matchlogs) { return true } } return false }
imageregistry
function
openshift/openshift-tests-private
7b6e4cd4-21f4-478b-9d09-53a40df3042a
getBearerTokenURLViaPod
['"fmt"', '"time"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getBearerTokenURLViaPod(ns, execPodName, url, bearer string) (string, error) { g.By("Get token via pod") cmd := fmt.Sprintf("curl --retry 15 --max-time 4 --retry-delay 1 -s -k -H 'Authorization: Bearer %s' %s", bearer, url) output, err := e2eoutput.RunHostCmd(ns, execPodName, cmd) if err != nil { return "", fmt.Errorf("host command failed: %v\n%s", err, output) } return output, nil }
imageregistry
function
openshift/openshift-tests-private
f4813b20-0506-4925-9387-05fb7f57eade
create
['bcSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (bcsrc *bcSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", bcsrc.template, "-p", "OUTNAME="+bcsrc.outname, "NAME="+bcsrc.name, "NAMESPACE="+bcsrc.namespace) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
b21fec29-685c-4986-ab1c-af0d78301545
create
['authRole']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (authrole *authRole) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", authrole.template, "-p", "NAMESPACE="+authrole.namespace, "ROLE_NAME="+authrole.rolename) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
f6b35585-be56-4d5a-a19f-30bff75e611a
parseToJSON
['"encoding/json"', '"time"', '"github.com/aws/aws-sdk-go-v2/config"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func parseToJSON(oc *exutil.CLI, parameters []string) string { var configFile string err := wait.Poll(3*time.Second, 15*time.Second, func() (bool, error) { output, err := oc.AsAdmin().Run("process").Args(parameters...).OutputToFile(getRandomString() + "config.json") if err != nil { e2e.Logf("the err:%v, and try next round", err) return false, nil } configFile = output return true, nil }) exutil.AssertWaitPollNoErr(err, "Applying resources from template is failed") e2e.Logf("the file of resource is %s", configFile) return configFile }
imageregistry
function
openshift/openshift-tests-private
f5a17768-820f-44d1-b74d-58d0afdb2638
createResourceFromTemplate
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func createResourceFromTemplate(oc *exutil.CLI, parameters ...string) error { configFile := parseToJSON(oc, parameters) return oc.AsAdmin().WithoutNamespace().Run("create").Args("-f", configFile).Execute() }
imageregistry
function
openshift/openshift-tests-private
8d1531c3-372f-4f8c-b133-54e269f612e5
applyResourceFromTemplate
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func applyResourceFromTemplate(oc *exutil.CLI, parameters ...string) error { configFile := parseToJSON(oc, parameters) return oc.AsAdmin().WithoutNamespace().Run("apply").Args("-f", configFile).Execute() }
imageregistry
function
openshift/openshift-tests-private
3898076f-156b-4721-9ea1-8c8ec7afc0d1
getRandomString
['"math/rand"', '"time"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getRandomString() string { chars := "abcdefghijklmnopqrstuvwxyz" seed := rand.New(rand.NewSource(time.Now().UnixNano())) buffer := make([]byte, 8) for index := range buffer { buffer[index] = chars[seed.Intn(len(chars))] } return string(buffer) }
imageregistry
function
openshift/openshift-tests-private
9dc7340c-a537-41b6-bff1-199da1101ec9
getResource
['"fmt"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getResource(oc *exutil.CLI, asAdmin, withoutNamespace bool, parameters ...string) string { var result string var err error err = wait.Poll(3*time.Second, 150*time.Second, func() (bool, error) { result, err = doAction(oc, "get", asAdmin, withoutNamespace, parameters...) if err != nil { e2e.Logf("output is %v, error is %v, and try next", result, err) return false, nil } return true, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("Failed to get %v", parameters)) e2e.Logf("$oc get %v, the returned resource:%v", parameters, result) return result }
imageregistry
function
openshift/openshift-tests-private
32968daa-60c8-459d-8366-78b3d4d7f256
doAction
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func doAction(oc *exutil.CLI, action string, asAdmin, withoutNamespace bool, parameters ...string) (string, error) { if asAdmin && withoutNamespace { return oc.AsAdmin().WithoutNamespace().Run(action).Args(parameters...).Output() } if asAdmin && !withoutNamespace { return oc.AsAdmin().Run(action).Args(parameters...).Output() } if !asAdmin && withoutNamespace { return oc.WithoutNamespace().Run(action).Args(parameters...).Output() } if !asAdmin && !withoutNamespace { return oc.Run(action).Args(parameters...).Output() } return "", nil }
imageregistry
function
openshift/openshift-tests-private
17529ff7-bb97-4170-834d-465b20a08bf3
comparePodHostIP
['"context"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func comparePodHostIP(oc *exutil.CLI) (int, int) { var hostsIP = []string{} var numi, numj int podList, _ := oc.AdminKubeClient().CoreV1().Pods("openshift-image-registry").List(context.Background(), metav1.ListOptions{LabelSelector: "docker-registry=default"}) for _, pod := range podList.Items { hostsIP = append(hostsIP, pod.Status.HostIP) } for i := 0; i < len(hostsIP)-1; i++ { for j := i + 1; j < len(hostsIP); j++ { if hostsIP[i] == hostsIP[j] { numi++ } else { numj++ } } } return numi, numj }
imageregistry
function
openshift/openshift-tests-private
8cd9c201-62aa-4e9e-bae9-45f1bec46abd
imagePruneLog
['"fmt"', '"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func imagePruneLog(oc *exutil.CLI, matchLogs, notMatchLogs string) { podsOfImagePrune := []corev1.Pod{} err := wait.Poll(10*time.Second, 5*time.Minute, func() (bool, error) { podsOfImagePrune = listPodStartingWith("image-pruner", oc, "openshift-image-registry") if len(podsOfImagePrune) == 0 { e2e.Logf("Can't get pruner pods, go to next round") return false, nil } pod := podsOfImagePrune[len(podsOfImagePrune)-1] e2e.Logf("the pod status is %s", pod.Status.Phase) if pod.Status.Phase != "ContainerCreating" && pod.Status.Phase != "Pending" { depOutput, _ := oc.AsAdmin().WithoutNamespace().Run("logs").Args("pod/"+pod.Name, "-n", pod.Namespace).Output() if strings.Contains(depOutput, matchLogs) && !strings.Contains(depOutput, notMatchLogs) { return true, nil } } e2e.Logf("The image pruner log doesn't contain %v or contain %v", matchLogs, notMatchLogs) return false, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("Can't get the image pruner log or image pruner log doesn't contain %v or contain %v", matchLogs, notMatchLogs)) }
imageregistry
function
openshift/openshift-tests-private
4c5430c8-2d06-4125-bc9c-7ebc35e0db92
configureRegistryStorageToEmptyDir
['"context"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func configureRegistryStorageToEmptyDir(oc *exutil.CLI) { emptydirstorage, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("configs.imageregistry/cluster", "-o=jsonpath={.status.storage.emptyDir}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if emptydirstorage == "{}" { g.By("Image registry is using EmptyDir now") } else { g.By("Set registry to use EmptyDir storage") storagetype, _ := getRegistryStorageConfig(oc) err = oc.AsAdmin().WithoutNamespace().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"storage":{"`+storagetype+`":null,"emptyDir":{}}, "replicas":1}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(30*time.Second, 2*time.Minute, func() (bool, error) { podList, _ := oc.AdminKubeClient().CoreV1().Pods("openshift-image-registry").List(context.Background(), metav1.ListOptions{LabelSelector: "docker-registry=default"}) o.Expect(err).NotTo(o.HaveOccurred()) if len(podList.Items) == 1 && podList.Items[0].Status.Phase == corev1.PodRunning { return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, "Image registry pod list is not 1") err = oc.AsAdmin().WithoutNamespace().Run("wait").Args("configs.imageregistry/cluster", "--for=condition=Available").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } }
imageregistry
function
openshift/openshift-tests-private
854d8e4e-38ac-4ebb-9f1d-47f409952f48
recoverRegistryStorageConfig
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func recoverRegistryStorageConfig(oc *exutil.CLI) { g.By("Set image registry storage to default value") platformtype, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.spec.platformSpec.type}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if platformtype != "VSphere" { if platformtype != "None" { err := oc.AsAdmin().WithoutNamespace().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"storage":null}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) g.By("Image registry will be auto-recovered to default storage") } } }
imageregistry
function
openshift/openshift-tests-private
20ae4266-2edc-417e-be0e-e7c4d17f0c3d
recoverRegistryDefaultReplicas
['"github.com/aws/aws-sdk-go-v2/config"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func recoverRegistryDefaultReplicas(oc *exutil.CLI) { g.By("Set image registry to default replicas") platforms := map[string]bool{ "VSphere": true, "None": true, "oVirt": true, } expectedStatus1 := map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} platformtype, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.spec.platformSpec.type}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !platforms[platformtype] { g.By("Check if cluster is sno") workerNodes, _ := exutil.GetClusterNodesBy(oc, "worker") if len(workerNodes) == 1 { err := oc.AsAdmin().WithoutNamespace().Run("patch").Args("config.imageregistry/cluster", "-p", `{"spec":{"replicas":1}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } else { err := oc.AsAdmin().WithoutNamespace().Run("patch").Args("config.imageregistry/cluster", "-p", `{"spec":{"replicas":2}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) } err = waitCoBecomes(oc, "image-registry", 240, expectedStatus1) o.Expect(err).NotTo(o.HaveOccurred()) } }
imageregistry
function
openshift/openshift-tests-private
6be58d40-212b-4fad-bd4e-aa7370c20a1e
getRegistryStorageConfig
['"github.com/aws/aws-sdk-go-v2/config"', '"github.com/aws/aws-sdk-go-v2/service/s3"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getRegistryStorageConfig(oc *exutil.CLI) (string, string) { var storagetype, storageinfo string g.By("Get image registry storage info") platformtype, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.spec.platformSpec.type}").Output() o.Expect(err).NotTo(o.HaveOccurred()) switch platformtype { case "AWS": storagetype = "s3" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.s3.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "Azure": storagetype = "azure" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.azure.container}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "GCP": storagetype = "gcs" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.gcs.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "OpenStack": storagetype = swiftType storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.swift.container}").Output() o.Expect(err).NotTo(o.HaveOccurred()) // On disconnect & openstack, the registry configure to use persistent volume if storageinfo == "" { storagetype = pvcType storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.pvc.claim}").Output() o.Expect(err).NotTo(o.HaveOccurred()) } case "AlibabaCloud": storagetype = "oss" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.oss.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "IBMCloud": storagetype = "ibmcos" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.ibmcos.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) case "BareMetal", "None", "VSphere", "Nutanix", "External": storagetype = pvcType storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.pvc.claim}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if storageinfo == "" { storagetype = emptyDir storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.emptyDir}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if storageinfo == "" { storagetype = "s3" storageinfo, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage.s3.bucket}").Output() o.Expect(err).NotTo(o.HaveOccurred()) } } default: e2e.Logf("Image Registry is using unknown storage type") } return storagetype, storageinfo }
imageregistry
function
openshift/openshift-tests-private
d649aaf0-67fa-4ef3-8ca1-caf94044f830
checkRegistrypodsRemoved
['"context"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func checkRegistrypodsRemoved(oc *exutil.CLI) { err := wait.Poll(25*time.Second, 3*time.Minute, func() (bool, error) { podList, err := oc.AdminKubeClient().CoreV1().Pods("openshift-image-registry").List(context.Background(), metav1.ListOptions{LabelSelector: "docker-registry=default"}) o.Expect(err).NotTo(o.HaveOccurred()) if len(podList.Items) == 0 { return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(err, "Image registry pods are not removed") }
imageregistry
function
openshift/openshift-tests-private
ff04d622-9996-4697-8728-7d02e3e35c44
create
['staSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (stafulsrc *staSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", stafulsrc.template, "-p", "NAME="+stafulsrc.name, "NAMESPACE="+stafulsrc.namespace, "IMAGE="+stafulsrc.image) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
eaa85f88-cdaf-4a7b-8ba8-eb8c5d6bfec4
checkPodsRunningWithLabel
['"context"', '"fmt"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func checkPodsRunningWithLabel(oc *exutil.CLI, namespace, label string, number int) { err := wait.Poll(25*time.Second, 6*time.Minute, func() (bool, error) { podList, _ := oc.AdminKubeClient().CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{LabelSelector: label}) if len(podList.Items) != number { e2e.Logf("the pod number is not %d, Continue to next round", number) return false, nil } for _, pod := range podList.Items { if pod.Status.Phase != corev1.PodRunning { e2e.Logf("Continue to next round") return false, nil } } return true, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("pods list are not %d", number)) }
imageregistry
function
openshift/openshift-tests-private
2d61a332-4121-4028-a033-8882e04e1e0c
create
['icspSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (icspsrc *icspSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", icspsrc.template, "-p", "NAME="+icspsrc.name, "MIRRORS="+icspsrc.mirrors, "SOURCE="+icspsrc.source) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
df5bff14-b3dd-4ae3-b3da-b99e4ade285e
delete
['icspSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (icspsrc *icspSource) delete(oc *exutil.CLI) { e2e.Logf("deleting icsp: %s", icspsrc.name) err := oc.AsAdmin().WithoutNamespace().Run("delete").Args("imagecontentsourcepolicy", icspsrc.name, "--ignore-not-found=true").Execute() o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
849ae947-6a45-4a94-b274-cb11fd7ce0c5
getRegistryDefaultRoute
['"time"', '"k8s.io/apimachinery/pkg/util/wait"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getRegistryDefaultRoute(oc *exutil.CLI) (defaultroute string) { err := wait.Poll(5*time.Second, 30*time.Second, func() (bool, error) { defroute, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("route", "-n", "openshift-image-registry", "default-route", "-o=jsonpath={.spec.host}").Output() if defroute == "" || err != nil { e2e.Logf("Continue to next round") return false, nil } defaultroute = defroute return true, nil }) exutil.AssertWaitPollNoErr(err, "Did not find registry route") return defaultroute }
imageregistry
function
openshift/openshift-tests-private
26ebb646-7c9c-440b-a16d-375f003f1c33
setImageregistryConfigs
['"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func setImageregistryConfigs(oc *exutil.CLI, pathinfo, matchlogs string) bool { foundInfo := false defer recoverRegistrySwiftSet(oc) err := oc.WithoutNamespace().AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"storage":{"swift":{`+pathinfo+`}}}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(5*time.Second, 20*time.Second, func() (bool, error) { output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("co/image-registry").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, matchlogs) { foundInfo = true return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, "No image registry error info found") return foundInfo }
imageregistry
function
openshift/openshift-tests-private
1d763c7a-3fe6-438c-8331-d3c575293364
recoverRegistrySwiftSet
['"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func recoverRegistrySwiftSet(oc *exutil.CLI) { matchInfo := "True False False" err := oc.WithoutNamespace().AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"storage":{"swift":{"authURL":null, "regionName":null, "regionID":null, "domainID":null, "domain":null, "tenantID":null}}}}`, "--type=merge").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(4*time.Second, 20*time.Second, func() (bool, error) { output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("co/image-registry", "-o=jsonpath={.status.conditions[*].status}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, matchInfo) { return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, "Image registry is degrade") }
imageregistry
function
openshift/openshift-tests-private
a64ca9d9-27f0-425c-96ab-7b120a9e381f
create
['podSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (podsrc *podSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", podsrc.template, "-p", "NAME="+podsrc.name, "NAMESPACE="+podsrc.namespace, "IMAGE="+podsrc.image) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
0eb3cee6-7305-46f2-9103-c765fd8def85
checkRegistryUsingFSVolume
['"strings"', '"github.com/aws/aws-sdk-go-v2/config"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func checkRegistryUsingFSVolume(oc *exutil.CLI) bool { storageinfo, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("config.image", "cluster", "-o=jsonpath={.spec.storage}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(storageinfo, pvcType) || strings.Contains(storageinfo, emptyDir) { return true } return false }
imageregistry
function
openshift/openshift-tests-private
7fc962fe-126d-44cc-b588-a5b1f44a3726
saveImageMetadataName
['"os"', '"os/exec"', '"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func saveImageMetadataName(oc *exutil.CLI, image string) string { imagemetadata, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("images").OutputToFile("imagemetadata.txt") o.Expect(err).NotTo(o.HaveOccurred()) defer os.Remove("imagemetadata.txt") manifest, err := exec.Command("bash", "-c", "cat "+imagemetadata+" | grep "+image+" | awk '{print $1}'").Output() o.Expect(err).NotTo(o.HaveOccurred()) return strings.TrimSuffix(string(manifest), "\n") }
imageregistry
function
openshift/openshift-tests-private
8172c6c5-af86-4223-8324-5cc9b558ca07
checkRegistryFunctionFine
['"fmt"', '"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func checkRegistryFunctionFine(oc *exutil.CLI, bcname, namespace string) { errTag := oc.AsAdmin().WithoutNamespace().Run("tag").Args("quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", "busybox:latest", "--reference-policy=local", "--import-mode=PreserveOriginal", "-n", namespace).Execute() o.Expect(errTag).NotTo(o.HaveOccurred()) errTag = waitForAnImageStreamTag(oc, namespace, "busybox", "latest") o.Expect(errTag).NotTo(o.HaveOccurred()) // Check if could push images to image registry err := oc.AsAdmin().WithoutNamespace().Run("new-build").Args("-D", "FROM quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f", "--to="+bcname, "-n", namespace).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = exutil.WaitForABuild(oc.BuildClient().BuildV1().Builds(namespace), bcname+"-1", nil, nil, nil) if err != nil { exutil.DumpBuildLogs(bcname, oc) } exutil.AssertWaitPollNoErr(err, "build is not complete") err = exutil.WaitForAnImageStreamTag(oc, namespace, bcname, "latest") o.Expect(err).NotTo(o.HaveOccurred()) // Check if could pull images from image registry imagename := "image-registry.openshift-image-registry.svc:5000/" + namespace + "/" + bcname + ":latest" err = oc.AsAdmin().WithoutNamespace().Run("run").Args(bcname, "--image", imagename, `--overrides={"spec":{"securityContext":{"runAsNonRoot":true,"seccompProfile":{"type":"RuntimeDefault"}}}}`, "-n", namespace, "--command", "--", "/bin/sleep", "120").Execute() o.Expect(err).NotTo(o.HaveOccurred()) var output string errWait := wait.Poll(10*time.Second, 3*time.Minute, func() (bool, error) { output, err = oc.AsAdmin().WithoutNamespace().Run("describe").Args("pod", bcname, "-n", namespace).Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, `Successfully pulled image`) { return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(errWait, fmt.Sprintf("Image registry is broken, can't pull image. the log:\n %v", output)) }
imageregistry
function
openshift/openshift-tests-private
eb64af82-eda7-46b5-82e0-5861fb86d0d6
checkRegistryDegraded
['"strings"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func checkRegistryDegraded(oc *exutil.CLI) bool { status := "TrueFalseFalse" output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("co/image-registry", "-o=jsonpath={.status.conditions[?(@.type==\"Available\")].status}{.status.conditions[?(@.type==\"Progressing\")].status}{.status.conditions[?(@.type==\"Degraded\")].status}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return !strings.Contains(output, status) }
imageregistry
function
openshift/openshift-tests-private
55d1d616-6f67-45d3-a8d5-eee687c3ab9c
getCreditFromCluster
['"encoding/base64"', '"encoding/json"', '"github.com/tidwall/gjson"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getCreditFromCluster(oc *exutil.CLI) (string, string, string) { credential, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("secret/aws-creds", "-n", "kube-system", "-o", "json").Output() o.Expect(err).NotTo(o.HaveOccurred()) accessKeyIDBase64, secureKeyBase64 := gjson.Get(credential, `data.aws_access_key_id`).Str, gjson.Get(credential, `data.aws_secret_access_key`).Str accessKeyID, err1 := base64.StdEncoding.DecodeString(accessKeyIDBase64) o.Expect(err1).NotTo(o.HaveOccurred()) secureKey, err2 := base64.StdEncoding.DecodeString(secureKeyBase64) o.Expect(err2).NotTo(o.HaveOccurred()) clusterRegion, err3 := oc.AsAdmin().WithoutNamespace().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.status.platformStatus.aws.region}").Output() o.Expect(err3).NotTo(o.HaveOccurred()) return string(accessKeyID), string(secureKey), clusterRegion }
imageregistry
function
openshift/openshift-tests-private
c70d1427-fc7e-438c-a603-58d7cdf6821e
getAWSClient
['"context"', '"github.com/aws/aws-sdk-go-v2/config"', '"github.com/aws/aws-sdk-go-v2/credentials"', '"github.com/aws/aws-sdk-go-v2/service/s3"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getAWSClient(oc *exutil.CLI) *s3.Client { accessKeyID, secureKey, clusterRegion := getCreditFromCluster(oc) cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKeyID, secureKey, "")), config.WithRegion(clusterRegion)) o.Expect(err).NotTo(o.HaveOccurred()) return s3.NewFromConfig(cfg) }
imageregistry
function
openshift/openshift-tests-private
6e1099ac-2bec-40fc-bdc3-82460454edd2
awsGetBucketTagging
['"context"', '"fmt"', '"github.com/aws/aws-sdk-go-v2/service/s3"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func awsGetBucketTagging(client *s3.Client, bucket string) (string, error) { tagOutput, err := client.GetBucketTagging(context.TODO(), &s3.GetBucketTaggingInput{Bucket: &bucket}) if err != nil { outputGetTag := fmt.Sprintf("Got an error GetBucketTagging for %s: %v", bucket, err) return outputGetTag, err } outputGetTag := "" for _, t := range tagOutput.TagSet { outputGetTag += *t.Key + " " + *t.Value + "\n" } return outputGetTag, nil }
imageregistry
function
openshift/openshift-tests-private
e8412d45-e891-40b0-830a-b003998b935d
newCheck
['checkDescription']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func newCheck(method string, executor bool, inlineNamespace bool, expectAction bool, expectContent string, expect bool, resource []string) checkDescription { return checkDescription{ method: method, executor: executor, inlineNamespace: inlineNamespace, expectAction: expectAction, expectContent: expectContent, expect: expect, resource: resource, } }
imageregistry
function
openshift/openshift-tests-private
b60a898d-95c6-4125-894e-c77aace43014
check
['"fmt"']
['checkDescription']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (ck checkDescription) check(oc *exutil.CLI) { switch ck.method { case "present": ok := isPresentResource(oc, ck.executor, ck.inlineNamespace, ck.expectAction, ck.resource...) o.Expect(ok).To(o.BeTrue()) case "expect": err := expectedResource(oc, ck.executor, ck.inlineNamespace, ck.expectAction, ck.expectContent, ck.expect, ck.resource...) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("expected content %s not found by %v", ck.expectContent, ck.resource)) default: err := fmt.Errorf("unknown method") o.Expect(err).NotTo(o.HaveOccurred()) } }
imageregistry
function
openshift/openshift-tests-private
cc1cc62e-edd2-426c-b06a-9ffd58a429f1
isPresentResource
['"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func isPresentResource(oc *exutil.CLI, asAdmin, withoutNamespace, present bool, parameters ...string) bool { parameters = append(parameters, "--ignore-not-found") err := wait.Poll(3*time.Second, 70*time.Second, func() (bool, error) { output, err := doAction(oc, "get", asAdmin, withoutNamespace, parameters...) if err != nil { e2e.Logf("the get error is %v, and try next", err) return false, nil } if !present && strings.Compare(output, "") == 0 { return true, nil } if present && strings.Compare(output, "") != 0 { return true, nil } return false, nil }) return err == nil }
imageregistry
function
openshift/openshift-tests-private
9062c4e9-5062-4dde-af5b-b47036121ab8
expectedResource
['"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func expectedResource(oc *exutil.CLI, asAdmin, withoutNamespace, isCompare bool, content string, expect bool, parameters ...string) error { expectMap := map[bool]string{ true: "do", false: "do not", } cc := func(a, b string, ic bool) bool { bs := strings.Split(b, "+2+") ret := false for _, s := range bs { if (ic && strings.Compare(a, s) == 0) || (!ic && strings.Contains(a, s)) { ret = true } } return ret } e2e.Logf("Running: oc get asAdmin(%t) withoutNamespace(%t) %s", asAdmin, withoutNamespace, strings.Join(parameters, " ")) return wait.Poll(3*time.Second, 150*time.Second, func() (bool, error) { output, err := doAction(oc, "get", asAdmin, withoutNamespace, parameters...) if err != nil { e2e.Logf("the get error is %v, and try next", err) return false, nil } e2e.Logf("---> we %v expect value: %s, in returned value: %s", expectMap[expect], content, output) if isCompare && expect && cc(output, content, isCompare) { e2e.Logf("the output %s matches one of the content %s, expected", output, content) return true, nil } if isCompare && !expect && !cc(output, content, isCompare) { e2e.Logf("the output %s does not matche the content %s, expected", output, content) return true, nil } if !isCompare && expect && cc(output, content, isCompare) { e2e.Logf("the output %s contains one of the content %s, expected", output, content) return true, nil } if !isCompare && !expect && !cc(output, content, isCompare) { e2e.Logf("the output %s does not contain the content %s, expected", output, content) return true, nil } e2e.Logf("---> Not as expected! Return false") return false, nil }) }
imageregistry
function
openshift/openshift-tests-private
f2a21805-8c94-442b-87ba-d29d36ab5316
exposeService
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func exposeService(oc *exutil.CLI, ns, resource, name, port string) { err := oc.AsAdmin().WithoutNamespace().Run("expose").Args(resource, "--name="+name, "--port="+port, "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
299d75bd-928e-422c-99db-4a3f1a9e3cc9
exposeRouteFromSVC
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func exposeRouteFromSVC(oc *exutil.CLI, rType, ns, route, service string) string { err := oc.AsAdmin().WithoutNamespace().Run("create").Args("route", rType, route, "--service="+service, "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) regRoute, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("route", route, "-n", ns, "-o=jsonpath={.spec.host}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return regRoute }
imageregistry
function
openshift/openshift-tests-private
c4a716a4-43ca-4a6b-9952-aacc5aee5487
listRepositories
['"fmt"', '"os/exec"', 'g "github.com/onsi/ginkgo/v2"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func listRepositories(regRoute, expect string) { curlCmd := fmt.Sprintf("curl -ks https://%s/v2/_catalog | grep %s", regRoute, expect) result, err := exec.Command("bash", "-c", curlCmd).CombinedOutput() if err != nil { e2e.Logf("Command: \"%s\" returned: %v", curlCmd, string(result)) o.Expect(err).NotTo(o.HaveOccurred()) } o.Expect(string(result)).To(o.ContainSubstring(expect)) }
imageregistry
function
openshift/openshift-tests-private
ac77d287-eea0-4a8d-bea1-b0e7b0813f30
setSecureRegistryWithoutAuth
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func setSecureRegistryWithoutAuth(oc *exutil.CLI, ns, regName, image, port string) string { err := oc.AsAdmin().WithoutNamespace().Run("create").Args("deploy", regName, "--image="+image, "--port=5000", "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) checkPodsRunningWithLabel(oc, ns, "app="+regName, 1) exposeService(oc, ns, "deploy/"+regName, regName, port) regRoute := exposeRouteFromSVC(oc, "edge", ns, regName, regName) checkDnsCO(oc) waitRouteReady(regRoute) listRepositories(regRoute, "repositories") return regRoute }
imageregistry
function
openshift/openshift-tests-private
b99ebdaf-32c7-4a21-b876-804977bc3466
setSecureRegistryEnableAuth
['"time"', '"k8s.io/apimachinery/pkg/util/wait"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func setSecureRegistryEnableAuth(oc *exutil.CLI, ns, regName, htpasswdFile, image string) string { regRoute := setSecureRegistryWithoutAuth(oc, ns, regName, image, "5000") ge1 := saveGeneration(oc, ns, "deployment/"+regName) err := oc.AsAdmin().WithoutNamespace().Run("create").Args("secret", "generic", "htpasswd", "--from-file="+htpasswdFile, "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = oc.WithoutNamespace().Run("set").Args("volume", "deployment/"+regName, "--add", "--mount-path=/auth", "--type=secret", "--secret-name=htpasswd", "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = oc.WithoutNamespace().Run("set").Args("env", "deployment/"+regName, "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd", "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm", "REGISTRY_AUTH=htpasswd", "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(5*time.Second, 60*time.Second, func() (bool, error) { ge2 := saveGeneration(oc, ns, "deployment/"+regName) if ge2 == ge1 { e2e.Logf("Continue to next round") return false, nil } return true, nil }) exutil.AssertWaitPollNoErr(err, "Custom registry does not update") checkPodsRunningWithLabel(oc, ns, "app="+regName, 1) return regRoute }
imageregistry
function
openshift/openshift-tests-private
c84721ae-ad69-4ffe-bf99-0da9df6e212a
generateHtpasswdFile
['"fmt"', '"os/exec"', '"path/filepath"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func generateHtpasswdFile(tempDataDir, user, pass string) (string, error) { htpasswdFile := filepath.Join(tempDataDir, "htpasswd") generateCMD := fmt.Sprintf("htpasswd -Bbn %s %s > %s", user, pass, htpasswdFile) _, err := exec.Command("bash", "-c", generateCMD).Output() if err != nil { e2e.Logf("Fail to generate htpasswd file: %v", err) return htpasswdFile, err } return htpasswdFile, nil }
imageregistry
function
openshift/openshift-tests-private
48662c2b-1c47-4a53-bdfc-4316b161179f
extractPullSecret
['"fmt"', '"os"', '"path/filepath"', '"github.com/aws/aws-sdk-go-v2/config"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func extractPullSecret(oc *exutil.CLI) (string, error) { tempDataDir := filepath.Join("/tmp/", fmt.Sprintf("ir-%s", getRandomString())) err := os.Mkdir(tempDataDir, 0o755) if err != nil { e2e.Logf("Fail to create directory: %v", err) return tempDataDir, err } err = oc.AsAdmin().Run("extract").Args("secret/pull-secret", "-n", "openshift-config", "--confirm", "--to="+tempDataDir).Execute() if err != nil { e2e.Logf("Fail to extract dockerconfig: %v", err) return tempDataDir, err } return tempDataDir, nil }
imageregistry
function
openshift/openshift-tests-private
2d76288a-d3eb-44e6-b56c-fbbdc9adee5b
appendPullSecretAuth
['"encoding/base64"', '"encoding/json"', '"fmt"', '"os/exec"', '"path/filepath"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func appendPullSecretAuth(authFile, regRouter, newRegUser, newRegPass string) (string, error) { fieldValue := newRegUser + ":" + newRegPass regToken := base64.StdEncoding.EncodeToString([]byte(fieldValue)) authDir, _ := filepath.Split(authFile) newAuthFile := filepath.Join(authDir, fmt.Sprintf("%s.json", getRandomString())) jqCMD := fmt.Sprintf(`cat %s | jq '.auths += {"%s":{"auth":"%s"}}' > %s`, authFile, regRouter, regToken, newAuthFile) _, err := exec.Command("bash", "-c", jqCMD).Output() if err != nil { e2e.Logf("Fail to extract dockerconfig: %v", err) return newAuthFile, err } return newAuthFile, nil }
imageregistry
function
openshift/openshift-tests-private
a9da0315-9130-418c-8a46-a813d9b4dc3b
updatePullSecret
['"github.com/aws/aws-sdk-go-v2/config"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func updatePullSecret(oc *exutil.CLI, authFile string) { err := oc.AsAdmin().WithoutNamespace().Run("set").Args("data", "secret/pull-secret", "-n", "openshift-config", "--from-file=.dockerconfigjson="+authFile).Execute() o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
ba9798a8-f19e-4c74-8584-826d836a9189
foundAffinityRules
['"context"', '"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func foundAffinityRules(oc *exutil.CLI, affinityRules string) bool { podList, _ := oc.AdminKubeClient().CoreV1().Pods("openshift-image-registry").List(context.Background(), metav1.ListOptions{LabelSelector: "docker-registry=default"}) for _, pod := range podList.Items { out, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("pod/"+pod.Name, "-n", pod.Namespace, "-o=jsonpath={.spec.affinity.podAntiAffinity}").Output() o.Expect(err).NotTo(o.HaveOccurred()) if !strings.Contains(out, affinityRules) { return false } } return true }
imageregistry
function
openshift/openshift-tests-private
83fa2dc4-5a69-4d8a-932f-f6d840392f7a
saveGlobalProxy
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func saveGlobalProxy(oc *exutil.CLI) (string, string, string) { httpProxy := getResource(oc, asAdmin, withoutNamespace, "proxy", "cluster", "-o=jsonpath={.status.httpProxy}") httpsProxy := getResource(oc, asAdmin, withoutNamespace, "proxy", "cluster", "-o=jsonpath={.status.httpsProxy}") noProxy := getResource(oc, asAdmin, withoutNamespace, "proxy", "cluster", "-o=jsonpath={.status.noProxy}") return httpProxy, httpsProxy, noProxy }
imageregistry
function
openshift/openshift-tests-private
ee039595-f39d-45c5-9761-bc4435a278f6
createSimpleRunPod
['"fmt"', '"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func createSimpleRunPod(oc *exutil.CLI, image, expectInfo string) { podName := getRandomString() err := oc.AsAdmin().WithoutNamespace().Run("run").Args(podName, "--image="+image, "-n", oc.Namespace(), `--overrides={"spec":{"securityContext":{"runAsNonRoot":true,"seccompProfile":{"type":"RuntimeDefault"}}}}`, "--image-pull-policy=Always", "--", "sleep", "300").Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(10*time.Second, 3*time.Minute, func() (bool, error) { output, err := oc.AsAdmin().WithoutNamespace().Run("describe").Args("pod", podName, "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, expectInfo) { return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("Pod doesn't show expected log %v", expectInfo)) }
imageregistry
function
openshift/openshift-tests-private
53818527-06f3-4fc6-b7d8-c4da5e442b56
newAppUseImageStream
['"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func newAppUseImageStream(oc *exutil.CLI, ns, imagestream, expectInfo string) { appName := getRandomString() err := oc.AsAdmin().WithoutNamespace().Run("new-app").Args("-i", imagestream, "--name="+appName, "-n", ns).Execute() o.Expect(err).NotTo(o.HaveOccurred()) err = wait.Poll(3*time.Second, 30*time.Second, func() (bool, error) { output, err := oc.AsAdmin().WithoutNamespace().Run("describe").Args("pod", "-l", "deployment="+appName, "-n", ns).Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(output, expectInfo) { return true, nil } e2e.Logf("Continue to next round") return false, nil }) exutil.AssertWaitPollNoErr(err, "Pod doesn't pull expected image") }
imageregistry
function
openshift/openshift-tests-private
615c2058-f044-4a79-a37d-f677a4d43799
saveGeneration
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func saveGeneration(oc *exutil.CLI, ns, resource string) string { num, err := oc.AsAdmin().WithoutNamespace().Run("get").Args(resource, "-n", ns, "-o=jsonpath={.metadata.generation}").Output() o.Expect(err).NotTo(o.HaveOccurred()) return num }
imageregistry
function
openshift/openshift-tests-private
1687ddb7-9b52-4a98-9abe-8af7a42c70fb
createRouteExposeRegistry
['e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func createRouteExposeRegistry(oc *exutil.CLI) { // Don't forget to restore the environment use func restoreRouteExposeRegistry output, err := oc.AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"defaultRoute":true}}`, "--type=merge").Output() if err != nil { e2e.Logf(output) } o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring("patched")) }
imageregistry
function
openshift/openshift-tests-private
5949a913-493d-4770-8502-21cb1e45fafc
restoreRouteExposeRegistry
['e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func restoreRouteExposeRegistry(oc *exutil.CLI) { output, err := oc.AsAdmin().Run("patch").Args("configs.imageregistry/cluster", "-p", `{"spec":{"defaultRoute":false}}`, "--type=merge").Output() if err != nil { e2e.Logf(output) } o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(output).To(o.ContainSubstring("patched")) }
imageregistry
function
openshift/openshift-tests-private
0a6a7178-34e2-4129-9fff-222e4539fb8e
getPodNodeListByLabel
['"strings"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getPodNodeListByLabel(oc *exutil.CLI, namespace, labelKey string) []string { output, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("pods", "-o", "wide", "-n", namespace, "-l", labelKey, "-o=jsonpath={.items[*].spec.nodeName}").Output() o.Expect(err).NotTo(o.HaveOccurred()) nodeNameList := strings.Fields(output) return nodeNameList }
imageregistry
function
openshift/openshift-tests-private
84652543-a3c4-4eb5-b965-49800c523244
getImageRegistryPodNumber
['"strconv"', '"github.com/aws/aws-sdk-go-v2/config"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getImageRegistryPodNumber(oc *exutil.CLI) int { podNum, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("config.image/cluster", "-o=jsonpath={.spec.replicas}").Output() o.Expect(err).NotTo(o.HaveOccurred()) intPodNum, _ := strconv.Atoi(podNum) return intPodNum }
imageregistry
function
openshift/openshift-tests-private
c9412b9c-2d3c-4bd0-ab98-99c4ab4fffa5
saveImageRegistryAuth
['"fmt"', '"path/filepath"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func saveImageRegistryAuth(oc *exutil.CLI, sa, regRoute, ns string) (string, error) { tempDataFile := filepath.Join("/tmp/", fmt.Sprintf("ir-auth-%s", getRandomString())) token, err := getSAToken(oc, sa, ns) o.Expect(err).NotTo(o.HaveOccurred()) err = oc.NotShowInfo().AsAdmin().WithoutNamespace().Run("registry").Args("login", "--registry="+regRoute, "--auth-basic=anyuser:"+token, "--to="+tempDataFile, "--insecure", "-n", ns).Execute() if err != nil { e2e.Logf("Fail to login image registry: %v", err) return tempDataFile, err } return tempDataFile, nil }
imageregistry
function
openshift/openshift-tests-private
3c9c5a39-558f-4a14-8866-a443dd39ad43
getSAToken
['"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getSAToken(oc *exutil.CLI, sa, ns string) (string, error) { e2e.Logf("Getting a token assgined to specific serviceaccount from %s namespace...", ns) token, err := oc.AsAdmin().WithoutNamespace().Run("create").Args("token", sa, "-n", ns).Output() if err != nil { if strings.Contains(token, "unknown command") { // oc client is old version, create token is not supported e2e.Logf("oc create token is not supported by current client, use oc sa get-token instead") token, err = oc.AsAdmin().WithoutNamespace().Run("sa").Args("get-token", sa, "-n", ns).Output() } else { return "", err } } return token, err }
imageregistry
function
openshift/openshift-tests-private
1729581e-8a89-465d-ae08-7d51b4d703b3
waitForMCPComplete
['"fmt"', '"strconv"', '"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
['machineConfig']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (mc *machineConfig) waitForMCPComplete(oc *exutil.CLI) { machineCount, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mcp", mc.pool, "-ojsonpath={.status.machineCount}").Output() e2e.Logf("machineCount: %v", machineCount) o.Expect(err).NotTo(o.HaveOccurred()) mcCount, _ := strconv.Atoi(machineCount) timeToWait := time.Duration(10*mcCount) * time.Minute e2e.Logf("Waiting %s for MCP %s to be completed.", timeToWait, mc.pool) err = wait.Poll(1*time.Minute, timeToWait, func() (bool, error) { mcpStatus, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mcp", mc.pool, `-ojsonpath={.status.conditions[?(@.type=="Updated")].status}`).Output() e2e.Logf("mcpStatus: %v", mcpStatus) if err != nil { e2e.Logf("the err:%v, and try next round", err) return false, nil } if strings.Contains(mcpStatus, "True") { // i.e. mcp updated=true, mc is applied successfully e2e.Logf("mc operation is completed on mcp %s", mc.pool) return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(err, fmt.Sprintf("mc operation is not completed on mcp %s", mc.pool)) }
imageregistry
function
openshift/openshift-tests-private
6784d6af-9893-4145-b7c8-601362ed2075
createWithCheck
['"fmt"', '"strings"', '"time"', '"github.com/aws/aws-sdk-go-v2/config"', '"k8s.io/apimachinery/pkg/util/wait"']
['machineConfig']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (mc *machineConfig) createWithCheck(oc *exutil.CLI) { mc.name = mc.name + "-" + exutil.GetRandomString() params := []string{"--ignore-unknown-parameters=true", "-f", mc.template, "-p", "NAME=" + mc.name, "POOL=" + mc.pool, "SOURCE=" + mc.source, "PATH=" + mc.path} params = append(params, mc.parameters...) exutil.CreateClusterResourceFromTemplate(oc, params...) pollerr := wait.Poll(5*time.Second, 1*time.Minute, func() (bool, error) { stdout, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mc/"+mc.name, "-o", "jsonpath='{.metadata.name}'").Output() if err != nil { e2e.Logf("the err:%v, and try next round", err) return false, nil } if strings.Contains(stdout, mc.name) { e2e.Logf("mc %s is created successfully", mc.name) return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(pollerr, fmt.Sprintf("create machine config %v failed", mc.name)) mc.waitForMCPComplete(oc) }
imageregistry
function
openshift/openshift-tests-private
ed968d24-b0de-4ec1-a09e-860413203dac
delete
['machineConfig']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (mc *machineConfig) delete(oc *exutil.CLI) { err := oc.AsAdmin().WithoutNamespace().Run("delete").Args("mc", mc.name, "--ignore-not-found=true").Execute() o.Expect(err).NotTo(o.HaveOccurred()) mc.waitForMCPComplete(oc) }
imageregistry
function
openshift/openshift-tests-private
43f4ea77-12b5-4f60-abe8-6d5a8ec6d9b4
createWithCheck
['"fmt"', '"strings"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
['runtimeClass']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (rtc *runtimeClass) createWithCheck(oc *exutil.CLI) { rtc.name = rtc.name + "-" + exutil.GetRandomString() params := []string{"--ignore-unknown-parameters=true", "-f", rtc.template, "-p", "NAME=" + rtc.name, "HANDLER=" + rtc.handler} exutil.CreateClusterResourceFromTemplate(oc, params...) rtcerr := wait.Poll(5*time.Second, 1*time.Minute, func() (bool, error) { stdout, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("runtimeclass/"+rtc.name, "-o", "jsonpath='{.metadata.name}'").Output() if err != nil { e2e.Logf("the err:%v, and try next round", err) return false, nil } if strings.Contains(stdout, rtc.name) { e2e.Logf("runtimeClass %s is created successfully", rtc.name) return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(rtcerr, fmt.Sprintf("create runtimeClass %v failed", rtc.name)) }
imageregistry
function
openshift/openshift-tests-private
cf600df4-66ef-4fbb-b158-d247577e7860
delete
['runtimeClass']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (rtc *runtimeClass) delete(oc *exutil.CLI) { err := oc.AsAdmin().WithoutNamespace().Run("delete").Args("runtimeclass", rtc.name, "--ignore-not-found=true").Execute() o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
f5be6f5a-01fa-424c-aa8c-8431e471607e
create
['limitSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (limitsrc *limitSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", limitsrc.template, "-p", "NAME="+limitsrc.name, "NAMESPACE="+limitsrc.namespace, "SIZE="+limitsrc.size) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
972da1a3-ef2b-41b8-9d36-42630b173688
checkDnsCO
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func checkDnsCO(oc *exutil.CLI) { expectedStatus := map[string]string{"Available": "True", "Progressing": "False", "Degraded": "False"} err := waitCoBecomes(oc, "ingress", 240, expectedStatus) o.Expect(err).NotTo(o.HaveOccurred()) err = waitCoBecomes(oc, "dns", 240, expectedStatus) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
6de7fd8a-56f5-4a50-ac7a-c80d0ede9451
waitRouteReady
['"os/exec"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"', 'e2eoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func waitRouteReady(route string) { curlCmd := "curl -k https://" + route var output []byte var curlErr error pollErr := wait.Poll(5*time.Second, 1*time.Minute, func() (bool, error) { output, curlErr = exec.Command("bash", "-c", curlCmd).CombinedOutput() if curlErr != nil { e2e.Logf("the route is not ready, go to next round") return false, nil } return true, nil }) if pollErr != nil { e2e.Logf("output is: %v with error %v", string(output), curlErr.Error()) } exutil.AssertWaitPollNoErr(pollErr, "The route can't be used") }
imageregistry
function
openshift/openshift-tests-private
a68765ba-1222-43d8-b796-350f103a1046
create
['signatureSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (signsrc *signatureSource) create(oc *exutil.CLI) { err := createResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", signsrc.template, "-p", "NAME="+signsrc.name, "IMAGEID="+signsrc.imageid, "TITLE="+signsrc.title, "CONTENT="+signsrc.content) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
de30262c-b9ef-4ea2-aab8-206d623b201f
create
['isSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (issrc *isSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", issrc.template, "-p", "NAME="+issrc.name, "REPO="+issrc.repo, "NAMESPACE="+issrc.namespace, "TAGNAME="+issrc.tagname, "IMAGE="+issrc.image) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
ef9d082e-0334-4dcb-b74c-9ffae75dd136
waitForAnImageStreamTag
['"time"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func waitForAnImageStreamTag(oc *exutil.CLI, namespace, name, tag string) error { return exutil.TimedWaitForAnImageStreamTag(oc, namespace, name, tag, time.Second*420) }
imageregistry
function
openshift/openshift-tests-private
fd49c76b-0ef8-4030-a956-4059fdfc8cbf
waitCoBecomes
['"reflect"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func waitCoBecomes(oc *exutil.CLI, coName string, waitTime int, expectedStatus map[string]string) error { var gottenStatus map[string]string err := wait.Poll(15*time.Second, time.Duration(waitTime)*time.Second, func() (bool, error) { gottenStatus := getCoStatus(oc, coName, expectedStatus) eq := reflect.DeepEqual(expectedStatus, gottenStatus) if eq { e2e.Logf("Given operator %s becomes %s", coName, gottenStatus) return true, nil } return false, nil }) if err != nil { for key, value := range gottenStatus { e2e.Logf("\ncheck the %v status %v is %v\n", coName, key, value) } } return err }
imageregistry
function
openshift/openshift-tests-private
d702bacd-9cd4-4d18-a61c-b13e1529b380
getCoStatus
['"fmt"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getCoStatus(oc *exutil.CLI, coName string, statusToCompare map[string]string) map[string]string { newStatusToCompare := make(map[string]string) for key := range statusToCompare { args := fmt.Sprintf(`-o=jsonpath={.status.conditions[?(@.type == "%s")].status}`, key) status, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("co", args, coName).Output() o.Expect(err).NotTo(o.HaveOccurred()) newStatusToCompare[key] = status } return newStatusToCompare }
imageregistry
function
openshift/openshift-tests-private
4ab1278d-96ba-415d-b70e-a16f1acbf927
checkPodsRemovedWithLabel
['"context"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func checkPodsRemovedWithLabel(oc *exutil.CLI, namespace, label string) { err := wait.Poll(25*time.Second, 3*time.Minute, func() (bool, error) { podList, err := oc.AdminKubeClient().CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{LabelSelector: label}) o.Expect(err).NotTo(o.HaveOccurred()) if len(podList.Items) == 0 { return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(err, "Pods are not removed") }
imageregistry
function
openshift/openshift-tests-private
4147cd34-8fd8-4a68-b762-3164d14046c1
create
['dsSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (dssrc *dsSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", dssrc.template, "-p", "NAME="+dssrc.name, "NAMESPACE="+dssrc.namespace, "IMAGE="+dssrc.image) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
b629dd5b-f9d0-40c5-9010-96031b85c5cd
create
['isImportSource']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (issrc *isImportSource) create(oc *exutil.CLI) { err := applyResourceFromTemplate(oc, "--ignore-unknown-parameters=true", "-f", issrc.template, "-p", "NAME="+issrc.name, "NAMESPACE="+issrc.namespace, "IMAGE="+issrc.image, "POLICY="+issrc.policy, "MODE="+issrc.mode) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
fe35a909-5653-44fb-8641-483cb90a5bf5
pruneImage
['"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func pruneImage(oc *exutil.CLI, isName, imageName, refRoute, token string, num int) { g.By("Check image object and sub-manifest created for the manifest list") isOut, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("is/"+isName, "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(strings.Contains(isOut, isName)).To(o.BeTrue()) imageOut, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("images", "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) imageCount := strings.Count(imageOut, imageName) o.Expect(imageCount).To(o.Equal(num)) g.By("Prune image") out, err := oc.AsAdmin().WithoutNamespace().Run("adm").Args("prune", "images", "--token="+token, "--registry-url="+refRoute, "--confirm").Output() o.Expect(err).NotTo(o.HaveOccurred()) o.Expect(strings.Contains(out, "Summary: deleted")).To(o.BeTrue()) imageOut, err = oc.AsAdmin().WithoutNamespace().Run("get").Args("images", "-n", oc.Namespace()).Output() o.Expect(err).NotTo(o.HaveOccurred()) imageCount = strings.Count(imageOut, imageName) o.Expect(imageCount).To(o.Equal(num)) }
imageregistry
function
openshift/openshift-tests-private
07630260-9647-476f-a13d-1a38c6d4f760
doPrometheusQuery
['"encoding/json"', '"fmt"', '"os/exec"', '"strconv"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
['prometheusImageregistryQueryHTTP']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func doPrometheusQuery(oc *exutil.CLI, token, url string) int { var ( data prometheusImageregistryQueryHTTP count int ) msg, _, err := oc.AsAdmin().WithoutNamespace().Run("exec").Args( "-n", "openshift-monitoring", "-c", "prometheus", "prometheus-k8s-0", "-i", "--", "curl", "-k", "-H", fmt.Sprintf("Authorization: Bearer %v", token), fmt.Sprintf("%s", url)).Outputs() if err != nil { e2e.Failf("Failed Prometheus query, error: %v", err) } o.Expect(msg).NotTo(o.BeEmpty()) json.Unmarshal([]byte(msg), &data) err = wait.Poll(60*time.Second, 120*time.Second, func() (bool, error) { if len(data.Data.Result) != 0 { return true, nil } return false, nil }) exutil.AssertWaitPollNoErr(err, "cannot get query result") count, err = strconv.Atoi(data.Data.Result[0].Value[1].(string)) o.Expect(err).NotTo(o.HaveOccurred()) return count }
imageregistry
function
openshift/openshift-tests-private
f8c4ca41-ae4b-42be-bde3-391c49eb7d9a
copyFile
['"io/ioutil"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func copyFile(source string, dest string) { bytesRead, err := ioutil.ReadFile(source) o.Expect(err).NotTo(o.HaveOccurred()) err = ioutil.WriteFile(dest, bytesRead, 0644) o.Expect(err).NotTo(o.HaveOccurred()) }
imageregistry
function
openshift/openshift-tests-private
5859c7fd-40ac-4713-ba00-54156d3a4e03
getManifestObject
['"os"', '"strings"']
['imageObject']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func (c *imageObject) getManifestObject(oc *exutil.CLI, resource, name, namespace string) *imageObject { archList, err := oc.AsAdmin().WithoutNamespace().Run("get").Args(resource, name, "-n", namespace, "-ojsonpath={..dockerImageManifests[*].architecture}").Output() o.Expect(err).NotTo(o.HaveOccurred()) c.architecture = strings.Split(archList, " ") digestList, err := oc.AsAdmin().WithoutNamespace().Run("get").Args(resource, name, "-n", namespace, "-ojsonpath={..dockerImageManifests[*].digest}").Output() o.Expect(err).NotTo(o.HaveOccurred()) c.digest = strings.Split(digestList, " ") osList, err := oc.AsAdmin().WithoutNamespace().Run("get").Args(resource, name, "-n", namespace, "-ojsonpath={..dockerImageManifests[*].os}").Output() o.Expect(err).NotTo(o.HaveOccurred()) c.os = strings.Split(osList, " ") return c }
imageregistry
function
openshift/openshift-tests-private
93ec1cae-e190-4760-a34f-29abcf368cf8
getManifestList
['"encoding/json"', '"fmt"', '"os/exec"', '"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func getManifestList(oc *exutil.CLI, image, auth string) string { jqCMD := fmt.Sprintf(`oc image info %s -a %s --insecure --show-multiarch -o json| jq -r '.[0].listDigest'`, image, auth) manifestList, err := exec.Command("bash", "-c", jqCMD).Output() o.Expect(err).NotTo(o.HaveOccurred()) return strings.TrimSuffix(string(manifestList), "\n") }
imageregistry
function
openshift/openshift-tests-private
5c18a9ab-a1b7-4e89-921b-cee8b28c381b
checkOptionalOperatorInstalled
['"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func checkOptionalOperatorInstalled(oc *exutil.CLI, operator string) bool { installedOperators, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("clusterversion", "version", "-o=jsonpath={.status.capabilities.enabledCapabilities}").Output() if err != nil { e2e.Failf("get enabledCapabilities failed err %v .", err) } if strings.Contains(installedOperators, operator) { e2e.Logf("The %v operator is installed", operator) return true } e2e.Logf("The %v operator is not installed", operator) return false }
imageregistry
function
openshift/openshift-tests-private
9eb40c6d-4eb9-4a3b-b88f-267832941221
checkICSP
['"strings"']
github.com/openshift/openshift-tests-private/test/extended/image_registry/util.go
func checkICSP(oc *exutil.CLI) bool { icsp, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("ImageContentSourcePolicy").Output() o.Expect(err).NotTo(o.HaveOccurred()) if strings.Contains(icsp, "No resources found") { e2e.Logf("there is no ImageContentSourcePolicy in this cluster") return false } return true }
imageregistry