From 6964c29ddeeec3ef3d434a49599fffe086c1df46 Mon Sep 17 00:00:00 2001 From: Jason Deal Date: Fri, 13 Oct 2023 10:42:27 -0700 Subject: [PATCH] changes for injection cleanup --- pkg/cloudprovider/cloudprovider.go | 4 +++- pkg/operator/options/options.go | 36 +++++++++++++----------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/pkg/cloudprovider/cloudprovider.go b/pkg/cloudprovider/cloudprovider.go index f6248c68aabf..b2f8231da176 100644 --- a/pkg/cloudprovider/cloudprovider.go +++ b/pkg/cloudprovider/cloudprovider.go @@ -27,12 +27,14 @@ import ( corev1beta1 "github.com/aws/karpenter-core/pkg/apis/v1beta1" "github.com/aws/karpenter-core/pkg/events" + coreoptions "github.com/aws/karpenter-core/pkg/operator/options" "github.com/aws/karpenter-core/pkg/utils/functional" machineutil "github.com/aws/karpenter-core/pkg/utils/machine" nodepoolutil "github.com/aws/karpenter-core/pkg/utils/nodepool" "github.com/aws/karpenter/pkg/apis" "github.com/aws/karpenter/pkg/apis/v1alpha1" "github.com/aws/karpenter/pkg/apis/v1beta1" + "github.com/aws/karpenter/pkg/operator/options" "github.com/aws/karpenter/pkg/utils" nodeclassutil "github.com/aws/karpenter/pkg/utils/nodeclass" @@ -63,7 +65,7 @@ func init() { v1alpha5.NormalizedLabels = lo.Assign(v1alpha5.NormalizedLabels, map[string]string{"topology.ebs.csi.aws.com/zone": v1.LabelTopologyZone}) corev1beta1.NormalizedLabels = lo.Assign(corev1beta1.NormalizedLabels, map[string]string{"topology.ebs.csi.aws.com/zone": v1.LabelTopologyZone}) coreapis.Settings = append(coreapis.Settings, apis.Settings...) - coreapis.Options = append(coreapis.Options, apis.Options...) + coreoptions.Injectables = append(coreoptions.Injectables, &options.Options{}) } var _ cloudprovider.CloudProvider = (*CloudProvider)(nil) diff --git a/pkg/operator/options/options.go b/pkg/operator/options/options.go index b43597b4e6d3..68013a4b45b4 100644 --- a/pkg/operator/options/options.go +++ b/pkg/operator/options/options.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" - coresettings "github.com/aws/karpenter-core/pkg/apis/settings" "github.com/aws/karpenter-core/pkg/utils/env" "github.com/aws/karpenter/pkg/apis/settings" ) @@ -117,29 +116,24 @@ func (*Options) Inject(ctx context.Context, args ...string) (context.Context, er } } - ctx = ToContext(ctx, o) - return ctx, nil + return ToContext(ctx, o), nil } -func (*Options) MergeSettings(ctx context.Context, injectables ...coresettings.Injectable) context.Context { - for _, in := range injectables { - _, ok := in.(*settings.Settings) - if !ok { - continue - } - s := in.FromContext(ctx).(*settings.Settings) - o := FromContext(ctx) - mergeField(&o.AssumeRoleARN, s.AssumeRoleARN, o.AssumeRoleARNSet) - mergeField(&o.AssumeRoleDuration, s.AssumeRoleDuration, o.AssumeRoleDurationSet) - mergeField(&o.ClusterCABundle, s.ClusterCABundle, o.ClusterCABundleSet) - mergeField(&o.ClusterName, s.ClusterName, o.ClusterNameSet) - mergeField(&o.ClusterEndpoint, s.ClusterEndpoint, o.ClusterEndpointSet) - mergeField(&o.IsolatedVPC, s.IsolatedVPC, o.IsolatedVPCSet) - mergeField(&o.VMMemoryOverheadPercent, s.VMMemoryOverheadPercent, o.VMMemoryOverheadPercentSet) - mergeField(&o.InterruptionQueueName, s.InterruptionQueueName, o.InterruptionQueueNameSet) - ctx = ToContext(ctx, o) +func (*Options) MergeSettings(ctx context.Context) context.Context { + s := settings.FromContext(ctx) + if s == nil { + return ctx } - return ctx + o := FromContext(ctx) + mergeField(&o.AssumeRoleARN, s.AssumeRoleARN, o.AssumeRoleARNSet) + mergeField(&o.AssumeRoleDuration, s.AssumeRoleDuration, o.AssumeRoleDurationSet) + mergeField(&o.ClusterCABundle, s.ClusterCABundle, o.ClusterCABundleSet) + mergeField(&o.ClusterName, s.ClusterName, o.ClusterNameSet) + mergeField(&o.ClusterEndpoint, s.ClusterEndpoint, o.ClusterEndpointSet) + mergeField(&o.IsolatedVPC, s.IsolatedVPC, o.IsolatedVPCSet) + mergeField(&o.VMMemoryOverheadPercent, s.VMMemoryOverheadPercent, o.VMMemoryOverheadPercentSet) + mergeField(&o.InterruptionQueueName, s.InterruptionQueueName, o.InterruptionQueueNameSet) + return ToContext(ctx, o) } func ToContext(ctx context.Context, opts *Options) context.Context {