Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Plural
platform
external-dns
Commits
f837b653
Commit
f837b653
authored
8 years ago
by
Martin Linkhorst
Committed by
Henning Jacobs
8 years ago
Browse files
Options
Download
Email Patches
Plain Diff
feat(plan): allow plan to have multiple policies (#204)
parent
406afacb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
controller/controller.go
+3
-3
controller/controller.go
plan/plan.go
+6
-4
plan/plan.go
plan/plan_test.go
+16
-16
plan/plan_test.go
with
25 additions
and
23 deletions
+25
-23
controller/controller.go
+
3
-
3
View file @
f837b653
...
...
@@ -54,9 +54,9 @@ func (c *Controller) RunOnce() error {
}
plan
:=
&
plan
.
Plan
{
Polic
y
:
c
.
Policy
,
Current
:
records
,
Desired
:
endpoints
,
Polic
ies
:
[]
plan
.
Policy
{
c
.
Policy
}
,
Current
:
records
,
Desired
:
endpoints
,
}
plan
=
plan
.
Calculate
()
...
...
This diff is collapsed.
Click to expand it.
plan/plan.go
+
6
-
4
View file @
f837b653
...
...
@@ -28,8 +28,8 @@ type Plan struct {
Current
[]
*
endpoint
.
Endpoint
// List of desired records
Desired
[]
*
endpoint
.
Endpoint
// Polic
y
under which the desired changes are calculated
Polic
y
Policy
// Polic
ies
under which the desired changes are calculated
Polic
ies
[]
Policy
// List of changes necessary to move towards desired state
// Populated after calling Calculate()
Changes
*
Changes
...
...
@@ -86,8 +86,10 @@ func (p *Plan) Calculate() *Plan {
}
}
// Apply policy to list of changes.
changes
=
p
.
Policy
.
Apply
(
changes
)
// Apply policies to list of changes.
for
_
,
pol
:=
range
p
.
Policies
{
changes
=
pol
.
Apply
(
changes
)
}
plan
:=
&
Plan
{
Current
:
p
.
Current
,
...
...
This diff is collapsed.
Click to expand it.
plan/plan_test.go
+
16
-
16
View file @
f837b653
...
...
@@ -47,34 +47,34 @@ func TestCalculate(t *testing.T) {
typedV1
:=
[]
*
endpoint
.
Endpoint
{
endpoint
.
NewEndpoint
(
"foo"
,
"v1"
,
"A"
)}
for
_
,
tc
:=
range
[]
struct
{
polic
y
Policy
polic
ies
[]
Policy
current
,
desired
[]
*
endpoint
.
Endpoint
create
,
updateOld
,
updateNew
,
delete
[]
*
endpoint
.
Endpoint
}{
// Nothing exists and nothing desired doesn't change anything.
{
&
SyncPolicy
{},
empty
,
empty
,
empty
,
empty
,
empty
,
empty
},
{[]
Policy
{
&
SyncPolicy
{}
}
,
empty
,
empty
,
empty
,
empty
,
empty
,
empty
},
// More desired than current creates the desired.
{
&
SyncPolicy
{},
empty
,
fooV1
,
fooV1
,
empty
,
empty
,
empty
},
{[]
Policy
{
&
SyncPolicy
{}
}
,
empty
,
fooV1
,
fooV1
,
empty
,
empty
,
empty
},
// Desired equals current doesn't change anything.
{
&
SyncPolicy
{},
fooV1
,
fooV1
,
empty
,
empty
,
empty
,
empty
},
{[]
Policy
{
&
SyncPolicy
{}
}
,
fooV1
,
fooV1
,
empty
,
empty
,
empty
,
empty
},
// Nothing is desired deletes the current.
{
&
SyncPolicy
{},
fooV1
,
empty
,
empty
,
empty
,
empty
,
fooV1
},
{[]
Policy
{
&
SyncPolicy
{}
}
,
fooV1
,
empty
,
empty
,
empty
,
empty
,
fooV1
},
// Current and desired match but Target is different triggers an update.
{
&
SyncPolicy
{},
fooV1
,
fooV2
,
empty
,
fooV1
,
fooV2
,
empty
},
{[]
Policy
{
&
SyncPolicy
{}
}
,
fooV1
,
fooV2
,
empty
,
fooV1
,
fooV2
,
empty
},
// Both exist but are different creates desired and deletes current.
{
&
SyncPolicy
{},
fooV1
,
bar
,
bar
,
empty
,
empty
,
fooV1
},
{[]
Policy
{
&
SyncPolicy
{}
}
,
fooV1
,
bar
,
bar
,
empty
,
empty
,
fooV1
},
// Nothing is desired but policy doesn't allow deletions.
{
&
UpsertOnlyPolicy
{},
fooV1
,
empty
,
empty
,
empty
,
empty
,
empty
},
{[]
Policy
{
&
UpsertOnlyPolicy
{}
}
,
fooV1
,
empty
,
empty
,
empty
,
empty
,
empty
},
// Labels should be inherited
{
&
SyncPolicy
{},
labeledV1
,
noLabels
,
empty
,
labeledV1
,
labeledV2
,
empty
},
{[]
Policy
{
&
SyncPolicy
{}
}
,
labeledV1
,
noLabels
,
empty
,
labeledV1
,
labeledV2
,
empty
},
// RecordType should be inherited
{
&
SyncPolicy
{},
typedV1
,
noType
,
empty
,
typedV1
,
typedV2
,
empty
},
{[]
Policy
{
&
SyncPolicy
{}
}
,
typedV1
,
noType
,
empty
,
typedV1
,
typedV2
,
empty
},
}
{
// setup plan
plan
:=
&
Plan
{
Polic
y
:
tc
.
polic
y
,
Current
:
tc
.
current
,
Desired
:
tc
.
desired
,
Polic
ies
:
tc
.
polic
ies
,
Current
:
tc
.
current
,
Desired
:
tc
.
desired
,
}
// calculate actions
plan
=
plan
.
Calculate
()
...
...
@@ -116,9 +116,9 @@ func ExamplePlan() {
// * bar should be updated from v1 to v2
// * baz should be created
plan
:=
&
Plan
{
Polic
y
:
&
SyncPolicy
{},
Current
:
[]
*
endpoint
.
Endpoint
{
foo
,
barV1
},
Desired
:
[]
*
endpoint
.
Endpoint
{
barV2
,
baz
},
Polic
ies
:
[]
Policy
{
&
SyncPolicy
{}
}
,
Current
:
[]
*
endpoint
.
Endpoint
{
foo
,
barV1
},
Desired
:
[]
*
endpoint
.
Endpoint
{
barV2
,
baz
},
}
// calculate actions
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment