diff --git a/go.mod b/go.mod index dc905f88..1e875d28 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/onsi/gomega v1.32.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.17.0 - github.com/rs/xid v1.5.0 github.com/stretchr/testify v1.9.0 golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f golang.org/x/net v0.26.0 diff --git a/go.sum b/go.sum index a8b7189a..059e370b 100644 --- a/go.sum +++ b/go.sum @@ -167,8 +167,6 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= -github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= diff --git a/internal/provider/aws/aws.go b/internal/provider/aws/aws.go index f99ab8ac..90a3430a 100644 --- a/internal/provider/aws/aws.go +++ b/internal/provider/aws/aws.go @@ -54,10 +54,9 @@ const ( type Route53DNSProvider struct { *externaldnsprovideraws.AWSProvider - awsConfig externaldnsprovideraws.AWSConfig - logger logr.Logger - route53Client *route53.Route53 - healthCheckReconciler provider.HealthCheckReconciler + awsConfig externaldnsprovideraws.AWSConfig + logger logr.Logger + route53Client *route53.Route53 } var _ provider.Provider = &Route53DNSProvider{} @@ -183,14 +182,6 @@ func (p *Route53DNSProvider) DNSZoneForHost(ctx context.Context, host string) (* return provider.FindDNSZoneForHost(ctx, host, zones) } -func (p *Route53DNSProvider) HealthCheckReconciler() provider.HealthCheckReconciler { - if p.healthCheckReconciler == nil { - p.healthCheckReconciler = NewRoute53HealthCheckReconciler(p.route53Client) - } - - return p.healthCheckReconciler -} - func (*Route53DNSProvider) ProviderSpecific() provider.ProviderSpecificLabels { return provider.ProviderSpecificLabels{ Weight: providerSpecificWeight, diff --git a/internal/provider/aws/health.go b/internal/provider/aws/health.go deleted file mode 100644 index f501e3a5..00000000 --- a/internal/provider/aws/health.go +++ /dev/null @@ -1,335 +0,0 @@ -package aws - -import ( - "context" - "errors" - "fmt" - "strings" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/awserr" - "github.com/aws/aws-sdk-go/service/route53" - "github.com/aws/aws-sdk-go/service/route53/route53iface" - "github.com/rs/xid" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - externaldns "sigs.k8s.io/external-dns/endpoint" - - "github.com/kuadrant/dns-operator/api/v1alpha1" - "github.com/kuadrant/dns-operator/internal/provider" -) - -const ( - idTag = "kuadrant.dev/healthcheck" - - defaultHealthCheckPath = "/" - defaultHealthCheckPort = 80 - defaultHealthCheckFailureThreshold = 3 -) - -var ( - callerReference func(id string) *string -) - -type Route53HealthCheckReconciler struct { - client route53iface.Route53API -} - -var _ provider.HealthCheckReconciler = &Route53HealthCheckReconciler{} - -func NewRoute53HealthCheckReconciler(client route53iface.Route53API) *Route53HealthCheckReconciler { - return &Route53HealthCheckReconciler{ - client: client, - } -} - -func getTransitionTime(probeConditions []metav1.Condition, conditionType string, conditionStatus metav1.ConditionStatus) metav1.Time { - for _, c := range probeConditions { - if c.Type == conditionType && c.Status == conditionStatus { - return c.LastTransitionTime - } - } - return metav1.Now() -} - -func (r *Route53HealthCheckReconciler) HealthCheckExists(ctx context.Context, probeStatus *v1alpha1.HealthCheckStatusProbe) (bool, error) { - _, exists, err := r.findHealthCheck(ctx, probeStatus) - return exists, err -} - -func (r *Route53HealthCheckReconciler) Reconcile(ctx context.Context, spec provider.HealthCheckSpec, endpoint *externaldns.Endpoint, probeStatus *v1alpha1.HealthCheckStatusProbe, address string) provider.HealthCheckResult { - healthCheck, exists, err := r.findHealthCheck(ctx, probeStatus) - if err != nil { - lastTransition := metav1.Now() - if probeStatus != nil { - lastTransition = getTransitionTime(probeStatus.Conditions, "ProbeSynced", "False") - } - return provider.HealthCheckResult{ - Result: provider.HealthCheckFailed, - ID: "", - IPAddress: address, - Host: *spec.Host, - Condition: metav1.Condition{ - Type: "ProbeSynced", - Status: "False", - LastTransitionTime: lastTransition, - Reason: "DNSProviderError", - Message: fmt.Sprintf("probe (id: %v, address: %v, host: %v) error recovering existing health check: %v", "", address, *spec.Host, err), - }, - } - } - - if exists { - status, err := r.updateHealthCheck(ctx, spec, endpoint, healthCheck, address) - if err != nil { - return provider.HealthCheckResult{ - Result: provider.HealthCheckFailed, - ID: "", - IPAddress: address, - Host: *spec.Host, - Condition: metav1.Condition{ - Type: "ProbeSynced", - Status: "False", - LastTransitionTime: getTransitionTime(probeStatus.Conditions, "ProbeSynced", "False"), - Reason: "DNSProviderError", - Message: fmt.Sprintf("probe (id: %v, address: %v, host: %v) error updating existing health check: %v", "", address, *spec.Host, err), - }, - } - } - - return provider.NewHealthCheckResult(status, *healthCheck.Id, address, *spec.Host, metav1.Condition{ - Type: "ProbeSynced", - Status: "True", - LastTransitionTime: getTransitionTime(probeStatus.Conditions, "ProbeSynced", "True"), - Reason: "ProbeSyncSuccessful", - Message: fmt.Sprintf("probe (id: %v, address: %v, host: %v) synced successfully", *healthCheck.Id, address, *spec.Host), - }) - } - - healthCheck, err = r.createHealthCheck(ctx, spec, address) - if err != nil { - lastTransition := metav1.Now() - if probeStatus != nil { - lastTransition = getTransitionTime(probeStatus.Conditions, "ProbeSynced", "False") - } - return provider.HealthCheckResult{ - Result: provider.HealthCheckFailed, - ID: "", - IPAddress: address, - Host: *spec.Host, - Condition: metav1.Condition{ - Type: "ProbeSynced", - Status: "False", - LastTransitionTime: lastTransition, - Reason: "DNSProviderError", - Message: fmt.Sprintf("probe (id: %v, address: %v, host: %v) error from DNS Provider: %v", "", address, *spec.Host, err), - }, - } - } - lastTransition := metav1.Now() - if probeStatus != nil { - lastTransition = getTransitionTime(probeStatus.Conditions, "ProbeSynced", "True") - } - return provider.NewHealthCheckResult(provider.HealthCheckCreated, *healthCheck.Id, address, *spec.Host, metav1.Condition{ - Type: "ProbeSynced", - Status: "True", - LastTransitionTime: lastTransition, - Reason: "ProbeSyncSuccessful", - Message: fmt.Sprintf("probe (id: %v, address: %v, host: %v) synced successfully", *healthCheck.Id, address, *spec.Host), - }) -} - -func (r *Route53HealthCheckReconciler) Delete(ctx context.Context, _ *externaldns.Endpoint, probeStatus *v1alpha1.HealthCheckStatusProbe) (provider.HealthCheckResult, error) { - healthCheck, found, err := r.findHealthCheck(ctx, probeStatus) - if err != nil { - var awserror awserr.Error - _ = errors.As(err, &awserror) - if awserror.Code() != route53.ErrCodeNoSuchHealthCheck { - return provider.HealthCheckResult{}, err - } - } - - if !found { - return provider.NewHealthCheckResult(provider.HealthCheckNoop, "", "", "", metav1.Condition{}), nil - } - - _, err = r.client.DeleteHealthCheckWithContext(ctx, &route53.DeleteHealthCheckInput{ - HealthCheckId: healthCheck.Id, - }) - - if err != nil { - return provider.HealthCheckResult{}, err - } - - return provider.NewHealthCheckResult(provider.HealthCheckDeleted, *healthCheck.Id, "", "", metav1.Condition{}), nil -} - -func (r *Route53HealthCheckReconciler) findHealthCheck(ctx context.Context, probeStatus *v1alpha1.HealthCheckStatusProbe) (*route53.HealthCheck, bool, error) { - if probeStatus == nil || probeStatus.ID == "" { - return nil, false, nil - } - - response, err := r.client.GetHealthCheckWithContext(ctx, &route53.GetHealthCheckInput{ - HealthCheckId: &probeStatus.ID, - }) - if err != nil { - return nil, false, err - } - - return response.HealthCheck, true, nil - -} - -func (r *Route53HealthCheckReconciler) createHealthCheck(ctx context.Context, spec provider.HealthCheckSpec, address string) (*route53.HealthCheck, error) { - // Create the health check - output, err := r.client.CreateHealthCheck(&route53.CreateHealthCheckInput{ - - CallerReference: callerReference(spec.Id), - - HealthCheckConfig: &route53.HealthCheckConfig{ - IPAddress: &address, - FullyQualifiedDomainName: spec.Host, - Port: spec.Port, - ResourcePath: &spec.Path, - Type: healthCheckType(spec.Protocol), - FailureThreshold: spec.FailureThreshold, - }, - }) - if err != nil { - return nil, removeMetaData(err) - } - - // Add the tag to identify it - _, err = r.client.ChangeTagsForResourceWithContext(ctx, &route53.ChangeTagsForResourceInput{ - AddTags: []*route53.Tag{ - { - Key: aws.String(idTag), - Value: aws.String(spec.Id), - }, - { - Key: aws.String("Name"), - Value: &spec.Name, - }, - }, - ResourceId: output.HealthCheck.Id, - ResourceType: aws.String(route53.TagResourceTypeHealthcheck), - }) - if err != nil { - return nil, removeMetaData(err) - } - - return output.HealthCheck, nil -} - -func (r *Route53HealthCheckReconciler) updateHealthCheck(ctx context.Context, spec provider.HealthCheckSpec, endpoint *externaldns.Endpoint, healthCheck *route53.HealthCheck, address string) (provider.HealthCheckReconciliationResult, error) { - diff := healthCheckDiff(healthCheck, spec, endpoint, address) - if diff == nil { - return provider.HealthCheckNoop, nil - } - - _, err := r.client.UpdateHealthCheckWithContext(ctx, diff) - if err != nil { - return provider.HealthCheckFailed, removeMetaData(err) - } - - return provider.HealthCheckUpdated, nil -} - -// removeMetaData from the error responses to the API -// this is janky, but without removing this data, the constantly -// changing request ID and other data in the response causes -// our controller to never stop writing the status update -func removeMetaData(originalError error) error { - if awsErr, ok := originalError.(awserr.Error); ok { - chunks := strings.Split(awsErr.Message(), ":") - newErr := strings.TrimSpace(strings.ReplaceAll(chunks[len(chunks)-1], "'", "")) - return errors.New(newErr) - } - return originalError -} - -// healthCheckDiff creates a `UpdateHealthCheckInput` object with the fields to -// update on healthCheck based on the given spec. -// If the health check matches the spec, returns `nil` -func healthCheckDiff(healthCheck *route53.HealthCheck, spec provider.HealthCheckSpec, endpoint *externaldns.Endpoint, address string) *route53.UpdateHealthCheckInput { - var result *route53.UpdateHealthCheckInput - - // "Lazily" set the value for result only once and only when there is - // a change, to ensure that it's nil if there's no change - diff := func() *route53.UpdateHealthCheckInput { - if result == nil { - result = &route53.UpdateHealthCheckInput{ - HealthCheckId: healthCheck.Id, - } - } - - return result - } - - if !valuesEqual(&endpoint.DNSName, healthCheck.HealthCheckConfig.FullyQualifiedDomainName) { - diff().FullyQualifiedDomainName = spec.Host - } - - if !valuesEqual(&address, healthCheck.HealthCheckConfig.IPAddress) { - diff().IPAddress = &address - } - if !valuesEqualWithDefault(&spec.Path, healthCheck.HealthCheckConfig.ResourcePath, defaultHealthCheckPath) { - diff().ResourcePath = &spec.Path - } - if !valuesEqualWithDefault(spec.Port, healthCheck.HealthCheckConfig.Port, defaultHealthCheckPort) { - diff().Port = spec.Port - } - if !valuesEqualWithDefault(spec.FailureThreshold, healthCheck.HealthCheckConfig.FailureThreshold, defaultHealthCheckFailureThreshold) { - diff().FailureThreshold = spec.FailureThreshold - } - - return result -} - -func init() { - sid := xid.New() - callerReference = func(s string) *string { - return aws.String(fmt.Sprintf("%s.%s", s, sid)) - } -} - -func healthCheckType(protocol *provider.HealthCheckProtocol) *string { - if protocol == nil { - return nil - } - - switch *protocol { - case provider.HealthCheckProtocolHTTP: - return aws.String(route53.HealthCheckTypeHttp) - - case provider.HealthCheckProtocolHTTPS: - return aws.String(route53.HealthCheckTypeHttps) - } - - return nil -} - -func valuesEqual[T comparable](ptr1, ptr2 *T) bool { - if (ptr1 == nil && ptr2 != nil) || (ptr1 != nil && ptr2 == nil) { - return false - } - if ptr1 == nil && ptr2 == nil { - return true - } - - return *ptr1 == *ptr2 -} - -func valuesEqualWithDefault[T comparable](ptr1, ptr2 *T, defaultValue T) bool { - value1 := defaultValue - if ptr1 != nil { - value1 = *ptr1 - } - - value2 := defaultValue - if ptr2 != nil { - value2 = *ptr2 - } - - return value1 == value2 -} diff --git a/internal/provider/aws/health_test.go b/internal/provider/aws/health_test.go deleted file mode 100644 index d27c7a50..00000000 --- a/internal/provider/aws/health_test.go +++ /dev/null @@ -1,115 +0,0 @@ -//go:build unit - -package aws - -import ( - "errors" - "testing" - "time" - - "github.com/aws/aws-sdk-go/aws/awserr" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func TestRemoveMetaData(t *testing.T) { - tests := []struct { - Name string - Error error - Validate func(*testing.T, error) - }{ - { - Name: "AWS error is trimmed", - Error: awserr.NewRequestFailure( - awserr.New( - "InvalidInput", - "Invalid XML ; javax.xml.stream.XMLStreamException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 140; cvc-datatype-valid.1.2.3: 'test.external.com' is not a valid value of union type 'IPAddress'", - nil), - 400, - "a887212e-60fe-4dab-8075-ea7b09f604dc"), - Validate: func(t *testing.T, err error) { - expected := "test.external.com is not a valid value of union type IPAddress" - if err.Error() != expected { - t.Fatalf("expected '%v', got '%v'", expected, err.Error()) - } - }, - }, - { - Name: "non AWS error is unaffected", - Error: errors.New("unrelated error"), - Validate: func(t *testing.T, err error) { - if err.Error() != "unrelated error" { - t.Fatalf("expected '%v' got '%v'", "unrelated error", err.Error()) - } - }, - }, - } - for _, tt := range tests { - t.Run(tt.Name, func(t *testing.T) { - err := removeMetaData(tt.Error) - tt.Validate(t, err) - }) - } -} - -func TestGetTransitionTime(t *testing.T) { - tests := []struct { - Name string - Conditions []metav1.Condition - Type string - Status metav1.ConditionStatus - Validate func(*testing.T, metav1.Time) - }{ - { - Name: "Transition time is now with no existing condition", - Conditions: []metav1.Condition{}, - Type: "expectedType", - Status: metav1.ConditionStatus("expectedStatus"), - Validate: func(t *testing.T, timeVal metav1.Time) { - if timeVal.Unix() != metav1.Now().Unix() { - t.Fatalf("expected '%v' got '%v'", metav1.Now(), timeVal) - } - }, - }, - { - Name: "Transition time is preserved with existing condition", - Conditions: []metav1.Condition{ - { - Type: "expectedType", - Status: "expectedStatus", - LastTransitionTime: metav1.NewTime(time.Now().Add(time.Duration(-5) * time.Second)), - }, - }, - Type: "expectedType", - Status: metav1.ConditionStatus("expectedStatus"), - Validate: func(t *testing.T, timeVal metav1.Time) { - if timeVal.Unix() != metav1.NewTime(time.Now().Add(time.Duration(-5)*time.Second)).Unix() { - t.Fatalf("expected '%v' got '%v'", metav1.NewTime(time.Now().Add(time.Duration(-5)*time.Second)), timeVal) - } - }, - }, - { - Name: "Transition time is updated with existing condition and changed status", - Conditions: []metav1.Condition{ - { - Type: "expectedType", - Status: "unexpectedStatus", - LastTransitionTime: metav1.NewTime(time.Now().Add(time.Duration(-5) * time.Second)), - }, - }, - Type: "expectedType", - Status: metav1.ConditionStatus("expectedStatus"), - Validate: func(t *testing.T, timeVal metav1.Time) { - if timeVal.Unix() != metav1.Now().Unix() { - t.Fatalf("expected '%v' got '%v'", metav1.NewTime(time.Now().Add(time.Duration(-5)*time.Second)), timeVal) - } - }, - }, - } - for _, tt := range tests { - t.Run(tt.Name, func(t *testing.T) { - time := getTransitionTime(tt.Conditions, tt.Type, tt.Status) - tt.Validate(t, time) - }) - } -} diff --git a/internal/provider/azure/azure.go b/internal/provider/azure/azure.go index cca090f4..825cbd18 100644 --- a/internal/provider/azure/azure.go +++ b/internal/provider/azure/azure.go @@ -100,10 +100,6 @@ func (p *AzureProvider) DNSZoneForHost(ctx context.Context, host string) (*provi return provider.FindDNSZoneForHost(ctx, host, zones) } -func (p *AzureProvider) HealthCheckReconciler() provider.HealthCheckReconciler { - return NewAzureHealthCheckReconciler() -} - func (p *AzureProvider) ProviderSpecific() provider.ProviderSpecificLabels { return provider.ProviderSpecificLabels{} } diff --git a/internal/provider/azure/health.go b/internal/provider/azure/health.go deleted file mode 100644 index 4b418656..00000000 --- a/internal/provider/azure/health.go +++ /dev/null @@ -1,31 +0,0 @@ -package azure - -import ( - "context" - - externaldns "sigs.k8s.io/external-dns/endpoint" - - "github.com/kuadrant/dns-operator/api/v1alpha1" - "github.com/kuadrant/dns-operator/internal/provider" -) - -type AzureHealthCheckReconciler struct { -} - -var _ provider.HealthCheckReconciler = &AzureHealthCheckReconciler{} - -func NewAzureHealthCheckReconciler() *AzureHealthCheckReconciler { - return &AzureHealthCheckReconciler{} -} - -func (r *AzureHealthCheckReconciler) HealthCheckExists(_ context.Context, _ *v1alpha1.HealthCheckStatusProbe) (bool, error) { - return true, nil -} - -func (r *AzureHealthCheckReconciler) Reconcile(_ context.Context, _ provider.HealthCheckSpec, _ *externaldns.Endpoint, _ *v1alpha1.HealthCheckStatusProbe, _ string) provider.HealthCheckResult { - return provider.HealthCheckResult{} -} - -func (r *AzureHealthCheckReconciler) Delete(_ context.Context, _ *externaldns.Endpoint, _ *v1alpha1.HealthCheckStatusProbe) (provider.HealthCheckResult, error) { - return provider.HealthCheckResult{}, nil -} diff --git a/internal/provider/cached.go b/internal/provider/cached.go deleted file mode 100644 index 1cde53d9..00000000 --- a/internal/provider/cached.go +++ /dev/null @@ -1,73 +0,0 @@ -package provider - -import ( - "context" - "reflect" - "sync" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - externaldns "sigs.k8s.io/external-dns/endpoint" - - "github.com/kuadrant/dns-operator/api/v1alpha1" -) - -type CachedHealthCheckReconciler struct { - reconciler HealthCheckReconciler - provider Provider - - syncCache *sync.Map -} - -var _ HealthCheckReconciler = &CachedHealthCheckReconciler{} - -func NewCachedHealthCheckReconciler(provider Provider, reconciler HealthCheckReconciler) *CachedHealthCheckReconciler { - return &CachedHealthCheckReconciler{ - reconciler: reconciler, - provider: provider, - syncCache: &sync.Map{}, - } -} - -func (r *CachedHealthCheckReconciler) HealthCheckExists(ctx context.Context, probeStatus *v1alpha1.HealthCheckStatusProbe) (bool, error) { - return r.reconciler.HealthCheckExists(ctx, probeStatus) -} - -// Delete implements HealthCheckReconciler -func (r *CachedHealthCheckReconciler) Delete(ctx context.Context, endpoint *externaldns.Endpoint, probeStatus *v1alpha1.HealthCheckStatusProbe) (HealthCheckResult, error) { - id, ok := r.getHealthCheckID(endpoint) - if !ok { - return NewHealthCheckResult(HealthCheckNoop, "", "", "", metav1.Condition{}), nil - } - - defer r.syncCache.Delete(id) - return r.reconciler.Delete(ctx, endpoint, probeStatus) -} - -// Reconcile implements HealthCheckReconciler -func (r *CachedHealthCheckReconciler) Reconcile(ctx context.Context, spec HealthCheckSpec, endpoint *externaldns.Endpoint, probeStatus *v1alpha1.HealthCheckStatusProbe, address string) HealthCheckResult { - id, ok := r.getHealthCheckID(endpoint) - if !ok { - return r.reconciler.Reconcile(ctx, spec, endpoint, probeStatus, address) - } - - // Update the cache with the new spec - defer r.syncCache.Store(id, spec) - - // If the health heck is not cached, delegate the reconciliation - existingSpec, ok := r.syncCache.Load(id) - if !ok { - return r.reconciler.Reconcile(ctx, spec, endpoint, probeStatus, address) - } - - // If the spec is unchanged, return Noop - if reflect.DeepEqual(spec, existingSpec.(HealthCheckSpec)) { - return NewHealthCheckResult(HealthCheckNoop, id, "", "", metav1.Condition{Message: "spec unchanged"}) - } - - // Otherwise, delegate the reconciliation - return r.reconciler.Reconcile(ctx, spec, endpoint, probeStatus, address) -} - -func (r *CachedHealthCheckReconciler) getHealthCheckID(endpoint *externaldns.Endpoint) (string, bool) { - return endpoint.GetProviderSpecificProperty(r.provider.ProviderSpecific().HealthCheckID) -} diff --git a/internal/provider/fake.go b/internal/provider/fake.go deleted file mode 100644 index c18c14c0..00000000 --- a/internal/provider/fake.go +++ /dev/null @@ -1,25 +0,0 @@ -package provider - -import ( - "context" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - externaldns "sigs.k8s.io/external-dns/endpoint" - - "github.com/kuadrant/dns-operator/api/v1alpha1" -) - -type FakeHealthCheckReconciler struct{} - -func (*FakeHealthCheckReconciler) HealthCheckExists(ctx context.Context, probeStatus *v1alpha1.HealthCheckStatusProbe) (bool, error) { - return true, nil -} -func (*FakeHealthCheckReconciler) Reconcile(_ context.Context, _ HealthCheckSpec, _ *externaldns.Endpoint, _ *v1alpha1.HealthCheckStatusProbe, _ string) HealthCheckResult { - return HealthCheckResult{HealthCheckCreated, "fakeID", "", "", metav1.Condition{}} -} - -func (*FakeHealthCheckReconciler) Delete(_ context.Context, _ *externaldns.Endpoint, _ *v1alpha1.HealthCheckStatusProbe) (HealthCheckResult, error) { - return HealthCheckResult{HealthCheckDeleted, "fakeID", "", "", metav1.Condition{}}, nil -} - -var _ HealthCheckReconciler = &FakeHealthCheckReconciler{} diff --git a/internal/provider/google/google.go b/internal/provider/google/google.go index cb8755c4..9a6961aa 100644 --- a/internal/provider/google/google.go +++ b/internal/provider/google/google.go @@ -322,10 +322,6 @@ func (p *GoogleDNSProvider) DNSZoneForHost(ctx context.Context, host string) (*p return provider.FindDNSZoneForHost(ctx, host, zones) } -func (p *GoogleDNSProvider) HealthCheckReconciler() provider.HealthCheckReconciler { - return NewGCPHealthCheckReconciler() -} - func (p *GoogleDNSProvider) ProviderSpecific() provider.ProviderSpecificLabels { return provider.ProviderSpecificLabels{} } diff --git a/internal/provider/google/health.go b/internal/provider/google/health.go deleted file mode 100644 index f6363657..00000000 --- a/internal/provider/google/health.go +++ /dev/null @@ -1,31 +0,0 @@ -package google - -import ( - "context" - - externaldns "sigs.k8s.io/external-dns/endpoint" - - "github.com/kuadrant/dns-operator/api/v1alpha1" - "github.com/kuadrant/dns-operator/internal/provider" -) - -type GCPHealthCheckReconciler struct { -} - -var _ provider.HealthCheckReconciler = &GCPHealthCheckReconciler{} - -func NewGCPHealthCheckReconciler() *GCPHealthCheckReconciler { - return &GCPHealthCheckReconciler{} -} - -func (r *GCPHealthCheckReconciler) HealthCheckExists(_ context.Context, _ *v1alpha1.HealthCheckStatusProbe) (bool, error) { - return true, nil -} - -func (r *GCPHealthCheckReconciler) Reconcile(_ context.Context, _ provider.HealthCheckSpec, _ *externaldns.Endpoint, _ *v1alpha1.HealthCheckStatusProbe, _ string) provider.HealthCheckResult { - return provider.HealthCheckResult{} -} - -func (r *GCPHealthCheckReconciler) Delete(_ context.Context, _ *externaldns.Endpoint, _ *v1alpha1.HealthCheckStatusProbe) (provider.HealthCheckResult, error) { - return provider.HealthCheckResult{}, nil -} diff --git a/internal/provider/health.go b/internal/provider/health.go deleted file mode 100644 index de9e8f9f..00000000 --- a/internal/provider/health.go +++ /dev/null @@ -1,59 +0,0 @@ -package provider - -import ( - "context" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - externaldns "sigs.k8s.io/external-dns/endpoint" - - "github.com/kuadrant/dns-operator/api/v1alpha1" -) - -type HealthCheckReconciler interface { - Reconcile(ctx context.Context, spec HealthCheckSpec, endpoint *externaldns.Endpoint, probeStatus *v1alpha1.HealthCheckStatusProbe, address string) HealthCheckResult - Delete(ctx context.Context, endpoint *externaldns.Endpoint, probeStatus *v1alpha1.HealthCheckStatusProbe) (HealthCheckResult, error) - HealthCheckExists(ctx context.Context, probeStatus *v1alpha1.HealthCheckStatusProbe) (bool, error) -} - -type HealthCheckSpec struct { - Id string - Name string - Port *int64 - FailureThreshold *int64 - Protocol *HealthCheckProtocol - Host *string - Path string -} - -type HealthCheckResult struct { - Result HealthCheckReconciliationResult - ID string - IPAddress string - Host string - Condition metav1.Condition -} - -func NewHealthCheckResult(result HealthCheckReconciliationResult, id, ipaddress, host string, condition metav1.Condition) HealthCheckResult { - return HealthCheckResult{ - Result: result, - Condition: condition, - ID: id, - IPAddress: ipaddress, - Host: host, - } -} - -type HealthCheckReconciliationResult string - -const ( - HealthCheckCreated HealthCheckReconciliationResult = "Created" - HealthCheckUpdated HealthCheckReconciliationResult = "Updated" - HealthCheckDeleted HealthCheckReconciliationResult = "Deleted" - HealthCheckNoop HealthCheckReconciliationResult = "Noop" - HealthCheckFailed HealthCheckReconciliationResult = "Failed" -) - -type HealthCheckProtocol string - -const HealthCheckProtocolHTTP HealthCheckProtocol = "HTTP" -const HealthCheckProtocolHTTPS HealthCheckProtocol = "HTTPS" diff --git a/internal/provider/inmemory/inmemory.go b/internal/provider/inmemory/inmemory.go index 163b0f8e..1f9efb96 100644 --- a/internal/provider/inmemory/inmemory.go +++ b/internal/provider/inmemory/inmemory.go @@ -90,10 +90,6 @@ func (p *InMemoryDNSProvider) DNSZoneForHost(ctx context.Context, host string) ( return provider.FindDNSZoneForHost(ctx, host, zones) } -func (i *InMemoryDNSProvider) HealthCheckReconciler() provider.HealthCheckReconciler { - return &provider.FakeHealthCheckReconciler{} -} - func (i *InMemoryDNSProvider) ProviderSpecific() provider.ProviderSpecificLabels { return provider.ProviderSpecificLabels{} } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 6f519573..edd66aed 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -33,9 +33,6 @@ type Provider interface { // DNSZoneForHost returns the DNSZone that best matches the given host in the providers list of zones DNSZoneForHost(ctx context.Context, host string) (*DNSZone, error) - // HealthCheckReconciler Get an instance of HealthCheckReconciler for this provider - HealthCheckReconciler() HealthCheckReconciler - ProviderSpecific() ProviderSpecificLabels }