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

Add pkg/log package and cleanup logging around the codebase #544

Merged
merged 7 commits into from
Jul 15, 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
9 changes: 9 additions & 0 deletions src/k8s/cmd/k8sd/k8sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package k8sd
import (
cmdutil "github.com/canonical/k8s/cmd/util"
"github.com/canonical/k8s/pkg/k8sd/app"
"github.com/canonical/k8s/pkg/log"
"github.com/spf13/cobra"
)

var rootCmdOpts struct {
logDebug bool
logVerbose bool
logLevel int
stateDir string
pprofAddress string
disableNodeConfigController bool
Expand All @@ -22,6 +24,12 @@ func NewRootCmd(env cmdutil.ExecutionEnvironment) *cobra.Command {
Use: "k8sd",
Short: "Canonical Kubernetes orchestrator and clustering daemon",
Run: func(cmd *cobra.Command, args []string) {
// configure logging
log.Configure(log.Options{
LogLevel: rootCmdOpts.logLevel,
AddDirHeader: true,
})

app, err := app.New(app.Config{
Debug: rootCmdOpts.logDebug,
Verbose: rootCmdOpts.logVerbose,
Expand Down Expand Up @@ -51,6 +59,7 @@ func NewRootCmd(env cmdutil.ExecutionEnvironment) *cobra.Command {
cmd.SetOut(env.Stdout)
cmd.SetErr(env.Stderr)

cmd.PersistentFlags().IntVarP(&rootCmdOpts.logLevel, "log-level", "l", 0, "k8sd log level")
cmd.PersistentFlags().BoolVarP(&rootCmdOpts.logDebug, "debug", "d", false, "Show all debug messages")
cmd.PersistentFlags().BoolVarP(&rootCmdOpts.logVerbose, "verbose", "v", true, "Show all information messages")
cmd.PersistentFlags().StringVar(&rootCmdOpts.stateDir, "state-dir", "", "Directory with the dqlite datastore")
Expand Down
4 changes: 4 additions & 0 deletions src/k8s/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
k8s_apiserver_proxy "github.com/canonical/k8s/cmd/k8s-apiserver-proxy"
"github.com/canonical/k8s/cmd/k8sd"
cmdutil "github.com/canonical/k8s/cmd/util"
"github.com/canonical/k8s/pkg/log"
"github.com/spf13/cobra"
)

Expand All @@ -21,6 +22,9 @@ func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

// logging
ctx = log.NewContext(ctx, log.L())

// ensure hooks from all commands are executed
cobra.EnableTraverseRunHooks = true

Expand Down
8 changes: 4 additions & 4 deletions src/k8s/cmd/util/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"
"io"
"log"

"github.com/canonical/k8s/pkg/log"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -35,7 +35,7 @@ type plainFormatter struct {

func (p plainFormatter) Print(data any) {
if _, err := fmt.Fprint(p.writer, data, "\n"); err != nil {
log.Printf("Failed to format output: %v", err)
log.L().WithCallDepth(1).Error(err, "Failed to format output")
}
}

Expand All @@ -47,7 +47,7 @@ func (j jsonFormatter) Print(data any) {
encoder := json.NewEncoder(j.writer)
encoder.SetIndent("", " ")
if err := encoder.Encode(data); err != nil {
log.Printf("Failed to format JSON output: %v", err)
log.L().WithCallDepth(1).Error(err, "Failed to format JSON output")
}
}

Expand All @@ -57,6 +57,6 @@ type yamlFormatter struct {

func (y yamlFormatter) Print(data any) {
if err := yaml.NewEncoder(y.writer).Encode(data); err != nil {
log.Printf("Failed to format YAML output: %v", err)
log.L().WithCallDepth(1).Error(err, "Failed to format YAML output")
}
}
21 changes: 11 additions & 10 deletions src/k8s/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ require (
github.com/canonical/go-dqlite v1.21.0
github.com/canonical/lxd v0.0.0-20240403135607-df45915ce961
github.com/canonical/microcluster v0.0.0-20240418162032-e0f837527e02
github.com/go-logr/logr v1.4.1
github.com/mitchellh/mapstructure v1.5.0
github.com/moby/sys/mountinfo v0.7.1
github.com/onsi/gomega v1.30.0
github.com/onsi/gomega v1.32.0
github.com/pelletier/go-toml v1.9.5
github.com/spf13/cobra v1.8.0
golang.org/x/net v0.23.0
golang.org/x/sys v0.19.0
gopkg.in/yaml.v2 v2.4.0
helm.sh/helm/v3 v3.14.2
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/api v0.30.1
k8s.io/apimachinery v0.30.1
k8s.io/cli-runtime v0.29.0
k8s.io/client-go v0.29.0
k8s.io/client-go v0.30.1
k8s.io/klog/v2 v2.120.1
)

require (
Expand Down Expand Up @@ -59,7 +61,6 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
Expand Down Expand Up @@ -112,6 +113,7 @@ require (
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/onsi/ginkgo/v2 v2.17.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
Expand Down Expand Up @@ -154,11 +156,10 @@ require (
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
k8s.io/apiextensions-apiserver v0.29.0 // indirect
k8s.io/apiserver v0.29.0 // indirect
k8s.io/component-base v0.29.0 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/apiextensions-apiserver v0.30.1 // indirect
k8s.io/apiserver v0.30.1 // indirect
k8s.io/component-base v0.30.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/kubectl v0.29.0 // indirect
k8s.io/utils v0.0.0-20240310230437-4693a0247e57 // indirect
oras.land/oras-go v1.2.4 // indirect
Expand Down
41 changes: 20 additions & 21 deletions src/k8s/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
Expand Down Expand Up @@ -477,10 +476,10 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8=
github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
github.com/onsi/gomega v1.32.0 h1:JRYU78fJ1LPxlckP6Txi/EYqJvjtMrDC04/MM5XRHPk=
github.com/onsi/gomega v1.32.0/go.mod h1:a4x4gW6Pz2yK1MAmvluYme5lvYTn61afQ2ETw/8n4Lg=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand Down Expand Up @@ -1036,24 +1035,24 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.29.0 h1:NiCdQMY1QOp1H8lfRyeEf8eOwV6+0xA6XEE44ohDX2A=
k8s.io/api v0.29.0/go.mod h1:sdVmXoz2Bo/cb77Pxi71IPTSErEW32xa4aXwKH7gfBA=
k8s.io/apiextensions-apiserver v0.29.0 h1:0VuspFG7Hj+SxyF/Z/2T0uFbI5gb5LRgEyUVE3Q4lV0=
k8s.io/apiextensions-apiserver v0.29.0/go.mod h1:TKmpy3bTS0mr9pylH0nOt/QzQRrW7/h7yLdRForMZwc=
k8s.io/apimachinery v0.29.0 h1:+ACVktwyicPz0oc6MTMLwa2Pw3ouLAfAon1wPLtG48o=
k8s.io/apimachinery v0.29.0/go.mod h1:eVBxQ/cwiJxH58eK/jd/vAk4mrxmVlnpBH5J2GbMeis=
k8s.io/apiserver v0.29.0 h1:Y1xEMjJkP+BIi0GSEv1BBrf1jLU9UPfAnnGGbbDdp7o=
k8s.io/apiserver v0.29.0/go.mod h1:31n78PsRKPmfpee7/l9NYEv67u6hOL6AfcE761HapDM=
k8s.io/api v0.30.1 h1:kCm/6mADMdbAxmIh0LBjS54nQBE+U4KmbCfIkF5CpJY=
k8s.io/api v0.30.1/go.mod h1:ddbN2C0+0DIiPntan/bye3SW3PdwLa11/0yqwvuRrJM=
k8s.io/apiextensions-apiserver v0.30.1 h1:4fAJZ9985BmpJG6PkoxVRpXv9vmPUOVzl614xarePws=
k8s.io/apiextensions-apiserver v0.30.1/go.mod h1:R4GuSrlhgq43oRY9sF2IToFh7PVlF1JjfWdoG3pixk4=
k8s.io/apimachinery v0.30.1 h1:ZQStsEfo4n65yAdlGTfP/uSHMQSoYzU/oeEbkmF7P2U=
k8s.io/apimachinery v0.30.1/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
k8s.io/apiserver v0.30.1 h1:BEWEe8bzS12nMtDKXzCF5Q5ovp6LjjYkSp8qOPk8LZ8=
k8s.io/apiserver v0.30.1/go.mod h1:i87ZnQ+/PGAmSbD/iEKM68bm1D5reX8fO4Ito4B01mo=
k8s.io/cli-runtime v0.29.0 h1:q2kC3cex4rOBLfPOnMSzV2BIrrQlx97gxHJs21KxKS4=
k8s.io/cli-runtime v0.29.0/go.mod h1:VKudXp3X7wR45L+nER85YUzOQIru28HQpXr0mTdeCrk=
k8s.io/client-go v0.29.0 h1:KmlDtFcrdUzOYrBhXHgKw5ycWzc3ryPX5mQe0SkG3y8=
k8s.io/client-go v0.29.0/go.mod h1:yLkXH4HKMAywcrD82KMSmfYg2DlE8mepPR4JGSo5n38=
k8s.io/component-base v0.29.0 h1:T7rjd5wvLnPBV1vC4zWd/iWRbV8Mdxs+nGaoaFzGw3s=
k8s.io/component-base v0.29.0/go.mod h1:sADonFTQ9Zc9yFLghpDpmNXEdHyQmFIGbiuZbqAXQ1M=
k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0=
k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo=
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780=
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
k8s.io/client-go v0.30.1 h1:uC/Ir6A3R46wdkgCV3vbLyNOYyCJ8oZnjtJGKfytl/Q=
k8s.io/client-go v0.30.1/go.mod h1:wrAqLNs2trwiCH/wxxmT/x3hKVH9PuV0GGW0oDoHVqc=
k8s.io/component-base v0.30.1 h1:bvAtlPh1UrdaZL20D9+sWxsJljMi0QZ3Lmw+kmZAaxQ=
k8s.io/component-base v0.30.1/go.mod h1:e/X9kDiOebwlI41AvBHuWdqFriSRrX50CdwA9TFaHLI=
k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw=
k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
k8s.io/kubectl v0.29.0 h1:Oqi48gXjikDhrBF67AYuZRTcJV4lg2l42GmvsP7FmYI=
k8s.io/kubectl v0.29.0/go.mod h1:0jMjGWIcMIQzmUaMgAzhSELv5WtHo2a8pq67DtviAJs=
k8s.io/utils v0.0.0-20240310230437-4693a0247e57 h1:gbqbevonBh57eILzModw6mrkbwM0gQBEuevE/AaBsHY=
Expand Down
11 changes: 7 additions & 4 deletions src/k8s/pkg/client/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"path"

"github.com/canonical/k8s/pkg/log"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/storage/driver"
Expand All @@ -31,18 +31,21 @@ func NewClient(manifestsBaseDir string, restClientGetter func(string) genericcli
}
}

func (h *client) newActionConfiguration(namespace string) (*action.Configuration, error) {
func (h *client) newActionConfiguration(ctx context.Context, namespace string) (*action.Configuration, error) {
actionConfig := new(action.Configuration)

if err := actionConfig.Init(h.restClientGetter(namespace), namespace, "", log.Printf); err != nil {
log := log.FromContext(ctx).WithName("helm")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

if err := actionConfig.Init(h.restClientGetter(namespace), namespace, "", func(format string, v ...interface{}) {
log.Info(fmt.Sprintf(format, v...))
}); err != nil {
return nil, fmt.Errorf("failed to initialize: %w", err)
}
return actionConfig, nil
}

// Apply implements the Client interface.
func (h *client) Apply(ctx context.Context, c InstallableChart, desired State, values map[string]any) (bool, error) {
cfg, err := h.newActionConfiguration(c.Namespace)
cfg, err := h.newActionConfiguration(ctx, c.Namespace)
if err != nil {
return false, fmt.Errorf("failed to create action configuration: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions src/k8s/pkg/client/kubernetes/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package kubernetes
import (
"context"
"fmt"
"log"

"github.com/canonical/k8s/pkg/log"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
applyv1 "k8s.io/client-go/applyconfigurations/core/v1"
)

func (c *Client) WatchConfigMap(ctx context.Context, namespace string, name string, reconcile func(configMap *v1.ConfigMap) error) error {
log := log.FromContext(ctx).WithValues("namespace", namespace, "name", name)
w, err := c.CoreV1().ConfigMaps(namespace).Watch(ctx, metav1.SingleObject(metav1.ObjectMeta{Name: name}))
if err != nil {
return fmt.Errorf("failed to watch configmap, namespace: %s name: %s: %w", namespace, name, err)
return fmt.Errorf("failed to watch configmap namespace=%s name=%s: %w", namespace, name, err)
}
defer w.Stop()
for {
Expand All @@ -30,7 +31,7 @@ func (c *Client) WatchConfigMap(ctx context.Context, namespace string, name stri
}

if err := reconcile(configMap); err != nil {
log.Println(fmt.Errorf("failed to reconcile configmap, namespace: %s name: %s: %w", namespace, name, err))
log.Error(err, "Reconcile ConfigMap failed")
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/k8s/pkg/k8sd/api/cluster_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"database/sql"
"fmt"
"log"
"net/http"

apiv1 "github.com/canonical/k8s/api/v1"
"github.com/canonical/k8s/pkg/log"
"github.com/canonical/k8s/pkg/utils"
"github.com/canonical/k8s/pkg/utils/control"
nodeutil "github.com/canonical/k8s/pkg/utils/node"
Expand All @@ -32,29 +32,32 @@ func (e *Endpoints) postClusterRemove(s *state.State, r *http.Request) response.
defer cancel()
}

log := log.FromContext(s.Context).WithValues("name", req.Name)
bschimke95 marked this conversation as resolved.
Show resolved Hide resolved

isControlPlane, err := nodeutil.IsControlPlaneNode(ctx, s, req.Name)
if err != nil {
return response.InternalError(fmt.Errorf("failed to check if node is control-plane: %w", err))
}
if isControlPlane {
log.Printf("Waiting for node to not be pending")
log.Info("Waiting for node to not be pending")
control.WaitUntilReady(ctx, func() (bool, error) {
var notPending bool
if err := s.Database.Transaction(ctx, func(ctx context.Context, tx *sql.Tx) error {
member, err := cluster.GetInternalClusterMember(ctx, tx, req.Name)
if err != nil {
log.Printf("Failed to get member: %v", err)
log.Error(err, "Failed to get member")
return nil
}
log.Printf("Node %s is %s", member.Name, member.Role)
log.WithValues("role", member.Role).Info("Current node role")
notPending = member.Role != cluster.Pending
return nil
}); err != nil {
log.Printf("Transaction to check cluster member role failed: %v", err)
log.Error(err, "Transaction to check cluster member role failed")
}
return notPending, nil
})
log.Printf("Starting node deletion")

log.Info("Starting node deletion")

// Remove control plane via microcluster API.
// The postRemove hook will take care of cleaning up kubernetes.
Expand Down
20 changes: 6 additions & 14 deletions src/k8s/pkg/k8sd/api/impl/k8sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package impl
import (
"context"
"fmt"
"log"

apiv1 "github.com/canonical/k8s/api/v1"
"github.com/canonical/k8s/pkg/snap"
Expand Down Expand Up @@ -46,22 +45,15 @@ func GetLocalNodeStatus(ctx context.Context, s *state.State, snap snap.Snap) (ap
if err != nil {
return apiv1.NodeStatus{}, fmt.Errorf("failed to check if node is a worker: %w", err)
}

if isWorker {
clusterRole = apiv1.ClusterRoleWorker
} else {
node, err := nodeutil.GetControlPlaneNode(ctx, s, s.Name())
if err != nil {
// The node is likely in a joining or leaving phase where the role is not yet settled.
// Use the unknown role but still log this incident for debugging.
log.Printf("Failed to check if node is control-plane. This is expected if the node is in a joining/leaving phase. %v", err)
clusterRole = apiv1.ClusterRoleUnknown
} else {
if node != nil {
return *node, nil
}
}

} else if node, err := nodeutil.GetControlPlaneNode(ctx, s, s.Name()); err != nil {
clusterRole = apiv1.ClusterRoleUnknown
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the log here no longer necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, removed log lines that did not provide any useful context here and in some other places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bschimke95 is this useful to keep around?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep around the comment on when this might happen. Let's remove the logs though.

} else if node != nil {
return *node, nil
}

return apiv1.NodeStatus{
Name: s.Name(),
Address: s.Address().Hostname(),
Expand Down
Loading
Loading