Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1549448

Summary: JenkinsPipeline bc and its related pods cannot be deleted via oc delete bc after jenkins pod being ready
Product: OpenShift Container Platform Reporter: Wenjing Zheng <wzheng>
Component: BuildAssignee: Gabe Montero <gmontero>
Status: CLOSED CURRENTRELEASE QA Contact: Wenjing Zheng <wzheng>
Severity: urgent Docs Contact:
Priority: medium    
Version: 3.9.0CC: aos-bugs, bparees, gmontero, jokerman, mmccomas, vlaad, wsun
Target Milestone: ---   
Target Release: 3.9.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Cause: Jenkins core is notifying OpenShift Jenkins Sync plugin on both the "modified" and "deleted" ItemListener callbacks when a Jenkins job is deleted as the result of a delete event on the OpenShift BuildConfig watch Consequence: The corresponding Jenkins Job for an OpenShift BuildConfig would be deleted and then immediately recreated Fix: The OpenShift Jenkins Sync plugin now maintains sufficient state such that it knows the processing of a BuildConfig delete is in progress when an ItemListener "modified" callback occurs Result: Corresponding Jenkins Jobs are deleted when OpenShift BuildConfigs are deleted
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-09-11 18:15:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Wenjing Zheng 2018-02-27 06:26:11 UTC
Description of problem:
JenkinsPipeline bc and its related pods cannot be delete via oc delete bc after jenkins pod being ready
$ oc delete bc --all
buildconfig "sample-pipeline" deleted
$ oc get bc
NAME              TYPE              FROM      LATEST
sample-pipeline   JenkinsPipeline             0
$ oc delete bc sample-pipeline
buildconfig "nodejs-mongodb-example" deleted
buildconfig "sample-pipeline" deleted
$ oc get bc
NAME              TYPE              FROM      LATEST
sample-pipeline   JenkinsPipeline             0
$oc get pods
NAME               READY     STATUS    RESTARTS   AGE
jenkins-1-dg7sd   1/1       Running   0          1m
mongodb-1-mk2z9   1/1       Running   0          1m


Version-Release number of selected component (if applicable):
openshift v3.9.0-0.53.0
kubernetes v1.9.1+a0ce1bc657
etcd 3.2.8

How reproducible:
always

Steps to Reproduce:
1.Create pipeline bc and other resources
$ oc new-app -f https://raw.githubusercontent.com/openshift/origin/master/examples/jenkins/pipeline/samplepipeline.yaml 
2. wait untile jenkins pod is ready
$oc delete bc --all
3.oc get bc
4.oc delete bc sample-pipeline
5.oc get bc

Actual results:
JenkinsPipeline bc cannot be deleted and also pods cannot be deleted either.

Expected results:
They should be deleted.

Additional info:

Comment 1 Ben Parees 2018-02-27 14:14:12 UTC
There's nothing magic about those resources with respect to deletion, I seem to recall another bug related to inability to delete resources, hopefully the master team has a theory/recollection.

Comment 2 Ben Parees 2018-02-27 14:51:19 UTC
ah. I see what is happening.  The BC is being recreated after it is deleted.  This is likely the sync plugin.

Comment 3 Ben Parees 2018-02-27 14:53:36 UTC
Gabe, this is part of what i was afraid of w/ doing two-way sync between openshift and jenkins build definitions.  I thought we had an annotation that told us whether the buildconfig originated in openshift or jenkins, so we wouldn't have this problem?  (We should recognize the jenkins job was created based on a buildconfig defined in openshift, thus when then openshift buildconfig is deleted, we should not recreate the buildconfig in openshift based on the jenkins job..in fact we should be deleting the jenkins job)

Comment 4 Gabe Montero 2018-02-27 16:19:32 UTC
Disclaimer, I'm not dismissing Ben's concerns when I note this (in fact, I think this is a validation of them, as there are some many moving parts and dependencies here).  

Turns out Jenkins calls the onUpdated callback when a deletion occurs in addition in addition to the onDeleted callback.

See this portion of some stack trace debug I added:

	at io.fabric8.jenkins.openshiftsync.PipelineJobListener.onUpdated(PipelineJobListener.java:99)
	at hudson.model.listeners.ItemListener$3.apply(ItemListener.java:229)
	at hudson.model.listeners.ItemListener$3.apply(ItemListener.java:227)
	at hudson.model.listeners.ItemListener.forAll(ItemListener.java:180)
	at hudson.model.listeners.ItemListener.fireOnUpdated(ItemListener.java:227)
	at jenkins.model.ParameterizedJobMixIn$ParameterizedJob.makeDisabled(ParameterizedJobMixIn.java:503)
	at org.jenkinsci.plugins.workflow.job.WorkflowJob.performDelete(WorkflowJob.java:640)
	at hudson.model.AbstractItem.delete(AbstractItem.java:675)
	at hudson.model.Job.delete(Job.java:681)
	at io.fabric8.jenkins.openshiftsync.BuildConfigWatcher$4.call(BuildConfigWatcher.java:466)
	at io.fabric8.jenkins.openshiftsync.BuildConfigWatcher$4.call(BuildConfigWatcher.java:462)
	at hudson.security.ACL.impersonate(ACL.java:260)
	at io.fabric8.jenkins.openshiftsync.BuildConfigWatcher.innerDeleteEventToJenkinsJob(BuildConfigWatcher.java:461)
	at io.fabric8.jenkins.openshiftsync.BuildConfigWatcher.deleteEventToJenkinsJob(BuildConfigWatcher.java:502)
	at io.fabric8.jenkins.openshiftsync.BuildConfigWatcher.eventReceived(BuildConfigWatcher.java:166)


Not sure if it has always been this way, or if we've ran into a new Jenkins "feature".

In any event, it appears we end up with both update and delete going and voila.  

The update winning appears to be consistent so far, so I'm thinking validating the fix (better synchronization between the update and delete paths, clearing out the cache immediately during delete so update processing aborts) should be straight forward.

Comment 5 Gabe Montero 2018-02-27 16:21:17 UTC
And yes, part of that protection might/could/should also involve checking the annotations on whether the creation flow was bc->job or job-> bc.

Comment 6 Gabe Montero 2018-02-27 18:10:10 UTC
https://github.com/openshift/jenkins-sync-plugin/pull/211 is in progress for delivering the fix.

Reminder, this list of steps is needed in order for QA to verify:
1) the above PR merges
2) we cut a new version of the plugin at the jenkins update center, in this case, it will be v1.0.7
3) we update the openshift jenkins repo to pull in that version of the plugin
4) we run the internal ci job to build the jenkins plugin rpm for our rhel image
5) an openshift jenkins rhel image with that rpm gets created in the brew-pulp machinery

I'll move this to ON_QA after I do 4), where QA can monitor brew-pulp for the image to verify.

Comment 7 Gabe Montero 2018-02-28 00:21:06 UTC
v1.0.7 of openshift-sync plugin is available

https://github.com/openshift/jenkins/pull/512 brings it into the jenkins centos image

Comment 8 Gabe Montero 2018-02-28 01:32:10 UTC
The job which updated the plugin rpm for the openshift jenkins rhel image is https://buildvm.openshift.eng.bos.redhat.com:8443/job/devex/job/devex%252Fjenkins-plugins/33/ and has completed and the dist-git http://pkgs.devel.redhat.com/cgit/rpms/jenkins-2-plugins/?h=rhaos-3.9-rhel-7 is updated.

Moving to on qa.  They should be able to track whether brew-pulp or the opsregistry generates an image with this rpm.

Comment 9 Wenjing Zheng 2018-02-28 08:28:12 UTC
Thanks for the quick fix, Gabe! 
QE have tested with v1.0.7 plugin and pipeline buildconfig can be deleted and no recreate now. However, its related pods still exist. User can still access Jenkins console.

Comment 10 Wenjing Zheng 2018-02-28 08:31:26 UTC
[wzheng@openshift-qe test]$ oc delete bc --all
buildconfig "nodejs-mongodb-example" deleted
buildconfig "sample-pipeline" deleted
[wzheng@openshift-qe test]$ oc get bc
No resources found.
[wzheng@openshift-qe test]$ oc get pods
NAME              READY     STATUS    RESTARTS   AGE
jenkins-1-kzzn7   1/1       Running   0          12m
mongodb-1-c82bc   1/1       Running   0          12m

Comment 11 Gabe Montero 2018-02-28 12:36:33 UTC
Hi Wenjing,

The pods here will *NOT* be deleted just because you deleted the pipeline BC.
That is expected behavior.

Comment 12 Wenjing Zheng 2018-03-01 02:08:12 UTC
Per comment #11, will verify this bug now.Thanks, Gabe!