Skip to content

Commit

Permalink
Remove AWS options from CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Oct 29, 2022
1 parent 463b028 commit 6be6e7f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 52 deletions.
3 changes: 2 additions & 1 deletion pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ func NewOperator() (context.Context, *Operator) {

// Settings
settingsStore := settingsstore.WatchSettingsOrDie(ctx, kubernetesInterface, configMapWatcher, apis.Settings.List()...)
ctx = settingsStore.InjectSettings(ctx)

// Logging
logger := NewLogger(ctx, component, config, configMapWatcher)
ctx = logging.WithLogger(ctx, logger)

// Inject settings after starting the ConfigMapWatcher
lo.Must0(configMapWatcher.Start(ctx.Done()))
ctx = settingsStore.InjectSettings(ctx)

// Manager
manager, err := controllerruntime.NewManager(config, controllerruntime.Options{
Expand Down
51 changes: 0 additions & 51 deletions pkg/operator/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ package options
import (
"errors"
"flag"
"fmt"
"net/url"
"os"
"runtime/debug"

"go.uber.org/multierr"

"github.com/aws/karpenter-core/pkg/utils/env"
)

Expand All @@ -47,15 +43,6 @@ type Options struct {
EnableProfiling bool
EnableLeaderElection bool
MemoryLimit int64
// AWS Specific
ClusterName string
ClusterEndpoint string
VMMemoryOverhead float64
AWSNodeNameConvention string
AWSENILimitedPodDensity bool
AWSDefaultInstanceProfile string
AWSEnablePodENI bool
AWSIsolatedVPC bool
}

// New creates an Options struct and registers CLI flags and environment variables to fill-in the Options struct fields
Expand All @@ -74,15 +61,6 @@ func New() *Options {
f.BoolVar(&opts.EnableProfiling, "enable-profiling", env.WithDefaultBool("ENABLE_PROFILING", false), "Enable the profiling on the metric endpoint")
f.BoolVar(&opts.EnableLeaderElection, "leader-elect", env.WithDefaultBool("LEADER_ELECT", true), "Start leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.")
f.Int64Var(&opts.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.")
// AWS Specific
f.StringVar(&opts.ClusterName, "cluster-name", env.WithDefaultString("CLUSTER_NAME", ""), "The kubernetes cluster name for resource discovery")
f.StringVar(&opts.ClusterEndpoint, "cluster-endpoint", env.WithDefaultString("CLUSTER_ENDPOINT", ""), "The external kubernetes cluster endpoint for new nodes to connect with")
f.Float64Var(&opts.VMMemoryOverhead, "vm-memory-overhead", env.WithDefaultFloat64("VM_MEMORY_OVERHEAD", 0.075), "The VM memory overhead as a percent that will be subtracted from the total memory for all instance types")
f.StringVar(&opts.AWSNodeNameConvention, "aws-node-name-convention", env.WithDefaultString("AWS_NODE_NAME_CONVENTION", string(IPName)), "The node naming convention used by the AWS cloud provider. DEPRECATION WARNING: this field may be deprecated at any time")
f.BoolVar(&opts.AWSENILimitedPodDensity, "aws-eni-limited-pod-density", env.WithDefaultBool("AWS_ENI_LIMITED_POD_DENSITY", true), "Indicates whether new nodes should use ENI-based pod density. DEPRECATED: Use `.spec.kubeletConfiguration.maxPods` to set pod density on a per-provisioner basis")
f.StringVar(&opts.AWSDefaultInstanceProfile, "aws-default-instance-profile", env.WithDefaultString("AWS_DEFAULT_INSTANCE_PROFILE", ""), "The default instance profile to use when provisioning nodes in AWS")
f.BoolVar(&opts.AWSEnablePodENI, "aws-enable-pod-eni", env.WithDefaultBool("AWS_ENABLE_POD_ENI", false), "If true then instances that support pod ENI will report a vpc.amazonaws.com/pod-eni resource")
f.BoolVar(&opts.AWSIsolatedVPC, "aws-isolated-vpc", env.WithDefaultBool("AWS_ISOLATED_VPC", false), "If true then assume we can't reach AWS services which don't have a VPC endpoint. This also has the effect of disabling look-ups to the AWS pricing endpoint.")

if opts.MemoryLimit > 0 {
newLimit := int64(float64(opts.MemoryLimit) * 0.9)
Expand All @@ -102,34 +80,5 @@ func (o *Options) MustParse() *Options {
if err != nil {
panic(err)
}
if err := o.Validate(); err != nil {
panic(err)
}
return o
}

func (o Options) Validate() (err error) {
err = multierr.Append(err, o.validateEndpoint())
if o.ClusterName == "" {
err = multierr.Append(err, fmt.Errorf("CLUSTER_NAME is required"))
}
awsNodeNameConvention := AWSNodeNameConvention(o.AWSNodeNameConvention)
if awsNodeNameConvention != IPName && awsNodeNameConvention != ResourceName {
err = multierr.Append(err, fmt.Errorf("aws-node-name-convention may only be either ip-name or resource-name"))
}
return err
}

func (o Options) validateEndpoint() error {
endpoint, err := url.Parse(o.ClusterEndpoint)
// url.Parse() will accept a lot of input without error; make
// sure it's a real URL
if err != nil || !endpoint.IsAbs() || endpoint.Hostname() == "" {
return fmt.Errorf("\"%s\" not a valid CLUSTER_ENDPOINT URL", o.ClusterEndpoint)
}
return nil
}

func (o Options) GetAWSNodeNameConvention() AWSNodeNameConvention {
return AWSNodeNameConvention(o.AWSNodeNameConvention)
}

0 comments on commit 6be6e7f

Please sign in to comment.