Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storagenode: add run-mode flag to version checker chore
This gives options to either disable the version checker in spc air-gapped environments or set it to run once (especially for docker nodes that have the updater binary already running periodically to check for new versions). It is set to run periodically by default. Issue: #6486 Change-Id: I40fa392309b9a36cd589e839298e2351d6814d9e
- Loading branch information
Showing
4 changed files
with
139 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (C) 2024 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package version | ||
|
||
import ( | ||
"github.com/zeebo/errs" | ||
|
||
"storj.io/storj/private/version/checker" | ||
) | ||
|
||
// Config is the config for the Storagenode Version Checker. | ||
type Config struct { | ||
checker.Config | ||
|
||
RunMode Mode `help:"Define the run mode for the version checker. Options (once,periodic,disable)" default:"periodic"` | ||
} | ||
|
||
// Mode is the mode to run the version checker in. | ||
type Mode string | ||
|
||
const ( | ||
checkerModeOnce Mode = "once" // run the version checker once | ||
checkerModePeriodic Mode = "periodic" // run the version checker periodically | ||
checkerModeDisable Mode = "disable" // disable the version checker | ||
) | ||
|
||
// String implements pflag.Value. | ||
func (m *Mode) String() string { | ||
return string(*m) | ||
} | ||
|
||
// Set implements pflag.Value. | ||
func (m *Mode) Set(s string) error { | ||
if s == "" { | ||
return errs.New("checker mode cannot be empty") | ||
} | ||
|
||
mode, err := ParseCheckerMode(s) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
*m = mode | ||
return nil | ||
} | ||
|
||
// Type implements pflag.Value. | ||
func (m *Mode) Type() string { | ||
return "run-mode" | ||
} | ||
|
||
// Disabled returns true if the checker is disabled. | ||
func (m *Mode) Disabled() bool { | ||
return *m == checkerModeDisable | ||
} | ||
|
||
// Periodic returns true if the checker is periodic. | ||
func (m *Mode) Periodic() bool { | ||
return *m == checkerModePeriodic | ||
} | ||
|
||
// Once returns true if the checker is once. | ||
func (m *Mode) Once() bool { | ||
return *m == checkerModeOnce | ||
} | ||
|
||
// ParseCheckerMode parses the string representation of the CheckerMode. | ||
func ParseCheckerMode(s string) (Mode, error) { | ||
switch Mode(s) { | ||
case checkerModeOnce, checkerModePeriodic, checkerModeDisable: | ||
return Mode(s), nil | ||
default: | ||
return "", errs.New("invalid checker run mode %q", s) | ||
} | ||
} |