Skip to content

Commit

Permalink
feat: Drop Env Vars for v1 (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
rschalo authored Jul 24, 2024
1 parent 8a530b7 commit 07ae836
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 107 deletions.
2 changes: 1 addition & 1 deletion pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func NewOperator() (context.Context, *Operator) {
// Manager
mgrOpts := ctrl.Options{
Logger: logging.IgnoreDebugEvents(logger),
LeaderElection: options.FromContext(ctx).EnableLeaderElection,
LeaderElection: !options.FromContext(ctx).DisableLeaderElection,
LeaderElectionID: "karpenter-leader-election",
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
LeaderElectionNamespace: system.Namespace(),
Expand Down
32 changes: 16 additions & 16 deletions pkg/operator/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ type FeatureGates struct {

// Options contains all CLI flags / env vars for karpenter-core. It adheres to the options.Injectable interface.
type Options struct {
ServiceName string
DisableWebhook bool
WebhookPort int
MetricsPort int
WebhookMetricsPort int
HealthProbePort int
KubeClientQPS int
KubeClientBurst int
EnableProfiling bool
EnableLeaderElection bool
MemoryLimit int64
LogLevel string
BatchMaxDuration time.Duration
BatchIdleDuration time.Duration
FeatureGates FeatureGates
ServiceName string
DisableWebhook bool
WebhookPort int
MetricsPort int
WebhookMetricsPort int
HealthProbePort int
KubeClientQPS int
KubeClientBurst int
EnableProfiling bool
DisableLeaderElection bool
MemoryLimit int64
LogLevel string
BatchMaxDuration time.Duration
BatchIdleDuration time.Duration
FeatureGates FeatureGates
}

type FlagSet struct {
Expand Down Expand Up @@ -90,7 +90,7 @@ func (o *Options) AddFlags(fs *FlagSet) {
fs.IntVar(&o.KubeClientQPS, "kube-client-qps", env.WithDefaultInt("KUBE_CLIENT_QPS", 200), "The smoothed rate of qps to kube-apiserver")
fs.IntVar(&o.KubeClientBurst, "kube-client-burst", env.WithDefaultInt("KUBE_CLIENT_BURST", 300), "The maximum allowed burst of queries to the kube-apiserver")
fs.BoolVarWithEnv(&o.EnableProfiling, "enable-profiling", "ENABLE_PROFILING", false, "Enable the profiling on the metric endpoint")
fs.BoolVarWithEnv(&o.EnableLeaderElection, "leader-elect", "LEADER_ELECT", true, "Start leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.")
fs.BoolVarWithEnv(&o.DisableLeaderElection, "disable-leader-election", "DISABLE_LEADER_ELECTION", false, "Disable the leader election client before executing the main loop. Disable when running replicated components for high availability is not desired.")
fs.Int64Var(&o.MemoryLimit, "memory-limit", env.WithDefaultInt64("MEMORY_LIMIT", -1), "Memory limit on the container running the controller. The GC soft memory limit is set to 90% of this value.")
fs.StringVar(&o.LogLevel, "log-level", env.WithDefaultString("LOG_LEVEL", "info"), "Log verbosity level. Can be one of 'debug', 'info', or 'error'")
fs.DurationVar(&o.BatchMaxDuration, "batch-max-duration", env.WithDefaultDuration("BATCH_MAX_DURATION", 10*time.Second), "The maximum length of a batch window. The longer this is, the more pods we can consider for provisioning at one time which usually results in fewer but larger nodes.")
Expand Down
122 changes: 61 additions & 61 deletions pkg/operator/options/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var _ = Describe("Options", func() {
"KUBE_CLIENT_QPS",
"KUBE_CLIENT_BURST",
"ENABLE_PROFILING",
"LEADER_ELECT",
"DISABLE_LEADER_ELECTION",
"MEMORY_LIMIT",
"LOG_LEVEL",
"BATCH_MAX_DURATION",
Expand Down Expand Up @@ -96,20 +96,20 @@ var _ = Describe("Options", func() {
err := opts.Parse(fs)
Expect(err).To(BeNil())
expectOptionsMatch(opts, test.Options(test.OptionsFields{
ServiceName: lo.ToPtr(""),
DisableWebhook: lo.ToPtr(false),
WebhookPort: lo.ToPtr(8443),
MetricsPort: lo.ToPtr(8000),
WebhookMetricsPort: lo.ToPtr(8001),
HealthProbePort: lo.ToPtr(8081),
KubeClientQPS: lo.ToPtr(200),
KubeClientBurst: lo.ToPtr(300),
EnableProfiling: lo.ToPtr(false),
EnableLeaderElection: lo.ToPtr(true),
MemoryLimit: lo.ToPtr[int64](-1),
LogLevel: lo.ToPtr("info"),
BatchMaxDuration: lo.ToPtr(10 * time.Second),
BatchIdleDuration: lo.ToPtr(time.Second),
ServiceName: lo.ToPtr(""),
DisableWebhook: lo.ToPtr(false),
WebhookPort: lo.ToPtr(8443),
MetricsPort: lo.ToPtr(8000),
WebhookMetricsPort: lo.ToPtr(8001),
HealthProbePort: lo.ToPtr(8081),
KubeClientQPS: lo.ToPtr(200),
KubeClientBurst: lo.ToPtr(300),
EnableProfiling: lo.ToPtr(false),
DisableLeaderElection: lo.ToPtr(false),
MemoryLimit: lo.ToPtr[int64](-1),
LogLevel: lo.ToPtr("info"),
BatchMaxDuration: lo.ToPtr(10 * time.Second),
BatchIdleDuration: lo.ToPtr(time.Second),
FeatureGates: test.FeatureGates{
SpotToSpotConsolidation: lo.ToPtr(false),
},
Expand All @@ -128,7 +128,7 @@ var _ = Describe("Options", func() {
"--kube-client-qps", "0",
"--kube-client-burst", "0",
"--enable-profiling",
"--leader-elect=false",
"--disable-leader-election=true",
"--memory-limit", "0",
"--log-level", "debug",
"--batch-max-duration", "5s",
Expand All @@ -137,20 +137,20 @@ var _ = Describe("Options", func() {
)
Expect(err).To(BeNil())
expectOptionsMatch(opts, test.Options(test.OptionsFields{
ServiceName: lo.ToPtr("cli"),
DisableWebhook: lo.ToPtr(true),
WebhookPort: lo.ToPtr(0),
MetricsPort: lo.ToPtr(0),
WebhookMetricsPort: lo.ToPtr(0),
HealthProbePort: lo.ToPtr(0),
KubeClientQPS: lo.ToPtr(0),
KubeClientBurst: lo.ToPtr(0),
EnableProfiling: lo.ToPtr(true),
EnableLeaderElection: lo.ToPtr(false),
MemoryLimit: lo.ToPtr[int64](0),
LogLevel: lo.ToPtr("debug"),
BatchMaxDuration: lo.ToPtr(5 * time.Second),
BatchIdleDuration: lo.ToPtr(5 * time.Second),
ServiceName: lo.ToPtr("cli"),
DisableWebhook: lo.ToPtr(true),
WebhookPort: lo.ToPtr(0),
MetricsPort: lo.ToPtr(0),
WebhookMetricsPort: lo.ToPtr(0),
HealthProbePort: lo.ToPtr(0),
KubeClientQPS: lo.ToPtr(0),
KubeClientBurst: lo.ToPtr(0),
EnableProfiling: lo.ToPtr(true),
DisableLeaderElection: lo.ToPtr(true),
MemoryLimit: lo.ToPtr[int64](0),
LogLevel: lo.ToPtr("debug"),
BatchMaxDuration: lo.ToPtr(5 * time.Second),
BatchIdleDuration: lo.ToPtr(5 * time.Second),
FeatureGates: test.FeatureGates{
SpotToSpotConsolidation: lo.ToPtr(true),
},
Expand All @@ -167,7 +167,7 @@ var _ = Describe("Options", func() {
os.Setenv("KUBE_CLIENT_QPS", "0")
os.Setenv("KUBE_CLIENT_BURST", "0")
os.Setenv("ENABLE_PROFILING", "true")
os.Setenv("LEADER_ELECT", "false")
os.Setenv("DISABLE_LEADER_ELECTION", "true")
os.Setenv("MEMORY_LIMIT", "0")
os.Setenv("LOG_LEVEL", "debug")
os.Setenv("BATCH_MAX_DURATION", "5s")
Expand All @@ -180,20 +180,20 @@ var _ = Describe("Options", func() {
err := opts.Parse(fs)
Expect(err).To(BeNil())
expectOptionsMatch(opts, test.Options(test.OptionsFields{
ServiceName: lo.ToPtr("env"),
DisableWebhook: lo.ToPtr(true),
WebhookPort: lo.ToPtr(0),
MetricsPort: lo.ToPtr(0),
WebhookMetricsPort: lo.ToPtr(0),
HealthProbePort: lo.ToPtr(0),
KubeClientQPS: lo.ToPtr(0),
KubeClientBurst: lo.ToPtr(0),
EnableProfiling: lo.ToPtr(true),
EnableLeaderElection: lo.ToPtr(false),
MemoryLimit: lo.ToPtr[int64](0),
LogLevel: lo.ToPtr("debug"),
BatchMaxDuration: lo.ToPtr(5 * time.Second),
BatchIdleDuration: lo.ToPtr(5 * time.Second),
ServiceName: lo.ToPtr("env"),
DisableWebhook: lo.ToPtr(true),
WebhookPort: lo.ToPtr(0),
MetricsPort: lo.ToPtr(0),
WebhookMetricsPort: lo.ToPtr(0),
HealthProbePort: lo.ToPtr(0),
KubeClientQPS: lo.ToPtr(0),
KubeClientBurst: lo.ToPtr(0),
EnableProfiling: lo.ToPtr(true),
DisableLeaderElection: lo.ToPtr(true),
MemoryLimit: lo.ToPtr[int64](0),
LogLevel: lo.ToPtr("debug"),
BatchMaxDuration: lo.ToPtr(5 * time.Second),
BatchIdleDuration: lo.ToPtr(5 * time.Second),
FeatureGates: test.FeatureGates{
SpotToSpotConsolidation: lo.ToPtr(true),
},
Expand All @@ -208,7 +208,7 @@ var _ = Describe("Options", func() {
os.Setenv("KUBE_CLIENT_QPS", "0")
os.Setenv("KUBE_CLIENT_BURST", "0")
os.Setenv("ENABLE_PROFILING", "true")
os.Setenv("LEADER_ELECT", "false")
os.Setenv("DISABLE_LEADER_ELECTION", "true")
os.Setenv("MEMORY_LIMIT", "0")
os.Setenv("LOG_LEVEL", "debug")
os.Setenv("BATCH_MAX_DURATION", "5s")
Expand All @@ -225,20 +225,20 @@ var _ = Describe("Options", func() {
)
Expect(err).To(BeNil())
expectOptionsMatch(opts, test.Options(test.OptionsFields{
ServiceName: lo.ToPtr("cli"),
DisableWebhook: lo.ToPtr(true),
WebhookPort: lo.ToPtr(0),
MetricsPort: lo.ToPtr(0),
WebhookMetricsPort: lo.ToPtr(0),
HealthProbePort: lo.ToPtr(0),
KubeClientQPS: lo.ToPtr(0),
KubeClientBurst: lo.ToPtr(0),
EnableProfiling: lo.ToPtr(true),
EnableLeaderElection: lo.ToPtr(false),
MemoryLimit: lo.ToPtr[int64](0),
LogLevel: lo.ToPtr("debug"),
BatchMaxDuration: lo.ToPtr(5 * time.Second),
BatchIdleDuration: lo.ToPtr(5 * time.Second),
ServiceName: lo.ToPtr("cli"),
DisableWebhook: lo.ToPtr(true),
WebhookPort: lo.ToPtr(0),
MetricsPort: lo.ToPtr(0),
WebhookMetricsPort: lo.ToPtr(0),
HealthProbePort: lo.ToPtr(0),
KubeClientQPS: lo.ToPtr(0),
KubeClientBurst: lo.ToPtr(0),
EnableProfiling: lo.ToPtr(true),
DisableLeaderElection: lo.ToPtr(true),
MemoryLimit: lo.ToPtr[int64](0),
LogLevel: lo.ToPtr("debug"),
BatchMaxDuration: lo.ToPtr(5 * time.Second),
BatchIdleDuration: lo.ToPtr(5 * time.Second),
FeatureGates: test.FeatureGates{
SpotToSpotConsolidation: lo.ToPtr(true),
},
Expand Down Expand Up @@ -294,7 +294,7 @@ func expectOptionsMatch(optsA, optsB *options.Options) {
Expect(optsA.KubeClientQPS).To(Equal(optsB.KubeClientQPS))
Expect(optsA.KubeClientBurst).To(Equal(optsB.KubeClientBurst))
Expect(optsA.EnableProfiling).To(Equal(optsB.EnableProfiling))
Expect(optsA.EnableLeaderElection).To(Equal(optsB.EnableLeaderElection))
Expect(optsA.DisableLeaderElection).To(Equal(optsB.DisableLeaderElection))
Expect(optsA.MemoryLimit).To(Equal(optsB.MemoryLimit))
Expect(optsA.LogLevel).To(Equal(optsB.LogLevel))
Expect(optsA.BatchMaxDuration).To(Equal(optsB.BatchMaxDuration))
Expand Down
58 changes: 29 additions & 29 deletions pkg/test/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ import (

type OptionsFields struct {
// Vendor Neutral
ServiceName *string
DisableWebhook *bool
WebhookPort *int
MetricsPort *int
WebhookMetricsPort *int
HealthProbePort *int
KubeClientQPS *int
KubeClientBurst *int
EnableProfiling *bool
EnableLeaderElection *bool
MemoryLimit *int64
LogLevel *string
BatchMaxDuration *time.Duration
BatchIdleDuration *time.Duration
FeatureGates FeatureGates
ServiceName *string
DisableWebhook *bool
WebhookPort *int
MetricsPort *int
WebhookMetricsPort *int
HealthProbePort *int
KubeClientQPS *int
KubeClientBurst *int
EnableProfiling *bool
DisableLeaderElection *bool
MemoryLimit *int64
LogLevel *string
BatchMaxDuration *time.Duration
BatchIdleDuration *time.Duration
FeatureGates FeatureGates
}

type FeatureGates struct {
Expand All @@ -58,20 +58,20 @@ func Options(overrides ...OptionsFields) *options.Options {
}

return &options.Options{
ServiceName: lo.FromPtrOr(opts.ServiceName, ""),
DisableWebhook: lo.FromPtrOr(opts.DisableWebhook, false),
WebhookPort: lo.FromPtrOr(opts.WebhookPort, 8443),
MetricsPort: lo.FromPtrOr(opts.MetricsPort, 8000),
WebhookMetricsPort: lo.FromPtrOr(opts.WebhookMetricsPort, 8001),
HealthProbePort: lo.FromPtrOr(opts.HealthProbePort, 8081),
KubeClientQPS: lo.FromPtrOr(opts.KubeClientQPS, 200),
KubeClientBurst: lo.FromPtrOr(opts.KubeClientBurst, 300),
EnableProfiling: lo.FromPtrOr(opts.EnableProfiling, false),
EnableLeaderElection: lo.FromPtrOr(opts.EnableLeaderElection, true),
MemoryLimit: lo.FromPtrOr(opts.MemoryLimit, -1),
LogLevel: lo.FromPtrOr(opts.LogLevel, ""),
BatchMaxDuration: lo.FromPtrOr(opts.BatchMaxDuration, 10*time.Second),
BatchIdleDuration: lo.FromPtrOr(opts.BatchIdleDuration, time.Second),
ServiceName: lo.FromPtrOr(opts.ServiceName, ""),
DisableWebhook: lo.FromPtrOr(opts.DisableWebhook, false),
WebhookPort: lo.FromPtrOr(opts.WebhookPort, 8443),
MetricsPort: lo.FromPtrOr(opts.MetricsPort, 8000),
WebhookMetricsPort: lo.FromPtrOr(opts.WebhookMetricsPort, 8001),
HealthProbePort: lo.FromPtrOr(opts.HealthProbePort, 8081),
KubeClientQPS: lo.FromPtrOr(opts.KubeClientQPS, 200),
KubeClientBurst: lo.FromPtrOr(opts.KubeClientBurst, 300),
EnableProfiling: lo.FromPtrOr(opts.EnableProfiling, false),
DisableLeaderElection: lo.FromPtrOr(opts.DisableLeaderElection, false),
MemoryLimit: lo.FromPtrOr(opts.MemoryLimit, -1),
LogLevel: lo.FromPtrOr(opts.LogLevel, ""),
BatchMaxDuration: lo.FromPtrOr(opts.BatchMaxDuration, 10*time.Second),
BatchIdleDuration: lo.FromPtrOr(opts.BatchIdleDuration, time.Second),
FeatureGates: options.FeatureGates{
SpotToSpotConsolidation: lo.FromPtrOr(opts.FeatureGates.SpotToSpotConsolidation, false),
},
Expand Down

0 comments on commit 07ae836

Please sign in to comment.