From 2d071de12a62a61e919b7ff7020ab256eb3a4a28 Mon Sep 17 00:00:00 2001 From: Amanuel Engeda Date: Thu, 14 Nov 2024 00:20:06 -0800 Subject: [PATCH] Add events based metrics --- charts/karpenter/templates/clusterrole-core.yaml | 3 +++ go.mod | 4 ++-- go.sum | 8 ++++---- pkg/controllers/controllers.go | 3 +++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/charts/karpenter/templates/clusterrole-core.yaml b/charts/karpenter/templates/clusterrole-core.yaml index eccc9fb7acc6..edb7ca93d54e 100644 --- a/charts/karpenter/templates/clusterrole-core.yaml +++ b/charts/karpenter/templates/clusterrole-core.yaml @@ -44,6 +44,9 @@ rules: - apiGroups: ["policy"] resources: ["poddisruptionbudgets"] verbs: ["get", "list", "watch"] + - apiGroups: [] + resources: ["events"] + verbs: ["get", list, "watch"] # Write - apiGroups: ["karpenter.sh"] resources: ["nodeclaims", "nodeclaims/status"] diff --git a/go.mod b/go.mod index 0e971701773d..4752a4684e9a 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/aws/karpenter-provider-aws/tools/kompat v0.0.0-20240410220356-6b868db24881 github.com/aws/smithy-go v1.22.0 github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647 - github.com/awslabs/operatorpkg v0.0.0-20241112190830-be645b3ea0ad + github.com/awslabs/operatorpkg v0.0.0-20241113231831-a84e1d1b5e47 github.com/go-logr/zapr v1.3.0 github.com/imdario/mergo v0.3.16 github.com/mitchellh/hashstructure/v2 v2.0.2 @@ -108,7 +108,7 @@ require ( golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sys v0.26.0 // indirect golang.org/x/term v0.25.0 // indirect - golang.org/x/text v0.20.0 // indirect + golang.org/x/text v0.19.0 // indirect golang.org/x/time v0.8.0 // indirect golang.org/x/tools v0.26.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 6ca544a38fa8..d8d37ed37424 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647 h1:8yRBVsjGmI7qQsPWtIrbWP+XfwHO9Wq7gdLVzjqiZFs= github.com/awslabs/amazon-eks-ami/nodeadm v0.0.0-20240229193347-cfab22a10647/go.mod h1:9NafTAUHL0FlMeL6Cu5PXnMZ1q/LnC9X2emLXHsVbM8= -github.com/awslabs/operatorpkg v0.0.0-20241112190830-be645b3ea0ad h1:40ZsADFFLtStcyh6MQxTi5sFezU7ghdFR0uaGBsVpB4= -github.com/awslabs/operatorpkg v0.0.0-20241112190830-be645b3ea0ad/go.mod h1:qO5OXavA/cGkE7eTT7ruVD54P5vVpL7HoCEl2bnB/r0= +github.com/awslabs/operatorpkg v0.0.0-20241113231831-a84e1d1b5e47 h1:Dwbau4djwbA8+/H43LI9HH9vTNamDOqncgfYBv/qOic= +github.com/awslabs/operatorpkg v0.0.0-20241113231831-a84e1d1b5e47/go.mod h1:qO5OXavA/cGkE7eTT7ruVD54P5vVpL7HoCEl2bnB/r0= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -266,8 +266,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= -golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/pkg/controllers/controllers.go b/pkg/controllers/controllers.go index 19900d385180..aa3d77d2a2a5 100644 --- a/pkg/controllers/controllers.go +++ b/pkg/controllers/controllers.go @@ -18,6 +18,7 @@ import ( "context" "github.com/awslabs/operatorpkg/controller" + opevents "github.com/awslabs/operatorpkg/events" "github.com/awslabs/operatorpkg/status" "github.com/patrickmn/go-cache" "sigs.k8s.io/controller-runtime/pkg/manager" @@ -37,6 +38,7 @@ import ( servicesqs "github.com/aws/aws-sdk-go-v2/service/sqs" "github.com/samber/lo" + corev1 "k8s.io/api/core/v1" "k8s.io/utils/clock" "sigs.k8s.io/controller-runtime/pkg/client" @@ -86,6 +88,7 @@ func NewControllers( controllersinstancetypecapacity.NewController(kubeClient, instanceTypeProvider), ssminvalidation.NewController(ssmCache, amiProvider), status.NewController[*v1.EC2NodeClass](kubeClient, mgr.GetEventRecorderFor("karpenter")), + opevents.NewController[*corev1.Node](kubeClient, clk), } if options.FromContext(ctx).InterruptionQueue != "" { sqsapi := servicesqs.NewFromConfig(cfg)