@@ -166,19 +166,28 @@ type configGeneratorFunc func(tmpl *template.Template, r *clickhouseReconciler,
166166type baseConfigParams struct {
167167 Path string
168168 Log controller.LoggerConfig
169- Macros map [string ]any
169+ Macros []macro
170+
171+ KeeperNodes []keeperNode
172+ KeeperIdentityEnv string
170173
171- KeeperNodes []keeperNode
172- KeeperIdentityEnv string
173174 DistributedDDLPath string
174175 DistributedDDLProfileName string
175176 UsersXMLPath string
176177 UsersZookeeperPath string
177178 UDFZookeeperPath string
178179
180+ ClusterSecretEnv string
181+ ManagementPort uint16
182+ ClusterHosts [][]string
183+
179184 OpenSSL controller.OpenSSLConfig
180185}
181186
187+ type macro struct {
188+ Name string
189+ Value any
190+ }
182191type keeperNode struct {
183192 Host string
184193 Port int32
@@ -226,23 +235,38 @@ func baseConfigGenerator(tmpl *template.Template, r *clickhouseReconciler, id v1
226235 openSSL .Client .PreferServerCiphers = true
227236 }
228237
238+ clusterHosts := make ([][]string , r .Cluster .Shards ())
239+ for shard := range r .Cluster .Shards () {
240+ hosts := make ([]string , r .Cluster .Replicas ())
241+ for replica := range r .Cluster .Replicas () {
242+ hosts [replica ] = r .Cluster .HostnameByID (v1.ClickHouseReplicaID {ShardID : shard , Index : replica })
243+ }
244+
245+ clusterHosts [shard ] = hosts
246+ }
247+
229248 params := baseConfigParams {
230249 Path : internal .ClickHouseDataPath ,
231250 Log : controller .GenerateLoggerConfig (r .Cluster .Spec .Settings .Logger , LogPath , "clickhouse-server" ),
232- Macros : map [ string ] any {
233- "cluster" : DefaultClusterName ,
234- "shard" : id .ShardID ,
235- "replica" : id .Index ,
251+ Macros : [] macro {
252+ { Name : "cluster" , Value : DefaultClusterName } ,
253+ { Name : "shard" , Value : id .ShardID } ,
254+ { Name : "replica" , Value : id .Index } ,
236255 },
237256
238- KeeperNodes : keeperNodes ,
239- KeeperIdentityEnv : EnvKeeperIdentity ,
257+ KeeperNodes : keeperNodes ,
258+ KeeperIdentityEnv : EnvKeeperIdentity ,
259+
240260 DistributedDDLPath : KeeperPathDistributedDDL ,
241261 DistributedDDLProfileName : DefaultProfileName ,
242262 UsersXMLPath : UsersFileName ,
243263 UsersZookeeperPath : KeeperPathUsers ,
244264 UDFZookeeperPath : KeeperPathUDF ,
245265
266+ ClusterSecretEnv : EnvClusterSecret ,
267+ ManagementPort : PortManagement ,
268+ ClusterHosts : clusterHosts ,
269+
246270 OpenSSL : openSSL ,
247271 }
248272
@@ -259,13 +283,28 @@ type networkConfigParams struct {
259283 InterserverHTTPUser string
260284 InterserverHTTPPasswordEnvVar string
261285 ManagementPort uint16
262- Protocols map [string ]protocol
286+ Protocols []namedProtocol
287+ }
288+
289+ type namedProtocol struct {
290+ Name string
291+ Protocol protocol
263292}
264293
265294func networkConfigGenerator (tmpl * template.Template , r * clickhouseReconciler , _ v1.ClickHouseReplicaID ) (string , error ) {
266- protocols := buildProtocols (r .Cluster )
267- delete (protocols , "interserver" )
268- delete (protocols , "management" )
295+ var protocols []namedProtocol
296+ for name , proto := range buildProtocols (r .Cluster ) {
297+ if name == "interserver" || name == "management" {
298+ continue
299+ }
300+
301+ protocols = append (protocols , namedProtocol {
302+ Name : name ,
303+ Protocol : proto ,
304+ })
305+ }
306+
307+ controllerutil .SortKey (protocols , func (p namedProtocol ) string { return p .Name })
269308
270309 params := networkConfigParams {
271310 InterserverHTTPPort : PortInterserver ,
0 commit comments