-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract the Resource, Changes and State structure Extend the State structure to record more data to track added resource and templates changes
- Loading branch information
1 parent
6522992
commit d1cfa7c
Showing
9 changed files
with
308 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Temporary files | ||
*~ | ||
.*~ | ||
\#*\# | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package changes | ||
|
||
import ( | ||
"github.com/AirVantage/overlord/pkg/set" | ||
) | ||
|
||
// Changes keeps track of added/removed IPs for a Resource. | ||
// We store IPs as strings to support both IPv4 and IPv6. | ||
type Changes[T comparable] struct { | ||
addedIPs *set.Set[T] | ||
removedIPs *set.Set[T] | ||
} | ||
|
||
// NewChanges return a pointer to an initialized Changes struct. | ||
func New[T comparable]() *Changes[T] { | ||
return &Changes[T]{ | ||
addedIPs: set.New[T](), | ||
removedIPs: set.New[T](), | ||
} | ||
} | ||
|
||
|
||
// Log changes | ||
func (c *Changes[T])Add(add T) { | ||
c.addedIPs.Add(add) | ||
} | ||
func (c *Changes[T])Remove(rem T) { | ||
c.removedIPs.Add(rem) | ||
} | ||
|
||
// Return changes as slice | ||
func (c *Changes[T])Added() []T { | ||
return c.addedIPs.ToSlice() | ||
} | ||
func (c *Changes[T])Removed() []T { | ||
return c.removedIPs.ToSlice() | ||
} | ||
|
||
// Return a deep copy of current object | ||
func (c *Changes[T])Copy() *Changes[T] { | ||
var copy *Changes[T] = New[T]() | ||
|
||
for _, added := range c.addedIPs.ToSlice() { | ||
copy.addedIPs.Add(added) | ||
} | ||
for _, removed := range c.removedIPs.ToSlice() { | ||
copy.removedIPs.Add(removed) | ||
} | ||
return copy | ||
} | ||
|
||
// NewChanges return a pointer to an initialized Changes struct. | ||
func (c *Changes[T])Merge(m *Changes[T]) *Changes[T] { | ||
var merged *Changes[T] = c.Copy() | ||
|
||
for _, added := range m.addedIPs.ToSlice() { | ||
merged.addedIPs.Add(added) | ||
} | ||
for _, removed := range m.removedIPs.ToSlice() { | ||
merged.removedIPs.Add(removed) | ||
} | ||
return merged | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package resource | ||
// Configuration file structure | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/AirVantage/overlord/pkg/lookable" | ||
) | ||
|
||
|
||
type ResourceConfig struct { | ||
Resource Resource `toml:"template"` | ||
} | ||
|
||
type Resource struct { | ||
Src string | ||
Dest string | ||
Groups []lookable.AutoScalingGroup | ||
Tags []lookable.Tag | ||
Subnets []lookable.Subnet | ||
ReloadCmd string `toml:"reload_cmd"` | ||
SrcFSInfo os.FileInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.