turndown

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScheduleTurndownSuccess is used as part of the Event 'reason' when a TurndownSchedule
	// resource is successfully scheduled
	ScheduleTurndownSuccess        = "ScheduleTurndownSuccess"
	ScheduleTurndownSuccessMessage = "Successfully scheduled turndown"

	CancelTurndownSuccess        = "CancelTurndownSuccess"
	CancelTurndownSuccessMessage = "Successfully cancelled turndown"

	// ErrAlreadyScheduled is used as part of the Event 'reason' when a TurndownSchedule fails
	// due to an existing turndown schedule.
	ErrAlreadyScheduled = "ErrAlreadyScheduled"

	TurndownScheduleFinalizer = "finalizer.kubecost.com"

	ScheduleStateSuccess   = "ScheduleSuccess"
	ScheduleStateFailed    = "ScheduleFailed"
	ScheduleStateCompleted = "ScheduleCompleted"
)
View Source
const (
	TurndownJobType   = "type"
	TurndownJobRepeat = "repeat"

	TurndownJobTypeScaleDown = "scaledown"
	TurndownJobTypeScaleUp   = "scaleup"
	TurndownJobTypeReset     = "reset"

	TurndownJobRepeatNone   = "none"
	TurndownJobRepeatDaily  = "daily"
	TurndownJobRepeatWeekly = "weekly"
)
View Source
const (
	RFC3339Milli = "2006-01-02T15:04:05.000Z"
)

Variables

View Source
var (
	CancelledErr           = errors.New("Cancelled")
	EnvironmentPrepareErr  = errors.New("EnvironmentPrepare")
	NoSchedulesToCancelErr = errors.New("No Schedules to Cancel")
	CancelWhileRunningErr  = errors.New("Cannot Cancel Turndown while Running")
)
View Source
var (
	KubecostFlattenerOmit = []string{"kube-dns", "kube-dns-autoscaler"}
)

Functions

func WriteSchedule

func WriteSchedule(schedule *Schedule, status *v1alpha1.TurndownScheduleStatus)

func WriteScheduleStatus

func WriteScheduleStatus(status *v1alpha1.TurndownScheduleStatus, schedule *Schedule)

Types

type DataEnvelope

type DataEnvelope struct {
	Code   int         `json:"code"`
	Status string      `json:"status"`
	Data   interface{} `json:"data"`
}

DataEnvelope is a generic wrapper struct for http response data

type DiskScheduleStore

type DiskScheduleStore struct {
	// contains filtered or unexported fields
}

Disk based implementation of persistent schedule storage.

func (*DiskScheduleStore) Clear

func (dss *DiskScheduleStore) Clear()

func (*DiskScheduleStore) Complete

func (dss *DiskScheduleStore) Complete()

func (*DiskScheduleStore) Create

func (dss *DiskScheduleStore) Create(schedule *Schedule) error

func (*DiskScheduleStore) GetSchedule

func (dss *DiskScheduleStore) GetSchedule() (*Schedule, error)

func (*DiskScheduleStore) Update

func (dss *DiskScheduleStore) Update(schedule *Schedule) error

type JobCompleteHandler

type JobCompleteHandler func(id string, scheduled time.Time, metadata map[string]string, err error)

JobCompleteHandler occurs after the job executes passing back the identifier, metadata, and any errors

type JobFunc

type JobFunc func() error

JobFunc definition that runs on a specific schedule

type JobScheduler

type JobScheduler interface {
	Schedule(next time.Time, job JobFunc, metadata map[string]string) (id string, err error)
	ScheduleWithID(id string, next time.Time, jobFunc JobFunc, metadata map[string]string) (string, error)
	Cancel(id string) bool
	NextScheduledTimeFor(id string) (next time.Time, ok bool)
	SetJobCompleteHandler(handler JobCompleteHandler)
	IsRunning(jobID string) bool
}

JobScheduler interface contains

func NewSimpleScheduler

func NewSimpleScheduler() JobScheduler

type KubernetesScheduleStore

type KubernetesScheduleStore struct {
	// contains filtered or unexported fields
}

func (*KubernetesScheduleStore) Clear

func (kss *KubernetesScheduleStore) Clear()

func (*KubernetesScheduleStore) Complete

func (kss *KubernetesScheduleStore) Complete()

func (*KubernetesScheduleStore) Create

func (kss *KubernetesScheduleStore) Create(schedule *Schedule) error

func (*KubernetesScheduleStore) GetSchedule

func (kss *KubernetesScheduleStore) GetSchedule() (*Schedule, error)

func (*KubernetesScheduleStore) Update

func (kss *KubernetesScheduleStore) Update(schedule *Schedule) error

type KubernetesTurndownManager

type KubernetesTurndownManager struct {
	// contains filtered or unexported fields
}

func (*KubernetesTurndownManager) IsRunningOnTurndownNode

func (ktdm *KubernetesTurndownManager) IsRunningOnTurndownNode() (bool, error)

func (*KubernetesTurndownManager) IsScaledDown

func (ktdm *KubernetesTurndownManager) IsScaledDown() bool

func (*KubernetesTurndownManager) PrepareTurndownEnvironment

func (ktdm *KubernetesTurndownManager) PrepareTurndownEnvironment() error

func (*KubernetesTurndownManager) ResetTurndownEnvironment

func (ktdm *KubernetesTurndownManager) ResetTurndownEnvironment() error

func (*KubernetesTurndownManager) ScaleDownCluster

func (ktdm *KubernetesTurndownManager) ScaleDownCluster() error

func (*KubernetesTurndownManager) ScaleUpCluster

func (ktdm *KubernetesTurndownManager) ScaleUpCluster() error

type Schedule

type Schedule struct {
	Current           string            `json:"current"`
	ScaleDownID       string            `json:"scaleDownId"`
	ScaleDownTime     time.Time         `json:"scaleDownTime"`
	ScaleDownMetadata map[string]string `json:"scaleDownMetadata"`
	ScaleUpID         string            `json:"scaleUpID"`
	ScaleUpTime       time.Time         `json:"scaleUpTime"`
	ScaleUpMetadata   map[string]string `json:"scaleUpMetadata"`
}

type ScheduleStore

type ScheduleStore interface {
	GetSchedule() (*Schedule, error)
	Create(schedule *Schedule) error
	Update(schedule *Schedule) error
	Complete()
	Clear()
}

Persistent Schedule Storage interface for storing and retrieving a single stored schedule.

func NewDiskScheduleStore

func NewDiskScheduleStore(file string) ScheduleStore

Creates a new disk schedule storage instance

func NewKubernetesScheduleStore

func NewKubernetesScheduleStore(client clientset.Interface) ScheduleStore

type ScheduleTurndownRequest

type ScheduleTurndownRequest struct {
	Start  time.Time `json:"start"`
	End    time.Time `json:"end"`
	Repeat string    `json:"repeat,omitempty"`
}

ScheduleTurndownRequest is the POST encoding used to

type SimpleJob

type SimpleJob struct {
	// contains filtered or unexported fields
}

type SimpleJobScheduler

type SimpleJobScheduler struct {
	// contains filtered or unexported fields
}

func (*SimpleJobScheduler) Cancel

func (sjs *SimpleJobScheduler) Cancel(id string) bool

func (*SimpleJobScheduler) IsRunning

func (sjs *SimpleJobScheduler) IsRunning(jobID string) bool

func (*SimpleJobScheduler) NextScheduledTimeFor

func (sjs *SimpleJobScheduler) NextScheduledTimeFor(id string) (time.Time, bool)

Looks up and returns the next scheduled time a job will execute.

func (*SimpleJobScheduler) Schedule

func (sjs *SimpleJobScheduler) Schedule(next time.Time, jobFunc JobFunc, metadata map[string]string) (string, error)

func (*SimpleJobScheduler) ScheduleWithID

func (sjs *SimpleJobScheduler) ScheduleWithID(id string, next time.Time, jobFunc JobFunc, metadata map[string]string) (string, error)

func (*SimpleJobScheduler) SetJobCompleteHandler

func (sjs *SimpleJobScheduler) SetJobCompleteHandler(handler JobCompleteHandler)

Sets the job complete handler. If one is already

type TurndownEndpoints

type TurndownEndpoints struct {
	// contains filtered or unexported fields
}

func NewTurndownEndpoints

func NewTurndownEndpoints(
	kubeClient kubernetes.Interface,
	client clientset.Interface,
	scheduler *TurndownScheduler,
	turndown TurndownManager,
	provider provider.TurndownProvider) *TurndownEndpoints

func (*TurndownEndpoints) HandleCancelSchedule

func (te *TurndownEndpoints) HandleCancelSchedule(w http.ResponseWriter, r *http.Request)

func (*TurndownEndpoints) HandleInitEnvironment

func (te *TurndownEndpoints) HandleInitEnvironment(w http.ResponseWriter, r *http.Request)

func (*TurndownEndpoints) HandleStartSchedule

func (te *TurndownEndpoints) HandleStartSchedule(w http.ResponseWriter, r *http.Request)

type TurndownManager

type TurndownManager interface {
	// Whether or not the cluster is scaled down or not
	IsScaledDown() bool

	// Whether or not the current pod is running on the node designated for turndown
	// or not
	IsRunningOnTurndownNode() (bool, error)

	// Prepares the turndown environment by creating or selecting a target host node,
	// applying specific labeling to that host node such that we can run our turndown
	// logic from a "safe-from-turndown" node
	PrepareTurndownEnvironment() error

	// Resets the turndown environment to what it was originally
	ResetTurndownEnvironment() error

	// Scales down the cluster leaving the single small node pool running the scheduled
	// scale up
	ScaleDownCluster() error

	// Scales back up the cluster
	ScaleUpCluster() error
}

TurndownManager is an implementation prototype for an object capable of managing turndown and turnup for a kubernetes cluster

func NewKubernetesTurndownManager

func NewKubernetesTurndownManager(client kubernetes.Interface, provider provider.TurndownProvider, strategy strategy.TurndownStrategy, currentNode string) TurndownManager

type TurndownScheduleResourceController

type TurndownScheduleResourceController struct {
	// contains filtered or unexported fields
}

TurndownScheduleResourceController is the controller implementation for TurndownSchedule, the custom resource definition for turndown.

func NewTurndownScheduleResourceController

func NewTurndownScheduleResourceController(
	kubeclientset kubernetes.Interface,
	clientset clientset.Interface,
	scheduler *TurndownScheduler,
	schedulesInformer informers.TurndownScheduleInformer) *TurndownScheduleResourceController

NewTurndownScheduleResourceController creates a new controller for TurndownSchedule, the custom resource definition for turndown.

func (*TurndownScheduleResourceController) Run

func (c *TurndownScheduleResourceController) Run(threadiness int, stopCh <-chan struct{}) error

Runs the resource controller workqueue processing

type TurndownScheduler

type TurndownScheduler struct {
	// contains filtered or unexported fields
}

func NewTurndownScheduler

func NewTurndownScheduler(manager TurndownManager, store ScheduleStore) *TurndownScheduler

func (*TurndownScheduler) Cancel

func (ts *TurndownScheduler) Cancel(force bool) error

Cancels the turndown from occurring. The force bool should be used only if the job is cancelled by a running child job.

func (*TurndownScheduler) GetSchedule

func (ts *TurndownScheduler) GetSchedule() *Schedule

func (*TurndownScheduler) ScheduleTurndown

func (ts *TurndownScheduler) ScheduleTurndown(from time.Time, to time.Time, repeatType string) (*Schedule, error)

Schedules Turndown for the current kubernetes cluster

func (*TurndownScheduler) ScheduleTurndownBySchedule

func (ts *TurndownScheduler) ScheduleTurndownBySchedule(schedule *Schedule) error

Turndown via a Schedule instance. Assumes prior validation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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