assistant

package module
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2020 License: GPL-3.0 Imports: 17 Imported by: 0

README

assistant-base

Base package for an assistant

Reference

Default config items

The following items are included in the assistant-base config, but can be overridden by the assistant

  • local: If this is true, then no connections to kubernetes will be established
  • configmap_for_work: String of the configmap name to update for shared work

Create a new assistant

Create a repo at https://git.parlette.us that includes a readme and license

cp -R ~/src/assistant-base/template ~/src/assistant-new
cd ~/src/assistant-new
git init -b main
git remote add public git@git.parlette.us:matthew/assistant-new.git
git push -u public main
Drone

The repo needs to have the following secrets:

  • notify_channel
  • notify_username
  • notify_webhook
  • registry (available in pull requests) (registry.url)
  • repo (available in pull requests) (registry.url:assistant/template)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Callbacks holds the function calls for load, reconcile, and sync
	Callbacks *callbacks

	// Config holds the configuration for the assistant
	Config *Configuration

	// Shutdown is the channel that tells every routine to stop
	Shutdown chan bool
)
View Source
var (
	// Ready is when a configuration is initialized and ready to be used
	Ready sync.WaitGroup
)

Functions

func AddLoadCallback

func AddLoadCallback(f func())

AddLoadCallback stores a function to call starting on the next load cycle

func AddReconcileCallback

func AddReconcileCallback(f func())

AddReconcileCallback stores a function to call starting on the next reconcile cycle

func AddSyncCallback

func AddSyncCallback(f func())

AddSyncCallback stores a function to call starting on the next sync cycle

func Debug added in v2.5.1

func Debug(v ...interface{})

Debug will print a message to the log if the Config.Debug boolean is true

func FindStringInSlice

func FindStringInSlice(slice []string, val string) int

FindStringInSlice returns the index of a string in a slice, or -1 if it doesn't exist

func GetJSONString

func GetJSONString(key string, value string) []byte

GetJSONString generates a byte array of JSON to be used with updating a configmap

func GetKubeClient

func GetKubeClient() (*kubernetes.Clientset, error)

GetKubeClient returns an in-cluster kubernetes client

func GetOrCreateConfigmap

func GetOrCreateConfigmap(client *kubernetes.Clientset, name string) (*v1.ConfigMap, error)

GetOrCreateConfigmap gets an existing ConfigMap by name if it exists, or creates it if it does not exist

func ListenForShutdown

func ListenForShutdown(shutdown <-chan bool)

ListenForShutdown handles when the shutdown channel receives true

func Load

func Load()

Load calls the load callbacks and waits for a number of seconds to repeat

func Log added in v2.5.1

func Log(v ...interface{})

Log will print a message to the log

func Reconcile

func Reconcile()

Reconcile calls the reconcile callbacks and waits for a number of seconds to repeat

func Start

func Start()

Start begins the cycles for running load and reconcile callbacks

func Stop

func Stop()

Stop prevents callbacks from running again

func Sync

func Sync()

Sync calls the sync callbacks and waits for a number of seconds to repeat

func SyncSharedWork

func SyncSharedWork()

SyncSharedWork pulls the latest configmap data to the local object

func SyncWorkToConfigmap

func SyncWorkToConfigmap(w *Work) error

SyncWorkToConfigmap updates a configmap with a serialized representation of a work object

func UpdateConfigmap

func UpdateConfigmap(client *kubernetes.Clientset, cm *v1.ConfigMap, key string, value string) *v1.ConfigMap

UpdateConfigmap sets one key and value in a Configmap

func UpdateWorkCache

func UpdateWorkCache(w *Work)

UpdateWorkCache takes a work object as w and adds to the cache or updates an existing entry

func UpdateWorkCacheIfNew

func UpdateWorkCacheIfNew(w *Work)

UpdateWorkCacheIfNew adds a new Work item to the cache. If it already exists, nothing is done.

Types

type Configuration

type Configuration struct {
	// Path is the directory that holds the config setting files
	Path string
	// Settings holds the user defined key-value pairs
	Settings map[string]string

	// Kube holds the in-cluster kubernetes connection
	Kube *kubernetes.Clientset
	// WorkShared is the shared configmap between assistants for work
	WorkShared *v1.ConfigMap
	// WorkCache is a local cache of Work objects
	WorkCache map[string]*Work
	// WorkConfigmapName is the name of the config map that shares work
	WorkConfigmapName string
	// Local disables any kubernetes connections
	Local bool
	// Debug will print debug messages
	Debug bool
	// contains filtered or unexported fields
}

Configuration holds the key-value pairs used by the assistant

func NewConfiguration

func NewConfiguration(configPath string) *Configuration

NewConfiguration generates a configuration with the required settings. Path to the configuration settings is allowed, but defaults to /config if you pass an empty string

func (*Configuration) Add

func (c *Configuration) Add(name string, defaultValue string)

Add a config value and watch for updates

func (*Configuration) Connect

func (c *Configuration) Connect()

Connect tries to connect to the Kubernetes cluster and load the WorkShared configmap

func (*Configuration) Get

func (c *Configuration) Get(name string) string

Get a value for a given key

func (*Configuration) Refresh

func (c *Configuration) Refresh()

Refresh loads all config key-value pairs from the corresponding files

func (*Configuration) RefreshWorkShared

func (c *Configuration) RefreshWorkShared()

RefreshWorkShared pulls the latest config map to the local copy

func (*Configuration) Require

func (c *Configuration) Require(key string)

Require will block until a setting has a value

func (*Configuration) RequireKube

func (c *Configuration) RequireKube()

RequireKube will block until the cluster is connected

func (*Configuration) RequireWorkCache

func (c *Configuration) RequireWorkCache()

RequireWorkCache will block until the Work Cache has been created

func (*Configuration) RequireWorkShared

func (c *Configuration) RequireWorkShared()

RequireWorkShared will block until the Work Configmap has been loaded

type Work

type Work struct {
	ID          string
	Title       string
	From        string
	Status      WorkStatus
	URL         string
	Description string
	Updated     bool
}

Work is something that needs to be done

func DeserializeString

func DeserializeString(s string) *Work

DeserializeString returns a one line string representing this object to be saved as a value in a configmap

func (*Work) Equals

func (w *Work) Equals(other *Work) bool

Equals compares two Work objects and returns a boolean

func (*Work) Print

func (w *Work) Print()

Print a Work object on a single line

func (*Work) SerializeString

func (w *Work) SerializeString() string

SerializeString returns a one line string representing this object to be saved as a value in a configmap

type WorkStatus

type WorkStatus int

WorkStatus defines the states that Work can be in

const (
	// Open work item
	Open WorkStatus = iota
	// Waiting on someone else
	Waiting
	// Closed work item
	Closed
	// None allows a work item to have no status
	None
)

func (WorkStatus) String

func (w WorkStatus) String() string

Jump to

Keyboard shortcuts

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