Skip to content

Commit

Permalink
Remove unused args and method
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Sluiter <[email protected]>
  • Loading branch information
slintes committed Jun 18, 2024
1 parent 5cccd20 commit 6b2e057
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion controllers/selfnoderemediation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func (r *SelfNodeRemediationReconciler) setTimeAssumedRebooted(ctx context.Conte
return nil
}
// get reboot duration
rebootDuration, err := r.RebootDurationCalculator.GetRebootDuration(r.Client, ctx, node)
rebootDuration, err := r.RebootDurationCalculator.GetRebootDuration(ctx, node)
if err != nil {
r.logger.Error(err, "failed to get assumed reboot duration")
return err
Expand Down
2 changes: 1 addition & 1 deletion controllers/tests/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var _ reboot.Calculator = &MockRebootDurationCalculator{}

type MockRebootDurationCalculator struct{}

func (m MockRebootDurationCalculator) GetRebootDuration(_ client.Client, _ context.Context, _ *corev1.Node) (time.Duration, error) {
func (m MockRebootDurationCalculator) GetRebootDuration(_ context.Context, _ *corev1.Node) (time.Duration, error) {
return CalculatedRebootDuration, nil
}

Expand Down
18 changes: 6 additions & 12 deletions pkg/reboot/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const (
type Calculator interface {
// GetRebootDuration returns the safe time to assume node was already rebooted.
// Can be either the specified SafeTimeToAssumeNodeRebootedSeconds or the calculated minimum reboot duration.
// Note that this time must include the time for a unhealthy node without api-server access to reach the conclusion that it's unhealthy.
// Note that this time must include the time for an unhealthy node without api-server access to reach the conclusion that it's unhealthy.
// This should be at least worst-case time to reach a conclusion from the other peers * request context timeout + watchdog interval + maxFailuresThreshold * reconcileInterval + padding
GetRebootDuration(k8sClient client.Client, ctx context.Context, node *v1.Node) (time.Duration, error)
GetRebootDuration(ctx context.Context, node *v1.Node) (time.Duration, error)
// SetConfig sets the SelfNodeRemediationConfig to be used for calculating the minimum reboot duration
SetConfig(config *v1alpha1.SelfNodeRemediationConfig)
}
Expand All @@ -54,7 +54,7 @@ func (r *calculator) SetConfig(config *v1alpha1.SelfNodeRemediationConfig) {
}

// TODO add unit test!
func (r *calculator) GetRebootDuration(k8sClient client.Client, ctx context.Context, node *v1.Node) (time.Duration, error) {
func (r *calculator) GetRebootDuration(ctx context.Context, node *v1.Node) (time.Duration, error) {

if r.snrConfig == nil {
return 0, errors.New("SelfNodeRemediationConfig not set yet, can't calculate minimum reboot duration")
Expand All @@ -67,7 +67,7 @@ func (r *calculator) GetRebootDuration(k8sClient client.Client, ctx context.Cont
r.log.Error(err, "failed to get watchdog timeout from node annotations, will use the default timeout", "node", node.Name, "default timeout in seconds", defaultWatchdogTimeout.Seconds())
watchdogTimeout = defaultWatchdogTimeout
}
minimumCalculatedRebootDuration, err := r.calculateMinimumRebootDuration(k8sClient, ctx, watchdogTimeout)
minimumCalculatedRebootDuration, err := r.calculateMinimumRebootDuration(ctx, watchdogTimeout)
if err != nil {
return 0, errors.Wrap(err, "failed to calculate minimum reboot duration")
}
Expand All @@ -92,7 +92,7 @@ func (r *calculator) GetRebootDuration(k8sClient client.Client, ctx context.Cont
return specRebootDuration, nil
}

func (r *calculator) calculateMinimumRebootDuration(k8sClient client.Client, ctx context.Context, watchdogTimeout time.Duration) (time.Duration, error) {
func (r *calculator) calculateMinimumRebootDuration(ctx context.Context, watchdogTimeout time.Duration) (time.Duration, error) {

spec := r.snrConfig.Spec

Expand All @@ -107,7 +107,7 @@ func (r *calculator) calculateMinimumRebootDuration(k8sClient client.Client, ctx
minTime += MaxTimeForNoPeersResponse

// 2. plus time for asking peers (10% batches + 1st smaller batch)
numBatches, err := r.calcNumOfBatches(k8sClient, ctx)
numBatches, err := r.calcNumOfBatches(r.k8sClient, ctx)
if err != nil {
return 0, errors.Wrap(err, "failed to calculate number of batches")
}
Expand Down Expand Up @@ -150,9 +150,3 @@ func (r *calculator) calcNumOfBatches(k8sClient client.Client, ctx context.Conte
}
return numberOfBatches, nil
}

func (r *calculator) getConfig(k8sClient client.Client, ctx context.Context, namespace string) (*v1alpha1.SelfNodeRemediationConfig, error) {
config := &v1alpha1.SelfNodeRemediationConfig{}
err := k8sClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: v1alpha1.ConfigCRName}, config)
return config, err
}

0 comments on commit 6b2e057

Please sign in to comment.