gitbacked

package module
v0.0.0-...-f1ac91e Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

Git Backed Controller

The basic idea is to write a k8s controller that runs against git and not k8s apiserver. So the controller is reading and writing objects to git and responding to changes in git. This is accomplished by creating a custom implemenation of the clients and caches in controller-runtime.

Status

This is totally hacked up and just proving an idea. There's most likely a lot of issues with this code. For one the RESTMapping logic is completely wrong as offline you have knowledge if a resource is namespaced or not.

Basic approach

You should just be able to write a controller as normal but in the setup just set the NewClient, NewCache, and MapperProvider to the git based ones.

	git, err := gitbacked.New(ctx, url, gitbacked.Options{
		Branch:       branch,
		SubDirectory: subdir,
		Interval:     interval,
	})
	defer git.Close()

	mgr, err := ctrl.NewManager(&rest.Config{}, ctrl.Options{
		Scheme:         scheme,
		NewClient:      git.NewClient,
		NewCache:       git.NewCache,
		MapperProvider: git.MapperProvider,
	})

Authentication

The controller will pull from and push to the same branch. Right now the code will just call git push so it is expect that that call will work with no user input (ssh keys or some agent based setup is in place).

Example

A more complete example is in the ./example folder.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitStore

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

func New

func New(ctx context.Context, url string, opts Options) (*GitStore, error)

func (*GitStore) Close

func (g *GitStore) Close() error

func (*GitStore) MapperProvider

func (g *GitStore) MapperProvider(c *rest.Config) (meta.RESTMapper, error)

func (*GitStore) NewCache

func (g *GitStore) NewCache(_ *rest.Config, opts cache.Options) (cache.Cache, error)

func (*GitStore) NewClient

func (g *GitStore) NewClient(_ cache.Cache, _ *rest.Config, options client.Options, _ ...client.Object) (client.Client, error)

type Options

type Options struct {
	Branch       string
	SubDirectory string
	Interval     time.Duration
}

Directories

Path Synopsis
pkg
git

Jump to

Keyboard shortcuts

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