Skip to content

Commit cc34879

Browse files
Frank Hsiaomergify[bot]
Frank Hsiao
authored andcommitted
resources: add support for setting custom samba configuration
Add new fields to handle custom Samba configurations. For [global] section, a new field customGlobalConfig is added under smbCommonConfig to handle custom settings. For individual share configurations, modifications can be made in customShareConfig field under smbShare. This design is chosen because, in group mode, a single server may correspond to several grouped shares. Signed-off-by: FTS152 <[email protected]>
1 parent 905f0e9 commit cc34879

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

api/v1alpha1/smbcommonconfig_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ type SmbCommonConfigSpec struct {
3838
// under PodSettings allow admins and users to customize how pods
3939
// are scheduled in a kubernetes cluster.
4040
PodSettings *SmbCommonConfigPodSettings `json:"podSettings,omitempty"`
41+
42+
// GloabalConfig are configuration values that are applied to [gloabal]
43+
// section in smb.conf for the smb server. This allows users to add or
44+
// override default configurations.
45+
// +opional
46+
CustomGlobalConfig *SmbCommonConfigGlobalConfig `json:"customGlobalConfig,omitempty"`
4147
}
4248

4349
// SmbCommonNetworkSpec values define networking properties for the services
@@ -61,6 +67,13 @@ type SmbCommonConfigPodSettings struct {
6167
Affinity *corev1.Affinity `json:"affinity,omitempty"`
6268
}
6369

70+
// SmbCommonConfigGlobalConfig contains values for customizing configs in
71+
// [global] section in smb.conf
72+
type SmbCommonConfigGlobalConfig struct {
73+
//Configs specify keys and values to smb.conf
74+
Configs map[string]string `json:"configs,omitempty"`
75+
}
76+
6477
// SmbCommonConfigStatus defines the observed state of SmbCommonConfig
6578
type SmbCommonConfigStatus struct {
6679
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster

api/v1alpha1/smbshare_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ type SmbShareSpec struct {
6464
// +optional
6565
CommonConfig string `json:"commonConfig,omitempty"`
6666

67+
// CustomShareConfig specifies custom config values to be applied
68+
// to share section in smb.conf
69+
// +optional
70+
CustomShareConfig *SmbShareConfig `json:"customShareConfig,omitempty"`
71+
6772
// Scaling specifies parameters relating to how share resources can and
6873
// should be scaled.
6974
Scaling *SmbShareScalingSpec `json:"scaling,omitempty"`
@@ -76,6 +81,11 @@ type SmbShareStorageSpec struct {
7681
Pvc *SmbSharePvcSpec `json:"pvc,omitempty"`
7782
}
7883

84+
type SmbShareConfig struct {
85+
//Configs specify keys and values to smb.conf
86+
Configs map[string]string `json:"configs,omitempty"`
87+
}
88+
7989
// SmbSharePvcSpec defines how a PVC may be associated with a share.
8090
type SmbSharePvcSpec struct {
8191
// Name of the PVC to use for the share.

config/crd/bases/samba-operator.samba.org_smbcommonconfigs.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,15 @@ spec:
510510
description: NodeSelector values will be assigned to a PodSpec's NodeSelector.
511511
type: object
512512
type: object
513+
customGlobalConfig:
514+
description: custom configuration that are applied to [gloabal] section in smb.conf for the smb server.
515+
properties:
516+
configs:
517+
additionalProperties:
518+
type: string
519+
description: configuration keys and values.
520+
type: object
521+
type: object
513522
type: object
514523
status:
515524
description: SmbCommonConfigStatus defines the observed state of SmbCommonConfig

config/crd/bases/samba-operator.samba.org_smbshares.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ spec:
5454
description: CommonConfig specifies which SmbCommonConfig CR is to be used for this share. If left blank, the operator's default will be used.
5555
minLength: 1
5656
type: string
57+
customShareConfig:
58+
description: custom configuration that are applied to [share] section in smb.conf for the smb server.
59+
properties:
60+
configs:
61+
additionalProperties:
62+
type: string
63+
description: configuration keys and values.
64+
type: object
65+
type: object
5766
readOnly:
5867
default: false
5968
description: ReadOnly controls if this share is to be read-only or not.

internal/planner/configuration.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ func (pl *Planner) Update() (changed bool, err error) {
9696
pl.ConfigState.Shares[shareKey] = share
9797
changed = true
9898
}
99+
if pl.CommonConfig != nil {
100+
if c := applyCustomGlobal(pl.ConfigState.Globals[smbcc.Globals], pl.CommonConfig.Spec); c {
101+
changed = true
102+
}
103+
}
104+
if c := applyCustomShare(share, pl.SmbShare.Spec); c {
105+
changed = true
106+
}
99107
if c := applyShareValues(share, pl.SmbShare.Spec); c {
100108
changed = true
101109
}
@@ -165,6 +173,34 @@ func (pl *Planner) Prune() (changed bool, err error) {
165173
return
166174
}
167175

176+
func applyCustomGlobal(globals smbcc.GlobalConfig, spec api.SmbCommonConfigSpec) bool {
177+
changed := false
178+
if spec.CustomGlobalConfig != nil {
179+
for k, v := range spec.CustomGlobalConfig.Configs {
180+
oriValue, ok := globals.Options[k]
181+
if !ok || (ok && oriValue != v) {
182+
globals.Options[k] = v
183+
changed = true
184+
}
185+
}
186+
}
187+
return changed
188+
}
189+
190+
func applyCustomShare(share smbcc.ShareConfig, spec api.SmbShareSpec) bool {
191+
changed := false
192+
if spec.CustomShareConfig != nil {
193+
for k, v := range spec.CustomShareConfig.Configs {
194+
oriValue, ok := share.Options[k]
195+
if !ok || (ok && oriValue != v) {
196+
share.Options[k] = v
197+
changed = true
198+
}
199+
}
200+
}
201+
return changed
202+
}
203+
168204
func applyShareValues(share smbcc.ShareConfig, spec api.SmbShareSpec) bool {
169205
changed := false
170206

0 commit comments

Comments
 (0)