Skip to content

Commit 93b0608

Browse files
committed
Refactoring apply
1 parent 680cd06 commit 93b0608

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

src/codeflare_sdk/common/kueue/test_kueue.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from ..utils.unit_test_support import get_local_queue, create_cluster_config, get_template_variables, apply_template
14+
from ..utils.unit_test_support import (
15+
get_local_queue,
16+
create_cluster_config,
17+
get_template_variables,
18+
apply_template,
19+
)
1520
from unittest.mock import patch
1621
from codeflare_sdk.ray.cluster.cluster import Cluster, ClusterConfiguration
1722
import yaml

src/codeflare_sdk/ray/cluster/cluster.py

+16-23
Original file line numberDiff line numberDiff line change
@@ -194,40 +194,33 @@ def apply(self, force=False):
194194
# check if RayCluster CustomResourceDefinition exists if not throw RuntimeError
195195
self._throw_for_no_raycluster()
196196
namespace = self.config.namespace
197-
197+
name = self.config.name
198198
try:
199199
self.config_check()
200200
api_instance = client.CustomObjectsApi(get_api_client())
201201
crds = self.get_dynamic_client().resources
202-
api_instance = crds.get(
203-
api_version="workload.codeflare.dev/v1beta2", kind="AppWrapper"
204-
)
205202
if self.config.appwrapper:
203+
api_version = "workload.codeflare.dev/v1beta2"
204+
api_instance = crds.get(api_version, kind="AppWrapper")
205+
# defaulting body to resource_yaml
206+
body = self.resource_yaml
206207
if self.config.write_to_file:
208+
# if write_to_file is True, load the file from AppWrapper yaml and update body
207209
with open(self.resource_yaml) as f:
208210
aw = yaml.load(f, Loader=yaml.FullLoader)
209-
api_instance.server_side_apply(
210-
group="workload.codeflare.dev",
211-
version="v1beta2",
212-
namespace=namespace,
213-
plural="appwrappers",
214-
body=aw,
215-
)
216-
else:
217-
api_instance.server_side_apply(
218-
group="workload.codeflare.dev",
219-
version="v1beta2",
220-
namespace=namespace,
221-
plural="appwrappers",
222-
body=self.resource_yaml,
223-
)
224-
print(f"AppWrapper: '{self.config.name}' has successfully been created")
211+
body = aw
212+
api_instance.server_side_apply(
213+
group="workload.codeflare.dev",
214+
version="v1beta2",
215+
namespace=namespace,
216+
plural="appwrappers",
217+
body=body,
218+
)
219+
print(f"AppWrapper: '{name}' has successfully been created")
225220
else:
226221
api_instance = crds.get(api_version="ray.io/v1", kind="RayCluster")
227222
self._component_resources_apply(namespace, api_instance)
228-
print(
229-
f"Ray Cluster: '{self.config.name}' has successfully been applied"
230-
)
223+
print(f"Ray Cluster: '{name}' has successfully been applied")
231224
except Exception as e: # pragma: no cover
232225
return _kube_api_error_handling(e)
233226

0 commit comments

Comments
 (0)