controller

package module
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: MIT Imports: 22 Imported by: 0

README

RestStrategy Controller

Go Report Card

Custom Controller used to listen to changes on a specific object (CRD -> RestStrategy)

Everytime a set of changes is done on the types a client needs to be regenerated and unit tests updated.

Useful resources

Kubernetes maintained sample-controller repo is a great reference.

Includes the below image, highlighting the area of responsibility between the client (client-go in this case the most mature, and best suited for concurrency) and user code (custom controller)

CustomController!

Helper resources

Debug controllers video

A VSCode launch.json is shared in the controller dir.

Notes

Build locally and test in cluster.

docker build --build-arg REVISION=abcd1234 --build-arg VERSION=0.6.2 -t dnitsch/reststrategy-controller .

Deployment

Run in minikube - installation instructions here.

You can deploy just the CRD when testing changes and run controller locally and have updated kubecontext e.g.:

"args": [
    "--kubeconfig",
    "${env:HOME}/.kube/config",
    "--controllercount",
    "2",
    "--namespace",
    "reststrategy",
    "--loglevel",
    "debug"
]

Secret Token

As Part of the orchstrator it does a token replace before calling the relevant service endpoint

This way we are not storing secrets in etcd and calling a kubectl describe reststrategy will only fetch back token from the CRD stored in ETCD.

The controller is using the configmanager to perform token replacement, so if you are running in EKS/AKS/GKE - it is highly recommended you store any secrets in the Cloud provided secrets storage like AWS SecretsManager and ensure your deployment of the controller has valid pod identity to be able to perform the relevant retrieve operation.

e.g. in AWS secretsmanager:GetSecret

Unit testing

To generate a JUNIT style report we are using this package

sample usage see >> Makefile

go test ``go list ./... | grep -v */generated/`` -coverprofile .coverage

Documentation

Index

Constants

View Source
const (
	// SuccessSynced is used as part of the Event 'reason' when a RestStrategy is synced
	SuccessSynced = "Synced"
	// ErrResourceExists is used as part of the Event 'reason' when a RestStrategy fails
	// to sync due to a Deployment of the same name already existing.
	ErrSync = "Failed"

	// FailedToSyncAll is the message used for Events when a resource
	// fails to sync due to not all resources syncing correctly
	FailedToSyncAll = "Failed due to not all subcomponents within RestStrategy successfully completed. see additionalInfo for more details"
	FailReason      = "SubcomponentsFailed"
	// MessageResourceSynced is the message used for an Event fired when a RestStrategy
	// is synced successfully
	MessageResourceSynced = "RestStrategy successfully executed"
	MessageResourceFailed = "RestStrategy failed to sync"
)

Variables

View Source
var (
	Version  string = "0.0.1"
	Revision string = "1111aaaa"
)

Functions

This section is empty.

Types

type Controller

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

Controller is the controller implementation for RestStrategy resources

func NewController

func NewController(
	kubeclientset kubernetes.Interface,
	reststrategyclientset clientset.Interface,

	reststrategyInformer informers.RestStrategyInformer,
	resyncServicePeriodHours int,
) *Controller

NewController returns a new RestStrategy controller

func (*Controller) Run

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

Run will set up the event handlers for types we are interested in, as well as syncing informer caches and starting workers. It will block until stopCh is closed, at which point it will shutdown the workqueue and wait for workers to finish processing their current work items.

func (*Controller) WithLogger

func (c *Controller) WithLogger(l log.Logger) *Controller

WithLogger overwrites logger with Custom implementation

func (*Controller) WithRestClient

func (c *Controller) WithRestClient(rc rest.Client) *Controller

WithService assigns a service instance

Directories

Path Synopsis
cmd
internal
pkg

Jump to

Keyboard shortcuts

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