Bug 2036826 - `oc adm prune deployments` can prune the RC/RS
Summary: `oc adm prune deployments` can prune the RC/RS
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: oc
Version: 4.10
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: ---
: 4.10.0
Assignee: Ross Peoples
QA Contact: zhou ying
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-01-04 06:20 UTC by zhou ying
Modified: 2022-03-11 18:15 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-03-11 18:15:11 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github openshift oc pull 1015 0 None open Bug 2036826: Fix prune deploy resolver 2022-01-07 00:50:43 UTC
Github openshift oc pull 1019 0 None open Bug 2036826: Improved prune deployments 2022-01-11 11:19:17 UTC

Description zhou ying 2022-01-04 06:20:20 UTC
Description of problem:
`oc adm prune deployments` can prune the RC/RS 

Version-Release number of selected component (if applicable):
[root@localhost ~]# oc version --client
Client Version: 4.10.0-202201031825.p0.g25851bd.assembly.stream-25851bd

How reproducible:
always

Steps to Reproduce:
1.Create RSs :
[root@localhost ~]# oc get rs 
NAME                         DESIRED   CURRENT   READY   AGE
hello-openshift-54c7d9b5fd   0         0         0       54m
hello-openshift-64746b5c7b   0         0         0       54m
hello-openshift-768995fdcf   0         0         0       54m
hello-openshift-7965bf8cdf   0         0         0       54m
hello-openshift-8447df5bfd   15        15        15      54m
hello-openshift-86cd95745c   0         0         0       52m
hello-openshift-9cc9fd576    0         0         0       54m
hello-openshift-b97f9584b    0         0         0       55m
hello-openshift-c99cf7ffd    10        10        0       51m
hello-openshift-f58c964df    0         0         0       54m

2. Use the `oc adm prune deployments  --keep-complete=2 --keep-failed=1 --keep-younger-than=1m  --replica-sets=true  --confirm` to prune rs;

3. Create RCs:
[root@localhost ~]# oc get rc
NAME     DESIRED   CURRENT   READY   AGE
mydc-1   0         0         0       49m
mydc-2   0         0         0       47m
mydc-3   0         0         0       42m
mydc-4   0         0         0       39m
mydc-5   0         0         0       37m
mydc-6   0         0         0       35m
mydc-7   0         0         0       26m
mydc-8   1         1         1       26m
mydc-9   0         0         0       26m
4. Use the `oc adm prune deployments --confirm=true --keep-complete=2 --keep-failed=1 --keep-younger-than=1m` to prune the rc:



Actual results:
3. No RSs were pruned:
[root@localhost ~]# oc adm prune deployments  --keep-complete=2 --keep-failed=1 --keep-younger-than=1m  --replica-sets=true  --confirm
[root@localhost ~]# oc get rs 
NAME                         DESIRED   CURRENT   READY   AGE
hello-openshift-54c7d9b5fd   0         0         0       54m
hello-openshift-64746b5c7b   0         0         0       55m
hello-openshift-768995fdcf   0         0         0       54m
hello-openshift-7965bf8cdf   0         0         0       54m
hello-openshift-8447df5bfd   15        15        15      54m
hello-openshift-86cd95745c   0         0         0       52m
hello-openshift-9cc9fd576    0         0         0       54m
hello-openshift-b97f9584b    0         0         0       55m
hello-openshift-c99cf7ffd    10        10        0       52m
hello-openshift-f58c964df    0         0         0       54m
4. No RCs were pruned:

Expected results:
3-4: RC/RS were pruned as expected.
[root@localhost ~]#  oc adm prune deployments --confirm=true --keep-complete=2 --keep-failed=1 --keep-younger-than=1m
[root@localhost ~]# oc get rc
NAME     DESIRED   CURRENT   READY   AGE
mydc-1   0         0         0       50m
mydc-2   0         0         0       47m
mydc-3   0         0         0       42m
mydc-4   0         0         0       40m
mydc-5   0         0         0       37m
mydc-6   0         0         0       35m
mydc-7   0         0         0       27m
mydc-8   1         1         1       26m
mydc-9   0         0         0       26m

Additional info:
old oc work well for RC:
[root@localhost ~]# ./oc version 
Client Version: 4.9.0-fc.0
[root@localhost ~]# ./oc adm  prune deployments --confirm=true --keep-complete=2 --keep-failed=1 --keep-younger-than=1m
NAMESPACE   NAME
testdc      mydc-5
testdc      mydc-4
testdc      mydc-3
testdc      mydc-2
testdc      mydc-1
[root@localhost ~]# oc get rc 
NAME     DESIRED   CURRENT   READY   AGE
mydc-6   0         0         0       38m
mydc-7   0         0         0       29m
mydc-8   1         1         1       29m
mydc-9   0         0         0       28m

Comment 1 Ross Peoples 2022-01-06 22:24:39 UTC
Are there any associated Deployments or DeploymentConfigs? If not, can you try adding the `--orphans` flag?

Comment 2 Ross Peoples 2022-01-07 00:52:46 UTC
I think I found the issue, PR submitted for testing.

Comment 7 zhou ying 2022-01-11 12:34:58 UTC
[root@localhost ~]# oc version --client
Client Version: 4.10.0-202201102246.p0.g293b52e.assembly.stream-293b52e

[root@localhost ~]# oc get rc
NAME       DESIRED   CURRENT   READY   AGE
my-dc-1    0         0         0       3h20m
my-dc-10   0         0         0       70m
my-dc-11   0         0         0       10m
my-dc-2    0         0         0       3h20m
my-dc-3    0         0         0       3h17m
my-dc-4    0         0         0       3h16m
my-dc-5    0         0         0       3h14m
my-dc-6    0         0         0       3h11m
my-dc-7    0         0         0       3h9m
my-dc-8    0         0         0       3h7m
my-dc-9    1         1         1       71m
[root@localhost ~]# oc adm  prune deployments --confirm=true --keep-complete=2 --keep-failed=1 --keep-younger-than=1m
NAMESPACE   NAME
zhout       my-dc-6
zhout       my-dc-5
zhout       my-dc-4
zhout       my-dc-3
zhout       my-dc-2
zhout       my-dc-1
zhout       my-dc-10
[root@localhost ~]# oc get rc
NAME       DESIRED   CURRENT   READY   AGE
my-dc-11   0         0         0       11m
my-dc-7    0         0         0       3h10m
my-dc-8    0         0         0       3h8m
my-dc-9    1         1         1       72m


[root@localhost ~]# oc get rs  --sort-by='{.metadata.creationTimestamp}'
NAME                         DESIRED   CURRENT   READY   AGE
hello-openshift-b97f9584b    0         0         0       29m
hello-openshift-64746b5c7b   0         0         0       27m
hello-openshift-f58c964df    0         0         0       24m
hello-openshift-54c7d9b5fd   0         0         0       22m
hello-openshift-768995fdcf   0         0         0       20m
hello-openshift-9cc9fd576    0         0         0       19m
hello-openshift-7965bf8cdf   0         0         0       18m
hello-openshift-8447df5bfd   0         0         0       16m
hello-openshift-55bf5dc7f    15        15        15      15m
hello-openshift-66bd77f944   0         0         0       15m
hello-openshift-7579f658f9   10        10        0       14m
[root@localhost ~]# oc adm prune deployments --keep-younger-than=1m --replica-sets=true --keep-complete=2
Dry run enabled - no modifications will be made. Add --confirm to remove deployments
NAMESPACE   NAME
zhout       hello-openshift-7965bf8cdf
zhout       hello-openshift-9cc9fd576
zhout       hello-openshift-768995fdcf
zhout       hello-openshift-54c7d9b5fd
zhout       hello-openshift-f58c964df
zhout       hello-openshift-64746b5c7b
[root@localhost ~]# oc get rs  --sort-by='{.metadata.creationTimestamp}'
NAME                         DESIRED   CURRENT   READY   AGE
hello-openshift-b97f9584b    0         0         0       29m
hello-openshift-64746b5c7b   0         0         0       28m
hello-openshift-f58c964df    0         0         0       24m
hello-openshift-54c7d9b5fd   0         0         0       22m
hello-openshift-768995fdcf   0         0         0       20m
hello-openshift-9cc9fd576    0         0         0       19m
hello-openshift-7965bf8cdf   0         0         0       18m
hello-openshift-8447df5bfd   0         0         0       17m
hello-openshift-55bf5dc7f    15        15        15      15m
hello-openshift-66bd77f944   0         0         0       15m
hello-openshift-7579f658f9   10        10        0       14m
[root@localhost ~]# oc adm prune deployments --keep-younger-than=1m --replica-sets=true --keep-complete=2 --confirm
NAMESPACE   NAME
zhout       hello-openshift-7965bf8cdf
zhout       hello-openshift-9cc9fd576
zhout       hello-openshift-768995fdcf
zhout       hello-openshift-54c7d9b5fd
zhout       hello-openshift-f58c964df
zhout       hello-openshift-64746b5c7b
[root@localhost ~]# oc get rs  --sort-by='{.metadata.creationTimestamp}' 
NAME                         DESIRED   CURRENT   READY   AGE
hello-openshift-b97f9584b    0         0         0       31m
hello-openshift-8447df5bfd   0         0         0       19m
hello-openshift-55bf5dc7f    15        15        15      18m
hello-openshift-66bd77f944   0         0         0       18m
hello-openshift-7579f658f9   10        10        0       17m


Note You need to log in before you can comment on or make changes to this bug.