Adding security_context flag to charms
[osm/devops.git] / installers / charm / mysqld-exporter / src / charm.py
index 6aeea5d..91be02a 100755 (executable)
@@ -55,6 +55,7 @@ class ConfigModel(ModelValidator):
     tls_secret_name: Optional[str]
     mysql_uri: Optional[str]
     image_pull_policy: str
+    security_context: bool
 
     @validator("site_url")
     def validate_site_url(cls, v):
@@ -190,7 +191,9 @@ class MysqlExporterCharm(CharmedOsmBase):
         )
 
         # Create Builder for the PodSpec
-        pod_spec_builder = PodSpecV3Builder()
+        pod_spec_builder = PodSpecV3Builder(
+            enable_security_context=config.security_context
+        )
 
         # Add secrets to the pod
         mysql_secret_name = f"{self.app.name}-mysql-secret"
@@ -201,7 +204,10 @@ class MysqlExporterCharm(CharmedOsmBase):
 
         # Build container
         container_builder = ContainerV3Builder(
-            self.app.name, image_info, config.image_pull_policy
+            self.app.name,
+            image_info,
+            config.image_pull_policy,
+            run_as_non_root=config.security_context,
         )
         container_builder.add_port(name=self.app.name, port=PORT)
         container_builder.add_http_readiness_probe(