From b75e37e9772256d827421057526accce7987eb38 Mon Sep 17 00:00:00 2001 From: Jonathan Innis Date: Fri, 8 Dec 2023 09:21:16 -0800 Subject: [PATCH] chore: Move `build_info` metric to `kubernetes-sigs` and bump (#5281) --- go.mod | 4 ++-- go.sum | 4 ++-- pkg/apis/crds/karpenter.sh_nodepools.yaml | 24 +++++++++++------------ pkg/operator/operator.go | 20 ++----------------- pkg/operator/suite_test.go | 10 ---------- 5 files changed, 18 insertions(+), 44 deletions(-) diff --git a/go.mod b/go.mod index 77fbedbaf5cd..313b0567abbb 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pelletier/go-toml/v2 v2.1.0 github.com/prometheus/client_golang v1.17.0 - github.com/prometheus/client_model v0.5.0 github.com/samber/lo v1.39.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.26.0 @@ -28,7 +27,7 @@ require ( k8s.io/utils v0.0.0-20230726121419-3b25d923346b knative.dev/pkg v0.0.0-20231010144348-ca8c009405dd sigs.k8s.io/controller-runtime v0.16.3 - sigs.k8s.io/karpenter v0.33.1-0.20231207192330-58e1d7552081 + sigs.k8s.io/karpenter v0.33.1-0.20231208060535-cc54b340f630 ) require ( @@ -80,6 +79,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect github.com/prometheus/statsd_exporter v0.24.0 // indirect diff --git a/go.sum b/go.sum index ef4ca0d45864..fbde8d5de184 100644 --- a/go.sum +++ b/go.sum @@ -763,8 +763,8 @@ sigs.k8s.io/controller-runtime v0.16.3 h1:2TuvuokmfXvDUamSx1SuAOO3eTyye+47mJCigw sigs.k8s.io/controller-runtime v0.16.3/go.mod h1:j7bialYoSn142nv9sCOJmQgDXQXxnroFU4VnX/brVJ0= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= -sigs.k8s.io/karpenter v0.33.1-0.20231207192330-58e1d7552081 h1:/axynNIcyHkij4uXbyi3EN1ZiPTwJOU0iiCKpss4mso= -sigs.k8s.io/karpenter v0.33.1-0.20231207192330-58e1d7552081/go.mod h1:J/nUafEcmZrz34hS0B8H51hqgoAd5LhGeS63kMauOjs= +sigs.k8s.io/karpenter v0.33.1-0.20231208060535-cc54b340f630 h1:l+zO3G5VV49YnSiX5RPSVGzWiNpidD1jiXz9stgcEhU= +sigs.k8s.io/karpenter v0.33.1-0.20231208060535-cc54b340f630/go.mod h1:J/nUafEcmZrz34hS0B8H51hqgoAd5LhGeS63kMauOjs= sigs.k8s.io/structured-merge-diff/v4 v4.3.0 h1:UZbZAZfX0wV2zr7YZorDz6GXROfDFj6LvqCRm4VUVKk= sigs.k8s.io/structured-merge-diff/v4 v4.3.0/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= diff --git a/pkg/apis/crds/karpenter.sh_nodepools.yaml b/pkg/apis/crds/karpenter.sh_nodepools.yaml index 64249994ab7a..4fd3720548f2 100644 --- a/pkg/apis/crds/karpenter.sh_nodepools.yaml +++ b/pkg/apis/crds/karpenter.sh_nodepools.yaml @@ -48,32 +48,32 @@ spec: properties: budgets: default: - - maxUnavailable: 10% - description: Budgets is a list of Budgets. If there are multiple active budgets, Karpenter uses the most restrictive maxUnavailable. If left undefined, this will default to one budget with a maxUnavailable to 10%. + - nodes: 10% + description: Budgets is a list of Budgets. If there are multiple active budgets, Karpenter uses the most restrictive value. If left undefined, this will default to one budget with a value to 10%. items: description: Budget defines when Karpenter will restrict the number of Node Claims that can be terminating simultaneously. properties: - crontab: - description: Crontab specifies when a budget begins being active, using the upstream cronjob syntax. If omitted, the budget is always active. Currently timezones are not supported. This is required if Duration is set. - pattern: ^(@(annually|yearly|monthly|weekly|daily|midnight|hourly))|((.+)\s(.+)\s(.+)\s(.+)\s(.+))$ - type: string duration: - description: Duration determines how long a Budget is active since each Crontab hit. Only minutes and hours are accepted, as cron does not work in seconds. If omitted, the budget is always active. This is required if Crontab is set. This regex has an optional 0s at the end since the duration.String() always adds a 0s at the end. + description: Duration determines how long a Budget is active since each Schedule hit. Only minutes and hours are accepted, as cron does not work in seconds. If omitted, the budget is always active. This is required if Schedule is set. This regex has an optional 0s at the end since the duration.String() always adds a 0s at the end. pattern: ^([0-9]+(m|h)+(0s)?)$ type: string - maxUnavailable: + nodes: default: 10% - description: 'MaxUnavailable dictates how many NodeClaims owned by this NodePool can be terminating at once. It must be set. This only considers NodeClaims with the karpenter.sh/disruption taint. We can''t use an intstr.IntOrString since kubebuilder doesn''t support pattern checking for int values for IntOrString values. Ref: https://github.com/kubernetes-sigs/controller-tools/blob/55efe4be40394a288216dab63156b0a64fb82929/pkg/crd/markers/validation.go#L379-L388' + description: 'Nodes dictates how many NodeClaims owned by this NodePool can be terminating at once. It must be set. This only considers NodeClaims with the karpenter.sh/disruption taint. We can''t use an intstr.IntOrString since kubebuilder doesn''t support pattern checking for int nodes for IntOrString nodes. Ref: https://github.com/kubernetes-sigs/controller-tools/blob/55efe4be40394a288216dab63156b0a64fb82929/pkg/crd/markers/validation.go#L379-L388' pattern: ^((100|[0-9]{1,2})%|[0-9]+)$ type: string + schedule: + description: Schedule specifies when a budget begins being active, using the upstream cronjob syntax. If omitted, the budget is always active. Currently timezones are not supported. This is required if Duration is set. + pattern: ^(@(annually|yearly|monthly|weekly|daily|midnight|hourly))|((.+)\s(.+)\s(.+)\s(.+)\s(.+))$ + type: string required: - - maxUnavailable + - nodes type: object maxItems: 50 type: array x-kubernetes-validations: - - message: '''crontab'' must be set with ''duration''' - rule: '!self.all(x, (has(x.crontab) && !has(x.duration)) || (!has(x.crontab) && has(x.duration)))' + - message: '''schedule'' must be set with ''duration''' + rule: '!self.all(x, (has(x.schedule) && !has(x.duration)) || (!has(x.schedule) && has(x.duration)))' consolidateAfter: description: ConsolidateAfter is the duration the controller will wait before attempting to terminate nodes that are underutilized. Refer to ConsolidationPolicy for how underutilization is considered. pattern: ^(([0-9]+(s|m|h))+)|(Never)$ diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index bc2bdfd3b329..33d6d4528c84 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "net" - "runtime" "time" "github.com/aws/aws-sdk-go/aws" @@ -38,22 +37,17 @@ import ( "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/ssm" "github.com/patrickmn/go-cache" - "github.com/prometheus/client_golang/prometheus" - corev1 "k8s.io/api/core/v1" - "sigs.k8s.io/controller-runtime/pkg/client" - crmetrics "sigs.k8s.io/controller-runtime/pkg/metrics" - "github.com/samber/lo" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/transport" - "knative.dev/pkg/changeset" "knative.dev/pkg/logging" "knative.dev/pkg/ptr" + "sigs.k8s.io/controller-runtime/pkg/client" corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1" - "sigs.k8s.io/karpenter/pkg/metrics" "sigs.k8s.io/karpenter/pkg/operator" "sigs.k8s.io/karpenter/pkg/operator/scheme" @@ -71,19 +65,9 @@ import ( "github.com/aws/karpenter-provider-aws/pkg/providers/version" ) -var BuildInfo = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: metrics.Namespace, - Name: "build_info", - Help: "A metric with a constant '1' value labeled by version from which karpenter was built.", - }, - []string{"version", "goversion", "commit"}) - func init() { lo.Must0(apis.AddToScheme(scheme.Scheme)) corev1beta1.NormalizedLabels = lo.Assign(corev1beta1.NormalizedLabels, map[string]string{"topology.ebs.csi.aws.com/zone": corev1.LabelTopologyZone}) - crmetrics.Registry.MustRegister(BuildInfo) - BuildInfo.WithLabelValues(operator.Version, runtime.Version(), changeset.Get()).Set(1) } // Operator is injected into the AWS CloudProvider's factories diff --git a/pkg/operator/suite_test.go b/pkg/operator/suite_test.go index 899bf6bd70b0..f725b2f23652 100644 --- a/pkg/operator/suite_test.go +++ b/pkg/operator/suite_test.go @@ -22,7 +22,6 @@ import ( "github.com/aws/aws-sdk-go/service/eks" "github.com/samber/lo" - prometheusmodel "github.com/prometheus/client_model/go" "sigs.k8s.io/karpenter/pkg/operator/scheme" coretest "sigs.k8s.io/karpenter/pkg/test" @@ -103,13 +102,4 @@ var _ = Describe("Operator", func() { _, err := awscontext.ResolveClusterEndpoint(ctx, fakeEKSAPI) Expect(err).To(HaveOccurred()) }) - It("should fire a metric with the build_info", func() { - m, found := FindMetricWithLabelValues("karpenter_build_info", map[string]string{}) - Expect(found).To(BeTrue()) - - for _, label := range []string{"version", "goversion", "commit"} { - _, ok := lo.Find(m.GetLabel(), func(l *prometheusmodel.LabelPair) bool { return lo.FromPtr(l.Name) == label }) - Expect(ok).To(BeTrue()) - } - }) })