Adding ImagePullPolicy config option to OSM Charms
[osm/devops.git] / installers / charm / prometheus / src / charm.py
index 5fdee72..3dcb5d4 100755 (executable)
@@ -56,9 +56,11 @@ class ConfigModel(ModelValidator):
     max_file_size: int
     site_url: Optional[str]
     cluster_issuer: Optional[str]
+    ingress_class: Optional[str]
     ingress_whitelist_source_range: Optional[str]
     tls_secret_name: Optional[str]
     enable_web_admin_api: bool
+    image_pull_policy: Optional[str]
 
     @validator("web_subpath")
     def validate_web_subpath(cls, v):
@@ -86,6 +88,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 PrometheusCharm(CharmedOsmBase):
 
@@ -156,7 +170,9 @@ class PrometheusCharm(CharmedOsmBase):
         pod_spec_builder.add_container(backup_container)
 
         # 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(
             "/-/ready",
@@ -196,8 +212,10 @@ class PrometheusCharm(CharmedOsmBase):
                     str(config.max_file_size) + "m"
                     if config.max_file_size > 0
                     else config.max_file_size
-                ),
+                )
             }
+            if config.ingress_class:
+                annotations["kubernetes.io/ingress.class"] = config.ingress_class
             ingress_resource_builder = IngressResourceV3Builder(
                 f"{self.app.name}-ingress", annotations
             )