Adding ImagePullPolicy config option to OSM Charms
[osm/devops.git] / installers / charm / kafka-exporter / src / charm.py
index 123fa0b..fd24964 100755 (executable)
@@ -49,8 +49,10 @@ PORT = 9308
 class ConfigModel(ModelValidator):
     site_url: Optional[str]
     cluster_issuer: Optional[str]
+    ingress_class: Optional[str]
     ingress_whitelist_source_range: Optional[str]
     tls_secret_name: Optional[str]
+    image_pull_policy: Optional[str]
 
     @validator("site_url")
     def validate_site_url(cls, v):
@@ -66,6 +68,18 @@ class ConfigModel(ModelValidator):
             ip_network(v)
         return v
 
+    @validator("image_pull_policy")
+    def validate_image_pull_policy(cls, v):
+        values = {
+            "always": "Always",
+            "ifnotpresent": "IfNotPresent",
+            "never": "Never",
+        }
+        v = v.lower()
+        if v not in values.keys():
+            raise ValueError("value must be always, ifnotpresent or never")
+        return values[v]
+
 
 class KafkaExporterCharm(CharmedOsmBase):
     def __init__(self, *args) -> NoReturn:
@@ -162,7 +176,9 @@ class KafkaExporterCharm(CharmedOsmBase):
         pod_spec_builder = PodSpecV3Builder()
 
         # Build container
-        container_builder = ContainerV3Builder(self.app.name, image_info)
+        container_builder = ContainerV3Builder(
+            self.app.name, image_info, config.image_pull_policy
+        )
         container_builder.add_port(name=self.app.name, port=PORT)
         container_builder.add_http_readiness_probe(
             path="/api/health",
@@ -195,6 +211,8 @@ class KafkaExporterCharm(CharmedOsmBase):
         if config.site_url:
             parsed = urlparse(config.site_url)
             annotations = {}
+            if config.ingress_class:
+                annotations["kubernetes.io/ingress.class"] = config.ingress_class
             ingress_resource_builder = IngressResourceV3Builder(
                 f"{self.app.name}-ingress", annotations
             )