New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-53790] PodTemplate Container Docker image check #497
Conversation
…ass it down to AllContainersPodWatcher, which does a check for invalid docker images used, will print an error msg to the build console and cancel the job to prevent infinte looping
CHANGELOG.md
Outdated
@@ -11,6 +11,10 @@ Unreleased | |||
---------- | |||
* Explicit inheritance should override implicit inheritance. Declarative k8s template do not inherit from parent pod template by default. [#480](https://github.com/jenkinsci/kubernetes-plugin/pull/480) [JENKINS-57548](https://issues.jenkins-ci.org/browse/JENKINS-57548) | |||
|
|||
1.15.7 | |||
------ | |||
* Check on ContainerWaitingState if the Docker image can't be found, prints message to build console and cancels and removes job from build queue. [#497](https://github.com/jenkinsci/kubernetes-plugin/pull/497) [JENKINS-53790](https://issues.jenkins-ci.org/browse/JENKINS-53790) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to be moved to Unreleased
src/main/java/org/csanchez/jenkins/plugins/kubernetes/AllContainersRunningPodWatcher.java
Outdated
Show resolved
Hide resolved
Queue q = jenkins.getQueue(); | ||
for (Queue.Item item : q.getItems()) { | ||
Label itemLabel = item.getAssignedLabel(); | ||
if (itemLabel != null && isCorrespondingLabels(itemLabel.getDisplayName(), pod.getMetadata().getName())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the intent, but this is out of line here. Eventually could be added to exception handling in the launcher
kubernetes-plugin/src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesLauncher.java
Lines 200 to 208 in 3225773
setProblem(ex); | |
LOGGER.log(Level.WARNING, String.format("Error in provisioning; agent=%s, template=%s", slave, template), ex); | |
LOGGER.log(Level.FINER, "Removing Jenkins node: {0}", slave.getNodeName()); | |
try { | |
slave.terminate(); | |
} catch (IOException | InterruptedException e) { | |
LOGGER.log(Level.WARNING, "Unable to remove Jenkins node", e); | |
} | |
throw Throwables.propagate(ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying that the KubernetesLauncher should be in charge of canceling the job? We've seen that unless a job is canceled, it'll get put back in the queue and infinitely fail due to that bad pod template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a better place than in AllContainersRunningPodWatcher
, certainly.
src/main/java/org/csanchez/jenkins/plugins/kubernetes/AllContainersRunningPodWatcher.java
Outdated
Show resolved
Hide resolved
src/main/java/org/csanchez/jenkins/plugins/kubernetes/AllContainersRunningPodWatcher.java
Outdated
Show resolved
Hide resolved
…ld item to use for canceling bad docker image pod template jobs, added tests for this
@jglick Looks like you made some changes and have fixed the issue I was seeing. |
|
Test failures seem to be infrastructural. Suggest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I had several comments pending for a while, sorry for that
String waitingStateMsg = waitingState.getMessage(); | ||
if (waitingStateMsg != null && waitingStateMsg.contains("Back-off pulling image")) { | ||
runListener.error("Unable to pull Docker image \""+containerStatus.getImage()+"\". Check if image name is spelled correctly"); | ||
throw new IllegalStateException("BAD_DOCKER_IMAGE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a specific exception type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception is needed in the stack of AllContainersRunningPodWatcher.areAllContainersRunning()
<- periodicAwait()
<- await()
.
Creating a new exception type causes a clash in AllContainersRunningPodWatcher.eventReceived()
which is overriding the parent method of Watcher.eventReceived()
To allow the aforementioned flow, it also causes the flow of areAllContainersRunning()
<- updateState()
<- eventReceived()
Would you suggest:
- catching the exception at
updateState()
oreventReceived()
such thateventReceived()
has to also pass it along. - Remain with the branching usage of the
IllegalStateException
, whicheventReceived()
already throws - Some alternative ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make your exception extend RuntimeException
.
try (Watch _w = client.pods().inNamespace(namespace1).withName(podName).watch(watcher)) { | ||
watcher.await(template.getSlaveConnectTimeout(), TimeUnit.SECONDS); | ||
} catch (IllegalStateException e) { | ||
if (e.getMessage().equals("BAD_DOCKER_IMAGE")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesLauncher.java
Outdated
Show resolved
Hide resolved
/* itemTaskName is format of "part of <ORGANIZATION> <JOB NAME> >> <BRANCH> #<BUILD NUMBER> */ | ||
/* <ORGANIZATION> and <BRANCH> are only there if Pipeline created through BlueOcean, else just <JOB NAME> */ | ||
private String getJobName(String itemTaskName) { | ||
final String partOfStr = "part of "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very fragile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this method as the only use was logging in the case there was an unexpected job name and not actually used in the feature functionality.
@@ -14,6 +14,7 @@ | |||
import javax.annotation.Nonnull; | |||
|
|||
import com.google.common.annotations.VisibleForTesting; | |||
import hudson.model.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set your IDE to avoid wildcard imports.
…sed getJobName method
We have a flake (ContainerExecDecoratorTest.testCommandExecution) which can be ignored, but there are two other tests failing that need to be addressed.
|
@Vlatombe I've fixed those tests. But the KubernetesPipelineTest.runInPodFromYaml is failing in Jenkins, but it's passing for me locally. However, KubernetesPipelineTest.cascadeDelete is failing for me locally. Even a clean clone from the jenkinsci/kubernetes-plugin master is failing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay overall.
src/main/java/org/csanchez/jenkins/plugins/kubernetes/KubernetesLauncher.java
Outdated
Show resolved
Hide resolved
@jglick please review. Thank you. |
Check on ContainerWaitingState if the Docker image can't be found, prints message to build console and cancels and removes job from build queue.
JENKINS-53790
Cleaned up and reforked, previous PR #440