Add annotations to routes and apps (#866)

Adds 'annotations' attribute to Routes and Apps
This commit is contained in:
Owen Cliffe
2018-03-20 18:02:49 +00:00
committed by GitHub
parent 845f40ee86
commit d25b5af59d
31 changed files with 1838 additions and 669 deletions

View File

@@ -36,6 +36,7 @@ type Route struct {
Timeout int32 `json:"timeout" db:"timeout"`
IdleTimeout int32 `json:"idle_timeout" db:"idle_timeout"`
Config Config `json:"config,omitempty" db:"config"`
Annotations Annotations `json:"annotations,omitempty" db:"annotations"`
CreatedAt strfmt.DateTime `json:"created_at,omitempty" db:"created_at"`
UpdatedAt strfmt.DateTime `json:"updated_at,omitempty" db:"updated_at"`
}
@@ -129,6 +130,11 @@ func (r *Route) Validate() error {
return ErrRoutesInvalidMemory
}
err = r.Annotations.Validate()
if err != nil {
return err
}
return nil
}
@@ -169,6 +175,7 @@ func (r1 *Route) Equals(r2 *Route) bool {
eq = eq && r1.Timeout == r2.Timeout
eq = eq && r1.IdleTimeout == r2.IdleTimeout
eq = eq && r1.Config.Equals(r2.Config)
eq = eq && r1.Annotations.Equals(r2.Annotations)
// NOTE: datastore tests are not very fun to write with timestamp checks,
// and these are not values the user may set so we kind of don't care.
//eq = eq && time.Time(r1.CreatedAt).Equal(time.Time(r2.CreatedAt))
@@ -179,35 +186,35 @@ func (r1 *Route) Equals(r2 *Route) bool {
// Update updates fields in r with non-zero field values from new, and sets
// updated_at if any of the fields change. 0-length slice Header values, and
// empty-string Config values trigger removal of map entry.
func (r *Route) Update(new *Route) {
func (r *Route) Update(patch *Route) {
original := r.Clone()
if new.Image != "" {
r.Image = new.Image
if patch.Image != "" {
r.Image = patch.Image
}
if new.Memory != 0 {
r.Memory = new.Memory
if patch.Memory != 0 {
r.Memory = patch.Memory
}
if new.CPUs != 0 {
r.CPUs = new.CPUs
if patch.CPUs != 0 {
r.CPUs = patch.CPUs
}
if new.Type != "" {
r.Type = new.Type
if patch.Type != "" {
r.Type = patch.Type
}
if new.Timeout != 0 {
r.Timeout = new.Timeout
if patch.Timeout != 0 {
r.Timeout = patch.Timeout
}
if new.IdleTimeout != 0 {
r.IdleTimeout = new.IdleTimeout
if patch.IdleTimeout != 0 {
r.IdleTimeout = patch.IdleTimeout
}
if new.Format != "" {
r.Format = new.Format
if patch.Format != "" {
r.Format = patch.Format
}
if new.Headers != nil {
if patch.Headers != nil {
if r.Headers == nil {
r.Headers = Headers(make(http.Header))
}
for k, v := range new.Headers {
for k, v := range patch.Headers {
if len(v) == 0 {
http.Header(r.Headers).Del(k)
} else {
@@ -215,11 +222,11 @@ func (r *Route) Update(new *Route) {
}
}
}
if new.Config != nil {
if patch.Config != nil {
if r.Config == nil {
r.Config = make(Config)
}
for k, v := range new.Config {
for k, v := range patch.Config {
if v == "" {
delete(r.Config, k)
} else {
@@ -228,6 +235,8 @@ func (r *Route) Update(new *Route) {
}
}
r.Annotations = r.Annotations.MergeChange(patch.Annotations)
if !r.Equals(original) {
r.UpdatedAt = strfmt.DateTime(time.Now())
}