Skip to content

Add retry metadata to replacement agent pods - #2841

Open
wuhuizuo wants to merge 3 commits into
jenkinsci:masterfrom
wuhuizuo:feat/retry-pod-label
Open

Add retry metadata to replacement agent pods#2841
wuhuizuo wants to merge 3 commits into
jenkinsci:masterfrom
wuhuizuo:feat/retry-pod-label

Conversation

@wuhuizuo

@wuhuizuo wuhuizuo commented Jun 5, 2026

Copy link
Copy Markdown

Testing done

  • Added unit coverage in KubernetesSlaveTest#testRetryAttemptTracking for retry-attempt tracking and counter cleanup.
  • Added unit coverage in PodTemplateBuilderTest#testNoRetryLabelOnFirstAttempt and PodTemplateBuilderTest#testRetryLabelAndAnnotationOnRetryAttempt for retry pod metadata.
  • Ran docker run --rm -v /Users/zuowuhui/apps/github.com/wuhuizuo/jenkins-kubernetes-plugin:/workspace -w /workspace maven:3.9.9-eclipse-temurin-17 mvn -Dmaven.repo.local=/workspace/.codex-m2-repo -Dtest=KubernetesSlaveTest,PodTemplateBuilderTest test.
  • Result: Tests run: 41, Failures: 0, Errors: 0, Skipped: 0, BUILD SUCCESS.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
    • Track repeated provisioning for the same dynamic pod template.
    • Add kubernetes.jenkins.io/retry=true to retry pods.
    • Add kubernetes.jenkins.io/retry-attempt with the retry index.
    • Clear the retry counter when the dynamic template is removed.
  • Link to relevant issues in GitHub or Jira
    • No existing GitHub issue or Jira ticket was linked for this change.
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

@wuhuizuo
wuhuizuo requested a review from a team as a code owner June 5, 2026 02:36
ti-chi-bot Bot pushed a commit to PingCAP-QE/ee-ops that referenced this pull request Jun 5, 2026
…d8f in gcp staging (#2014)

## Summary
- add a staging-only Jenkins plugin override for kubernetes
- pin the plugin version to 4437.vd64141124d8f
- fetch the HPI from the GitHub release asset built from the upstream
change

## Release
-
https://github.com/wuhuizuo/jenkins-kubernetes-plugin/releases/tag/4437.vd64141124d8f
-
https://github.com/wuhuizuo/jenkins-kubernetes-plugin/releases/download/4437.vd64141124d8f/kubernetes-4437.vd64141124d8f.hpi

## Upstream PR
- jenkinsci/kubernetes-plugin#2841
Comment thread .gitignore Outdated

@jglick jglick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation is probably wrong, and tests are unconvincing.

* (i.e., when the {@code podTemplate} step block exits). See
* {@link KubernetesCloud#removeDynamicTemplate(PodTemplate)}.
*/
static final ConcurrentHashMap<String, AtomicInteger> TEMPLATE_PROVISION_COUNTS = new ConcurrentHashMap<>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static field ⇒ will not survive Jenkins restart

* {@code 2} means two prior attempts failed, etc.
* This is a transient field set at construction time and never persisted.
*/
private transient int retryAttempt;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. Maybe you meant to have something in PodTemplateStepExecution?


@Test
public void testNoRetryLabelOnFirstAttempt() throws Exception {
when(slave.getRetryAttempt()).thenReturn(0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid Mockito.

KubernetesSlave first = new KubernetesSlave.Builder()
.podTemplate(podTemplate)
.cloud(cloud)
.build();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests do not necessarily reflect real behavior. A convincing test would be in a AbstractKubernetesPipelineTest subclass and actually run a pipeline with a retry step and actually run two node blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants