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

Remove some context fields from some structs #4746

Merged
merged 1 commit into from
Jul 12, 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 cmd/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (c *command) start(ctx context.Context) error {
ClusterConfig: nodeConfig,
},
Socket: c.K0sVars.StatusSocketPath,
CertManager: worker.NewCertificateManager(ctx, c.K0sVars.KubeletAuthConfigPath),
CertManager: worker.NewCertificateManager(c.K0sVars.KubeletAuthConfigPath),
})

if nodeConfig.Spec.Storage.Type == v1beta1.EtcdStorageType && !nodeConfig.Spec.Storage.Etcd.IsExternalClusterUsed() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (c *Command) Start(ctx context.Context) error {
DualStackEnabled: workerConfig.DualStackEnabled,
})

certManager := worker.NewCertificateManager(ctx, kubeletKubeconfigPath)
certManager := worker.NewCertificateManager(kubeletKubeconfigPath)

// if running inside a controller, status component is already running
if !c.SingleNode && !c.EnableWorker {
Expand Down
4 changes: 1 addition & 3 deletions pkg/component/controller/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type Etcd struct {
supervisor supervisor.Supervisor
uid int
gid int
ctx context.Context
}

var _ manager.Component = (*Etcd)(nil)
Expand Down Expand Up @@ -144,7 +143,6 @@ func (e *Etcd) syncEtcdConfig(ctx context.Context, etcdRequest v1beta1.EtcdReque

// Run runs etcd if external cluster is not configured
func (e *Etcd) Start(ctx context.Context) error {
e.ctx = ctx
if e.Config.IsExternalClusterUsed() {
return nil
}
Expand Down Expand Up @@ -325,7 +323,7 @@ func (e *Etcd) setupCerts(ctx context.Context) error {
// Health-check interface
func (e *Etcd) Ready() error {
logrus.WithField("component", "etcd").Debug("checking etcd endpoint for health")
ctx, cancel := context.WithTimeout(e.ctx, 1*time.Second)
ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second)
defer cancel()
err := etcd.CheckEtcdReady(ctx, e.K0sVars.CertRootDir, e.K0sVars.EtcdCertDir, e.Config)
return err
Expand Down
9 changes: 5 additions & 4 deletions pkg/component/controller/kine.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type Kine struct {
supervisor supervisor.Supervisor
uid int
bypassClient *etcd.Client
ctx context.Context
}

var _ manager.Component = (*Kine)(nil)
Expand Down Expand Up @@ -105,7 +104,6 @@ func (k *Kine) Init(_ context.Context) error {
// Run runs kine
func (k *Kine) Start(ctx context.Context) error {
logrus.Info("Starting kine")
k.ctx = ctx

k.supervisor = supervisor.Supervisor{
Name: "kine",
Expand Down Expand Up @@ -137,15 +135,18 @@ const hcKey = "/k0s-health-check"
const hcValue = "value"

func (k *Kine) Ready() error {
ok, err := k.bypassClient.Write(k.ctx, hcKey, hcValue, 64*time.Second)
ctx, cancel := context.WithTimeout(context.TODO(), 1*time.Second)
defer cancel()

ok, err := k.bypassClient.Write(ctx, hcKey, hcValue, 64*time.Second)
if err != nil {
return fmt.Errorf("kine-etcd-health: %w", err)
}
if !ok {
logrus.Warningf("kine-etcd-health: health-check value was not written")
}

v, err := k.bypassClient.Read(k.ctx, hcKey)
v, err := k.bypassClient.Read(ctx, hcKey)
if err != nil {
return fmt.Errorf("kine-etcd-health read: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/component/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Status struct {
}

type certManager interface {
GetRestConfig() (*rest.Config, error)
GetRestConfig(ctx context.Context) (*rest.Config, error)
}

var _ manager.Component = (*Status)(nil)
Expand Down Expand Up @@ -173,7 +173,7 @@ func (sh *statusHandler) buildWorkerSideKubeAPIClient(ctx context.Context) (kube
timeout, cancel := context.WithTimeout(ctx, defaultPollTimeout)
defer cancel()
if err := wait.PollUntilWithContext(timeout, defaultPollDuration, func(ctx context.Context) (done bool, err error) {
if restConfig, err = sh.Status.CertManager.GetRestConfig(); err != nil {
if restConfig, err = sh.Status.CertManager.GetRestConfig(ctx); err != nil {
return false, nil
}
return true, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/worker/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (a *Autopilot) Start(ctx context.Context) error {
// needed by autopilot.
if err := wait.PollUntilWithContext(timeout, defaultPollDuration, func(ctx context.Context) (done bool, err error) {
log.Debugf("Attempting to load autopilot client config")
if restConfig, err = a.CertManager.GetRestConfig(); err != nil {
if restConfig, err = a.CertManager.GetRestConfig(ctx); err != nil {
log.WithError(err).Warnf("Failed to load autopilot client config, retrying in %v", defaultPollDuration)
return false, nil
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/component/worker/certificate_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
var _ certificate.Manager = (*CertificateManager)(nil)

type CertificateManager struct {
ctx context.Context
config *rest.Config
kubeletClientConfigPath string

Expand Down Expand Up @@ -91,7 +90,7 @@ func (c *CertificateManager) Current() *tls.Certificate {
return c.currentCertificate
}

func (c *CertificateManager) GetRestConfig() (*rest.Config, error) {
func (c *CertificateManager) GetRestConfig(ctx context.Context) (*rest.Config, error) {
restConfig, err := clientcmd.BuildConfigFromFlags("", c.kubeletClientConfigPath)
if err != nil {
return nil, err
Expand All @@ -101,7 +100,7 @@ func (c *CertificateManager) GetRestConfig() (*rest.Config, error) {
return nil, err
}
transportConfig := rest.AnonymousClientConfig(restConfig)
if _, err := k8skubeletcert.UpdateTransport(c.ctx.Done(), transportConfig, c, 0); err != nil {
if _, err := k8skubeletcert.UpdateTransport(ctx.Done(), transportConfig, c, 0); err != nil {
return nil, err
}

Expand All @@ -114,9 +113,8 @@ func (c *CertificateManager) Start() {}
func (c *CertificateManager) Stop() {}
func (c *CertificateManager) ServerHealthy() bool { return true }

func NewCertificateManager(ctx context.Context, kubeletClientConfigPath string) *CertificateManager {
func NewCertificateManager(kubeletClientConfigPath string) *CertificateManager {
return &CertificateManager{
ctx: ctx,
kubeletClientConfigPath: kubeletClientConfigPath,
}
}
Loading