Skip to content

Commit d810430

Browse files
Frank Hsiaos-burris
authored andcommitted
resources: Add hint for custom configuration
1. Add a key to check if the user already read docs and know the risks that custom configs may lead to unexpected behaviors. Custom settings are ignored if acknowledgement flags are not set if useUnsafeCustomConfig not set to true explicitly. 2. fix comment typoes Co-authored-by: Spencer B. <[email protected]> Signed-off-by: FTS152 <[email protected]>
1 parent cc34879 commit d810430

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

api/v1alpha1/smbcommonconfig_types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type SmbCommonConfigSpec struct {
3939
// are scheduled in a kubernetes cluster.
4040
PodSettings *SmbCommonConfigPodSettings `json:"podSettings,omitempty"`
4141

42-
// GloabalConfig are configuration values that are applied to [gloabal]
42+
// GlobalConfig are configuration values that are applied to [global]
4343
// section in smb.conf for the smb server. This allows users to add or
4444
// override default configurations.
4545
// +opional
@@ -70,7 +70,9 @@ type SmbCommonConfigPodSettings struct {
7070
// SmbCommonConfigGlobalConfig contains values for customizing configs in
7171
// [global] section in smb.conf
7272
type SmbCommonConfigGlobalConfig struct {
73-
//Configs specify keys and values to smb.conf
73+
// Check if the user wants to use custom configs
74+
UseUnsafeCustomConfig bool `json:"useUnsafeCustomConfig,omitempty"`
75+
// Configs specify keys and values to smb.conf
7476
Configs map[string]string `json:"configs,omitempty"`
7577
}
7678

api/v1alpha1/smbshare_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ type SmbShareStorageSpec struct {
8181
Pvc *SmbSharePvcSpec `json:"pvc,omitempty"`
8282
}
8383

84+
// SmbShareConfig defines custom config values for share section
8485
type SmbShareConfig struct {
85-
//Configs specify keys and values to smb.conf
86+
// Check if the user wants to use custom configs
87+
UseUnsafeCustomConfig bool `json:"useUnsafeCustomConfig,omitempty"`
88+
// Configs specify keys and values to smb.conf
8689
Configs map[string]string `json:"configs,omitempty"`
8790
}
8891

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ spec:
3030
spec:
3131
description: SmbCommonConfigSpec values act as a template for properties of the services that will host shares.
3232
properties:
33+
customGlobalConfig:
34+
description: GlobalConfig are configuration values that are applied to [global] section in smb.conf for the smb server. This allows users to add or override default configurations.
35+
properties:
36+
configs:
37+
additionalProperties:
38+
type: string
39+
description: Configs specify keys and values to smb.conf
40+
type: object
41+
useUnsafeCustomConfig:
42+
description: Check if the user wants to use custom configs
43+
type: boolean
44+
type: object
3345
network:
3446
description: Network specifies what kind of networking shares associated with this config will use.
3547
properties:
@@ -510,15 +522,6 @@ spec:
510522
description: NodeSelector values will be assigned to a PodSpec's NodeSelector.
511523
type: object
512524
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
522525
type: object
523526
status:
524527
description: SmbCommonConfigStatus defines the observed state of SmbCommonConfig

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ spec:
5555
minLength: 1
5656
type: string
5757
customShareConfig:
58-
description: custom configuration that are applied to [share] section in smb.conf for the smb server.
58+
description: CustomShareConfig specifies custom config values to be applied to share section in smb.conf
5959
properties:
6060
configs:
6161
additionalProperties:
6262
type: string
63-
description: configuration keys and values.
63+
description: Configs specify keys and values to smb.conf
6464
type: object
65+
useUnsafeCustomConfig:
66+
description: Check if the user wants to use custom configs
67+
type: boolean
6568
type: object
6669
readOnly:
6770
default: false

internal/planner/configuration.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ func (pl *Planner) Update() (changed bool, err error) {
9797
changed = true
9898
}
9999
if pl.CommonConfig != nil {
100-
if c := applyCustomGlobal(pl.ConfigState.Globals[smbcc.Globals], pl.CommonConfig.Spec); c {
100+
if c := applyCustomGlobal(pl.ConfigState.Globals[smbcc.Globals],
101+
pl.CommonConfig.Spec); c {
101102
changed = true
102103
}
103104
}
@@ -176,6 +177,11 @@ func (pl *Planner) Prune() (changed bool, err error) {
176177
func applyCustomGlobal(globals smbcc.GlobalConfig, spec api.SmbCommonConfigSpec) bool {
177178
changed := false
178179
if spec.CustomGlobalConfig != nil {
180+
// check if the user wants to use custom configs
181+
// if not, just return
182+
if !spec.CustomGlobalConfig.UseUnsafeCustomConfig {
183+
return changed
184+
}
179185
for k, v := range spec.CustomGlobalConfig.Configs {
180186
oriValue, ok := globals.Options[k]
181187
if !ok || (ok && oriValue != v) {
@@ -190,6 +196,11 @@ func applyCustomGlobal(globals smbcc.GlobalConfig, spec api.SmbCommonConfigSpec)
190196
func applyCustomShare(share smbcc.ShareConfig, spec api.SmbShareSpec) bool {
191197
changed := false
192198
if spec.CustomShareConfig != nil {
199+
// check if the user wants to use custom configs
200+
// if not, just return
201+
if !spec.CustomShareConfig.UseUnsafeCustomConfig {
202+
return changed
203+
}
193204
for k, v := range spec.CustomShareConfig.Configs {
194205
oriValue, ok := share.Options[k]
195206
if !ok || (ok && oriValue != v) {

0 commit comments

Comments
 (0)