scanner

package
v0.0.0-...-7c39a50 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 19 Imported by: 0

README

Scanner

Nightshift scans and scales objects by use of scanners. A scanner is responsible for:

  • Discovery of existing objects
  • Scaling objects
  • Save and load of a state
  • Watch for live changes

Currently there are two watcher modules:

  • openshift - which scans, scales and watch OpenShift DeploymentConfig resources
  • deployment - which scans, scales and watch Kubernetes Deployment resources
  • statefulset - which scans, scales and watch Kubernetes/OpenShift Statefulset resources

To add a new scanner, implement a factory method that implements the factory type, and register that method with a new type. This type will then be available in the config as a new scanner type.

The scanner itself should implement the Scanner interface. The watch method is optional, and when implemented will result in live updates. However, the GetObjects method is called frequently as well (at the configured resync interval, default 15minutes).

The current scanners are targeted at OpenShift (or Kubernetes), but there is no limitation which platform a scanner can target. As long as the Scale/GetObjects methods can be implemented, a basic scanner can be implemented as well.

Documentation

Index

Constants

View Source
const (
	// EventAdd is used to indicate a resource was added in a Event
	EventAdd string = "add"
	// EventRemove is used to indicate a resource was removed in a Event
	EventRemove string = "remove"
	// EventUpdate is used to indicate a resource was updated in a Event
	EventUpdate string = "update"
)
View Source
const (
	// ScheduleAnnotation is the annotation used to define schedules on resources.
	ScheduleAnnotation string = "joyrex2001.com/nightshift.schedule"
	// IgnoreAnnotation is the annotation used to define a resource should be ignored.
	IgnoreAnnotation string = "joyrex2001.com/nightshift.ignore"
	// SaveStateAnnotation is the annotation used to store the state.
	SaveStateAnnotation string = "joyrex2001.com/nightshift.savestate"
)

Variables

This section is empty.

Functions

func RegisterModule

func RegisterModule(typ string, factory Factory)

RegisterModule will add the provided module, with given factory method to the list of available modules in order to support dependency injection, as well as easing up modular development for scanners.

Types

type Config

type Config struct {
	Id        string               `json:"id"`
	Namespace string               `json:"namespace"`
	Label     string               `json:"label"`
	Schedule  []*schedule.Schedule `json:"schedule"`
	Type      string               `json:"type"`
	Priority  int                  `json:"priority"`
}

Config describes the configuration of a scanner. It includes ScannerType to allow to be used by the factory NewForConfig method.

type DeploymentScanner

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

DeploymentScanner is the object that implements scanning of kubernetes Deployments.

func (*DeploymentScanner) GetConfig

func (s *DeploymentScanner) GetConfig() Config

GetConfig will return the config applied for this scanner.

func (*DeploymentScanner) GetObjects

func (s *DeploymentScanner) GetObjects() ([]*Object, error)

GetObjects will return a populated list of Objects containing the relavant resources with their schedule info.

func (*DeploymentScanner) GetState

func (s *DeploymentScanner) GetState(obj *Object) (int, error)

GetState will return the current number of replicas.

func (*DeploymentScanner) Scale

func (s *DeploymentScanner) Scale(obj *Object, state *int, replicas int) error

Scale will scale a given object to given amount of replicas.

func (*DeploymentScanner) SetConfig

func (s *DeploymentScanner) SetConfig(cfg Config)

SetConfig will set the generic configuration for this scanner.

func (*DeploymentScanner) Watch

func (s *DeploymentScanner) Watch(_stop chan bool) (chan Event, error)

Watch will return a channel on which Event objects will be published that describe change events in the cluster.

type Event

type Event struct {
	Object *Object
	Type   string
}

Event is the structure that is send by the watch method over the channel.

type Factory

type Factory func() (Scanner, error)

Factory is the factory method for a scanner implementation module.

type Object

type Object struct {
	Namespace string               `json:"namespace"`
	UID       string               `json:"uid"`
	Name      string               `json:"name"`
	Type      string               `json:"type"`
	Schedule  []*schedule.Schedule `json:"schedule"`
	State     *State               `json:"state"`
	Replicas  int                  `json:"replicas"`
	Priority  int                  `json:"priority"`
	ScannerId string               `json:"scanner_id"`
	// contains filtered or unexported fields
}

Object is an object found by the scanner.

func NewObjectForScanner

func NewObjectForScanner(scnr Scanner) *Object

NewObjectForScanner will return a new Object instance populated with the scanner details.

func (*Object) Copy

func (obj *Object) Copy() *Object

Copy will return a fresh copy of the Object object.

func (*Object) GetState

func (obj *Object) GetState() (*int, error)

GetState will return the current number of replicas.

func (*Object) Scale

func (obj *Object) Scale(state *int, replicas int) error

Scale will scale the Object to the given amount of replicas.

type OpenShiftScanner

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

OpenShiftScanner is the object that implements scanning of OpenShift DeploymentConfigs.

func (*OpenShiftScanner) GetConfig

func (s *OpenShiftScanner) GetConfig() Config

GetConfig will return the config applied for this scanner.

func (*OpenShiftScanner) GetObjects

func (s *OpenShiftScanner) GetObjects() ([]*Object, error)

GetObjects will return a populated list of Objects containing the relavant resources with their schedule info.

func (*OpenShiftScanner) GetState

func (s *OpenShiftScanner) GetState(obj *Object) (int, error)

GetState will save the current number of replicas.

func (*OpenShiftScanner) Scale

func (s *OpenShiftScanner) Scale(obj *Object, state *int, replicas int) error

Scale will scale a given object to given amount of replicas.

func (*OpenShiftScanner) SetConfig

func (s *OpenShiftScanner) SetConfig(cfg Config)

SetConfig will set the generic configuration for this scanner.

func (*OpenShiftScanner) Watch

func (s *OpenShiftScanner) Watch(_stop chan bool) (chan Event, error)

Watch will return a channel on which Event objects will be published that describe change events in the cluster.

type Scanner

type Scanner interface {
	SetConfig(Config)
	GetConfig() Config
	GetObjects() ([]*Object, error)
	GetState(*Object) (int, error)
	Scale(*Object, *int, int) error
	Watch(chan bool) (chan Event, error)
}

Scanner is the public interface of a scanner object.

func New

func New(typ string) (Scanner, error)

New will return a Scanner object for given ScannerType.

func NewDeploymentScanner

func NewDeploymentScanner() (Scanner, error)

NewDeploymentScanner will instantiate a new DeploymentScanner object.

func NewForConfig

func NewForConfig(cfg Config) (Scanner, error)

NewForConfig will return a Scanner object based on the given Config object.

func NewOpenShiftScanner

func NewOpenShiftScanner() (Scanner, error)

NewOpenShiftScanner will instantiate a new OpenShiftScanner object.

func NewStatefulSetScanner

func NewStatefulSetScanner() (Scanner, error)

NewStatefulSetScanner will instantiate a new StatefulSetScanner object.

type State

type State struct {
	Replicas int `json:"replicas"`
}

State defines a state of the object.

type StatefulSetScanner

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

StatefulSetScanner is the object that implements scanning of OpenShift/k8s statefulsets.

func (*StatefulSetScanner) GetConfig

func (s *StatefulSetScanner) GetConfig() Config

GetConfig will return the config applied for this scanner.

func (*StatefulSetScanner) GetObjects

func (s *StatefulSetScanner) GetObjects() ([]*Object, error)

GetObjects will return a populated list of Objects containing the relavant resources with their schedule info.

func (*StatefulSetScanner) GetState

func (s *StatefulSetScanner) GetState(obj *Object) (int, error)

GetState will save the current number of replicas.

func (*StatefulSetScanner) Scale

func (s *StatefulSetScanner) Scale(obj *Object, state *int, replicas int) error

Scale will scale a given object to given amount of replicas.

func (*StatefulSetScanner) SetConfig

func (s *StatefulSetScanner) SetConfig(cfg Config)

SetConfig will set the generic configuration for this scanner.

func (*StatefulSetScanner) Watch

func (s *StatefulSetScanner) Watch(_stop chan bool) (chan Event, error)

Watch will return a channel on which Event objects will be published that describe change events in the cluster.

Jump to

Keyboard shortcuts

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