plan

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2017 License: Apache-2.0 Imports: 2 Imported by: 36

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Policies = map[string]Policy{
	"sync":        &SyncPolicy{},
	"upsert-only": &UpsertOnlyPolicy{},
}

Policies is a registry of available policies.

Functions

This section is empty.

Types

type Changes

type Changes struct {
	// Records that need to be created
	Create []*endpoint.Endpoint
	// Records that need to be updated (current data)
	UpdateOld []*endpoint.Endpoint
	// Records that need to be updated (desired data)
	UpdateNew []*endpoint.Endpoint
	// Records that need to be deleted
	Delete []*endpoint.Endpoint
}

Changes holds lists of actions to be executed by dns providers

type Plan

type Plan struct {
	// List of current records
	Current []*endpoint.Endpoint
	// List of desired records
	Desired []*endpoint.Endpoint
	// Policies under which the desired changes are calculated
	Policies []Policy
	// List of changes necessary to move towards desired state
	// Populated after calling Calculate()
	Changes *Changes
}

Plan can convert a list of desired and current records to a series of create, update and delete actions.

Example

ExamplePlan shows how plan can be used.

foo := endpoint.NewEndpoint("foo.example.com", "1.2.3.4", "")
barV1 := endpoint.NewEndpoint("bar.example.com", "8.8.8.8", "")
barV2 := endpoint.NewEndpoint("bar.example.com", "8.8.4.4", "")
baz := endpoint.NewEndpoint("baz.example.com", "6.6.6.6", "")

// Plan where
// * foo should be deleted
// * bar should be updated from v1 to v2
// * baz should be created
plan := &Plan{
	Policies: []Policy{&SyncPolicy{}},
	Current:  []*endpoint.Endpoint{foo, barV1},
	Desired:  []*endpoint.Endpoint{barV2, baz},
}

// calculate actions
plan = plan.Calculate()

// print actions
fmt.Println("Create:")
for _, ep := range plan.Changes.Create {
	fmt.Println(ep)
}
fmt.Println("UpdateOld:")
for _, ep := range plan.Changes.UpdateOld {
	fmt.Println(ep)
}
fmt.Println("UpdateNew:")
for _, ep := range plan.Changes.UpdateNew {
	fmt.Println(ep)
}
fmt.Println("Delete:")
for _, ep := range plan.Changes.Delete {
	fmt.Println(ep)
}
// Create:
// &{baz.example.com 6.6.6.6 map[] }
// UpdateOld:
// &{bar.example.com 8.8.8.8 map[] }
// UpdateNew:
// &{bar.example.com 8.8.4.4 map[] }
// Delete:
// &{foo.example.com 1.2.3.4 map[] }
Output:

func (*Plan) Calculate

func (p *Plan) Calculate() *Plan

Calculate computes the actions needed to move current state towards desired state. It then passes those changes to the current policy for further processing. It returns a copy of Plan with the changes populated.

type Policy added in v0.3.0

type Policy interface {
	Apply(changes *Changes) *Changes
}

Policy allows to apply different rules to a set of changes.

type SyncPolicy added in v0.3.0

type SyncPolicy struct{}

SyncPolicy allows for full synchronization of DNS records.

func (*SyncPolicy) Apply added in v0.3.0

func (p *SyncPolicy) Apply(changes *Changes) *Changes

Apply applies the sync policy which returns the set of changes as is.

type UpsertOnlyPolicy added in v0.3.0

type UpsertOnlyPolicy struct{}

UpsertOnlyPolicy allows evrything but deleting DNS records.

func (*UpsertOnlyPolicy) Apply added in v0.3.0

func (p *UpsertOnlyPolicy) Apply(changes *Changes) *Changes

Apply applies the upsert-only policy which strips out any deletions.

Jump to

Keyboard shortcuts

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