-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor SourceApp before adding SourceJob * skip yaml files with wrong kind * start working on ContainerJob * update reconciler * update tests * skip on other kind * update readme * rewrite reconcile test to use t.Run() * remove comments * extend reconcile with job tests * update readme
- Loading branch information
1 parent
5244558
commit 6c9c215
Showing
25 changed files
with
3,202 additions
and
702 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
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,86 @@ | ||
package cache | ||
|
||
import ( | ||
"crypto/md5" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v2" | ||
) | ||
|
||
type JobCacheEntry struct { | ||
modified time.Time | ||
sourceJobHash string | ||
} | ||
|
||
type JobCache map[string]JobCacheEntry | ||
|
||
func NewJobCache() *JobCache { | ||
c := make(JobCache) | ||
return &c | ||
} | ||
|
||
func (c *JobCache) Set(name string, remoteJob, sourceJob *armappcontainers.Job) { | ||
if remoteJob == nil { | ||
return | ||
} | ||
if remoteJob.SystemData == nil { | ||
return | ||
} | ||
|
||
timestamp := remoteJob.SystemData.LastModifiedAt | ||
if timestamp == nil { | ||
if remoteJob.SystemData.CreatedAt == nil { | ||
return | ||
} | ||
timestamp = remoteJob.SystemData.CreatedAt | ||
} | ||
|
||
b, err := sourceJob.MarshalJSON() | ||
if err != nil { | ||
return | ||
} | ||
hash := fmt.Sprintf("%x", md5.Sum(b)) | ||
|
||
(*c)[name] = JobCacheEntry{ | ||
modified: *timestamp, | ||
sourceJobHash: hash, | ||
} | ||
} | ||
|
||
func (c *JobCache) NeedsUpdate(name string, remoteJob, sourceJob *armappcontainers.Job) (bool, string) { | ||
entry, ok := (*c)[name] | ||
if !ok { | ||
return true, "not in JobCache" | ||
} | ||
|
||
if remoteJob == nil { | ||
return true, "remoteJob nil" | ||
} | ||
if remoteJob.SystemData == nil { | ||
return true, "remoteJob SystemData nil" | ||
} | ||
|
||
if remoteJob.SystemData.LastModifiedAt != nil { | ||
if entry.modified != *remoteJob.SystemData.LastModifiedAt { | ||
return true, "changed LastModifiedAt" | ||
} | ||
} else if remoteJob.SystemData.CreatedAt != nil { | ||
if entry.modified != *remoteJob.SystemData.CreatedAt { | ||
return true, "changed CreatedAt" | ||
} | ||
} | ||
|
||
b, err := sourceJob.MarshalJSON() | ||
if err != nil { | ||
return true, "sourceJob MarshalJSON() failed" | ||
} | ||
|
||
hash := fmt.Sprintf("%x", md5.Sum(b)) | ||
|
||
if entry.sourceJobHash != hash { | ||
return true, "changed sourceJob hash" | ||
} | ||
|
||
return false, "no changes" | ||
} |
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.