| ... | ... |
@@ -15,6 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
"github.com/openshift/origin/pkg/api/latest" |
| 17 | 17 |
"github.com/openshift/origin/pkg/api/validation" |
| 18 |
+ buildapi "github.com/openshift/origin/pkg/build/api" |
|
| 18 | 19 |
deployapi "github.com/openshift/origin/pkg/deploy/api" |
| 19 | 20 |
imageapi "github.com/openshift/origin/pkg/image/api" |
| 20 | 21 |
projectapi "github.com/openshift/origin/pkg/project/api" |
| ... | ... |
@@ -88,6 +89,13 @@ func TestExampleObjectSchemas(t *testing.T) {
|
| 88 | 88 |
"postgresql-ephemeral-template": &templateapi.Template{},
|
| 89 | 89 |
"mongodb-ephemeral-template": &templateapi.Template{},
|
| 90 | 90 |
}, |
| 91 |
+ "../test/extended/fixtures/ldap": {
|
|
| 92 |
+ "ldapserver-buildconfig": &buildapi.BuildConfig{},
|
|
| 93 |
+ "ldapserver-deploymentconfig": &deployapi.DeploymentConfig{},
|
|
| 94 |
+ "ldapserver-imagestream": &imageapi.ImageStream{},
|
|
| 95 |
+ "ldapserver-imagestream-testenv": &imageapi.ImageStream{},
|
|
| 96 |
+ "ldapserver-service": &kapi.Service{},
|
|
| 97 |
+ }, |
|
| 91 | 98 |
"../test/integration/fixtures": {
|
| 92 | 99 |
"test-deployment-config": &deployapi.DeploymentConfig{},
|
| 93 | 100 |
"test-image": &imageapi.Image{},
|
| 94 | 101 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,54 @@ |
| 0 |
+#!/bin/bash |
|
| 1 |
+# |
|
| 2 |
+# This scripts starts the OpenShift server with a default configuration. |
|
| 3 |
+# The OpenShift Docker registry and router are installed. |
|
| 4 |
+# It will start all 'default_*_test.go' test cases. |
|
| 5 |
+ |
|
| 6 |
+set -o nounset |
|
| 7 |
+set -o pipefail |
|
| 8 |
+ |
|
| 9 |
+OS_ROOT=$(dirname "${BASH_SOURCE}")/../../..
|
|
| 10 |
+cd "${OS_ROOT}"
|
|
| 11 |
+ |
|
| 12 |
+source ${OS_ROOT}/hack/util.sh
|
|
| 13 |
+source ${OS_ROOT}/hack/common.sh
|
|
| 14 |
+ |
|
| 15 |
+ |
|
| 16 |
+set -e |
|
| 17 |
+ensure_ginkgo_or_die |
|
| 18 |
+set +e |
|
| 19 |
+ |
|
| 20 |
+os::build::extended |
|
| 21 |
+ |
|
| 22 |
+ensure_iptables_or_die |
|
| 23 |
+ |
|
| 24 |
+function cleanup() |
|
| 25 |
+{
|
|
| 26 |
+ out=$? |
|
| 27 |
+ cleanup_openshift |
|
| 28 |
+ echo "[INFO] Exiting" |
|
| 29 |
+ exit $out |
|
| 30 |
+} |
|
| 31 |
+ |
|
| 32 |
+echo "[INFO] Starting 'authentication' extended tests" |
|
| 33 |
+ |
|
| 34 |
+trap "exit" INT TERM |
|
| 35 |
+trap "cleanup" EXIT |
|
| 36 |
+ |
|
| 37 |
+export TMPDIR="${TMPDIR:-"/tmp"}"
|
|
| 38 |
+export BASETMPDIR="${TMPDIR}/openshift-extended-tests/authentication"
|
|
| 39 |
+setup_env_vars |
|
| 40 |
+reset_tmp_dir |
|
| 41 |
+configure_os_server |
|
| 42 |
+start_os_server |
|
| 43 |
+ |
|
| 44 |
+install_registry |
|
| 45 |
+wait_for_registry |
|
| 46 |
+ |
|
| 47 |
+# Run the tests |
|
| 48 |
+pushd ${OS_ROOT}/test/extended >/dev/null
|
|
| 49 |
+export KUBECONFIG="${ADMIN_KUBECONFIG}"
|
|
| 50 |
+export EXTENDED_TEST_PATH="${OS_ROOT}/test/extended"
|
|
| 51 |
+TMPDIR=${BASETMPDIR} ginkgo -progress -stream -v -focus="authentication:" -p ${OS_OUTPUT_BINPATH}/extended.test
|
|
| 52 |
+popd >/dev/null |
|
| 53 |
+ |
| 0 | 54 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,77 @@ |
| 0 |
+package authentication |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "regexp" |
|
| 5 |
+ "strings" |
|
| 6 |
+ |
|
| 7 |
+ g "github.com/onsi/ginkgo" |
|
| 8 |
+ o "github.com/onsi/gomega" |
|
| 9 |
+ |
|
| 10 |
+ exutil "github.com/openshift/origin/test/extended/util" |
|
| 11 |
+) |
|
| 12 |
+ |
|
| 13 |
+var _ = g.Describe("authentication: OpenLDAP build and deployment", func() {
|
|
| 14 |
+ defer g.GinkgoRecover() |
|
| 15 |
+ var ( |
|
| 16 |
+ imageStreamFixture = exutil.FixturePath("fixtures", "ldap", "ldapserver-imagestream.json")
|
|
| 17 |
+ imageStreamTargetFixture = exutil.FixturePath("fixtures", "ldap", "ldapserver-imagestream-testenv.json")
|
|
| 18 |
+ buildConfigFixture = exutil.FixturePath("fixtures", "ldap", "ldapserver-buildconfig.json")
|
|
| 19 |
+ deploymentConfigFixture = exutil.FixturePath("fixtures", "ldap", "ldapserver-deploymentconfig.json")
|
|
| 20 |
+ serviceConfigFixture = exutil.FixturePath("fixtures", "ldap", "ldapserver-service.json")
|
|
| 21 |
+ oc = exutil.NewCLI("openldap", exutil.KubeConfigPath())
|
|
| 22 |
+ ) |
|
| 23 |
+ |
|
| 24 |
+ g.Describe("Building and deploying an OpenLDAP server", func() {
|
|
| 25 |
+ g.It(fmt.Sprintf("should create a image from %s template and run it in a pod", buildConfigFixture), func() {
|
|
| 26 |
+ nameRegex := regexp.MustCompile(`"[A-Za-z0-9\-]+"`) |
|
| 27 |
+ oc.SetOutputDir(exutil.TestContext.OutputDir) |
|
| 28 |
+ |
|
| 29 |
+ g.By(fmt.Sprintf("calling oc create -f %s", imageStreamFixture))
|
|
| 30 |
+ imageStreamMessage, err := oc.Run("create").Args("-f", imageStreamFixture).Output()
|
|
| 31 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 32 |
+ |
|
| 33 |
+ imageStreamName := strings.Trim(nameRegex.FindString(imageStreamMessage), `"`) |
|
| 34 |
+ g.By("expecting the imagestream to fetch and tag the latest image")
|
|
| 35 |
+ err = exutil.WaitForAnImageStream(oc.REST().ImageStreams(oc.Namespace()), imageStreamName, |
|
| 36 |
+ exutil.CheckImageStreamLatestTagPopulatedFunc, exutil.CheckImageStreamTagNotFoundFunc) |
|
| 37 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 38 |
+ |
|
| 39 |
+ g.By(fmt.Sprintf("calling oc create -f %s", imageStreamTargetFixture))
|
|
| 40 |
+ err = oc.Run("create").Args("-f", imageStreamTargetFixture).Execute()
|
|
| 41 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 42 |
+ |
|
| 43 |
+ g.By(fmt.Sprintf("calling oc create -f %s", buildConfigFixture))
|
|
| 44 |
+ buildConfigMessage, err := oc.Run("create").Args("-f", buildConfigFixture).Output()
|
|
| 45 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 46 |
+ |
|
| 47 |
+ buildConfigName := strings.Trim(nameRegex.FindString(buildConfigMessage), `"`) |
|
| 48 |
+ g.By(fmt.Sprintf("calling oc start-build %s", buildConfigName))
|
|
| 49 |
+ buildName, err := oc.Run("start-build").Args(buildConfigName).Output()
|
|
| 50 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 51 |
+ |
|
| 52 |
+ g.By("expecting the build to be in Complete phase")
|
|
| 53 |
+ err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName, |
|
| 54 |
+ exutil.CheckBuildSuccessFunc, exutil.CheckBuildFailedFunc) |
|
| 55 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 56 |
+ |
|
| 57 |
+ g.By(fmt.Sprintf("calling oc create -f %s", deploymentConfigFixture))
|
|
| 58 |
+ deploymentConfigMessage, err := oc.Run("create").Args("-f", deploymentConfigFixture).Output()
|
|
| 59 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 60 |
+ |
|
| 61 |
+ deploymentConfigName := strings.Trim(nameRegex.FindString(deploymentConfigMessage), `"`) |
|
| 62 |
+ g.By(fmt.Sprintf("calling oc deploy %s", deploymentConfigName))
|
|
| 63 |
+ err = oc.Run("deploy").Args(deploymentConfigName).Execute()
|
|
| 64 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 65 |
+ |
|
| 66 |
+ g.By("expecting the deployment to be in Complete phase")
|
|
| 67 |
+ err = exutil.WaitForADeployment(oc.KubeREST().ReplicationControllers(oc.Namespace()), deploymentConfigName, |
|
| 68 |
+ exutil.CheckDeploymentCompletedFunc, exutil.CheckDeploymentFailedFunc) |
|
| 69 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 70 |
+ |
|
| 71 |
+ g.By(fmt.Sprintf("calling oc create -f %s", serviceConfigFixture))
|
|
| 72 |
+ err = oc.Run("create").Args("-f", serviceConfigFixture).Execute()
|
|
| 73 |
+ o.Expect(err).NotTo(o.HaveOccurred()) |
|
| 74 |
+ }) |
|
| 75 |
+ }) |
|
| 76 |
+}) |
| ... | ... |
@@ -16,6 +16,7 @@ import ( |
| 16 | 16 |
"k8s.io/kubernetes/pkg/client/clientcmd" |
| 17 | 17 |
"k8s.io/kubernetes/test/e2e" |
| 18 | 18 |
|
| 19 |
+ _ "github.com/openshift/origin/test/extended/authentication" |
|
| 19 | 20 |
_ "github.com/openshift/origin/test/extended/builds" |
| 20 | 21 |
_ "github.com/openshift/origin/test/extended/images" |
| 21 | 22 |
_ "github.com/openshift/origin/test/extended/router" |
| 22 | 23 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,40 @@ |
| 0 |
+{
|
|
| 1 |
+ "kind": "BuildConfig", |
|
| 2 |
+ "apiVersion": "v1", |
|
| 3 |
+ "metadata": {
|
|
| 4 |
+ "name": "openldap", |
|
| 5 |
+ "creationTimestamp": null, |
|
| 6 |
+ "labels": {
|
|
| 7 |
+ "name": "openldap" |
|
| 8 |
+ } |
|
| 9 |
+ }, |
|
| 10 |
+ "spec": {
|
|
| 11 |
+ "source": {
|
|
| 12 |
+ "type": "Git", |
|
| 13 |
+ "git": {
|
|
| 14 |
+ "uri": "git://github.com/openshift/origin.git", |
|
| 15 |
+ "ref": "master" |
|
| 16 |
+ }, |
|
| 17 |
+ "contextDir": "images/openldap" |
|
| 18 |
+ }, |
|
| 19 |
+ "strategy": {
|
|
| 20 |
+ "type": "Docker", |
|
| 21 |
+ "dockerStrategy": {
|
|
| 22 |
+ "from": {
|
|
| 23 |
+ "kind": "ImageStreamTag", |
|
| 24 |
+ "name": "openldap:latest" |
|
| 25 |
+ } |
|
| 26 |
+ } |
|
| 27 |
+ }, |
|
| 28 |
+ "output": {
|
|
| 29 |
+ "to": {
|
|
| 30 |
+ "kind": "ImageStreamTag", |
|
| 31 |
+ "name": "openldap-testenv:latest" |
|
| 32 |
+ } |
|
| 33 |
+ }, |
|
| 34 |
+ "resources": {}
|
|
| 35 |
+ }, |
|
| 36 |
+ "status": {
|
|
| 37 |
+ "lastVersion": 0 |
|
| 38 |
+ } |
|
| 39 |
+} |
|
| 0 | 40 |
\ No newline at end of file |
| 1 | 41 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,71 @@ |
| 0 |
+{
|
|
| 1 |
+ "kind": "DeploymentConfig", |
|
| 2 |
+ "apiVersion": "v1", |
|
| 3 |
+ "metadata": {
|
|
| 4 |
+ "name": "openldap-server", |
|
| 5 |
+ "creationTimestamp": null |
|
| 6 |
+ }, |
|
| 7 |
+ "spec": {
|
|
| 8 |
+ "strategy": {
|
|
| 9 |
+ "type": "Recreate", |
|
| 10 |
+ "resources": {}
|
|
| 11 |
+ }, |
|
| 12 |
+ "triggers": [ |
|
| 13 |
+ {
|
|
| 14 |
+ "type": "ImageChange", |
|
| 15 |
+ "imageChangeParams": {
|
|
| 16 |
+ "automatic": true, |
|
| 17 |
+ "containerNames": [ |
|
| 18 |
+ "openldap-server" |
|
| 19 |
+ ], |
|
| 20 |
+ "from": {
|
|
| 21 |
+ "kind": "ImageStreamTag", |
|
| 22 |
+ "name": "openldap-testenv:latest" |
|
| 23 |
+ }, |
|
| 24 |
+ "lastTriggeredImage": "" |
|
| 25 |
+ } |
|
| 26 |
+ }, |
|
| 27 |
+ {
|
|
| 28 |
+ "type": "ConfigChange" |
|
| 29 |
+ } |
|
| 30 |
+ ], |
|
| 31 |
+ "replicas": 1, |
|
| 32 |
+ "selector": {
|
|
| 33 |
+ "name": "openldap-server" |
|
| 34 |
+ }, |
|
| 35 |
+ "template": {
|
|
| 36 |
+ "metadata": {
|
|
| 37 |
+ "creationTimestamp": null, |
|
| 38 |
+ "labels": {
|
|
| 39 |
+ "name": "openldap-server" |
|
| 40 |
+ } |
|
| 41 |
+ }, |
|
| 42 |
+ "spec": {
|
|
| 43 |
+ "containers": [ |
|
| 44 |
+ {
|
|
| 45 |
+ "name": "openldap-server", |
|
| 46 |
+ "image": "openldap-testenv", |
|
| 47 |
+ "ports": [ |
|
| 48 |
+ {
|
|
| 49 |
+ "containerPort": 389, |
|
| 50 |
+ "protocol": "TCP" |
|
| 51 |
+ } |
|
| 52 |
+ ], |
|
| 53 |
+ "resources": {},
|
|
| 54 |
+ "terminationMessagePath": "/dev/termination-log", |
|
| 55 |
+ "imagePullPolicy": "IfNotPresent", |
|
| 56 |
+ "capabilities": {},
|
|
| 57 |
+ "securityContext": {
|
|
| 58 |
+ "capabilities": {},
|
|
| 59 |
+ "privileged": false |
|
| 60 |
+ } |
|
| 61 |
+ } |
|
| 62 |
+ ], |
|
| 63 |
+ "restartPolicy": "Always", |
|
| 64 |
+ "dnsPolicy": "ClusterFirst", |
|
| 65 |
+ "serviceAccount": "" |
|
| 66 |
+ } |
|
| 67 |
+ } |
|
| 68 |
+ }, |
|
| 69 |
+ "status": {}
|
|
| 70 |
+} |
|
| 0 | 71 |
\ No newline at end of file |
| 1 | 72 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,12 @@ |
| 0 |
+{
|
|
| 1 |
+ "kind": "ImageStream", |
|
| 2 |
+ "apiVersion": "v1", |
|
| 3 |
+ "metadata": {
|
|
| 4 |
+ "name": "openldap-testenv", |
|
| 5 |
+ "creationTimestamp": null |
|
| 6 |
+ }, |
|
| 7 |
+ "spec": {},
|
|
| 8 |
+ "status": {
|
|
| 9 |
+ "dockerImageRepository": "" |
|
| 10 |
+ } |
|
| 11 |
+} |
|
| 0 | 12 |
\ No newline at end of file |
| 1 | 13 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,25 @@ |
| 0 |
+{
|
|
| 1 |
+ "kind": "ImageStream", |
|
| 2 |
+ "apiVersion": "v1", |
|
| 3 |
+ "metadata": {
|
|
| 4 |
+ "name": "openldap", |
|
| 5 |
+ "creationTimestamp": null |
|
| 6 |
+ }, |
|
| 7 |
+ "spec": {
|
|
| 8 |
+ "dockerImageRepository": "openshift/openldap-2441-centos7", |
|
| 9 |
+ "tags": [ |
|
| 10 |
+ {
|
|
| 11 |
+ "tag": "latest", |
|
| 12 |
+ "annotations": {
|
|
| 13 |
+ "description": "Provides OpenLDAP v2.4.41", |
|
| 14 |
+ "iconClass": "fa-server", |
|
| 15 |
+ "tags": "server,openldap", |
|
| 16 |
+ "version": "2.4.41" |
|
| 17 |
+ } |
|
| 18 |
+ } |
|
| 19 |
+ ] |
|
| 20 |
+ }, |
|
| 21 |
+ "status": {
|
|
| 22 |
+ "dockerImageRepository": "" |
|
| 23 |
+ } |
|
| 24 |
+} |
|
| 0 | 25 |
\ No newline at end of file |
| 1 | 26 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,28 @@ |
| 0 |
+{
|
|
| 1 |
+ "kind": "Service", |
|
| 2 |
+ "apiVersion": "v1", |
|
| 3 |
+ "metadata": {
|
|
| 4 |
+ "name": "openldap-server", |
|
| 5 |
+ "creationTimestamp": null |
|
| 6 |
+ }, |
|
| 7 |
+ "spec": {
|
|
| 8 |
+ "ports": [ |
|
| 9 |
+ {
|
|
| 10 |
+ "name": "ldap", |
|
| 11 |
+ "protocol": "TCP", |
|
| 12 |
+ "port": 389, |
|
| 13 |
+ "targetPort": 389, |
|
| 14 |
+ "nodePort": 0 |
|
| 15 |
+ } |
|
| 16 |
+ ], |
|
| 17 |
+ "selector": {
|
|
| 18 |
+ "name": "openldap-server" |
|
| 19 |
+ }, |
|
| 20 |
+ "portalIP": "", |
|
| 21 |
+ "type": "ClusterIP", |
|
| 22 |
+ "sessionAffinity": "None" |
|
| 23 |
+ }, |
|
| 24 |
+ "status": {
|
|
| 25 |
+ "loadBalancer": {}
|
|
| 26 |
+ } |
|
| 27 |
+} |
|
| 0 | 28 |
\ No newline at end of file |
| ... | ... |
@@ -8,10 +8,6 @@ import ( |
| 8 | 8 |
"strings" |
| 9 | 9 |
"time" |
| 10 | 10 |
|
| 11 |
- "github.com/openshift/origin/pkg/api/latest" |
|
| 12 |
- buildapi "github.com/openshift/origin/pkg/build/api" |
|
| 13 |
- "github.com/openshift/origin/pkg/client" |
|
| 14 |
- "github.com/openshift/origin/pkg/util/namer" |
|
| 15 | 11 |
kapi "k8s.io/kubernetes/pkg/api" |
| 16 | 12 |
kclient "k8s.io/kubernetes/pkg/client" |
| 17 | 13 |
"k8s.io/kubernetes/pkg/fields" |
| ... | ... |
@@ -20,20 +16,17 @@ import ( |
| 20 | 20 |
kutil "k8s.io/kubernetes/pkg/util" |
| 21 | 21 |
"k8s.io/kubernetes/pkg/util/wait" |
| 22 | 22 |
"k8s.io/kubernetes/test/e2e" |
| 23 |
+ |
|
| 24 |
+ "github.com/openshift/origin/pkg/api/latest" |
|
| 25 |
+ buildapi "github.com/openshift/origin/pkg/build/api" |
|
| 26 |
+ "github.com/openshift/origin/pkg/client" |
|
| 27 |
+ deployapi "github.com/openshift/origin/pkg/deploy/api" |
|
| 28 |
+ imageapi "github.com/openshift/origin/pkg/image/api" |
|
| 29 |
+ "github.com/openshift/origin/pkg/util/namer" |
|
| 23 | 30 |
) |
| 24 | 31 |
|
| 25 | 32 |
var TestContext e2e.TestContextType |
| 26 | 33 |
|
| 27 |
-// The build succeeded |
|
| 28 |
-var CheckBuildSuccessFunc = func(b *buildapi.Build) bool {
|
|
| 29 |
- return b.Status.Phase == buildapi.BuildPhaseComplete |
|
| 30 |
-} |
|
| 31 |
- |
|
| 32 |
-// The build failed |
|
| 33 |
-var CheckBuildFailedFunc = func(b *buildapi.Build) bool {
|
|
| 34 |
- return b.Status.Phase == buildapi.BuildPhaseFailed || b.Status.Phase == buildapi.BuildPhaseError |
|
| 35 |
-} |
|
| 36 |
- |
|
| 37 | 34 |
// WriteObjectToFile writes the JSON representation of runtime.Object into a temporary |
| 38 | 35 |
// file. |
| 39 | 36 |
func WriteObjectToFile(obj runtime.Object, filename string) error {
|
| ... | ... |
@@ -85,6 +78,16 @@ func WaitForABuild(c client.BuildInterface, name string, isOK, isFailed func(*bu |
| 85 | 85 |
} |
| 86 | 86 |
} |
| 87 | 87 |
|
| 88 |
+// CheckBuildSuccessFunc returns true if the build succeeded |
|
| 89 |
+var CheckBuildSuccessFunc = func(b *buildapi.Build) bool {
|
|
| 90 |
+ return b.Status.Phase == buildapi.BuildPhaseComplete |
|
| 91 |
+} |
|
| 92 |
+ |
|
| 93 |
+// CheckBuildFailedFunc return true if the build failed |
|
| 94 |
+var CheckBuildFailedFunc = func(b *buildapi.Build) bool {
|
|
| 95 |
+ return b.Status.Phase == buildapi.BuildPhaseFailed || b.Status.Phase == buildapi.BuildPhaseError |
|
| 96 |
+} |
|
| 97 |
+ |
|
| 88 | 98 |
// WaitForBuilderAccount waits until the builder service account gets fully |
| 89 | 99 |
// provisioned |
| 90 | 100 |
func WaitForBuilderAccount(c kclient.ServiceAccountsInterface) error {
|
| ... | ... |
@@ -103,6 +106,123 @@ func WaitForBuilderAccount(c kclient.ServiceAccountsInterface) error {
|
| 103 | 103 |
return wait.Poll(60, time.Duration(1*time.Second), waitFunc) |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 |
+// WaitForAnImageStream waits for an ImageStream to fulfill the isOK function |
|
| 107 |
+func WaitForAnImageStream(client client.ImageStreamInterface, |
|
| 108 |
+ name string, |
|
| 109 |
+ isOK, isFailed func(*imageapi.ImageStream) bool) error {
|
|
| 110 |
+ for {
|
|
| 111 |
+ list, err := client.List(labels.Everything(), fields.Set{"name": name}.AsSelector())
|
|
| 112 |
+ if err != nil {
|
|
| 113 |
+ return err |
|
| 114 |
+ } |
|
| 115 |
+ for i := range list.Items {
|
|
| 116 |
+ if isOK(&list.Items[i]) {
|
|
| 117 |
+ return nil |
|
| 118 |
+ } |
|
| 119 |
+ if isFailed(&list.Items[i]) {
|
|
| 120 |
+ return fmt.Errorf("The deployment %q status is %q",
|
|
| 121 |
+ name, list.Items[i].Annotations[imageapi.DockerImageRepositoryCheckAnnotation]) |
|
| 122 |
+ } |
|
| 123 |
+ } |
|
| 124 |
+ |
|
| 125 |
+ rv := list.ResourceVersion |
|
| 126 |
+ w, err := client.Watch(labels.Everything(), fields.Set{"name": name}.AsSelector(), rv)
|
|
| 127 |
+ if err != nil {
|
|
| 128 |
+ return err |
|
| 129 |
+ } |
|
| 130 |
+ defer w.Stop() |
|
| 131 |
+ |
|
| 132 |
+ for {
|
|
| 133 |
+ val, ok := <-w.ResultChan() |
|
| 134 |
+ if !ok {
|
|
| 135 |
+ // reget and re-watch |
|
| 136 |
+ break |
|
| 137 |
+ } |
|
| 138 |
+ if e, ok := val.Object.(*imageapi.ImageStream); ok {
|
|
| 139 |
+ if isOK(e) {
|
|
| 140 |
+ return nil |
|
| 141 |
+ } |
|
| 142 |
+ if isFailed(e) {
|
|
| 143 |
+ return fmt.Errorf("The image stream %q status is %q",
|
|
| 144 |
+ name, e.Annotations[imageapi.DockerImageRepositoryCheckAnnotation]) |
|
| 145 |
+ } |
|
| 146 |
+ } |
|
| 147 |
+ } |
|
| 148 |
+ } |
|
| 149 |
+} |
|
| 150 |
+ |
|
| 151 |
+// CheckImageStreamLatestTagPopulatedFunc returns true if the imagestream has a ':latest' tag filed |
|
| 152 |
+var CheckImageStreamLatestTagPopulatedFunc = func(i *imageapi.ImageStream) bool {
|
|
| 153 |
+ _, ok := i.Status.Tags["latest"] |
|
| 154 |
+ return ok |
|
| 155 |
+} |
|
| 156 |
+ |
|
| 157 |
+// CheckImageStreamTagNotFoundFunc return true if the imagestream update was not successful |
|
| 158 |
+var CheckImageStreamTagNotFoundFunc = func(i *imageapi.ImageStream) bool {
|
|
| 159 |
+ return strings.Contains(i.Annotations[imageapi.DockerImageRepositoryCheckAnnotation], "not") || |
|
| 160 |
+ strings.Contains(i.Annotations[imageapi.DockerImageRepositoryCheckAnnotation], "error") |
|
| 161 |
+} |
|
| 162 |
+ |
|
| 163 |
+// WaitForADeployment waits for a Deployment to fulfill the isOK function |
|
| 164 |
+func WaitForADeployment(client kclient.ReplicationControllerInterface, |
|
| 165 |
+ name string, |
|
| 166 |
+ isOK, isFailed func(*kapi.ReplicationController) bool) error {
|
|
| 167 |
+ for {
|
|
| 168 |
+ requirement, err := labels.NewRequirement(deployapi.DeploymentConfigAnnotation, labels.EqualsOperator, kutil.NewStringSet(name)) |
|
| 169 |
+ if err != nil {
|
|
| 170 |
+ return fmt.Errorf("unexpected error generating label selector: %v", err)
|
|
| 171 |
+ } |
|
| 172 |
+ |
|
| 173 |
+ list, err := client.List(labels.LabelSelector{*requirement})
|
|
| 174 |
+ if err != nil {
|
|
| 175 |
+ return err |
|
| 176 |
+ } |
|
| 177 |
+ for i := range list.Items {
|
|
| 178 |
+ if isOK(&list.Items[i]) {
|
|
| 179 |
+ return nil |
|
| 180 |
+ } |
|
| 181 |
+ if isFailed(&list.Items[i]) {
|
|
| 182 |
+ return fmt.Errorf("The deployment %q status is %q",
|
|
| 183 |
+ name, list.Items[i].Annotations[deployapi.DeploymentStatusAnnotation]) |
|
| 184 |
+ } |
|
| 185 |
+ } |
|
| 186 |
+ |
|
| 187 |
+ rv := list.ResourceVersion |
|
| 188 |
+ w, err := client.Watch(labels.LabelSelector{*requirement}, fields.Everything(), rv)
|
|
| 189 |
+ if err != nil {
|
|
| 190 |
+ return err |
|
| 191 |
+ } |
|
| 192 |
+ defer w.Stop() |
|
| 193 |
+ |
|
| 194 |
+ for {
|
|
| 195 |
+ val, ok := <-w.ResultChan() |
|
| 196 |
+ if !ok {
|
|
| 197 |
+ // reget and re-watch |
|
| 198 |
+ break |
|
| 199 |
+ } |
|
| 200 |
+ if e, ok := val.Object.(*kapi.ReplicationController); ok {
|
|
| 201 |
+ if isOK(e) {
|
|
| 202 |
+ return nil |
|
| 203 |
+ } |
|
| 204 |
+ if isFailed(e) {
|
|
| 205 |
+ return fmt.Errorf("The deployment %q status is %q",
|
|
| 206 |
+ name, e.Annotations[deployapi.DeploymentStatusAnnotation]) |
|
| 207 |
+ } |
|
| 208 |
+ } |
|
| 209 |
+ } |
|
| 210 |
+ } |
|
| 211 |
+} |
|
| 212 |
+ |
|
| 213 |
+// CheckDeploymentCompletedFunc returns true if the deployment completed |
|
| 214 |
+var CheckDeploymentCompletedFunc = func(d *kapi.ReplicationController) bool {
|
|
| 215 |
+ return d.Annotations[deployapi.DeploymentStatusAnnotation] == string(deployapi.DeploymentStatusComplete) |
|
| 216 |
+} |
|
| 217 |
+ |
|
| 218 |
+// CheckDeploymentFailedFunc returns true if the deployment failed |
|
| 219 |
+var CheckDeploymentFailedFunc = func(d *kapi.ReplicationController) bool {
|
|
| 220 |
+ return d.Annotations[deployapi.DeploymentStatusAnnotation] == string(deployapi.DeploymentStatusFailed) |
|
| 221 |
+} |
|
| 222 |
+ |
|
| 106 | 223 |
// GetDockerImageReference retrieves the full Docker pull spec from the given ImageStream |
| 107 | 224 |
// and tag |
| 108 | 225 |
func GetDockerImageReference(c client.ImageStreamInterface, name, tag string) (string, error) {
|