From 7a4b3094ffb7a12760dd5603eec46ff868695f32 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Fri, 28 Jun 2024 12:08:42 -0400 Subject: [PATCH] log useful information about the cluster and the instance Signed-off-by: Davanum Srinivas --- pkg/providers/v1/aws.go | 8 ++++++++ pkg/providers/v1/aws_sdk.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pkg/providers/v1/aws.go b/pkg/providers/v1/aws.go index 5122ecd432..d1f9e9b9c9 100644 --- a/pkg/providers/v1/aws.go +++ b/pkg/providers/v1/aws.go @@ -681,6 +681,14 @@ func (c *Cloud) Initialize(clientBuilder cloudprovider.ControllerClientBuilder, c.eventBroadcaster.StartStructuredLogging(0) c.eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: c.kubeClient.CoreV1().Events("")}) c.eventRecorder = c.eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "aws-cloud-provider"}) + + v, err := c.kubeClient.Discovery().ServerVersion() + if err != nil { + klog.Errorf("Error looking up cluster version: %q", err) + } else { + klog.Infof("cluster version: v%s.%s. git version: %s. git tree state: %s. commit: %s. platform: %s", + v.Major, v.Minor, v.GitVersion, v.GitTreeState, v.GitCommit, v.Platform) + } } // Clusters returns the list of clusters. diff --git a/pkg/providers/v1/aws_sdk.go b/pkg/providers/v1/aws_sdk.go index 7776b33320..60a95100b8 100644 --- a/pkg/providers/v1/aws_sdk.go +++ b/pkg/providers/v1/aws_sdk.go @@ -31,6 +31,7 @@ import ( "github.com/aws/aws-sdk-go/service/elbv2" "github.com/aws/aws-sdk-go/service/kms" "k8s.io/client-go/pkg/version" + "k8s.io/klog/v2" "k8s.io/cloud-provider-aws/pkg/providers/v1/config" "k8s.io/cloud-provider-aws/pkg/providers/v1/iface" @@ -208,6 +209,20 @@ func (p *awsSDKProvider) Metadata() (config.EC2Metadata, error) { } client := ec2metadata.New(sess) p.addAPILoggingHandlers(&client.Handlers) + + identity, err := client.GetInstanceIdentityDocument() + if err != nil { + return nil, fmt.Errorf("unable to get instance identity document: %v", err) + } + klog.Info("instance metadata identity", + "region", identity.Region, + "availability-zone", identity.AvailabilityZone, + "instance-type", identity.InstanceType, + "architecture", identity.Architecture, + "instance-id", identity.InstanceID, + "private-ip", identity.PrivateIP, + "account-id", identity.AccountID, + "image-id", identity.ImageID) return client, nil }