Skip to content

Commit 233c70f

Browse files
authored
Merge branch 'master' into feat_enable_set_sc_statepvc
Signed-off-by: FTS152 <[email protected]>
2 parents d723111 + dcbe329 commit 233c70f

File tree

8 files changed

+126
-23
lines changed

8 files changed

+126
-23
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
- name: run the tests
5252
run: make test
5353
podmanbuild:
54-
runs-on: ubuntu-20.04
54+
runs-on: ubuntu-latest
5555
# don't run on push, since the "push" job contains the
5656
# image build step, so no need to do it twice.
5757
if: github.event_name == 'pull_request'
@@ -91,8 +91,7 @@ jobs:
9191
run: make CONTAINER_CMD=docker image-build
9292
test-kubernetes:
9393
#runs-on: ubuntu-latest
94-
# need to explicitly use 20.04 to avoid problems with jq...
95-
runs-on: ubuntu-20.04
94+
runs-on: ubuntu-latest
9695
env:
9796
CONTAINER_CMD: docker
9897
PR_NUM: ${{ github.event.pull_request.number }}

api/v1alpha1/smbcommonconfig_types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ type SmbCommonConfigSpec struct {
4343
// If left empty, the operator's default will be used.
4444
// +optional
4545
StatePVSCName string `json:"statePVSCName,omitempty"`
46+
47+
// GlobalConfig are configuration values that are applied to [global]
48+
// section in smb.conf for the smb server. This allows users to add or
49+
// override default configurations.
50+
// +opional
51+
CustomGlobalConfig *SmbCommonConfigGlobalConfig `json:"customGlobalConfig,omitempty"`
4652
}
4753

4854
// SmbCommonNetworkSpec values define networking properties for the services
@@ -66,6 +72,15 @@ type SmbCommonConfigPodSettings struct {
6672
Affinity *corev1.Affinity `json:"affinity,omitempty"`
6773
}
6874

75+
// SmbCommonConfigGlobalConfig contains values for customizing configs in
76+
// [global] section in smb.conf
77+
type SmbCommonConfigGlobalConfig struct {
78+
// Check if the user wants to use custom configs
79+
UseUnsafeCustomConfig bool `json:"useUnsafeCustomConfig,omitempty"`
80+
// Configs specify keys and values to smb.conf
81+
Configs map[string]string `json:"configs,omitempty"`
82+
}
83+
6984
// SmbCommonConfigStatus defines the observed state of SmbCommonConfig
7085
type SmbCommonConfigStatus struct {
7186
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster

api/v1alpha1/smbshare_types.go

Lines changed: 13 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,14 @@ type SmbShareStorageSpec struct {
7681
Pvc *SmbSharePvcSpec `json:"pvc,omitempty"`
7782
}
7883

84+
// SmbShareConfig defines custom config values for share section
85+
type SmbShareConfig struct {
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
89+
Configs map[string]string `json:"configs,omitempty"`
90+
}
91+
7992
// SmbSharePvcSpec defines how a PVC may be associated with a share.
8093
type SmbSharePvcSpec struct {
8194
// Name of the PVC to use for the share.

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

Lines changed: 12 additions & 0 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:

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ 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: CustomShareConfig specifies custom config values to be applied to share section in smb.conf
59+
properties:
60+
configs:
61+
additionalProperties:
62+
type: string
63+
description: Configs specify keys and values to smb.conf
64+
type: object
65+
useUnsafeCustomConfig:
66+
description: Check if the user wants to use custom configs
67+
type: boolean
68+
type: object
5769
readOnly:
5870
default: false
5971
description: ReadOnly controls if this share is to be read-only or not.

go.mod

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ require (
5959
go.uber.org/atomic v1.7.0 // indirect
6060
go.uber.org/multierr v1.6.0 // indirect
6161
go.uber.org/zap v1.24.0 // indirect
62-
golang.org/x/net v0.23.0 // indirect
62+
golang.org/x/net v0.38.0 // indirect
6363
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
64-
golang.org/x/sys v0.18.0 // indirect
65-
golang.org/x/term v0.18.0 // indirect
66-
golang.org/x/text v0.14.0 // indirect
64+
golang.org/x/sys v0.31.0 // indirect
65+
golang.org/x/term v0.30.0 // indirect
66+
golang.org/x/text v0.23.0 // indirect
6767
golang.org/x/time v0.3.0 // indirect
6868
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
6969
google.golang.org/appengine v1.6.7 // indirect
@@ -88,21 +88,21 @@ exclude (
8888
k8s.io/client-go v1.5.0
8989
k8s.io/client-go v1.5.1
9090
k8s.io/client-go v1.5.2
91-
k8s.io/client-go v10.0.0+incompatible
92-
k8s.io/client-go v11.0.0+incompatible
93-
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
94-
k8s.io/client-go v12.0.0+incompatible
95-
k8s.io/client-go v2.0.0+incompatible
9691
k8s.io/client-go v2.0.0-alpha.1+incompatible
97-
k8s.io/client-go v3.0.0+incompatible
92+
k8s.io/client-go v2.0.0+incompatible
9893
k8s.io/client-go v3.0.0-beta.0+incompatible
99-
k8s.io/client-go v4.0.0+incompatible
94+
k8s.io/client-go v3.0.0+incompatible
10095
k8s.io/client-go v4.0.0-beta.0+incompatible
96+
k8s.io/client-go v4.0.0+incompatible
10197
k8s.io/client-go v5.0.0+incompatible
10298
k8s.io/client-go v5.0.1+incompatible
10399
k8s.io/client-go v6.0.0+incompatible
104100
k8s.io/client-go v7.0.0+incompatible
105101
k8s.io/client-go v8.0.0+incompatible
106-
k8s.io/client-go v9.0.0+incompatible
107102
k8s.io/client-go v9.0.0-invalid+incompatible
103+
k8s.io/client-go v9.0.0+incompatible
104+
k8s.io/client-go v10.0.0+incompatible
105+
k8s.io/client-go v11.0.0+incompatible
106+
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
107+
k8s.io/client-go v12.0.0+incompatible
108108
)

go.sum

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
6262
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
6363
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
6464
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
65+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
6566
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
6667
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
6768
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
@@ -124,6 +125,7 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
124125
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
125126
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
126127
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
128+
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
127129
github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww=
128130
github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
129131
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
@@ -400,9 +402,11 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
400402
github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
401403
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
402404
github.com/onsi/ginkgo/v2 v2.6.0 h1:9t9b9vRUbFq3C4qKFCGkVuq/fIHji802N1nrtkh1mNc=
405+
github.com/onsi/ginkgo/v2 v2.6.0/go.mod h1:63DOGlLAH8+REH8jUGdL3YpCpu7JODesutUjdENfUAc=
403406
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
404407
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
405408
github.com/onsi/gomega v1.24.1 h1:KORJXNNTzJXzu4ScJWssJfJMnJ+2QJqhoQSRwNlze9E=
409+
github.com/onsi/gomega v1.24.1/go.mod h1:3AOiACssS3/MajrniINInwbfOOtfZvplPzuRSmvt1jM=
406410
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
407411
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
408412
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
@@ -526,6 +530,7 @@ go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
526530
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
527531
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
528532
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
533+
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
529534
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
530535
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
531536
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
@@ -618,8 +623,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
618623
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
619624
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
620625
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
621-
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
622-
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
626+
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
627+
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
623628
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
624629
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
625630
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -689,12 +694,12 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
689694
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
690695
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
691696
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
692-
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
693-
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
697+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
698+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
694699
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
695700
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
696-
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
697-
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
701+
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
702+
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
698703
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
699704
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
700705
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -703,8 +708,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
703708
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
704709
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
705710
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
706-
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
707-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
711+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
712+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
708713
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
709714
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
710715
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

internal/planner/configuration.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ 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],
101+
pl.CommonConfig.Spec); c {
102+
changed = true
103+
}
104+
}
105+
if c := applyCustomShare(share, pl.SmbShare.Spec); c {
106+
changed = true
107+
}
99108
if c := applyShareValues(share, pl.SmbShare.Spec); c {
100109
changed = true
101110
}
@@ -165,6 +174,44 @@ func (pl *Planner) Prune() (changed bool, err error) {
165174
return
166175
}
167176

177+
func applyCustomGlobal(globals smbcc.GlobalConfig, spec api.SmbCommonConfigSpec) bool {
178+
changed := false
179+
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+
}
185+
for k, v := range spec.CustomGlobalConfig.Configs {
186+
oriValue, ok := globals.Options[k]
187+
if !ok || (ok && oriValue != v) {
188+
globals.Options[k] = v
189+
changed = true
190+
}
191+
}
192+
}
193+
return changed
194+
}
195+
196+
func applyCustomShare(share smbcc.ShareConfig, spec api.SmbShareSpec) bool {
197+
changed := false
198+
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+
}
204+
for k, v := range spec.CustomShareConfig.Configs {
205+
oriValue, ok := share.Options[k]
206+
if !ok || (ok && oriValue != v) {
207+
share.Options[k] = v
208+
changed = true
209+
}
210+
}
211+
}
212+
return changed
213+
}
214+
168215
func applyShareValues(share smbcc.ShareConfig, spec api.SmbShareSpec) bool {
169216
changed := false
170217

0 commit comments

Comments
 (0)