mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 04:40:05 +01:00
fix: improve dns error logging
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -4164,6 +4164,42 @@ paths:
|
|||||||
external deletion policy)
|
external deletion policy)
|
||||||
tags:
|
tags:
|
||||||
- DNS
|
- DNS
|
||||||
|
get:
|
||||||
|
operationId: GetRecordSet
|
||||||
|
parameters:
|
||||||
|
- description: Organization UUID
|
||||||
|
in: header
|
||||||
|
name: X-Org-ID
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
- description: Record Set ID (UUID)
|
||||||
|
in: path
|
||||||
|
name: id
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/dto.RecordSetResponse'
|
||||||
|
description: OK
|
||||||
|
"403":
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
description: organization required
|
||||||
|
"404":
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
description: not found
|
||||||
|
summary: Get a record set (org scoped)
|
||||||
|
tags:
|
||||||
|
- DNS
|
||||||
patch:
|
patch:
|
||||||
operationId: UpdateRecordSet
|
operationId: UpdateRecordSet
|
||||||
parameters:
|
parameters:
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -9,6 +9,7 @@ require (
|
|||||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.6
|
github.com/aws/aws-sdk-go-v2/credentials v1.19.6
|
||||||
github.com/aws/aws-sdk-go-v2/service/route53 v1.62.0
|
github.com/aws/aws-sdk-go-v2/service/route53 v1.62.0
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.94.0
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.94.0
|
||||||
|
github.com/aws/smithy-go v1.24.0
|
||||||
github.com/coreos/go-oidc/v3 v3.17.0
|
github.com/coreos/go-oidc/v3 v3.17.0
|
||||||
github.com/dyaksa/archer v1.1.5
|
github.com/dyaksa/archer v1.1.5
|
||||||
github.com/fergusstrange/embedded-postgres v1.33.0
|
github.com/fergusstrange/embedded-postgres v1.33.0
|
||||||
@@ -52,7 +53,6 @@ require (
|
|||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.8 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sso v1.30.8 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12 // indirect
|
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.41.5 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sts v1.41.5 // indirect
|
||||||
github.com/aws/smithy-go v1.24.0 // indirect
|
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/bytedance/sonic v1.14.0 // indirect
|
github.com/bytedance/sonic v1.14.0 // indirect
|
||||||
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
||||||
|
|||||||
16
go.sum
16
go.sum
@@ -14,12 +14,8 @@ github.com/aws/aws-sdk-go-v2 v1.41.0 h1:tNvqh1s+v0vFYdA1xq0aOJH+Y5cRyZ5upu6roPgP
|
|||||||
github.com/aws/aws-sdk-go-v2 v1.41.0/go.mod h1:MayyLB8y+buD9hZqkCW3kX1AKq07Y5pXxtgB+rRFhz0=
|
github.com/aws/aws-sdk-go-v2 v1.41.0/go.mod h1:MayyLB8y+buD9hZqkCW3kX1AKq07Y5pXxtgB+rRFhz0=
|
||||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 h1:489krEF9xIGkOaaX3CE/Be2uWjiXrkCH6gUX+bZA/BU=
|
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 h1:489krEF9xIGkOaaX3CE/Be2uWjiXrkCH6gUX+bZA/BU=
|
||||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4/go.mod h1:IOAPF6oT9KCsceNTvvYMNHy0+kMF8akOjeDvPENWxp4=
|
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4/go.mod h1:IOAPF6oT9KCsceNTvvYMNHy0+kMF8akOjeDvPENWxp4=
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.32.5 h1:pz3duhAfUgnxbtVhIK39PGF/AHYyrzGEyRD9Og0QrE8=
|
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.32.5/go.mod h1:xmDjzSUs/d0BB7ClzYPAZMmgQdrodNjPPhd6bGASwoE=
|
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.32.6 h1:hFLBGUKjmLAekvi1evLi5hVvFQtSo3GYwi+Bx4lpJf8=
|
github.com/aws/aws-sdk-go-v2/config v1.32.6 h1:hFLBGUKjmLAekvi1evLi5hVvFQtSo3GYwi+Bx4lpJf8=
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.32.6/go.mod h1:lcUL/gcd8WyjCrMnxez5OXkO3/rwcNmvfno62tnXNcI=
|
github.com/aws/aws-sdk-go-v2/config v1.32.6/go.mod h1:lcUL/gcd8WyjCrMnxez5OXkO3/rwcNmvfno62tnXNcI=
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.5 h1:xMo63RlqP3ZZydpJDMBsH9uJ10hgHYfQFIk1cHDXrR4=
|
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.5/go.mod h1:hhbH6oRcou+LpXfA/0vPElh/e0M3aFeOblE1sssAAEk=
|
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.6 h1:F9vWao2TwjV2MyiyVS+duza0NIRtAslgLUM0vTA1ZaE=
|
github.com/aws/aws-sdk-go-v2/credentials v1.19.6 h1:F9vWao2TwjV2MyiyVS+duza0NIRtAslgLUM0vTA1ZaE=
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.6/go.mod h1:SgHzKjEVsdQr6Opor0ihgWtkWdfRAIwxYzSJ8O85VHY=
|
github.com/aws/aws-sdk-go-v2/credentials v1.19.6/go.mod h1:SgHzKjEVsdQr6Opor0ihgWtkWdfRAIwxYzSJ8O85VHY=
|
||||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.16 h1:80+uETIWS1BqjnN9uJ0dBUaETh+P1XwFy5vwHwK5r9k=
|
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.16 h1:80+uETIWS1BqjnN9uJ0dBUaETh+P1XwFy5vwHwK5r9k=
|
||||||
@@ -42,14 +38,10 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.16 h1:NSbvS17MlI2lu
|
|||||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.16/go.mod h1:SwT8Tmqd4sA6G1qaGdzWCJN99bUmPGHfRwwq3G5Qb+A=
|
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.16/go.mod h1:SwT8Tmqd4sA6G1qaGdzWCJN99bUmPGHfRwwq3G5Qb+A=
|
||||||
github.com/aws/aws-sdk-go-v2/service/route53 v1.62.0 h1:80pDB3Tpmb2RCSZORrK9/3iQxsd+w6vSzVqpT1FGiwE=
|
github.com/aws/aws-sdk-go-v2/service/route53 v1.62.0 h1:80pDB3Tpmb2RCSZORrK9/3iQxsd+w6vSzVqpT1FGiwE=
|
||||||
github.com/aws/aws-sdk-go-v2/service/route53 v1.62.0/go.mod h1:6EZUGGNLPLh5Unt30uEoA+KQcByERfXIkax9qrc80nA=
|
github.com/aws/aws-sdk-go-v2/service/route53 v1.62.0/go.mod h1:6EZUGGNLPLh5Unt30uEoA+KQcByERfXIkax9qrc80nA=
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.93.2 h1:U3ygWUhCpiSPYSHOrRhb3gOl9T5Y3kB8k5Vjs//57bE=
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.93.2/go.mod h1:79S2BdqCJpScXZA2y+cpZuocWsjGjJINyXnOsf5DTz8=
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.94.0 h1:SWTxh/EcUCDVqi/0s26V6pVUq0BBG7kx0tDTmF/hCgA=
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.94.0 h1:SWTxh/EcUCDVqi/0s26V6pVUq0BBG7kx0tDTmF/hCgA=
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.94.0/go.mod h1:79S2BdqCJpScXZA2y+cpZuocWsjGjJINyXnOsf5DTz8=
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.94.0/go.mod h1:79S2BdqCJpScXZA2y+cpZuocWsjGjJINyXnOsf5DTz8=
|
||||||
github.com/aws/aws-sdk-go-v2/service/signin v1.0.4 h1:HpI7aMmJ+mm1wkSHIA2t5EaFFv5EFYXePW30p1EIrbQ=
|
github.com/aws/aws-sdk-go-v2/service/signin v1.0.4 h1:HpI7aMmJ+mm1wkSHIA2t5EaFFv5EFYXePW30p1EIrbQ=
|
||||||
github.com/aws/aws-sdk-go-v2/service/signin v1.0.4/go.mod h1:C5RdGMYGlfM0gYq/tifqgn4EbyX99V15P2V3R+VHbQU=
|
github.com/aws/aws-sdk-go-v2/service/signin v1.0.4/go.mod h1:C5RdGMYGlfM0gYq/tifqgn4EbyX99V15P2V3R+VHbQU=
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.7 h1:eYnlt6QxnFINKzwxP5/Ucs1vkG7VT3Iezmvfgc2waUw=
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.7/go.mod h1:+fWt2UHSb4kS7Pu8y+BMBvJF0EWx+4H0hzNwtDNRTrg=
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.8 h1:aM/Q24rIlS3bRAhTyFurowU8A0SMyGDtEOY/l/s/1Uw=
|
github.com/aws/aws-sdk-go-v2/service/sso v1.30.8 h1:aM/Q24rIlS3bRAhTyFurowU8A0SMyGDtEOY/l/s/1Uw=
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.8/go.mod h1:+fWt2UHSb4kS7Pu8y+BMBvJF0EWx+4H0hzNwtDNRTrg=
|
github.com/aws/aws-sdk-go-v2/service/sso v1.30.8/go.mod h1:+fWt2UHSb4kS7Pu8y+BMBvJF0EWx+4H0hzNwtDNRTrg=
|
||||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12 h1:AHDr0DaHIAo8c9t1emrzAlVDFp+iMMKnPdYy6XO4MCE=
|
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12 h1:AHDr0DaHIAo8c9t1emrzAlVDFp+iMMKnPdYy6XO4MCE=
|
||||||
@@ -87,10 +79,6 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
|
|||||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.10 h1:zyueNbySn/z8mJZHLt6IPw0KoZsiQNszIpU+bX4+ZK0=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.10/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.11 h1:AQvxbp830wPhHTqc1u7nzoLT+ZFxGY7emj5DR5DYFik=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.11/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
github.com/gabriel-vasile/mimetype v1.4.12/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||||
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
|
github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=
|
||||||
@@ -124,10 +112,6 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
|
|||||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||||
github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0ktULL6FgHdG688=
|
|
||||||
github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU=
|
|
||||||
github.com/go-playground/validator/v10 v10.29.0 h1:lQlF5VNJWNlRbRZNeOIkWElR+1LL/OuHcc0Kp14w1xk=
|
|
||||||
github.com/go-playground/validator/v10 v10.29.0/go.mod h1:D6QxqeMlgIPuT02L66f2ccrZ7AGgHkzKmmTMZhk/Kc4=
|
|
||||||
github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w=
|
github.com/go-playground/validator/v10 v10.30.1 h1:f3zDSN/zOma+w6+1Wswgd9fLkdwy06ntQJp0BBvFG0w=
|
||||||
github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
|
github.com/go-playground/validator/v10 v10.30.1/go.mod h1:oSuBIQzuJxL//3MelwSLD5hc2Tu889bF0Idm9Dg26cM=
|
||||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/glueops/autoglue/internal/models"
|
"github.com/glueops/autoglue/internal/models"
|
||||||
"github.com/glueops/autoglue/internal/utils"
|
"github.com/glueops/autoglue/internal/utils"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
@@ -23,6 +24,8 @@ import (
|
|||||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||||
r53 "github.com/aws/aws-sdk-go-v2/service/route53"
|
r53 "github.com/aws/aws-sdk-go-v2/service/route53"
|
||||||
r53types "github.com/aws/aws-sdk-go-v2/service/route53/types"
|
r53types "github.com/aws/aws-sdk-go-v2/service/route53/types"
|
||||||
|
"github.com/aws/smithy-go"
|
||||||
|
smithyhttp "github.com/aws/smithy-go/transport/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
/************* args & small DTOs *************/
|
/************* args & small DTOs *************/
|
||||||
@@ -47,6 +50,9 @@ const externalDNSPoisonOwner = "autoglue-lock"
|
|||||||
// ExternalDNS poison content – fake owner so real external-dns skips it.
|
// ExternalDNS poison content – fake owner so real external-dns skips it.
|
||||||
const externalDNSPoisonValue = "heritage=external-dns,external-dns/owner=" + externalDNSPoisonOwner + ",external-dns/resource=manual/autoglue"
|
const externalDNSPoisonValue = "heritage=external-dns,external-dns/owner=" + externalDNSPoisonOwner + ",external-dns/resource=manual/autoglue"
|
||||||
|
|
||||||
|
// Default TTL for non-alias records (alias not supported in this reconciler)
|
||||||
|
const defaultRecordTTLSeconds int64 = 300
|
||||||
|
|
||||||
/************* entrypoint worker *************/
|
/************* entrypoint worker *************/
|
||||||
|
|
||||||
func DNSReconsileWorker(db *gorm.DB, jobs *Jobs) archer.WorkerFn {
|
func DNSReconsileWorker(db *gorm.DB, jobs *Jobs) archer.WorkerFn {
|
||||||
@@ -225,7 +231,14 @@ func processPendingRecordsForDomain(ctx context.Context, db *gorm.DB, d *models.
|
|||||||
applied := 0
|
applied := 0
|
||||||
for i := range records {
|
for i := range records {
|
||||||
if err := applyRecord(ctx, db, r53c, d, &records[i]); err != nil {
|
if err := applyRecord(ctx, db, r53c, d, &records[i]); err != nil {
|
||||||
log.Error().Err(err).Str("rr", records[i].Name).Msg("[dns] apply record failed")
|
log.Error().
|
||||||
|
Err(err).
|
||||||
|
Str("zone_id", d.ZoneID).
|
||||||
|
Str("domain", d.DomainName).
|
||||||
|
Str("record_id", records[i].ID.String()).
|
||||||
|
Str("name", records[i].Name).
|
||||||
|
Str("type", strings.ToUpper(records[i].Type)).
|
||||||
|
Msg("[dns] apply record failed")
|
||||||
_ = setRecordFailed(db, &records[i], err)
|
_ = setRecordFailed(db, &records[i], err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -249,12 +262,24 @@ func applyRecord(ctx context.Context, db *gorm.DB, r53c *r53.Client, d *models.D
|
|||||||
mname := markerName(fq)
|
mname := markerName(fq)
|
||||||
expected := buildMarkerValue(d.OrganizationID.String(), r.ID.String(), r.Fingerprint)
|
expected := buildMarkerValue(d.OrganizationID.String(), r.ID.String(), r.Fingerprint)
|
||||||
|
|
||||||
|
logCtx := log.With().
|
||||||
|
Str("zone_id", zoneID).
|
||||||
|
Str("domain", d.DomainName).
|
||||||
|
Str("fqdn", fq).
|
||||||
|
Str("rr_type", rt).
|
||||||
|
Str("record_id", r.ID.String()).
|
||||||
|
Str("org_id", d.OrganizationID.String()).
|
||||||
|
Logger()
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
// ---- ExternalDNS preflight ----
|
// ---- ExternalDNS preflight ----
|
||||||
extOwned, err := hasExternalDNSOwnership(ctx, r53c, zoneID, fq, rt)
|
extOwned, err := hasExternalDNSOwnership(ctx, r53c, zoneID, fq, rt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("external_dns_lookup: %w", err)
|
return fmt.Errorf("external_dns_lookup: %w", err)
|
||||||
}
|
}
|
||||||
if extOwned {
|
if extOwned {
|
||||||
|
logCtx.Warn().Msg("[dns] ownership conflict: external-dns claims this record")
|
||||||
r.Owner = "external"
|
r.Owner = "external"
|
||||||
_ = db.Save(r).Error
|
_ = db.Save(r).Error
|
||||||
return fmt.Errorf("ownership_conflict: external-dns claims %s; refusing to modify", strings.TrimSuffix(fq, "."))
|
return fmt.Errorf("ownership_conflict: external-dns claims %s; refusing to modify", strings.TrimSuffix(fq, "."))
|
||||||
@@ -265,6 +290,7 @@ func applyRecord(ctx context.Context, db *gorm.DB, r53c *r53.Client, d *models.D
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("marker lookup: %w", err)
|
return fmt.Errorf("marker lookup: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
hasForeignOwner := false
|
hasForeignOwner := false
|
||||||
hasOurExact := false
|
hasOurExact := false
|
||||||
for _, v := range markerVals {
|
for _, v := range markerVals {
|
||||||
@@ -279,25 +305,26 @@ func applyRecord(ctx context.Context, db *gorm.DB, r53c *r53.Client, d *models.D
|
|||||||
hasForeignOwner = true
|
hasForeignOwner = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logCtx.Debug().
|
||||||
|
Bool("externaldns_owned", extOwned).
|
||||||
|
Int("marker_txt_count", len(markerVals)).
|
||||||
|
Bool("marker_has_our_exact", hasOurExact).
|
||||||
|
Bool("marker_has_foreign", hasForeignOwner).
|
||||||
|
Msg("[dns] ownership preflight")
|
||||||
|
|
||||||
if hasForeignOwner {
|
if hasForeignOwner {
|
||||||
|
logCtx.Warn().Msg("[dns] ownership conflict: foreign _autoglue marker")
|
||||||
r.Owner = "external"
|
r.Owner = "external"
|
||||||
_ = db.Save(r).Error
|
_ = db.Save(r).Error
|
||||||
return fmt.Errorf("ownership_conflict: marker for %s is owned by another controller; refusing to modify", strings.TrimSuffix(fq, "."))
|
return fmt.Errorf("ownership_conflict: marker for %s is owned by another controller; refusing to modify", strings.TrimSuffix(fq, "."))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build RR change (UPSERT)
|
|
||||||
rrChange := r53types.Change{
|
|
||||||
Action: r53types.ChangeActionUpsert,
|
|
||||||
ResourceRecordSet: &r53types.ResourceRecordSet{
|
|
||||||
Name: aws.String(fq),
|
|
||||||
Type: r53types.RRType(rt),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decode user values
|
// Decode user values
|
||||||
var userVals []string
|
var userVals []string
|
||||||
if len(r.Values) > 0 {
|
rawVals := strings.TrimSpace(string(r.Values))
|
||||||
if err := jsonUnmarshalStrict([]byte(r.Values), &userVals); err != nil {
|
if rawVals != "" && rawVals != "null" {
|
||||||
|
if err := jsonUnmarshalStrict([]byte(rawVals), &userVals); err != nil {
|
||||||
return fmt.Errorf("values decode: %w", err)
|
return fmt.Errorf("values decode: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,15 +333,38 @@ func applyRecord(ctx context.Context, db *gorm.DB, r53c *r53.Client, d *models.D
|
|||||||
recs := make([]r53types.ResourceRecord, 0, len(userVals))
|
recs := make([]r53types.ResourceRecord, 0, len(userVals))
|
||||||
for _, v := range userVals {
|
for _, v := range userVals {
|
||||||
v = strings.TrimSpace(v)
|
v = strings.TrimSpace(v)
|
||||||
|
if v == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if rt == "TXT" && !(strings.HasPrefix(v, `"`) && strings.HasSuffix(v, `"`)) {
|
if rt == "TXT" && !(strings.HasPrefix(v, `"`) && strings.HasSuffix(v, `"`)) {
|
||||||
v = strconv.Quote(v)
|
v = strconv.Quote(v)
|
||||||
}
|
}
|
||||||
recs = append(recs, r53types.ResourceRecord{Value: aws.String(v)})
|
recs = append(recs, r53types.ResourceRecord{Value: aws.String(v)})
|
||||||
}
|
}
|
||||||
rrChange.ResourceRecordSet.ResourceRecords = recs
|
|
||||||
if r.TTL != nil {
|
// Alias is NOT supported - enforce at least one value for all record types we manage
|
||||||
ttl := int64(*r.TTL)
|
if len(recs) == 0 {
|
||||||
rrChange.ResourceRecordSet.TTL = aws.Int64(ttl)
|
logCtx.Warn().
|
||||||
|
Str("raw_values", truncateForLog(string(r.Values), 240)).
|
||||||
|
Int("decoded_value_count", len(userVals)).
|
||||||
|
Msg("[dns] invalid record: no values (alias not supported)")
|
||||||
|
return fmt.Errorf("invalid_record: %s %s requires at least one value (alias not supported)", strings.TrimSuffix(fq, "."), rt)
|
||||||
|
}
|
||||||
|
|
||||||
|
ttl := defaultRecordTTLSeconds
|
||||||
|
if r.TTL != nil && *r.TTL > 0 {
|
||||||
|
ttl = int64(*r.TTL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build RR change (UPSERT)
|
||||||
|
rrChange := r53types.Change{
|
||||||
|
Action: r53types.ChangeActionUpsert,
|
||||||
|
ResourceRecordSet: &r53types.ResourceRecordSet{
|
||||||
|
Name: aws.String(fq),
|
||||||
|
Type: r53types.RRType(rt),
|
||||||
|
TTL: aws.Int64(ttl),
|
||||||
|
ResourceRecords: recs,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build marker TXT change (UPSERT)
|
// Build marker TXT change (UPSERT)
|
||||||
@@ -323,7 +373,7 @@ func applyRecord(ctx context.Context, db *gorm.DB, r53c *r53.Client, d *models.D
|
|||||||
ResourceRecordSet: &r53types.ResourceRecordSet{
|
ResourceRecordSet: &r53types.ResourceRecordSet{
|
||||||
Name: aws.String(mname),
|
Name: aws.String(mname),
|
||||||
Type: r53types.RRTypeTxt,
|
Type: r53types.RRTypeTxt,
|
||||||
TTL: aws.Int64(300),
|
TTL: aws.Int64(defaultRecordTTLSeconds),
|
||||||
ResourceRecords: []r53types.ResourceRecord{
|
ResourceRecords: []r53types.ResourceRecord{
|
||||||
{Value: aws.String(strconv.Quote(expected))},
|
{Value: aws.String(strconv.Quote(expected))},
|
||||||
},
|
},
|
||||||
@@ -337,14 +387,26 @@ func applyRecord(ctx context.Context, db *gorm.DB, r53c *r53.Client, d *models.D
|
|||||||
changes := []r53types.Change{rrChange, markerChange}
|
changes := []r53types.Change{rrChange, markerChange}
|
||||||
changes = append(changes, poisonChanges...)
|
changes = append(changes, poisonChanges...)
|
||||||
|
|
||||||
|
// Log what we are about to send
|
||||||
|
logCtx.Debug().
|
||||||
|
Interface("route53_change_batch", toLogChangeBatch(zoneID, changes)).
|
||||||
|
Msg("[dns] route53 request preview")
|
||||||
|
|
||||||
_, err = r53c.ChangeResourceRecordSets(ctx, &r53.ChangeResourceRecordSetsInput{
|
_, err = r53c.ChangeResourceRecordSets(ctx, &r53.ChangeResourceRecordSetsInput{
|
||||||
HostedZoneId: aws.String(zoneID),
|
HostedZoneId: aws.String(zoneID),
|
||||||
ChangeBatch: &r53types.ChangeBatch{Changes: changes},
|
ChangeBatch: &r53types.ChangeBatch{Changes: changes},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logAWSError(logCtx, err)
|
||||||
|
logCtx.Info().Dur("elapsed", time.Since(start)).Msg("[dns] apply failed")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logCtx.Info().
|
||||||
|
Dur("elapsed", time.Since(start)).
|
||||||
|
Int("change_count", len(changes)).
|
||||||
|
Msg("[dns] apply ok")
|
||||||
|
|
||||||
// Success → mark ready & ownership
|
// Success → mark ready & ownership
|
||||||
r.Status = "ready"
|
r.Status = "ready"
|
||||||
r.LastError = ""
|
r.LastError = ""
|
||||||
@@ -352,6 +414,7 @@ func applyRecord(ctx context.Context, db *gorm.DB, r53c *r53.Client, d *models.D
|
|||||||
if err := db.Save(r).Error; err != nil {
|
if err := db.Save(r).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = hasOurExact // could be used to skip marker write in future
|
_ = hasOurExact // could be used to skip marker write in future
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -568,7 +631,7 @@ func buildExternalDNSPoisonTXTChanges(fqdn, rrType string) []r53types.Change {
|
|||||||
ResourceRecordSet: &r53types.ResourceRecordSet{
|
ResourceRecordSet: &r53types.ResourceRecordSet{
|
||||||
Name: aws.String(n),
|
Name: aws.String(n),
|
||||||
Type: r53types.RRTypeTxt,
|
Type: r53types.RRTypeTxt,
|
||||||
TTL: aws.Int64(300),
|
TTL: aws.Int64(defaultRecordTTLSeconds),
|
||||||
ResourceRecords: []r53types.ResourceRecord{
|
ResourceRecords: []r53types.ResourceRecord{
|
||||||
{Value: aws.String(val)},
|
{Value: aws.String(val)},
|
||||||
},
|
},
|
||||||
@@ -595,3 +658,125 @@ func jsonUnmarshalStrict(b []byte, dst any) error {
|
|||||||
}
|
}
|
||||||
return json.Unmarshal(b, dst)
|
return json.Unmarshal(b, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/************* logging DTOs & helpers *************/
|
||||||
|
|
||||||
|
type logRR struct {
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type logRRSet struct {
|
||||||
|
Action string `json:"action"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
TTL *int64 `json:"ttl,omitempty"`
|
||||||
|
Records []logRR `json:"records,omitempty"`
|
||||||
|
RecordCount int `json:"record_count"`
|
||||||
|
HasAliasTarget bool `json:"has_alias_target"`
|
||||||
|
SetIdentifier *string `json:"set_identifier,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type logChangeBatch struct {
|
||||||
|
HostedZoneID string `json:"hosted_zone_id"`
|
||||||
|
ChangeCount int `json:"change_count"`
|
||||||
|
Changes []logRRSet `json:"changes"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func truncateForLog(s string, max int) string {
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
|
if max <= 0 || len(s) <= max {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return s[:max] + "…"
|
||||||
|
}
|
||||||
|
|
||||||
|
func toLogChangeBatch(zoneID string, changes []r53types.Change) logChangeBatch {
|
||||||
|
out := logChangeBatch{
|
||||||
|
HostedZoneID: zoneID,
|
||||||
|
ChangeCount: len(changes),
|
||||||
|
Changes: make([]logRRSet, 0, len(changes)),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ch := range changes {
|
||||||
|
if ch.ResourceRecordSet == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
rrs := ch.ResourceRecordSet
|
||||||
|
lc := logRRSet{
|
||||||
|
Action: string(ch.Action),
|
||||||
|
Name: aws.ToString(rrs.Name),
|
||||||
|
Type: string(rrs.Type),
|
||||||
|
TTL: rrs.TTL,
|
||||||
|
HasAliasTarget: rrs.AliasTarget != nil,
|
||||||
|
SetIdentifier: rrs.SetIdentifier,
|
||||||
|
RecordCount: len(rrs.ResourceRecords),
|
||||||
|
Records: make([]logRR, 0, min(len(rrs.ResourceRecords), 5)),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log up to first 5 values (truncate each) to avoid log bloat / secrets
|
||||||
|
for i, rr := range rrs.ResourceRecords {
|
||||||
|
if i >= 5 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lc.Records = append(lc.Records, logRR{Value: truncateForLog(aws.ToString(rr.Value), 160)})
|
||||||
|
}
|
||||||
|
|
||||||
|
out.Changes = append(out.Changes, lc)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func min(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// logAWSError extracts useful smithy/HTTP metadata (status code + request id + api code) into logs.
|
||||||
|
// logAWSError extracts useful smithy/HTTP metadata (status code + request id + api code) into logs.
|
||||||
|
func logAWSError(l zerolog.Logger, err error) {
|
||||||
|
// Add operation context if present
|
||||||
|
var opErr *smithy.OperationError
|
||||||
|
if errors.As(err, &opErr) {
|
||||||
|
l = l.With().
|
||||||
|
Str("aws_service", opErr.ServiceID).
|
||||||
|
Str("aws_operation", opErr.OperationName).
|
||||||
|
Logger()
|
||||||
|
err = opErr.Unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTP status + request id (smithy-go transport/http)
|
||||||
|
var re *smithyhttp.ResponseError
|
||||||
|
if errors.As(err, &re) {
|
||||||
|
status := re.HTTPStatusCode()
|
||||||
|
|
||||||
|
reqID := ""
|
||||||
|
if resp := re.HTTPResponse(); resp != nil && resp.Header != nil {
|
||||||
|
reqID = resp.Header.Get("x-amzn-RequestId")
|
||||||
|
if reqID == "" {
|
||||||
|
reqID = resp.Header.Get("x-amz-request-id")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ev := l.Error().Int("http_status", status).Err(err)
|
||||||
|
if reqID != "" {
|
||||||
|
ev = ev.Str("aws_request_id", reqID)
|
||||||
|
}
|
||||||
|
ev.Msg("[dns] aws route53 call failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// API error code/message (best-effort)
|
||||||
|
var apiErr smithy.APIError
|
||||||
|
if errors.As(err, &apiErr) {
|
||||||
|
l.Error().
|
||||||
|
Str("aws_error_code", apiErr.ErrorCode()).
|
||||||
|
Str("aws_error_message", apiErr.ErrorMessage()).
|
||||||
|
Err(err).
|
||||||
|
Msg("[dns] aws route53 api error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l.Error().Err(err).Msg("[dns] aws route53 error")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user