Skip to content

Commit

Permalink
feat: generic config
Browse files Browse the repository at this point in the history
  • Loading branch information
eaudetcobello committed Nov 6, 2024
1 parent 743f4cf commit 4895e26
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions charms/worker/k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,34 @@ def _on_feature_relation_changed(self, event: ops.RelationChangedEvent):
relation_data = event.relation.data.get(event.unit) #type: ignore
if not relation_data:
log.warning("No relation data found for unit %s", event.unit)
return

feature_name = relation_data.get("feature-name")
feature_version = relation_data.get("feature-version") # library version
feature_attributes = relation_data.get("feature-attributes")

feature_config_classes: Dict[str, type] = {
"load-balancer": LoadBalancerConfig,
"local-storage": LocalStorageConfig,
}

if feature_name and feature_version and feature_attributes:
if feature_name == "load-balancer":
feature_attributes = json.loads(feature_attributes)
lb_config = LoadBalancerConfig(**feature_attributes)
feature_attributes = json.loads(feature_attributes)

config = UserFacingClusterConfig(load_balancer=lb_config)
config_class = feature_config_classes.get(feature_name)
if config_class:
feature_config = config_class(**feature_attributes)

feature_name = feature_name.replace("-", "_")
config = UserFacingClusterConfig(**{feature_name: feature_config})
update_request = UpdateClusterConfigRequest(config=config)
self.api_manager.update_cluster_config(update_request)

log.info("Got feature of type [%s], with version [%s] and attributes [%s]", feature_name, feature_version, json.dumps(lb_config.dict()))
log.info("Got feature of type [%s], with version [%s] and attributes [%s]", feature_name, feature_version, json.dumps(feature_config.dict()))
else:
log.warning("Unsupported feature name: %s", feature_name)
else:
log.warning("Feature relation data is incomplete, %s", relation_data)
log.warning("Feature relation data is incomplete: %s", relation_data)

log.info("Relation %s changed: %s", event.relation.name, relation_data)

Expand Down

0 comments on commit 4895e26

Please # to comment.