Skip to content

Commit 70ce314

Browse files
Implement Equals function using TestTags (#3)
* WIP add config option * Update controller-gen version Fixes the broken v0.9 of controller-gen because it causes a segfault when running `make install` * Update formatting for base CRDS * Working read secret * Fixed read secret * Use new secret function not client function * Revert random formatting changes * More stupid formatting fixes * Final formatting fixes I don't like formatting :( * Small fixes and docs update * Update example * Update CRDs * Add raw_post_data var to statuscake * Add user_agent var to statuscake * Update formatting for user_agent * Fix tabs in statuscake-monitor.go * Update base crds * Docs and example update * Update CRDs * Implement Equals function using TestTags It is mentioned in a comment in the code itself but because of the discrepency between the fields in the EndpointMonitor CR and the Statuscake API it is not immediately clear how to compare an old monitor with an updated monitor. The way I have elected to check this is to use the TestTags field to include some kind of identifier that should be updated on any change. So if the tags have changed then the monitor should be updated.
1 parent b97444a commit 70ce314

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

pkg/monitors/statuscake/statuscake-mappers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package statuscake
22

33
import (
4+
"strings"
5+
46
statuscake "github.com/StatusCakeDev/statuscake-go"
7+
endpointmonitorv1alpha1 "github.com/stakater/IngressMonitorController/v2/api/v1alpha1"
58
"github.com/stakater/IngressMonitorController/v2/pkg/models"
69
)
710

@@ -11,6 +14,10 @@ func StatusCakeMonitorMonitorToBaseMonitorMapper(statuscakeData StatusCakeMonito
1114
m.Name = statuscakeData.WebsiteName
1215
m.URL = statuscakeData.WebsiteURL
1316
m.ID = statuscakeData.TestID
17+
18+
var providerConfig endpointmonitorv1alpha1.StatusCakeConfig
19+
providerConfig.TestTags = strings.Join(statuscakeData.Tags, ",")
20+
m.Config = &providerConfig
1421
return &m
1522
}
1623

@@ -20,6 +27,10 @@ func StatusCakeApiResponseDataToBaseMonitorMapper(statuscakeData statuscake.Upti
2027
m.Name = statuscakeData.Data.Name
2128
m.URL = statuscakeData.Data.WebsiteURL
2229
m.ID = statuscakeData.Data.ID
30+
31+
var providerConfig endpointmonitorv1alpha1.StatusCakeConfig
32+
providerConfig.TestTags = strings.Join(statuscakeData.Data.Tags, ",")
33+
m.Config = &providerConfig
2334
return &m
2435
}
2536

pkg/monitors/statuscake/statuscake-monitor.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ type StatusCakeMonitorService struct {
3434
}
3535

3636
func (monitor *StatusCakeMonitorService) Equal(oldMonitor models.Monitor, newMonitor models.Monitor) bool {
37-
// TODO: Retrieve oldMonitor config and compare it here
38-
return false
37+
// Since there is a discrepency between the fields in the endpointmonitor CR and the statuscake API
38+
// use the tags to define a last updated by tags. This ensures we are not ratelimited by statuscake.
39+
oldConf := oldMonitor.Config.(*endpointmonitorv1alpha1.StatusCakeConfig)
40+
newConf := newMonitor.Config.(*endpointmonitorv1alpha1.StatusCakeConfig)
41+
if oldConf.TestTags != newConf.TestTags {
42+
msg := "Found a difference between the old TestTags and new TestTags. Updating the UptimeCheck..."
43+
log.Info(msg, "Old Tags", oldConf.TestTags, "New Tags", newConf.TestTags)
44+
return false
45+
} else {
46+
return true
47+
}
3948
}
4049

4150
// buildUpsertForm function is used to create the form needed to Add or update a monitor
@@ -219,15 +228,15 @@ func buildUpsertForm(m models.Monitor, cgroup string) url.Values {
219228
if providerConfig != nil && providerConfig.Confirmation > 0 {
220229
f.Add("confirmation", strconv.Itoa(providerConfig.Confirmation))
221230
}
222-
if providerConfig != nil {
231+
if providerConfig != nil && len(providerConfig.FindString) > 0 {
223232
f.Add("find_string", providerConfig.FindString)
224233
}
225234
if providerConfig != nil && len(providerConfig.RawPostData) > 0 {
226235
f.Add("post_raw", providerConfig.RawPostData)
227236
}
228-
if providerConfig != nil && len(providerConfig.UserAgent) > 0 {
229-
f.Add("user_agent", providerConfig.UserAgent)
230-
}
237+
if providerConfig != nil && len(providerConfig.UserAgent) > 0 {
238+
f.Add("user_agent", providerConfig.UserAgent)
239+
}
231240
return f
232241
}
233242

0 commit comments

Comments
 (0)