canonical / seldon-core-operator

Seldon Core Operator
Apache License 2.0
5 stars 10 forks source link

Charm fails to parse custom images with `:` in their name #205

Closed phoevos closed 1 year ago

phoevos commented 1 year ago

Bug Description

Images provided through the config receive special treatment as seen here: https://github.com/canonical/seldon-core-operator/blob/7ee415fa128b322f2c52b9d3ac484feffcf5f24e/src/charm.py#L309-L313

More specifically, the charm attempts to separate the image name from the tag, splitting the string in two using : as a separator. However, this will break the charm installation if the image name contains that special character, which could be the case if a local container registry address is provided for instance (e.g. 172.17.0.2:5000/tensorflow/serving:2.1.0).

To Reproduce

juju deploy seldon-core --trust \
  --config custom_images='{
    "configmap__predictor__tensorflow__tensorflow": "172.17.0.2:5000/tensorflow/serving:2.1.0",
  }'

Environment

This affects the latest/edge version of the seldon-core charm.

Relevant Log Output

unit-seldon-core-0: 14:55:41 ERROR unit.seldon-core/0.juju-log Uncaught exception while in charm code:
Traceback (most recent call last):
  File "./src/charm.py", line 629, in <module>
    main(SeldonCoreOperator)
  File "/var/lib/juju/agents/unit-seldon-core-0/charm/venv/ops/main.py", line 439, in main
    framework.reemit()
  File "/var/lib/juju/agents/unit-seldon-core-0/charm/venv/ops/framework.py", line 843, in reemit
    self._reemit()
  File "/var/lib/juju/agents/unit-seldon-core-0/charm/venv/ops/framework.py", line 922, in _reemit
    custom_handler(event)
  File "./src/charm.py", line 438, in _on_install
    self._apply_k8s_resources(force_conflicts=True)
  File "./src/charm.py", line 420, in _apply_k8s_resources
    self.configmap_resource_handler.apply()
  File "./src/charm.py", line 195, in configmap_resource_handler
    context={**self._context, **self._configmap_images},
  File "./src/charm.py", line 289, in _configmap_images
    return self._get_custom_images()
  File "./src/charm.py", line 310, in _get_custom_images
    (
ValueError: too many values to unpack (expected 2)

Additional Context

The tag is the string part following the last :. As a result, we could do something like this:

diff --git a/src/charm.py b/src/charm.py
index 70575d8..9ba4950 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -310,7 +310,7 @@ class SeldonCoreOperator(CharmBase):
                 (
                     custom_images[f"{image_name}__image"],
                     custom_images[f"{image_name}__version"],
-                ) = custom_images[image_name].split(":")
+                ) = custom_images[image_name].rsplit(":", 1)

         except yaml.YAMLError as err:
             self.logger.error(