Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provider API Update #7

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions api/v1alpha1/provider_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

const (
ProviderSpecificWeight = "weight"
ProviderSpecificGeoCode = "geo-code"
)
6 changes: 3 additions & 3 deletions internal/provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ func (p *Route53DNSProvider) changeForEndpoint(endpoint *v1alpha1.Endpoint, acti
if endpoint.SetIdentifier != "" {
resourceRecordSet.SetIdentifier = aws.String(endpoint.SetIdentifier)
}
if prop, ok := endpoint.GetProviderSpecificProperty(provider.ProviderSpecificWeight); ok {
if prop, ok := endpoint.GetProviderSpecificProperty(v1alpha1.ProviderSpecificWeight); ok {
weight, err := strconv.ParseInt(prop.Value, 10, 64)
if err != nil {
p.logger.Error(err, "Failed parsing value, using weight of 0", "weight", provider.ProviderSpecificWeight, "value", prop.Value)
p.logger.Error(err, "Failed parsing value, using weight of 0", "weight", v1alpha1.ProviderSpecificWeight, "value", prop.Value)
weight = 0
}
resourceRecordSet.Weight = aws.Int64(weight)
Expand All @@ -281,7 +281,7 @@ func (p *Route53DNSProvider) changeForEndpoint(endpoint *v1alpha1.Endpoint, acti
var geolocation = &route53.GeoLocation{}
useGeolocation := false

if prop, ok := endpoint.GetProviderSpecificProperty(provider.ProviderSpecificGeoCode); ok {
if prop, ok := endpoint.GetProviderSpecificProperty(v1alpha1.ProviderSpecificGeoCode); ok {
if provider.IsISO3166Alpha2Code(prop.Value) || prop.Value == "*" {
geolocation.CountryCode = aws.String(prop.Value)
} else {
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/google/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ func toResourceRecordSets(allEndpoints []*v1alpha1.Endpoint) []*dnsv1.ResourceRe
// and contain the same rrdata (weighted or geo), so we can just get that from the first endpoint in the list.
ttl := int64(endpoints[0].RecordTTL)
recordType := endpoints[0].RecordType
_, weighted := endpoints[0].GetProviderSpecificProperty(provider.ProviderSpecificWeight)
_, geoCode := endpoints[0].GetProviderSpecificProperty(provider.ProviderSpecificGeoCode)
_, weighted := endpoints[0].GetProviderSpecificProperty(v1alpha1.ProviderSpecificWeight)
_, geoCode := endpoints[0].GetProviderSpecificProperty(v1alpha1.ProviderSpecificGeoCode)

record := &dnsv1.ResourceRecordSet{
Name: ensureTrailingDot(dnsName),
Expand Down Expand Up @@ -452,7 +452,7 @@ func toResourceRecordSets(allEndpoints []*v1alpha1.Endpoint) []*dnsv1.ResourceRe
record.Rrdatas = targets
}
if weighted {
weightProp, _ := ep.GetProviderSpecificProperty(provider.ProviderSpecificWeight)
weightProp, _ := ep.GetProviderSpecificProperty(v1alpha1.ProviderSpecificWeight)
weight, err := strconv.ParseFloat(weightProp.Value, 64)
if err != nil {
weight = 0
Expand All @@ -464,7 +464,7 @@ func toResourceRecordSets(allEndpoints []*v1alpha1.Endpoint) []*dnsv1.ResourceRe
record.RoutingPolicy.Wrr.Items = append(record.RoutingPolicy.Wrr.Items, item)
}
if geoCode {
geoCodeProp, _ := ep.GetProviderSpecificProperty(provider.ProviderSpecificGeoCode)
geoCodeProp, _ := ep.GetProviderSpecificProperty(v1alpha1.ProviderSpecificGeoCode)
geoCodeValue := geoCodeProp.Value
targetIsDefaultGroup := strings.HasPrefix(ep.Targets[0], v1alpha1.DefaultGeo)
// GCP doesn't accept * as value for default geolocations like AWS does.
Expand Down
5 changes: 0 additions & 5 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import (
"github.com/kuadrant/kuadrant-dns-operator/api/v1alpha1"
)

const (
ProviderSpecificWeight = "weight"
ProviderSpecificGeoCode = "geo-code"
)

// Provider knows how to manage DNS zones only as pertains to routing.
type Provider interface {

Expand Down
Loading