resolver

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PolicyPathENV = "MAINTENANCE_POLICY_PATH"
)

Variables

View Source
var (
	ErrPolicyNotExists    = errors.New("maintenance policy doesn't exist")
	ErrUnknownOption      = errors.New("unknown option")
	ErrNoWindowInPolicies = errors.New("matched policies did not provide a window")
	ErrNoWindowFound      = errors.New("matches and defaults also failed to provide a window")
	ErrJSONUnmarshal      = errors.New("error during unmarshal")
)
View Source
var (
	ErrNoPolicyPathEnvVar = errors.New("no environment variable set for the maintenance policy path")
	ErrReadingDirectory   = errors.New("error while reading the directory")
)

Functions

func GetMaintenancePolicyPool

func GetMaintenancePolicyPool() (map[string]*[]byte, error)

GetMaintenancePolicyPool extracts and returns the maintenance policies we have under the policy directory.

Types

type FallbackDefault

type FallbackDefault bool

If matched policies had no available windows whether to fall back to the default, or bail out with an error.

type FirstMatchOnly

type FirstMatchOnly bool

Whether stop at first matched policy's windows.

type MaintenancePolicyMatch

type MaintenancePolicyMatch struct {
	GlobalAccountID Regexp `json:"globalAccountID,omitempty"` //nolint:tagliatelle,revive //changing that now would break the API
	Plan            Regexp `json:"plan,omitempty"`
	Region          Regexp `json:"region,omitempty"`
	PlatformRegion  Regexp `json:"platformRegion,omitempty"`
}

func (MaintenancePolicyMatch) Match

func (mpm MaintenancePolicyMatch) Match(runtime *Runtime) bool

func (MaintenancePolicyMatch) String

func (mpm MaintenancePolicyMatch) String() string

type MaintenancePolicyRule

type MaintenancePolicyRule struct {
	Match   MaintenancePolicyMatch `json:"match"`
	Windows MaintenanceWindows     `json:"windows"`
}

type MaintenanceWindow

type MaintenanceWindow struct {
	Days  []string   `json:"days"`
	Begin WindowTime `json:"begin"`
	End   WindowTime `json:"end"`
}

If days is empty, then begin and end are ISO8601 strings with exact times, otherwise if days is specified it's a time-only (with timezone).

func (*MaintenanceWindow) NextWindow

func (mw *MaintenanceWindow) NextWindow(opts *resolveOptions) *ResolvedWindow

this has two main modes: whether we have days or not.

type MaintenanceWindowPolicy

type MaintenanceWindowPolicy struct {
	Rules   []MaintenancePolicyRule `json:"rules"`
	Default MaintenanceWindow       `json:"default"`
}

func GetMaintenancePolicy

func GetMaintenancePolicy(pool map[string]*[]byte, name string) (*MaintenanceWindowPolicy, error)

GetMaintenancePolicy gets the maintenance window policy based on the policy name we specify * non-nil error returned if meeting one of below conditions: * - the speficied maintenance policy doesn't exist. * - error during unmarshal the policy data.

func NewMaintenanceWindowPolicyFromJSON

func NewMaintenanceWindowPolicyFromJSON(raw []byte) (MaintenanceWindowPolicy, error)

* This function parse a JSON document from a byte array into a * MaintenanceWindowPolicy structure, and returns it. If any errors * are encountered, the error is returned, and the structured return data * is undefined. * * Once a MaintenanceWindowPolicy is returned its Resolve method can be used to find * A suitable maintenance window.

func (*MaintenanceWindowPolicy) Resolve

func (mwp *MaintenanceWindowPolicy) Resolve(runtime *Runtime, opts ...interface{}) (*ResolvedWindow, error)

* Finds the next applicatable maintenance window for a given runtime on the plan. * * The algorithm can be parameterized using the following typed varargs: * - TimeStamp: A time.Time, to specify the resolving's time instead of now * - OngoingWindow: A boolean, if true then already started windows are returned * if long enough. Defaults to false. * - MinWindowSize: A time.Duration, when OngoingWindow is true, this holds the * minimum size for the windows. Defaults to 1h. * - FirstMatchOnly: A boolean indicating wether or not to stop at the first * matching rule in the ruleset before proceeding to the defaults. * Defaults to true. * - FallbackDefault: A boolean indicating whether or not fall back to the default * rules if no specific matching rules are found. Defaults to true. * * If a match is found then a ResolvedWindow pointer is returned with a nil error. * Otherwise an error is returned and the ResolvedWindow pointer is expected to be * nil.

type MaintenanceWindows

type MaintenanceWindows []MaintenanceWindow

func (*MaintenanceWindows) LookupAvailable

func (mws *MaintenanceWindows) LookupAvailable(opts *resolveOptions) *ResolvedWindow

type MinWindowSize

type MinWindowSize time.Duration

If taking ongoing windows into account, minimum duration.

type OngoingWindow

type OngoingWindow bool

Take ongoing windows into account.

type Regexp

type Regexp struct {
	Str    string
	Regexp *regexp.Regexp
}

func NewRegexp

func NewRegexp(pattern string) Regexp

func (Regexp) IsValid

func (r Regexp) IsValid() bool

func (Regexp) MatchString

func (r Regexp) MatchString(s string) bool

func (Regexp) String

func (r Regexp) String() string

func (*Regexp) UnmarshalJSON

func (r *Regexp) UnmarshalJSON(data []byte) error

type ResolvedWindow

type ResolvedWindow struct {
	Begin time.Time
	End   time.Time
}

func (ResolvedWindow) String

func (rw ResolvedWindow) String() string

type Runtime

type Runtime struct {
	InstanceID             string
	RuntimeID              string
	GlobalAccountID        string
	SubAccountID           string
	ShootName              string
	Plan                   string
	Region                 string
	PlatformRegion         string
	MaintenanceWindowBegin time.Time
	MaintenanceWindowEnd   time.Time
	MaintenanceDays        []string
}

Runtime is the data type which captures the needed runtime specific attributes to perform orchestrations on a given runtime.

type TimeStamp

type TimeStamp time.Time

Specify the time to calculate with.

type WindowTime

type WindowTime time.Time

type alias for (un)marshalling.

func (*WindowTime) T

func (wt *WindowTime) T() time.Time

func (*WindowTime) UnmarshalJSON

func (wt *WindowTime) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL