Adding ImagePullPolicy config option to OSM Charms
[osm/devops.git] / installers / charm / nbi / src / charm.py
index 550c88b..938a75a 100755 (executable)
@@ -57,9 +57,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]
     mongodb_uri: Optional[str]
+    image_pull_policy: Optional[str]
 
     @validator("auth_backend")
     def validate_auth_backend(cls, v):
@@ -99,6 +101,18 @@ class ConfigModel(ModelValidator):
             raise ValueError("mongodb_uri is not properly formed")
         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 NbiCharm(CharmedOsmBase):
     def __init__(self, *args) -> NoReturn:
@@ -179,7 +193,9 @@ class NbiCharm(CharmedOsmBase):
         )
 
         # 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_tcpsocket_readiness_probe(
             PORT,
@@ -210,7 +226,8 @@ class NbiCharm(CharmedOsmBase):
                 "OSMNBI_STORAGE_DRIVER": "mongo",
                 "OSMNBI_STORAGE_PATH": "/app/storage",
                 "OSMNBI_STORAGE_COLLECTION": "files",
-                "OSMNBI_STORAGE_URI": self.mongodb_client.connection_string,
+                "OSMNBI_STORAGE_URI": config.mongodb_uri
+                or self.mongodb_client.connection_string,
                 # Prometheus configuration
                 "OSMNBI_PROMETHEUS_HOST": self.prometheus_client.hostname,
                 "OSMNBI_PROMETHEUS_PORT": self.prometheus_client.port,
@@ -249,6 +266,8 @@ class NbiCharm(CharmedOsmBase):
                 ),
                 "nginx.ingress.kubernetes.io/backend-protocol": "HTTPS",
             }
+            if config.ingress_class:
+                annotations["kubernetes.io/ingress.class"] = config.ingress_class
             ingress_resource_builder = IngressResourceV3Builder(
                 f"{self.app.name}-ingress", annotations
             )