@@ -79,14 +79,14 @@ class PeerClusterOrchestratorData(ProviderData, RequirerData):
79
79
"""Broker provider data model."""
80
80
81
81
SECRET_LABEL_MAP = SECRET_LABEL_MAP
82
- SECRET_FIELDS = BALANCER .requested_secrets
82
+ SECRET_FIELDS = BROKER .requested_secrets
83
83
84
84
85
85
class PeerClusterData (ProviderData , RequirerData ):
86
86
"""Broker provider data model."""
87
87
88
88
SECRET_LABEL_MAP = SECRET_LABEL_MAP
89
- SECRET_FIELDS = BROKER .requested_secrets
89
+ SECRET_FIELDS = BALANCER .requested_secrets
90
90
91
91
92
92
class ClusterState (Object ):
@@ -126,42 +126,43 @@ def client_relations(self) -> set[Relation]:
126
126
return set (self .model .relations [REL_NAME ])
127
127
128
128
@property
129
- def peer_cluster_orchestrator_relations (self ) -> set [ Relation ] :
130
- """The `peer-cluster-orchestrator` relations that this charm is providing."""
131
- return set ( self .model .relations [ PEER_CLUSTER_ORCHESTRATOR_RELATION ] )
129
+ def peer_cluster_orchestrator_relation (self ) -> Relation | None :
130
+ """The `peer-cluster-orchestrator` relation that this charm is providing."""
131
+ return self .model .get_relation ( PEER_CLUSTER_ORCHESTRATOR_RELATION )
132
132
133
133
@property
134
134
def peer_cluster_relation (self ) -> Relation | None :
135
135
"""The `peer-cluster` relation that this charm is requiring."""
136
136
return self .model .get_relation (PEER_CLUSTER_RELATION )
137
137
138
138
@property
139
- def peer_clusters (self ) -> set [PeerCluster ]:
140
- """The state for all related `peer-cluster` applications that this charm is providing for."""
141
- peer_clusters = set ()
142
- balancer_kwargs : dict [str , Any ] = {
143
- "balancer_username" : self .cluster .balancer_username ,
144
- "balancer_password" : self .cluster .balancer_password ,
145
- "balancer_uris" : self .cluster .balancer_uris ,
146
- }
147
- for relation in self .peer_cluster_orchestrator_relations :
148
- if not relation .app or not self .runs_balancer :
149
- continue
150
-
151
- peer_clusters .add (
152
- PeerCluster (
153
- relation = relation ,
154
- data_interface = PeerClusterOrchestratorData (self .model , relation .name ),
155
- ** balancer_kwargs ,
156
- )
157
- )
139
+ def peer_cluster_orchestrator (self ) -> PeerCluster :
140
+ """The state for the related `peer-cluster-orchestrator` application that this charm is requiring from."""
141
+ balancer_kwargs : dict [str , Any ] = (
142
+ {
143
+ "balancer_username" : self .cluster .balancer_username ,
144
+ "balancer_password" : self .cluster .balancer_password ,
145
+ "balancer_uris" : self .cluster .balancer_uris ,
146
+ }
147
+ if self .runs_balancer
148
+ else {}
149
+ )
150
+ return PeerCluster (
151
+ relation = self .peer_cluster_relation ,
152
+ data_interface = PeerClusterData (self .model , PEER_CLUSTER_RELATION ),
153
+ ** balancer_kwargs ,
154
+ )
158
155
159
- return peer_clusters
156
+ @property
157
+ def peer_cluster (self ) -> PeerCluster :
158
+ """The state for the related `peer-cluster` application that this charm is providing to."""
159
+ return PeerCluster (
160
+ relation = self .peer_cluster_orchestrator_relation ,
161
+ data_interface = PeerClusterOrchestratorData (
162
+ self .model , PEER_CLUSTER_ORCHESTRATOR_RELATION
163
+ ),
164
+ )
160
165
161
- # FIXME: will need renaming once we use Kraft as the orchestrator
162
- # uses the 'already there' BALANCER username now
163
- # will need to create one independently with Basic HTTP auth + multiple broker apps
164
- # right now, multiple<->multiple is very brittle
165
166
@property
166
167
def balancer (self ) -> PeerCluster :
167
168
"""The state for the `peer-cluster-orchestrator` related balancer application."""
@@ -175,10 +176,12 @@ def balancer(self) -> PeerCluster:
175
176
else {}
176
177
)
177
178
178
- if self .runs_broker : # must be requiring , initialise with necessary broker data
179
+ if self .runs_broker : # must be providing , initialise with necessary broker data
179
180
return PeerCluster (
180
- relation = self .peer_cluster_relation , # if same app, this will be None and OK
181
- data_interface = PeerClusterData (self .model , PEER_CLUSTER_RELATION ),
181
+ relation = self .peer_cluster_orchestrator_relation , # if same app, this will be None and OK
182
+ data_interface = PeerClusterOrchestratorData (
183
+ self .model , PEER_CLUSTER_ORCHESTRATOR_RELATION
184
+ ),
182
185
broker_username = ADMIN_USER ,
183
186
broker_password = self .cluster .internal_user_credentials .get (ADMIN_USER , "" ),
184
187
broker_uris = self .bootstrap_server ,
@@ -191,9 +194,7 @@ def balancer(self) -> PeerCluster:
191
194
)
192
195
193
196
else : # must be roles=balancer only then, only load with necessary balancer data
194
- return list (self .peer_clusters )[
195
- 0
196
- ] # for broker - balancer relation, currently limited to 1
197
+ return self .peer_cluster_orchestrator
197
198
198
199
@property
199
200
def oauth_relation (self ) -> Relation | None :
@@ -345,7 +346,7 @@ def default_auth(self) -> AuthMap:
345
346
def enabled_auth (self ) -> list [AuthMap ]:
346
347
"""The currently enabled auth.protocols and their auth.mechanisms, based on related applications."""
347
348
enabled_auth = []
348
- if self .client_relations or self .runs_balancer or self .peer_cluster_relation :
349
+ if self .client_relations or self .runs_balancer or self .peer_cluster_orchestrator_relation :
349
350
enabled_auth .append (self .default_auth )
350
351
if self .oauth_relation :
351
352
enabled_auth .append (AuthMap (self .default_auth .protocol , "OAUTHBEARER" ))
@@ -457,7 +458,7 @@ def _balancer_status(self) -> Status:
457
458
if not self .runs_balancer or not self .unit_broker .unit .is_leader ():
458
459
return Status .ACTIVE
459
460
460
- if not self .peer_cluster_orchestrator_relations and not self .runs_broker :
461
+ if not self .peer_cluster_relation and not self .runs_broker :
461
462
return Status .NO_PEER_CLUSTER_RELATION
462
463
463
464
if not self .balancer .broker_connected :
0 commit comments