diff --git a/docs/howto_config.md b/docs/howto_config.md index 5d5f63d637..5fb4f11a2b 100644 --- a/docs/howto_config.md +++ b/docs/howto_config.md @@ -20,6 +20,12 @@ apiServer: - "" debugging: logLevel: "" +etcd: + quotaBackendSize: "" + defragCheckFreq: "" + doStartupDefrag: false + minDefragSize: "" + maxFragmentedPercentage: 0 ``` ## Default Settings @@ -42,6 +48,12 @@ apiServer: subjectAltNames: [] debugging: logLevel: "Normal" +etcd: + quotaBackendSize: "2Gi" + defragCheckFreq: "5m" + doStartupDefrag: true + minDefragSize: "100Mi" + maxFragmentedPercentage: 45 ``` ## Service NodePort range diff --git a/packaging/microshift/config.yaml b/packaging/microshift/config.yaml index a51ce8f498..a74e6c120f 100644 --- a/packaging/microshift/config.yaml +++ b/packaging/microshift/config.yaml @@ -29,3 +29,20 @@ apiServer: debugging: # Log verbosity ('Normal', 'Debug', 'Trace', 'TraceAll'): #logLevel: 'Normal' + +etcd: + # The limit on the size of the etcd database; the etcd server will start failing writes if its size on disk reaches this value. (Default: 2GB) + #quotaBackendSize: '2Gi' + + # How often to check the conditions for defragmenting the etcd database (0 means no defrags, except for a single on startup if `doStartupDefrag` is set). (Default: 5 minutes) + #defragCheckFreq: '5m' + + # Whether or not to defragment the etcd database when the etcd server finishes starting. (Default: true) + #doStartupDefrag: true + + # Defragment conditions: if both of the following are true when the condition check (controlled by the DefragCheckFreq) runs, defragment the etcd database. + # The minimum size of the etcd database, if the database is smaller than this value, defragmenting will not occur. (Default: 100MB) + #minDefragSize: '100Mi' + + # The maximum allowed fragmented percentage, if the database is fragmented less than this value, defragmenting will not occur. (Default: 45) + #maxFragmentedPercentage: 45 diff --git a/pkg/config/config.go b/pkg/config/config.go index cc2c3247fd..4855f3fc02 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -17,6 +17,7 @@ import ( "github.com/mitchellh/go-homedir" "github.com/spf13/pflag" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/component-base/logs" "k8s.io/klog/v2" @@ -58,7 +59,7 @@ type IngressConfig struct { ServingKey []byte } -type EtcdConfig struct { +type InternalEtcdConfig struct { // The limit on the size of the etcd database; etcd will start failing writes if its size on disk reaches this value QuotaBackendBytes int64 // If the backend is fragmented more than `maxFragmentedPercentage` @@ -71,6 +72,19 @@ type EtcdConfig struct { DoStartupDefrag bool } +type EtcdConfig struct { + // The limit on the size of the etcd database; etcd will start failing writes if its size on disk reaches this value + QuotaBackendSize string + // If the backend is fragmented more than `maxFragmentedPercentage` + // and the database size is greater than `minDefragSize`, do a defrag. + MinDefragSize string + MaxFragmentedPercentage float64 + // How often to check the conditions for defragging (0 means no defrags, except for a single on startup if `doStartupDefrag` is set). + DefragCheckFreq string + // Whether or not to do a defrag when the server finishes starting + DoStartupDefrag bool +} + type MicroshiftConfig struct { LogVLevel int `json:"logVLevel"` @@ -89,17 +103,18 @@ type MicroshiftConfig struct { BaseDomain string `json:"baseDomain"` Cluster ClusterConfig `json:"cluster"` - Ingress IngressConfig `json:"-"` - Etcd EtcdConfig `json:"etcd"` + Ingress IngressConfig `json:"-"` + Etcd InternalEtcdConfig `json:"etcd"` } // Top level config file type Config struct { - DNS DNS `json:"dns"` - Network Network `json:"network"` - Node Node `json:"node"` - ApiServer ApiServer `json:"apiServer"` - Debugging Debugging `json:"debugging"` + DNS DNS `json:"dns"` + Network Network `json:"network"` + Node Node `json:"node"` + ApiServer ApiServer `json:"apiServer"` + Debugging Debugging `json:"debugging"` + Etcd EtcdConfig `json:"etcd"` } type Network struct { @@ -238,7 +253,7 @@ func NewMicroshiftConfig() *MicroshiftConfig { ServiceCIDR: "10.43.0.0/16", ServiceNodePortRange: "30000-32767", }, - Etcd: EtcdConfig{ + Etcd: InternalEtcdConfig{ MinDefragBytes: 100 * 1024 * 1024, // 100MB MaxFragmentedPercentage: 45, // percent DefragCheckFreq: 5 * time.Minute, @@ -402,6 +417,36 @@ func (c *MicroshiftConfig) ReadFromConfigFile(configFile string) error { c.KASAdvertiseAddress = config.ApiServer.AdvertiseAddress } + if config.Etcd.DefragCheckFreq != "" { + d, err := time.ParseDuration(config.Etcd.DefragCheckFreq) + if err != nil { + return fmt.Errorf("failed to parse etcd defragCheckFreq: %v", err) + } + c.Etcd.DefragCheckFreq = d + } + if config.Etcd.MinDefragSize != "" { + q, err := resource.ParseQuantity(config.Etcd.MinDefragSize) + if err != nil { + return fmt.Errorf("failed to parse etcd minDefragSize: %v", err) + } + if !q.IsZero() { + c.Etcd.MinDefragBytes = q.Value() + } + } + if config.Etcd.MaxFragmentedPercentage > 0 { + c.Etcd.MaxFragmentedPercentage = config.Etcd.MaxFragmentedPercentage + } + if config.Etcd.QuotaBackendSize != "" { + q, err := resource.ParseQuantity(config.Etcd.QuotaBackendSize) + if err != nil { + return fmt.Errorf("failed to parse etcd quotaBackendSize: %v", err) + } + if !q.IsZero() { + c.Etcd.QuotaBackendBytes = q.Value() + } + } + c.Etcd.DoStartupDefrag = config.Etcd.DoStartupDefrag + return nil } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 40d14d4ca1..1be50403c6 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -57,6 +57,13 @@ func TestConfigFile(t *testing.T) { Debugging: Debugging{ LogLevel: "Debug", }, + Etcd: EtcdConfig{ + QuotaBackendSize: "2Gi", + MinDefragSize: "100Mi", + MaxFragmentedPercentage: 45, + DefragCheckFreq: "5m", + DoStartupDefrag: true, + }, }, expected: MicroshiftConfig{ LogVLevel: 4, @@ -71,7 +78,7 @@ func TestConfigFile(t *testing.T) { ServiceCIDR: "40.30.20.10/16", ServiceNodePortRange: "1024-32767", }, - Etcd: EtcdConfig{ + Etcd: InternalEtcdConfig{ QuotaBackendBytes: 2 * 1024 * 1024 * 1024, MinDefragBytes: 100 * 1024 * 1024, MaxFragmentedPercentage: 45, @@ -150,6 +157,13 @@ func TestMicroshiftConfigReadAndValidate(t *testing.T) { Debugging: Debugging{ LogLevel: "Debug", }, + Etcd: EtcdConfig{ + QuotaBackendSize: "2Gi", + MinDefragSize: "100Mi", + MaxFragmentedPercentage: 45, + DefragCheckFreq: "5m", + DoStartupDefrag: true, + }, }, expected: MicroshiftConfig{ LogVLevel: 4, @@ -166,7 +180,7 @@ func TestMicroshiftConfigReadAndValidate(t *testing.T) { ServiceNodePortRange: "1024-32767", DNS: "40.30.0.10", }, - Etcd: EtcdConfig{ + Etcd: InternalEtcdConfig{ QuotaBackendBytes: 2 * 1024 * 1024 * 1024, MinDefragBytes: 100 * 1024 * 1024, MaxFragmentedPercentage: 45,