mirror

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package mirror implements the logic that interprets the contents of a directory into a namespace.

TODO: This package also contains definitions used for database operations. This is logically separate from the main logic so this package should probably be split into two.

The process is broken down into three logical steps: (1) acquire the source, (2) parse/interpret the contents of the source, and (3) apply necessary changes to Direktiv.

(1) Acquire the source: the typical & classic source is a remote git repository. This package provides the methods needed to use it this way, but this is not the only way envisioned.

TODO: This is an interface overrideable by caller so that the logic can be reused by the CLI. This is critical for maintainability in the future. The CLI use-case has a lot in common with this code, but also a lot of differences.

(2) Parse/interpret the contents of the source: this is a read-only operation that has no impact on the server aside from logging. This is critical because the full sync logic may need to make many changes to a namespace and it is not trivial to implement a good revert if something goes wrong along the way. Substantial validation must be performed before ANY changes are made, to reduce the chance of the operation failing. Additionally, it is helpful to separate the read-only interpretation of the Source out from the application of that interpretation so that the logic can be used for UX features such as a Dry Run and local validation/linting in a CLI.

(3) Apply necessary changes to Direktiv. This step uses the report generated by the previous step to make changes to Direktiv. This is the only step permitted to modify the contents / behaviour of a namespace. IT SHOULD NOT DO ANY interpretation of the source of its own. In a simple world, it will have no if statements nor switches. In practice it may want to compare the desired state of the namespace as determined by the parser against the actual state of the namespace and reuse anything it can.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Applyer

type Applyer interface {
	// contains filtered or unexported methods
}

type Callbacks

type Callbacks interface {
	// ConfigureWorkflowFunc is a hookup function the gets called for every new or updated workflow file.
	ConfigureWorkflowFunc(ctx context.Context, nsID uuid.UUID, nsName string, file *filestore.File) error

	ProcessLogger() ProcessLogger

	Store() datastore.MirrorStore
	FileStore() filestore.FileStore
	VarStore() datastore.RuntimeVariablesStore
}

type DirectorySource

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

func NewDirectorySource

func NewDirectorySource(dir string) *DirectorySource

func (*DirectorySource) FS

func (src *DirectorySource) FS() fs.FS

func (*DirectorySource) Free

func (src *DirectorySource) Free() error

func (*DirectorySource) Notes

func (src *DirectorySource) Notes() map[string]string

type DirektivApplyer

type DirektivApplyer struct {
	NamespaceID uuid.UUID
	// contains filtered or unexported fields
}

type DryrunApplyer

type DryrunApplyer struct{}

type FormatLogger

type FormatLogger interface {
	Errorf(msg string, a ...interface{})
	Warnf(msg string, a ...interface{})
	Infof(msg string, a ...interface{})
	Debugf(msg string, a ...interface{})
}

type GitSourceConfig

type GitSourceConfig struct {
	URL             string
	GitRef          string
	InsecureSkipTLS bool
	TempDir         string
}

type GitSourceSSHAuthConf

type GitSourceSSHAuthConf struct {
	PublicKey            string
	PrivateKey           string
	PrivateKeyPassphrase string
}

type GitSourceTokenAuthConf

type GitSourceTokenAuthConf struct {
	Token string
}

type Manager

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

func NewManager

func NewManager(callbacks Callbacks) *Manager

func (*Manager) Cancel

func (d *Manager) Cancel(_ context.Context, id uuid.UUID) error

Cancel stops a currently running mirroring process.

func (*Manager) Execute

func (d *Manager) Execute(ctx context.Context, p *datastore.MirrorProcess, m *datastore.MirrorConfig, applyer Applyer)

Execute ..

func (*Manager) NewProcess

func (d *Manager) NewProcess(ctx context.Context, ns *datastore.Namespace, processType string) (*datastore.MirrorProcess, error)

type Parser

type Parser struct {
	Filters   map[string][]byte
	Workflows map[string][]byte
	Services  map[string][]byte
	Endpoints map[string][]byte
	Consumers map[string][]byte

	DeprecatedNamespaceVars map[string][]byte
	DeprecatedWorkflowVars  map[string]map[string][]byte
	// contains filtered or unexported fields
}

func NewParser

func NewParser(log FormatLogger, src Source) (*Parser, error)

func (*Parser) Close

func (p *Parser) Close() error

func (*Parser) ListFiles

func (p *Parser) ListFiles() ([]string, error)

type ProcessLogger

type ProcessLogger interface {
	Error(pid uuid.UUID, msg string, keysAndValues ...interface{})
	Warn(pid uuid.UUID, msg string, keysAndValues ...interface{})
	Info(pid uuid.UUID, msg string, keysAndValues ...interface{})
	Debug(pid uuid.UUID, msg string, keysAndValues ...interface{})
}

type Source

type Source interface {
	FS() fs.FS
	Free() error
	Notes() map[string]string
}

func GetSource added in v0.8.3

func GetSource(_ context.Context, cfg *datastore.MirrorConfig) (Source, error)

func NewGitSourceNoAuth

func NewGitSourceNoAuth(conf GitSourceConfig) (Source, error)

func NewGitSourceSSH

func NewGitSourceSSH(conf GitSourceConfig, auth GitSourceSSHAuthConf) (Source, error)

Jump to

Keyboard shortcuts

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