From e3a3e1257cbabd5063e481a1de5c214cc0bf2292 Mon Sep 17 00:00:00 2001 From: Lan Liang Date: Thu, 22 Aug 2024 06:06:54 +0000 Subject: [PATCH] chore: cleanup some knative const, delete env SYSTEM_NAMESPACE FROM operator. Signed-off-by: Lan Liang --- pkg/operator/logging/logging.go | 4 +--- pkg/operator/operator.go | 3 --- pkg/test/environment.go | 3 --- test/pkg/environment/common/environment.go | 2 -- 4 files changed, 1 insertion(+), 11 deletions(-) diff --git a/pkg/operator/logging/logging.go b/pkg/operator/logging/logging.go index 36edad94b5..0928c0be38 100644 --- a/pkg/operator/logging/logging.go +++ b/pkg/operator/logging/logging.go @@ -27,8 +27,6 @@ import ( "go.uber.org/zap/zapcore" "knative.dev/pkg/changeset" - "knative.dev/pkg/logging/logkey" - "sigs.k8s.io/karpenter/pkg/operator/options" ) @@ -84,7 +82,7 @@ func WithCommit(logger *zap.Logger) *zap.Logger { return logger } // Enrich logs with the components git revision. - return logger.With(zap.String(logkey.Commit, revision)) + return logger.With(zap.String("commit", revision)) } type ignoreDebugEventsSink struct { diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index e238a3d200..9b1237a7e1 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -55,7 +55,6 @@ import ( "k8s.io/utils/clock" knativeinjection "knative.dev/pkg/injection" "knative.dev/pkg/signals" - "knative.dev/pkg/system" "knative.dev/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" @@ -113,7 +112,6 @@ type Operator struct { func NewOperator() (context.Context, *Operator) { // Root Context ctx := signals.NewContext() - ctx = knativeinjection.WithNamespaceScope(ctx, system.Namespace()) // Options ctx = injection.WithOptionsOrDie(ctx, options.Injectables...) @@ -154,7 +152,6 @@ func NewOperator() (context.Context, *Operator) { LeaderElection: !options.FromContext(ctx).DisableLeaderElection, LeaderElectionID: "karpenter-leader-election", LeaderElectionResourceLock: resourcelock.LeasesResourceLock, - LeaderElectionNamespace: system.Namespace(), LeaderElectionReleaseOnCancel: true, Metrics: server.Options{ BindAddress: fmt.Sprintf(":%d", options.FromContext(ctx).MetricsPort), diff --git a/pkg/test/environment.go b/pkg/test/environment.go index f48f8ccbf2..d4573aac20 100644 --- a/pkg/test/environment.go +++ b/pkg/test/environment.go @@ -19,7 +19,6 @@ package test import ( "context" "log" - "os" "strings" "github.com/awslabs/operatorpkg/option" @@ -30,7 +29,6 @@ import ( "k8s.io/apimachinery/pkg/util/version" "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" - "knative.dev/pkg/system" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" @@ -88,7 +86,6 @@ func NewEnvironment(options ...option.Function[EnvironmentOptions]) *Environment opts := option.Resolve(options...) ctx, cancel := context.WithCancel(context.Background()) - os.Setenv(system.NamespaceEnvKey, "default") version := version.MustParseSemantic(strings.Replace(env.WithDefaultString("K8S_VERSION", "1.30.x"), ".x", ".0", -1)) environment := envtest.Environment{Scheme: scheme.Scheme, CRDs: opts.crds} if version.Minor() >= 21 { diff --git a/test/pkg/environment/common/environment.go b/test/pkg/environment/common/environment.go index ed5077dc05..4bdbf0c96c 100644 --- a/test/pkg/environment/common/environment.go +++ b/test/pkg/environment/common/environment.go @@ -42,7 +42,6 @@ import ( . "sigs.k8s.io/karpenter/pkg/utils/testing" //nolint:stylecheck "sigs.k8s.io/karpenter/test/pkg/debug" - "knative.dev/pkg/system" controllerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" @@ -77,7 +76,6 @@ func NewEnvironment(t *testing.T) *Environment { config := NewConfig() client := NewClient(ctx, config) - lo.Must0(os.Setenv(system.NamespaceEnvKey, "kube-system")) if val, ok := os.LookupEnv("GIT_REF"); ok { ctx = context.WithValue(ctx, GitRefContextKey, val) }