diff --git a/Makefile b/Makefile index 258f31e7c8..37ba45c55b 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,8 @@ presubmit: verify test licenses vulncheck ## Run all steps required for code to install-kwok: ## Install kwok provider UNINSTALL_KWOK=false ./hack/install-kwok.sh -uninstall-kwok: ## Install kwok provider + +uninstall-kwok: ## Uninstall kwok provider UNINSTALL_KWOK=true ./hack/install-kwok.sh build: ## Build the Karpenter KWOK controller images using ko build @@ -46,7 +47,7 @@ test: ## Run tests -race \ -timeout 15m \ --ginkgo.focus="${FOCUS}" \ - --ginkgo.timeout=15m \ + --ginkgo.randomize-all \ --ginkgo.v \ -cover -coverprofile=coverage.out -outputdir=. -coverpkg=./... @@ -94,4 +95,4 @@ download: ## Recursively "go mod download" on all directories where go.mod exist toolchain: ## Install developer toolchain ./hack/toolchain.sh -.PHONY: help presubmit dev test verify toolchain +.PHONY: help presubmit install-kwok uninstall-kwok build apply delete test deflake vulncheck licenses verify download toolchain \ No newline at end of file diff --git a/pkg/controllers/leasegarbagecollection/controller.go b/pkg/controllers/leasegarbagecollection/controller.go index 0580a8be09..f66a6c2093 100644 --- a/pkg/controllers/leasegarbagecollection/controller.go +++ b/pkg/controllers/leasegarbagecollection/controller.go @@ -57,7 +57,7 @@ func (c *Controller) Reconcile(ctx context.Context, l *v1.Lease) (reconcile.Resu err := c.kubeClient.Delete(ctx, l) if err == nil { logging.FromContext(ctx).Debug("found and delete leaked lease") - NodeLeaseDeletedCounter.Inc() + NodeLeaseDeletedCounter.WithLabelValues().Inc() } return reconcile.Result{}, client.IgnoreNotFound(err) diff --git a/pkg/controllers/leasegarbagecollection/metrics.go b/pkg/controllers/leasegarbagecollection/metrics.go index b6b0af8307..2a0ce4e832 100644 --- a/pkg/controllers/leasegarbagecollection/metrics.go +++ b/pkg/controllers/leasegarbagecollection/metrics.go @@ -24,13 +24,14 @@ import ( ) var ( - NodeLeaseDeletedCounter = prometheus.NewCounter( + NodeLeaseDeletedCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "karpenter", Subsystem: metrics.NodeSubsystem, Name: "leases_deleted", Help: "Number of deleted leaked leases.", }, + []string{}, ) ) diff --git a/pkg/controllers/leasegarbagecollection/suite_test.go b/pkg/controllers/leasegarbagecollection/suite_test.go index d78790be28..444aa85cde 100644 --- a/pkg/controllers/leasegarbagecollection/suite_test.go +++ b/pkg/controllers/leasegarbagecollection/suite_test.go @@ -21,12 +21,11 @@ import ( "testing" "time" + "github.com/samber/lo" coordinationsv1 "k8s.io/api/coordination/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/samber/lo" - "sigs.k8s.io/karpenter/pkg/apis" "sigs.k8s.io/karpenter/pkg/controllers/leasegarbagecollection" "sigs.k8s.io/karpenter/pkg/operator/controller" @@ -98,6 +97,10 @@ var _ = Describe("GarbageCollection", func() { }, } }) + AfterEach(func() { + // Reset the metrics collectors + leasegarbagecollection.NodeLeaseDeletedCounter.Reset() + }) Context("Metrics", func() { It("should fire the leaseDeletedCounter metric when deleting leases", func() { ExpectApplied(ctx, env.Client, badLease) diff --git a/pkg/controllers/nodeclaim/disruption/suite_test.go b/pkg/controllers/nodeclaim/disruption/suite_test.go index 68fc4fcd55..ba094cc5ec 100644 --- a/pkg/controllers/nodeclaim/disruption/suite_test.go +++ b/pkg/controllers/nodeclaim/disruption/suite_test.go @@ -76,10 +76,10 @@ var _ = AfterSuite(func() { var _ = BeforeEach(func() { ctx = options.ToContext(ctx, test.Options(test.OptionsFields{FeatureGates: test.FeatureGates{Drift: lo.ToPtr(true)}})) + fakeClock.SetTime(time.Now()) }) var _ = AfterEach(func() { - fakeClock.SetTime(time.Now()) cp.Reset() cluster.Reset() ExpectCleanedUp(ctx, env.Client) diff --git a/pkg/operator/options/suite_test.go b/pkg/operator/options/suite_test.go index 93b7dd7391..906e1677eb 100644 --- a/pkg/operator/options/suite_test.go +++ b/pkg/operator/options/suite_test.go @@ -43,7 +43,6 @@ func TestOptions(t *testing.T) { } var _ = Describe("Options", func() { - var envState map[string]string var environmentVariables = []string{ "KARPENTER_SERVICE", "DISABLE_WEBHOOK", @@ -51,6 +50,7 @@ var _ = Describe("Options", func() { "METRICS_PORT", "WEBHOOK_METRICS_PORT", "HEALTH_PROBE_PORT", + "KUBE_CLIENT_QPS", "KUBE_CLIENT_BURST", "ENABLE_PROFILING", "LEADER_ELECT", @@ -62,15 +62,6 @@ var _ = Describe("Options", func() { } BeforeEach(func() { - envState = map[string]string{} - for _, ev := range environmentVariables { - val, ok := os.LookupEnv(ev) - if ok { - envState[ev] = val - } - os.Unsetenv(ev) - } - fs = &options.FlagSet{ FlagSet: flag.NewFlagSet("karpenter", flag.ContinueOnError), } @@ -80,10 +71,7 @@ var _ = Describe("Options", func() { AfterEach(func() { for _, ev := range environmentVariables { - os.Unsetenv(ev) - } - for ev, val := range envState { - os.Setenv(ev, val) + Expect(os.Unsetenv(ev)).To(Succeed()) } })