@@ -81,6 +81,8 @@ class Config:
8181 smb_port : int
8282 ceph_config_entity : str
8383 vhostname : str
84+ metrics_image : str
85+ metrics_port : int
8486 # clustering related values
8587 rank : int
8688 rank_generation : int
@@ -103,6 +105,8 @@ def __init__(
103105 smb_port : int = 0 ,
104106 ceph_config_entity : str = 'client.admin' ,
105107 vhostname : str = '' ,
108+ metrics_image : str = '' ,
109+ metrics_port : int = 0 ,
106110 rank : int = - 1 ,
107111 rank_generation : int = - 1 ,
108112 cluster_meta_uri : str = '' ,
@@ -122,6 +126,8 @@ def __init__(
122126 self .smb_port = smb_port
123127 self .ceph_config_entity = ceph_config_entity
124128 self .vhostname = vhostname
129+ self .metrics_image = metrics_image
130+ self .metrics_port = metrics_port
125131 self .rank = rank
126132 self .rank_generation = rank_generation
127133 self .cluster_meta_uri = cluster_meta_uri
@@ -155,15 +161,34 @@ def _container_dns_args(cfg: Config) -> List[str]:
155161 return cargs
156162
157163
158- class SambaContainerCommon :
159- def __init__ (
160- self ,
161- cfg : Config ,
162- ) -> None :
164+ class ContainerCommon :
165+ def __init__ (self , cfg : Config , image : str = '' ) -> None :
163166 self .cfg = cfg
167+ self .image = image
164168
165169 def name (self ) -> str :
166- raise NotImplementedError ('samba container name' )
170+ raise NotImplementedError ('container name' )
171+
172+ def envs (self ) -> Dict [str , str ]:
173+ return {}
174+
175+ def envs_list (self ) -> List [str ]:
176+ return []
177+
178+ def args (self ) -> List [str ]:
179+ return []
180+
181+ def container_args (self ) -> List [str ]:
182+ return []
183+
184+ def container_image (self ) -> str :
185+ return self .image
186+
187+
188+ class SambaContainerCommon (ContainerCommon ):
189+ def __init__ (self , cfg : Config , image : str = '' ) -> None :
190+ self .cfg = cfg
191+ self .image = image
167192
168193 def envs (self ) -> Dict [str , str ]:
169194 environ = {
@@ -196,9 +221,6 @@ def args(self) -> List[str]:
196221 args .append (f'--debug-delay={ self .cfg .debug_delay } ' )
197222 return args
198223
199- def container_args (self ) -> List [str ]:
200- return []
201-
202224
203225class SambaNetworkedInitContainer (SambaContainerCommon ):
204226 """SambaContainerCommon subclass that enables additional networking
@@ -233,6 +255,9 @@ def container_args(self) -> List[str]:
233255 cargs = []
234256 if self .cfg .smb_port :
235257 cargs .append (f'--publish={ self .cfg .smb_port } :{ self .cfg .smb_port } ' )
258+ if self .cfg .metrics_port :
259+ metrics_port = self .cfg .metrics_port
260+ cargs .append (f'--publish={ metrics_port } :{ metrics_port } ' )
236261 cargs .extend (_container_dns_args (self .cfg ))
237262 return cargs
238263
@@ -284,6 +309,17 @@ def args(self) -> List[str]:
284309 return super ().args () + ['update-config' , '--watch' ]
285310
286311
312+ class SMBMetricsContainer (ContainerCommon ):
313+ def name (self ) -> str :
314+ return 'smbmetrics'
315+
316+ def args (self ) -> List [str ]:
317+ args = []
318+ if self .cfg .metrics_port > 0 :
319+ args .append (f'--port={ self .cfg .metrics_port } ' )
320+ return args
321+
322+
287323class CTDBMigrateInitContainer (SambaContainerCommon ):
288324 def name (self ) -> str :
289325 return 'ctdbMigrate'
@@ -358,13 +394,13 @@ def args(self) -> List[str]:
358394class ContainerLayout :
359395 init_containers : List [SambaContainerCommon ]
360396 primary : SambaContainerCommon
361- supplemental : List [SambaContainerCommon ]
397+ supplemental : List [ContainerCommon ]
362398
363399 def __init__ (
364400 self ,
365401 init_containers : List [SambaContainerCommon ],
366402 primary : SambaContainerCommon ,
367- supplemental : List [SambaContainerCommon ],
403+ supplemental : List [ContainerCommon ],
368404 ) -> None :
369405 self .init_containers = init_containers
370406 self .primary = primary
@@ -393,6 +429,7 @@ def __init__(self, ctx: CephadmContext, ident: DaemonIdentity):
393429 self ._cached_layout : Optional [ContainerLayout ] = None
394430 self ._rank_info = context_getters .fetch_rank_info (ctx )
395431 self .smb_port = 445
432+ self .metrics_port = 9922
396433 self ._network_mapper = _NetworkMapper (ctx )
397434 logger .debug ('Created SMB ContainerDaemonForm instance' )
398435
@@ -431,6 +468,8 @@ def validate(self) -> None:
431468 files = data_utils .dict_get (configs , 'files' , {})
432469 ceph_config_entity = configs .get ('config_auth_entity' , '' )
433470 vhostname = configs .get ('virtual_hostname' , '' )
471+ metrics_image = configs .get ('metrics_image' , '' )
472+ metrics_port = int (configs .get ('metrics_port' , '0' ))
434473 cluster_meta_uri = configs .get ('cluster_meta_uri' , '' )
435474 cluster_lock_uri = configs .get ('cluster_lock_uri' , '' )
436475 cluster_public_addrs = configs .get ('cluster_public_addrs' , [])
@@ -470,6 +509,8 @@ def validate(self) -> None:
470509 smb_port = self .smb_port ,
471510 ceph_config_entity = ceph_config_entity ,
472511 vhostname = vhostname ,
512+ metrics_image = metrics_image ,
513+ metrics_port = metrics_port ,
473514 cluster_meta_uri = cluster_meta_uri ,
474515 cluster_lock_uri = cluster_lock_uri ,
475516 cluster_public_addrs = _public_addrs ,
@@ -517,7 +558,7 @@ def _layout(self) -> ContainerLayout:
517558 if self ._cached_layout :
518559 return self ._cached_layout
519560 init_ctrs : List [SambaContainerCommon ] = []
520- ctrs : List [SambaContainerCommon ] = []
561+ ctrs : List [ContainerCommon ] = []
521562
522563 init_ctrs .append (ConfigInitContainer (self ._cfg ))
523564 ctrs .append (ConfigWatchContainer (self ._cfg ))
@@ -526,6 +567,11 @@ def _layout(self) -> ContainerLayout:
526567 init_ctrs .append (MustJoinContainer (self ._cfg ))
527568 ctrs .append (WinbindContainer (self ._cfg ))
528569
570+ metrics_image = self ._cfg .metrics_image .strip ()
571+ metrics_port = self ._cfg .metrics_port
572+ if metrics_image and metrics_port > 0 :
573+ ctrs .append (SMBMetricsContainer (self ._cfg , metrics_image ))
574+
529575 if self ._cfg .clustered :
530576 init_ctrs += [
531577 CTDBMigrateInitContainer (self ._cfg ),
@@ -564,7 +610,7 @@ def _to_init_container(
564610 )
565611
566612 def _to_sidecar_container (
567- self , ctx : CephadmContext , smb_ctr : SambaContainerCommon
613+ self , ctx : CephadmContext , smb_ctr : ContainerCommon
568614 ) -> SidecarContainer :
569615 volume_mounts : Dict [str , str ] = {}
570616 container_args : List [str ] = smb_ctr .container_args ()
@@ -587,10 +633,11 @@ def _to_sidecar_container(
587633 identity = DaemonSubIdentity .from_parent (
588634 self .identity , smb_ctr .name ()
589635 )
636+ img = smb_ctr .container_image () or ctx .image or self .default_image
590637 return SidecarContainer (
591638 ctx ,
592639 entrypoint = '' ,
593- image = ctx . image or self . default_image ,
640+ image = img ,
594641 identity = identity ,
595642 container_args = container_args ,
596643 args = smb_ctr .args (),
@@ -673,6 +720,9 @@ def customize_container_endpoints(
673720 ) -> None :
674721 if not any (ep .port == self .smb_port for ep in endpoints ):
675722 endpoints .append (EndPoint ('0.0.0.0' , self .smb_port ))
723+ if self .metrics_port > 0 :
724+ if not any (ep .port == self .metrics_port for ep in endpoints ):
725+ endpoints .append (EndPoint ('0.0.0.0' , self .metrics_port ))
676726
677727 def prepare_data_dir (self , data_dir : str , uid : int , gid : int ) -> None :
678728 self .validate ()
0 commit comments