Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Drop logger name injection and add consistent formatting for K8s objects #6255

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
k8s.io/apiextensions-apiserver v0.30.1
k8s.io/apimachinery v0.30.1
k8s.io/client-go v0.30.1
k8s.io/klog/v2 v2.120.1
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
knative.dev/pkg v0.0.0-20231010144348-ca8c009405dd
sigs.k8s.io/controller-runtime v0.18.2
Expand Down Expand Up @@ -111,7 +112,6 @@ require (
k8s.io/cloud-provider v0.30.1 // indirect
k8s.io/component-base v0.30.1 // indirect
k8s.io/csi-translation-lib v0.30.1 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
Expand Down
5 changes: 3 additions & 2 deletions pkg/controllers/interruption/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.uber.org/multierr"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2"
"k8s.io/utils/clock"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -179,9 +180,9 @@ func (c *Controller) deleteMessage(ctx context.Context, msg *sqsapi.Message) err
// handleNodeClaim retrieves the action for the message and then performs the appropriate action against the node
func (c *Controller) handleNodeClaim(ctx context.Context, msg messages.Message, nodeClaim *v1beta1.NodeClaim, node *v1.Node) error {
action := actionForMessage(msg)
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("nodeclaim", nodeClaim.Name, "action", string(action)))
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("NodeClaim", klog.KRef("", nodeClaim.Name), "action", string(action)))
if node != nil {
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("node", node.Name))
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KRef("", node.Name)))
}

// Record metric and event for this action
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/nodeclaim/garbagecollection/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -98,7 +99,7 @@ func (c *Controller) garbageCollect(ctx context.Context, nodeClaim *v1beta1.Node
if err := c.kubeClient.Delete(ctx, &node); err != nil {
return client.IgnoreNotFound(err)
}
log.FromContext(ctx).WithValues("node", node.Name).V(1).Info("garbage collected node")
log.FromContext(ctx).WithValues("Node", klog.KRef("", node.Name)).V(1).Info("garbage collected node")
}
return nil
}
Expand Down
1 change: 0 additions & 1 deletion pkg/controllers/nodeclaim/tagging/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func NewController(kubeClient client.Client, instanceProvider instance.Provider)
}

func (c *Controller) Reconcile(ctx context.Context, nodeClaim *corev1beta1.NodeClaim) (reconcile.Result, error) {
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithName("nodeclaim.tagging").WithValues("nodeclaim", nodeClaim.Name))
ctx = injection.WithControllerName(ctx, "nodeclaim.tagging")

stored := nodeClaim.DeepCopy()
Expand Down
2 changes: 0 additions & 2 deletions pkg/controllers/nodeclass/hash/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/karpenter/pkg/operator/injection"
Expand All @@ -45,7 +44,6 @@ func NewController(kubeClient client.Client) *Controller {
}

func (c *Controller) Reconcile(ctx context.Context, nodeClass *v1beta1.EC2NodeClass) (reconcile.Result, error) {
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithName("nodeclass.hash").WithValues("ec2nodeclass", nodeClass.Name))
ctx = injection.WithControllerName(ctx, "nodeclass.hash")

stored := nodeClass.DeepCopy()
Expand Down
2 changes: 0 additions & 2 deletions pkg/controllers/nodeclass/status/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/karpenter/pkg/operator/injection"
Expand Down Expand Up @@ -68,7 +67,6 @@ func NewController(kubeClient client.Client, subnetProvider subnet.Provider, sec
}

func (c *Controller) Reconcile(ctx context.Context, nodeClass *v1beta1.EC2NodeClass) (reconcile.Result, error) {
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithName("nodeclass.status").WithValues("ec2nodeclass", nodeClass.Name))
ctx = injection.WithControllerName(ctx, "nodeclass.status")

if !controllerutil.ContainsFinalizer(nodeClass, v1beta1.TerminationFinalizer) {
Expand Down
2 changes: 0 additions & 2 deletions pkg/controllers/nodeclass/termination/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"time"

"k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/karpenter/pkg/operator/injection"

"github.com/aws/karpenter-provider-aws/pkg/providers/launchtemplate"
Expand Down Expand Up @@ -66,7 +65,6 @@ func NewController(kubeClient client.Client, recorder events.Recorder,
}

func (c *Controller) Reconcile(ctx context.Context, nodeClass *v1beta1.EC2NodeClass) (reconcile.Result, error) {
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithName("nodeclass.termination").WithValues("ec2nodeclass", nodeClass.Name))
ctx = injection.WithControllerName(ctx, "nodeclass.termination")

if !nodeClass.GetDeletionTimestamp().IsZero() {
Expand Down
1 change: 1 addition & 0 deletions website/content/en/preview/upgrading/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ WHEN CREATING A NEW SECTION OF THE UPGRADE GUIDANCE FOR NEWER VERSIONS, ENSURE T

### Upgrading to `0.37.0`+

* Karpenter no longer updates the logger name when creating controller loggers. We now adhere to the controller-runtime standard, where the logger name will be set as `"logger": "controller"` always and the controller name will be stored in the structured value `"controller"`
* Karpenter updated the NodeClass controller naming in the following way: `nodeclass` -> `nodeclass.status`, `nodeclass.hash`, `nodeclass.termination`
* Karpenter's NodeClaim status conditions no longer include the `severity` field

Expand Down
Loading