Skip to content

Commit fd765b1

Browse files
authored
vSphere deprov delete pvcs (openshift#58877)
1 parent a24791f commit fd765b1

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../OWNERS
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
import logging
5+
import time
6+
7+
from kubernetes import client, config
8+
from kubernetes.client.rest import ApiException
9+
10+
try:
11+
from pylint.lint import Run
12+
13+
file_path = os.path.realpath(__file__)
14+
Run([file_path], exit=False)
15+
except ImportError:
16+
print("linter not available, run outside of CI")
17+
18+
# This step uses:
19+
# https://github.com/openshift-splat-team/vsphere-ci-images
20+
# https://github.com/openshift/release/pull/57722
21+
# https://quay.io/repository/ocp-splat/vsphere-ci-python
22+
23+
logging.basicConfig(
24+
format='%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s',
25+
level=logging.INFO)
26+
logger = logging.getLogger()
27+
28+
def main():
29+
cluster_profile_name = os.environ.get("CLUSTER_PROFILE_NAME")
30+
leased_resource = os.environ.get("LEASED_RESOURCE")
31+
kubeconfig = os.environ.get("KUBECONFIG")
32+
33+
if kubeconfig is None:
34+
logger.critical("KUBECONFIG is undefined")
35+
sys.exit(1)
36+
if cluster_profile_name is None:
37+
logger.critical("CLUSTER_PROFILE_NAME is undefined")
38+
sys.exit(1)
39+
40+
if leased_resource is None:
41+
logger.critical("failed to acquire lease")
42+
sys.exit(1)
43+
44+
config.load_config()
45+
core = client.CoreV1Api()
46+
47+
json_delete_patch = [{"op":"remove","path": "/metadata/finalizers"}]
48+
49+
for pv in core.list_persistent_volume().items:
50+
try:
51+
logger.info(f"pv name {pv.metadata.name}")
52+
core.delete_persistent_volume(name=pv.metadata.name)
53+
time.sleep(5)
54+
core.patch_persistent_volume(pv.metadata.name, json_delete_patch)
55+
except ApiException as e:
56+
logger.error(e)
57+
58+
59+
if __name__ == '__main__':
60+
main()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"path": "ipi/deprovision/vsphere/volumes/ipi-deprovision-vsphere-volumes-ref.yaml",
3+
"owners": {
4+
"approvers": [
5+
"vsphere-approvers"
6+
]
7+
}
8+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
ref:
2+
as: ipi-deprovision-vsphere-volumes
3+
from: vsphere-ci-python
4+
commands: ipi-deprovision-vsphere-volumes-commands.py
5+
run_as_script: true
6+
resources:
7+
requests:
8+
cpu: 10m
9+
memory: 100Mi
10+
credentials:
11+
- namespace: test-credentials
12+
name: ci-vsphere-elb
13+
mount_path: /var/run/vault/vsphere
14+
- namespace: test-credentials
15+
name: vsphere-ibmcloud-config
16+
mount_path: /var/run/vault/vsphere-ibmcloud-config
17+
documentation: >-
18+
will doc later...

ci-operator/step-registry/ipi/vsphere/post/ipi-vsphere-post-chain.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ chain:
44
- chain: gather
55
- ref: ipi-deprovision-vsphere-diags
66
- ref: ipi-deprovision-vsphere-diags-vcm
7+
- ref: ipi-deprovision-vsphere-volumes
78
- ref: ipi-deprovision-deprovision
89
- ref: ipi-deprovision-vsphere-dns
910
- ref: ipi-deprovision-vsphere-lb

0 commit comments

Comments
 (0)