software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerTaskFactory.java [341:384]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        final AtomicInteger finishCount = new AtomicInteger(0);

        ProcessTaskWrapper<String> waitForSuccess = Entities.submit(entity, newSimpleTaskFactory(String.format(JOBS_WAIT_COMPLETE_CMD, timeoutSeconds, kubeJobName, namespace))
                .summary("Wait for success ('complete')").allowingNonZeroExitCode().newTask());
        Entities.submit(entity, Tasks.create("Wait for success then notify", () -> {
            try {
                if (waitForSuccess.get().contains("condition met"))
                    LOG.debug("Container job " + kubeJobName + " detected as completed (succeeded) in kubernetes");
            } finally {
                synchronized (finishCount) {
                    finishCount.incrementAndGet();
                    finishCount.notifyAll();
                }
            }
        }));

        ProcessTaskWrapper<String> waitForFailed = Entities.submit(entity, newSimpleTaskFactory(String.format(JOBS_WAIT_FAILED_CMD, timeoutSeconds, kubeJobName, namespace))
                .summary("Wait for failed").allowingNonZeroExitCode().newTask());
        Entities.submit(entity, Tasks.create("Wait for failed then notify", () -> {
            try {
                if (waitForFailed.get().contains("condition met"))
                    LOG.debug("Container job " + kubeJobName + " detected as failed in kubernetes (may be valid non-zero exit)");
            } finally {
                synchronized (finishCount) {
                    finishCount.incrementAndGet();
                    finishCount.notifyAll();
                }
            }
        }));

        while (finishCount.get() == 0) {
            LOG.debug("Container job " + kubeJobName + " waiting on complete or failed");
            try {
                synchronized (finishCount) {
                    finishCount.wait(Duration.TEN_SECONDS.toMilliseconds());
                }
            } catch (InterruptedException e) {
                throw Exceptions.propagate(e);
            }
        }

        if (waitForSuccess.isDone() && waitForSuccess.getExitCode() == 0) return true;
        if (waitForFailed.isDone() && waitForFailed.getExitCode() == 0) return false;
        return null;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerTaskFactory.java [388:431]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        final AtomicInteger finishCount = new AtomicInteger(0);

        ProcessTaskWrapper<String> waitForSuccess = Entities.submit(entity, newSimpleTaskFactory(String.format(JOBS_WAIT_COMPLETE_CMD, timeoutSeconds, kubeJobName, namespace))
                .summary("Wait for success ('complete')").allowingNonZeroExitCode().newTask());
        Entities.submit(entity, Tasks.create("Wait for success then notify", () -> {
            try {
                if (waitForSuccess.get().contains("condition met"))
                    LOG.debug("Container job " + kubeJobName + " detected as completed (succeeded) in kubernetes");
            } finally {
                synchronized (finishCount) {
                    finishCount.incrementAndGet();
                    finishCount.notifyAll();
                }
            }
        }));

        ProcessTaskWrapper<String> waitForFailed = Entities.submit(entity, newSimpleTaskFactory(String.format(JOBS_WAIT_FAILED_CMD, timeoutSeconds, kubeJobName, namespace))
                .summary("Wait for failed").allowingNonZeroExitCode().newTask());
        Entities.submit(entity, Tasks.create("Wait for failed then notify", () -> {
            try {
                if (waitForFailed.get().contains("condition met"))
                    LOG.debug("Container job " + kubeJobName + " detected as failed in kubernetes (may be valid non-zero exit)");
            } finally {
                synchronized (finishCount) {
                    finishCount.incrementAndGet();
                    finishCount.notifyAll();
                }
            }
        }));

        while (finishCount.get() == 0) {
            LOG.debug("Container job " + kubeJobName + " waiting on complete or failed");
            try {
                synchronized (finishCount) {
                    finishCount.wait(Duration.TEN_SECONDS.toMilliseconds());
                }
            } catch (InterruptedException e) {
                throw Exceptions.propagate(e);
            }
        }

        if (waitForSuccess.isDone() && waitForSuccess.getExitCode() == 0) return true;
        if (waitForFailed.isDone() && waitForFailed.getExitCode() == 0) return false;
        return null;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



