Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option for turning on/off compaction from apiserver in etcd3 mode #51765

Merged
merged 1 commit into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cmd/kube-apiserver/app/options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ func TestAddFlags(t *testing.T) {
ServerList: nil,
Prefix: "/registry",
DeserializationCacheSize: 0,
Copier: kapi.Scheme,
Quorum: false,
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
Copier: kapi.Scheme,
Quorum: false,
KeyFile: "/var/run/kubernetes/etcd.key",
CAFile: "/var/run/kubernetes/etcdca.crt",
CertFile: "/var/run/kubernetes/etcdce.crt",
CompactionInterval: storagebackend.DefaultCompactInterval,
},
DefaultStorageMediaType: "application/vnd.kubernetes.protobuf",
DeleteCollectionWorkers: 1,
Expand Down
4 changes: 4 additions & 0 deletions staging/src/k8s.io/apiserver/pkg/server/options/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func (s *EtcdOptions) AddFlags(fs *pflag.FlagSet) {

fs.StringVar(&s.EncryptionProviderConfigFilepath, "experimental-encryption-provider-config", s.EncryptionProviderConfigFilepath,
"The file containing configuration for encryption providers to be used for storing secrets in etcd")

fs.DurationVar(&s.StorageConfig.CompactionInterval, "etcd-compaction-interval", s.StorageConfig.CompactionInterval,
"The interval of compaction requests. If 0, the compaction request from apiserver is disabled.")

}

func (s *EtcdOptions) ApplyTo(c *server.Config) error {
Expand Down
9 changes: 5 additions & 4 deletions staging/src/k8s.io/apiserver/pkg/storage/etcd3/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import (
)

const (
compactInterval = 5 * time.Minute
compactRevKey = "compact_rev_key"
compactRevKey = "compact_rev_key"
)

var (
Expand All @@ -44,7 +43,7 @@ func init() {
// By default, we save the most recent 10 minutes data and compact versions > 10minutes ago.
// It should be enough for slow watchers and to tolerate burst.
// TODO: We might keep a longer history (12h) in the future once storage API can take advantage of past version of keys.
func StartCompactor(ctx context.Context, client *clientv3.Client) {
func StartCompactor(ctx context.Context, client *clientv3.Client, compactInterval time.Duration) {
endpointsMapMu.Lock()
defer endpointsMapMu.Unlock()

Expand All @@ -60,7 +59,9 @@ func StartCompactor(ctx context.Context, client *clientv3.Client) {
endpointsMap[ep] = struct{}{}
}

go compactor(ctx, client, compactInterval)
if compactInterval != 0 {
go compactor(ctx, client, compactInterval)
}
}

// compactor periodically compacts historical versions of keys in etcd.
Expand Down
13 changes: 11 additions & 2 deletions staging/src/k8s.io/apiserver/pkg/storage/storagebackend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package storagebackend

import (
"time"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/storage/value"
)
Expand All @@ -25,6 +27,8 @@ const (
StorageTypeUnset = ""
StorageTypeETCD2 = "etcd2"
StorageTypeETCD3 = "etcd3"

DefaultCompactInterval = 5 * time.Minute
)

// Config is configuration for creating a storage backend.
Expand Down Expand Up @@ -55,6 +59,10 @@ type Config struct {
Copier runtime.ObjectCopier
// Transformer allows the value to be transformed prior to persisting into etcd.
Transformer value.Transformer

// CompactionInterval is an interval of requesting compaction from apiserver.
// If the value is 0, no compaction will be issued.
CompactionInterval time.Duration
}

func NewDefaultConfig(prefix string, copier runtime.ObjectCopier, codec runtime.Codec) *Config {
Expand All @@ -63,7 +71,8 @@ func NewDefaultConfig(prefix string, copier runtime.ObjectCopier, codec runtime.
// Default cache size to 0 - if unset, its size will be set based on target
// memory usage.
DeserializationCacheSize: 0,
Copier: copier,
Codec: codec,
Copier: copier,
Codec: codec,
CompactionInterval: DefaultCompactInterval,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newETCD3Storage(c storagebackend.Config) (storage.Interface, DestroyFunc, e
return nil, nil, err
}
ctx, cancel := context.WithCancel(context.Background())
etcd3.StartCompactor(ctx, client)
etcd3.StartCompactor(ctx, client, c.CompactionInterval)
destroyFunc := func() {
cancel()
client.Close()
Expand Down