@@ -17,30 +17,31 @@ import (
1717
1818 "github.com/home-operations/gatus-sidecar/internal/config"
1919 "github.com/home-operations/gatus-sidecar/internal/endpoint"
20- "github.com/home-operations/gatus-sidecar/internal/handler"
21- "github.com/home-operations/gatus-sidecar/internal/manager"
22- )
23-
24- const (
25- httpsPrefix = "https://"
26- httpPrefix = "http://"
27- httpProtocol = "http"
28- httpsProtocol = "https"
29- dnsTestURL = "1.1.1.1"
30- dnsEmptyBodyCondition = "len([BODY]) == 0"
31- dnsQueryType = "A"
32- ingressCondition = "[STATUS] == 200"
20+ "github.com/home-operations/gatus-sidecar/internal/resources"
21+ "github.com/home-operations/gatus-sidecar/internal/state"
3322)
3423
3524type Controller struct {
3625 gvr schema.GroupVersionResource
3726 options metav1.ListOptions
38- handler handler .ResourceHandler
27+ handler resources .ResourceHandler
3928 convert func (* unstructured.Unstructured ) (metav1.Object , error )
40- stateManager * manager .Manager
29+ stateManager * state .Manager
4130 dynamicClient dynamic.Interface
4231}
4332
33+ // New creates a controller using a ResourceDefinition
34+ func New (definition * resources.ResourceDefinition , stateManager * state.Manager , dynamicClient dynamic.Interface ) * Controller {
35+ return & Controller {
36+ gvr : definition .GVR ,
37+ options : metav1.ListOptions {},
38+ handler : resources .NewHandler (definition , dynamicClient ),
39+ stateManager : stateManager ,
40+ dynamicClient : dynamicClient ,
41+ convert : definition .ConvertFunc ,
42+ }
43+ }
44+
4445func (c * Controller ) GetResource () string {
4546 return c .gvr .Resource
4647}
@@ -227,24 +228,3 @@ func (c *Controller) deepMergeTemplates(parent, child map[string]any) map[string
227228
228229 return result
229230}
230-
231- func hasRequiredAnnotations (obj metav1.Object , cfg * config.Config ) bool {
232- annotations := obj .GetAnnotations ()
233- if annotations == nil {
234- return false
235- }
236-
237- _ , hasEnabledAnnotation := annotations [cfg .EnabledAnnotation ]
238- _ , hasTemplateAnnotation := annotations [cfg .TemplateAnnotation ]
239-
240- return hasEnabledAnnotation || hasTemplateAnnotation
241- }
242-
243- func applyGuardedTemplate (dnsQueryName string , endpoint * endpoint.Endpoint ) {
244- endpoint .URL = dnsTestURL
245- endpoint .DNS = map [string ]any {
246- "query-name" : dnsQueryName ,
247- "query-type" : dnsQueryType ,
248- }
249- endpoint .Conditions = []string {dnsEmptyBodyCondition }
250- }
0 commit comments