Skip to content

Commit 6d9afd3

Browse files
committed
Use read API to check resource status
1 parent 99821e0 commit 6d9afd3

File tree

2 files changed

+38
-43
lines changed

2 files changed

+38
-43
lines changed

test/e2e/v1beta1/scripts/gh-actions/run-e2e-experiment.py

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import os
55
import logging
66
from kubernetes import client, config
7-
87
from kubeflow.katib import ApiClient, KatibClient, models
98
from kubeflow.katib.utils.utils import FakeResponse
109
from kubeflow.katib.constants import constants
@@ -13,7 +12,7 @@
1312
EXPERIMENT_TIMEOUT = 60 * 40
1413

1514
# The default logging config.
16-
logging.basicConfig(level=logging.DEBUG)
15+
logging.basicConfig(level=logging.INFO)
1716

1817

1918
def verify_experiment_results(
@@ -111,45 +110,47 @@ def verify_experiment_results(
111110
):
112111
resource_name = exp_name + "-" + experiment.spec.algorithm.algorithm_name
113112

114-
# Suggestion's Service and Deployment should be deleted.
115113
config.load_kube_config()
116-
for _ in range(10):
117-
118-
services = client.CoreV1Api().list_namespaced_service(exp_namespace)
119-
for i in services.items:
120-
is_deleted = 0 if i.metadata.name == resource_name else 1
121-
122-
deployments = client.AppsV1Api().list_namespaced_deployment(exp_namespace)
123-
for i in deployments.items:
124-
is_deleted *= 0 if i.metadata.name == resource_name else 1
125-
if is_deleted == 1:
126-
break
127-
128-
# Deployment and Service deletion might take some time.
114+
# Suggestion's Service and Deployment should be deleted.
115+
for i in range(10):
116+
try:
117+
client.AppsV1Api().read_namespaced_deployment(
118+
resource_name, exp_namespace
119+
)
120+
except client.ApiException as e:
121+
if e.status == 404:
122+
break
123+
else:
124+
raise e
125+
# Deployment deletion might take some time.
129126
time.sleep(1)
127+
if i == 10:
128+
raise Exception(
129+
"Suggestion Deployment is still alive for Resume Policy: {}".format(
130+
experiment.spec.resume_policy
131+
)
132+
)
130133

131-
if is_deleted == 0:
134+
try:
135+
client.CoreV1Api().read_namespaced_service(resource_name, exp_namespace)
136+
except client.ApiException as e:
137+
if e.status != 404:
138+
raise e
139+
else:
132140
raise Exception(
133-
"Suggestion Service or Deployment is still alive for "
134-
f"ResumePolicy == {experiment.spec.resume_policy}. "
135-
f"Alive Services: {[i.metadata.name for i in services.items]}. "
136-
f"Alive Deployments: {[i.metadata.name for i in deployments.items]}."
141+
"Suggestion Service is still alive for Resume Policy: {}".format(
142+
experiment.spec.resume_policy
143+
)
137144
)
138145

139146
# For FromVolume resume policy PVC should not be deleted.
140147
if experiment.spec.resume_policy == "FromVolume":
141-
PVCs = client.CoreV1Api().list_namespaced_persistent_volume_claim(
142-
exp_namespace
143-
)
144-
is_deleted = 1
145-
for i in PVCs.items:
146-
if i.metadata.name == resource_name:
147-
is_deleted = 0
148-
if is_deleted == 1:
149-
raise Exception(
150-
"PVC is deleted for FromVolume resume policy. "
151-
f"Alive PVCs: {[i.metadata.name for i in PVCs.items]}."
148+
try:
149+
client.CoreV1Api().read_namespaced_persistent_volume_claim(
150+
resource_name, exp_namespace
152151
)
152+
except client.ApiException:
153+
raise Exception("PVC is deleted for FromVolume Resume Policy")
153154

154155

155156
def run_e2e_experiment(
@@ -206,15 +207,9 @@ def run_e2e_experiment(
206207
# Verify the Experiment results.
207208
verify_experiment_results(katib_client, experiment, exp_name, exp_namespace)
208209

209-
# Describe the Experiment and Suggestion.
210-
logging.debug(
211-
os.popen(f"kubectl describe experiment {exp_name} -n {exp_namespace}").read()
212-
)
213-
logging.debug("---------------------------------------------------------------")
214-
logging.debug("---------------------------------------------------------------")
215-
logging.debug(
216-
os.popen(f"kubectl describe suggestion {exp_name} -n {exp_namespace}").read()
217-
)
210+
# Print the Experiment and Suggestion.
211+
logging.debug(katib_client.get_experiment(exp_name, exp_namespace))
212+
logging.debug(katib_client.get_suggestion(exp_name, exp_namespace))
218213

219214

220215
if __name__ == "__main__":
@@ -231,7 +226,7 @@ def run_e2e_experiment(
231226
args = parser.parse_args()
232227

233228
if args.verbose:
234-
logging.getLogger().setLevel(logging.INFO)
229+
logging.getLogger().setLevel(logging.DEBUG)
235230

236231
logging.info("---------------------------------------------------------------")
237232
logging.info("---------------------------------------------------------------")

test/e2e/v1beta1/scripts/gh-actions/run-e2e-experiment.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fi
4444
for exp_name in "${EXPERIMENT_FILE_ARRAY[@]}"; do
4545
echo "Running Experiment from $exp_name file"
4646
exp_path=$(find ../../../../../examples/v1beta1 -name "${exp_name}.yaml")
47-
python run-e2e-experiment.py --experiment-path "${exp_path}" || (kubectl get pods -n kubeflow && exit 1)
47+
python run-e2e-experiment.py --experiment-path "${exp_path}" --verbose || (kubectl get pods -n kubeflow && exit 1)
4848
done
4949

5050
exit 0

0 commit comments

Comments
 (0)