@@ -23,7 +23,6 @@ import (
2323 "slices"
2424 "strconv"
2525
26- "github.com/aenix-io/etcd-operator/internal/log"
2726 appsv1 "k8s.io/api/apps/v1"
2827 corev1 "k8s.io/api/core/v1"
2928 "k8s.io/apimachinery/pkg/api/resource"
@@ -34,6 +33,7 @@ import (
3433
3534 etcdaenixiov1alpha1 "github.com/aenix-io/etcd-operator/api/v1alpha1"
3635 "github.com/aenix-io/etcd-operator/internal/k8sutils"
36+ "github.com/aenix-io/etcd-operator/internal/log"
3737)
3838
3939const (
@@ -256,36 +256,6 @@ func generateEtcdCommand() []string {
256256func generateEtcdArgs (cluster * etcdaenixiov1alpha1.EtcdCluster ) []string {
257257 args := []string {}
258258
259- if value , ok := cluster .Spec .Options ["quota-backend-bytes" ]; ! ok || value == "" {
260- var size resource.Quantity
261- if cluster .Spec .Storage .EmptyDir != nil {
262- if cluster .Spec .Storage .EmptyDir .SizeLimit != nil {
263- size = * cluster .Spec .Storage .EmptyDir .SizeLimit
264- }
265- } else {
266- size = * cluster .Spec .Storage .VolumeClaimTemplate .Spec .Resources .Requests .Storage ()
267- }
268- quota := float64 (size .Value ()) * defaultBackendQuotaBytesFraction
269- quota = math .Floor (quota )
270- if quota > 0 {
271- if cluster .Spec .Options == nil {
272- cluster .Spec .Options = make (map [string ]string , 1 )
273- }
274- cluster .Spec .Options ["quota-backend-bytes" ] = strconv .FormatInt (int64 (quota ), 10 )
275- }
276- }
277-
278- for name , value := range cluster .Spec .Options {
279- flag := "--" + name
280- if len (value ) == 0 {
281- args = append (args , flag )
282-
283- continue
284- }
285-
286- args = append (args , fmt .Sprintf ("%s=%s" , flag , value ))
287- }
288-
289259 peerTlsSettings := []string {"--peer-auto-tls" }
290260
291261 if cluster .Spec .Security != nil && cluster .Spec .Security .TLS .PeerSecret != "" {
@@ -335,7 +305,41 @@ func generateEtcdArgs(cluster *etcdaenixiov1alpha1.EtcdCluster) []string {
335305 args = append (args , clientTlsSettings ... )
336306 args = append (args , autoCompactionSettings ... )
337307
338- slices .Sort (args )
308+ extraArgs := []string {}
309+
310+ if value , ok := cluster .Spec .Options ["quota-backend-bytes" ]; ! ok || value == "" {
311+ var size resource.Quantity
312+ if cluster .Spec .Storage .EmptyDir != nil {
313+ if cluster .Spec .Storage .EmptyDir .SizeLimit != nil {
314+ size = * cluster .Spec .Storage .EmptyDir .SizeLimit
315+ }
316+ } else {
317+ size = * cluster .Spec .Storage .VolumeClaimTemplate .Spec .Resources .Requests .Storage ()
318+ }
319+ quota := float64 (size .Value ()) * defaultBackendQuotaBytesFraction
320+ quota = math .Floor (quota )
321+ if quota > 0 {
322+ if cluster .Spec .Options == nil {
323+ cluster .Spec .Options = make (map [string ]string , 1 )
324+ }
325+ cluster .Spec .Options ["quota-backend-bytes" ] = strconv .FormatInt (int64 (quota ), 10 )
326+ }
327+ }
328+
329+ for name , value := range cluster .Spec .Options {
330+ flag := "--" + name
331+ if len (value ) == 0 {
332+ extraArgs = append (extraArgs , flag )
333+
334+ continue
335+ }
336+
337+ extraArgs = append (extraArgs , fmt .Sprintf ("%s=%s" , flag , value ))
338+ }
339+
340+ // Sort the extra args to ensure a deterministic order
341+ slices .Sort (extraArgs )
342+ args = append (args , extraArgs ... )
339343
340344 return args
341345}
0 commit comments