@@ -69,7 +69,11 @@ const (
69
69
sameZoneAlias = "same-zone"
70
70
// Currently supported up to 10 health checks or hosted zones.
71
71
// https://docs.aws.amazon.com/Route53/latest/APIReference/API_ListTagsForResources.html#API_ListTagsForResources_RequestSyntax
72
- batchSize = 10
72
+ batchSize = 10
73
+ minLatitude = - 90.0
74
+ maxLatitude = 90.0
75
+ minLongitude = - 180.0
76
+ maxLongitude = 180.0
73
77
)
74
78
75
79
// see elb: https://docs.aws.amazon.com/general/latest/gr/elb.html
@@ -235,6 +239,12 @@ type profiledZone struct {
235
239
zone * route53types.HostedZone
236
240
}
237
241
242
+ type geoProximity struct {
243
+ location * route53types.GeoProximityLocation
244
+ endpoint * endpoint.Endpoint
245
+ isSet bool
246
+ }
247
+
238
248
func (cs Route53Changes ) Route53Changes () []route53types.Change {
239
249
var ret []route53types.Change
240
250
for _ , c := range cs {
@@ -868,16 +878,17 @@ func (p *AWSProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) ([]*endpoi
868
878
// if the endpoint is using geoproximity, set the bias to 0 if not set
869
879
// this is needed to avoid unnecessary Upserts if the desired endpoint doesn't specify a bias
870
880
func adjustGeoProximityLocationEndpoint (ep * endpoint.Endpoint ) {
871
- if ep .SetIdentifier != "" {
872
- _ , ok1 := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationAWSRegion )
873
- _ , ok2 := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationLocalZoneGroup )
874
- _ , ok3 := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationCoordinates )
875
-
876
- if ok1 || ok2 || ok3 {
877
- // check if ep has bias property and if not, set it to 0
878
- if _ , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationBias ); ! ok {
879
- ep .SetProviderSpecificProperty (providerSpecificGeoProximityLocationBias , "0" )
880
- }
881
+ if ep .SetIdentifier == "" {
882
+ return
883
+ }
884
+ _ , ok1 := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationAWSRegion )
885
+ _ , ok2 := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationLocalZoneGroup )
886
+ _ , ok3 := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationCoordinates )
887
+
888
+ if ok1 || ok2 || ok3 {
889
+ // check if ep has bias property and if not, set it to 0
890
+ if _ , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationBias ); ! ok {
891
+ ep .SetProviderSpecificProperty (providerSpecificGeoProximityLocationBias , "0" )
881
892
}
882
893
}
883
894
}
@@ -985,78 +996,99 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E
985
996
return change
986
997
}
987
998
988
- func withChangeForGeoProximityEndpoint (change * Route53Change , ep * endpoint.Endpoint ) {
989
- geoproximity := & route53types.GeoProximityLocation {}
990
- isGeoproximity := false
999
+ func newGeoProximity (ep * endpoint.Endpoint ) * geoProximity {
1000
+ return & geoProximity {
1001
+ location : & route53types.GeoProximityLocation {},
1002
+ endpoint : ep ,
1003
+ isSet : false ,
1004
+ }
1005
+ }
991
1006
992
- isGeoproximity = withGeoProximityAWSRegion (ep , geoproximity )
993
- isGeoproximity = isGeoproximity || withGeoProximityCoordinates (ep , geoproximity )
994
- isGeoproximity = isGeoproximity || withGeoProximityLocalZoneGroup (ep , geoproximity )
995
- withGeoProximityBias (ep , geoproximity )
1007
+ func (gp * geoProximity ) withAWSRegion () * geoProximity {
1008
+ if prop , ok := gp .endpoint .GetProviderSpecificProperty (providerSpecificGeoProximityLocationAWSRegion ); ok {
1009
+ gp .location .AWSRegion = aws .String (prop )
1010
+ gp .isSet = true
1011
+ }
1012
+ return gp
1013
+ }
996
1014
997
- if isGeoproximity {
998
- change .ResourceRecordSet .GeoProximityLocation = geoproximity
1015
+ // add a method to set the local zone group for the geoproximity location
1016
+ func (gp * geoProximity ) withLocalZoneGroup () * geoProximity {
1017
+ if prop , ok := gp .endpoint .GetProviderSpecificProperty (providerSpecificGeoProximityLocationLocalZoneGroup ); ok {
1018
+ gp .location .LocalZoneGroup = aws .String (prop )
1019
+ gp .isSet = true
999
1020
}
1021
+ return gp
1000
1022
}
1001
1023
1002
- func withGeoProximityAWSRegion (ep * endpoint.Endpoint , geoproximity * route53types.GeoProximityLocation ) bool {
1003
- if prop , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationAWSRegion ); ok {
1004
- geoproximity .AWSRegion = aws .String (prop )
1005
- return true
1024
+ // add a method to set the bias for the geoproximity location
1025
+ func (gp * geoProximity ) withBias () * geoProximity {
1026
+ if prop , ok := gp .endpoint .GetProviderSpecificProperty (providerSpecificGeoProximityLocationBias ); ok {
1027
+ bias , err := strconv .ParseInt (prop , 10 , 32 )
1028
+ if err != nil {
1029
+ log .Warnf ("Failed parsing value of %s: %s: %v; using bias of 0" , providerSpecificGeoProximityLocationBias , prop , err )
1030
+ bias = 0
1031
+ }
1032
+ gp .location .Bias = aws .Int32 (int32 (bias ))
1033
+ gp .isSet = true
1006
1034
}
1007
- return false
1035
+ return gp
1008
1036
}
1009
1037
1010
1038
// validateCoordinates checks if the given latitude and longitude are valid.
1011
1039
func validateCoordinates (lat , long string ) error {
1012
1040
latitude , err := strconv .ParseFloat (lat , 64 )
1013
- if err != nil || latitude < - 90 || latitude > 90 {
1014
- return errors . New ("invalid latitude: must be a number between -90 and 90" )
1041
+ if err != nil || latitude < minLatitude || latitude > maxLatitude {
1042
+ return fmt . Errorf ("invalid latitude: must be a number between %f and %f" , minLatitude , maxLatitude )
1015
1043
}
1016
1044
1017
1045
longitude , err := strconv .ParseFloat (long , 64 )
1018
- if err != nil || longitude < - 180 || longitude > 180 {
1019
- return errors . New ("invalid longitude: must be a number between -180 and 180" )
1046
+ if err != nil || longitude < minLongitude || longitude > maxLongitude {
1047
+ return fmt . Errorf ("invalid longitude: must be a number between %f and %f" , minLongitude , maxLongitude )
1020
1048
}
1021
1049
1022
1050
return nil
1023
1051
}
1024
1052
1025
- func withGeoProximityCoordinates ( ep * endpoint. Endpoint , geoproximity * route53types. GeoProximityLocation ) bool {
1026
- if prop , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationCoordinates ); ok {
1053
+ func ( gp * geoProximity ) withCoordinates () * geoProximity {
1054
+ if prop , ok := gp . endpoint .GetProviderSpecificProperty (providerSpecificGeoProximityLocationCoordinates ); ok {
1027
1055
coordinates := strings .Split (prop , "," )
1028
1056
if len (coordinates ) == 2 {
1029
1057
latitude := coordinates [0 ]
1030
1058
longitude := coordinates [1 ]
1031
1059
if err := validateCoordinates (latitude , longitude ); err != nil {
1032
- log .Errorf ("Invalid coordinates %s for name=%s setIdentifier=%s; %v" , prop , ep .DNSName , ep .SetIdentifier , err )
1033
- return false
1034
- }
1035
- geoproximity .Coordinates = & route53types.Coordinates {
1036
- Latitude : aws .String (latitude ),
1037
- Longitude : aws .String (longitude ),
1060
+ log .Warnf ("Invalid coordinates %s for name=%s setIdentifier=%s; %v" , prop , gp .endpoint .DNSName , gp .endpoint .SetIdentifier , err )
1061
+ } else {
1062
+ gp .location .Coordinates = & route53types.Coordinates {
1063
+ Latitude : aws .String (latitude ),
1064
+ Longitude : aws .String (longitude ),
1065
+ }
1066
+ gp .isSet = true
1038
1067
}
1039
- return true
1040
1068
} else {
1041
- log .Errorf ("Invalid coordinates format for %s: %s; expected format 'latitude,longitude'" , providerSpecificGeoProximityLocationCoordinates , prop )
1069
+ log .Warnf ("Invalid coordinates format for %s: %s; expected format 'latitude,longitude'" , providerSpecificGeoProximityLocationCoordinates , prop )
1042
1070
}
1043
1071
}
1044
- return false
1072
+ return gp
1045
1073
}
1046
1074
1047
- func withGeoProximityLocalZoneGroup (ep * endpoint.Endpoint , geoproximity * route53types.GeoProximityLocation ) bool {
1048
- if prop , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationLocalZoneGroup ); ok {
1049
- geoproximity .LocalZoneGroup = aws .String (prop )
1050
- return true
1075
+ func (gp * geoProximity ) build () * route53types.GeoProximityLocation {
1076
+ if gp .isSet {
1077
+ return gp .location
1051
1078
}
1052
- return false
1079
+ return nil
1053
1080
}
1054
1081
1055
- func withGeoProximityBias (ep * endpoint.Endpoint , geoproximity * route53types.GeoProximityLocation ) {
1056
- if prop , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationBias ); ok {
1057
- bias , _ := strconv .ParseInt (prop , 10 , 32 )
1058
- geoproximity .Bias = aws .Int32 (int32 (bias ))
1059
- }
1082
+ func withChangeForGeoProximityEndpoint (change * Route53Change , ep * endpoint.Endpoint ) {
1083
+
1084
+ geoProx := newGeoProximity (ep ).
1085
+ withAWSRegion ().
1086
+ withCoordinates ().
1087
+ withLocalZoneGroup ().
1088
+ withBias ()
1089
+
1090
+ change .ResourceRecordSet .GeoProximityLocation = geoProx .build ()
1091
+
1060
1092
}
1061
1093
1062
1094
// searches for `changes` that are contained in `queue` and returns the `changes` separated by whether they were found in the queue (`foundChanges`) or not (`notFoundChanges`)
0 commit comments