aws-controllers-k8s / community

AWS Controllers for Kubernetes (ACK) is a project enabling you to manage AWS services from Kubernetes
https://aws-controllers-k8s.github.io/community/
Apache License 2.0
2.39k stars 253 forks source link

Panic when adopting a Route53 RecordSet #2108

Open krishnan-sivanantham opened 1 month ago

krishnan-sivanantham commented 1 month ago

Describe the bug Route53 controller crashed when adopting a route53 recordset.

Steps to reproduce

apiVersion: services.k8s.aws/v1alpha1
kind: AdoptedResource
metadata:
  name: adopted-route53-resource
  namespace: default
spec:
  aws:
    nameOrID: test.sub-domain
    additionalKeys:
      hostedZoneID: Z0623630ZABRGM0R8YG7 
  kubernetes:
    group: route53.services.k8s.aws
    kind: RecordSet
    metadata:  
      name: test-recordset

Expected outcome The route53 record set is adopted and the corresponding kubernetes object is created in the cluster with INSYNC status.

Environment

Logs

{"level":"info","ts":"2024-07-11T06:25:37.305Z","logger":"adoption.adopted-reconciler","msg":"starting adoption reconciliation","target_group":"route53.services.k8s.aws","target_kind":"RecordSet","namespace":"default","name":"adopted-route53-resource","generation":1}
{"level":"info","ts":"2024-07-11T06:25:39.097Z","msg":"Observed a panic in reconciler: runtime error: invalid memory address or nil pointer dereference","controller":"adoptedresource","controllerGroup":"services.k8s.aws","controllerKind":"AdoptedResource","AdoptedResource":{"name":"adopted-route53-resource","namespace":"default"},"namespace":"default","name":"adopted-route53-resource","reconcileID":"d7420e8b-91ec-4d29-93da-86cc240a75ee"}
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x19a1c22]

goroutine 258 [running]:
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()
    /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.17.2/pkg/internal/controller/controller.go:116 +0x1e5
panic({0x1b9fde0?, 0x33a68a0?})
    /usr/local/go/src/runtime/panic.go:770 +0x132
github.com/aws-controllers-k8s/route53-controller/pkg/resource/record_set.(*resourceManager).sdkFind(0xc0001416c0, {0x24bb088, 0xc0008610b0}, 0xc000132208)
    /github.com/aws-controllers-k8s/route53-controller/pkg/resource/record_set/sdk.go:150 +0x902
github.com/aws-controllers-k8s/route53-controller/pkg/resource/record_set.(*resourceManager).ReadOne(0xc0001416c0, {0x24bb088?, 0xc0008610b0?}, {0x24c4808?, 0xc000132208})
    /github.com/aws-controllers-k8s/route53-controller/pkg/resource/record_set/manager.go:105 +0x4b
github.com/aws-controllers-k8s/runtime/pkg/runtime.(*adoptionReconciler).Sync(0xc000052b60, {0x24bb088, 0xc0008610b0}, {0x24c2080, 0x343d7a0}, {0x24c47a0, 0xc0001416c0}, 0xc00018a8c0)
    /go/pkg/mod/github.com/aws-controllers-k8s/runtime@v0.34.0/pkg/runtime/adoption_reconciler.go:175 +0xf2
github.com/aws-controllers-k8s/runtime/pkg/runtime.(*adoptionReconciler).reconcile(0xc000052b60, {0x24bb088, 0xc0008610b0}, {{{0xc0009441f0?, 0x0?}, {0xc000bb6258?, 0x5?}}})
    /go/pkg/mod/github.com/aws-controllers-k8s/runtime@v0.34.0/pkg/runtime/adoption_reconciler.go:160 +0x850
github.com/aws-controllers-k8s/runtime/pkg/runtime.(*adoptionReconciler).Reconcile(0xc000052b60, {0x24bb088?, 0xc0008610b0?}, {{{0xc0009441f0?, 0x5?}, {0xc000bb6258?, 0xc000c63d10?}}})
    /go/pkg/mod/github.com/aws-controllers-k8s/runtime@v0.34.0/pkg/runtime/adoption_reconciler.go:72 +0x2c
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x24bf990?, {0x24bb088?, 0xc0008610b0?}, {{{0xc0009441f0?, 0xb?}, {0xc000bb6258?, 0x0?}}})
    /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.17.2/pkg/internal/controller/controller.go:119 +0xb7
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc000b94a00, {0x24bb0c0, 0xc00065c8c0}, {0x1c64d00, 0xc0009481e0})
    /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.17.2/pkg/internal/controller/controller.go:316 +0x3bc
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc000b94a00, {0x24bb0c0, 0xc00065c8c0})
    /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.17.2/pkg/internal/controller/controller.go:266 +0x1be
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
    /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.17.2/pkg/internal/controller/controller.go:227 +0x79
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2 in goroutine 136
    /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.17.2/pkg/internal/controller/controller.go:223 +0x50c
krishnan-sivanantham commented 1 month ago

Error is in this line

if elem.Type == nil || (*elem.Type != *ko.Spec.RecordType) {
    continue
}

The record I am trying to adopt is of type CNAME so elem.Type is not nil. In the adoption reconciliation flow, ko.Spec.RecordType is never set but accessed in the code above causing a panic error.