Skip to content

Using example AccessLogPolicy in readme results in nil pointer exception  #626

@shulin-sq

Description

@shulin-sq

using this sample accesslogpolicy

```yaml
apiVersion: application-networking.k8s.aws/v1alpha1
kind: AccessLogPolicy
metadata:
name: my-access-log-policy
spec:
destinationArn: "arn:aws:logs:us-west-2:123456789012:log-group:myloggroup:*"
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: inventory

results in an NPE

this is because in the controller:

targetRefNamespace := k8s.NamespaceOrDefault(alp.Spec.TargetRef.Namespace)
if targetRefNamespace != alp.Namespace {
message := fmt.Sprintf("The targetRef's namespace, \"%s\", does not match the Access Log Policy's"+
" namespace, \"%s\"", string(*alp.Spec.TargetRef.Namespace), alp.Namespace)
r.eventRecorder.Event(alp, corev1.EventTypeWarning, k8s.FailedReconcileEvent, message)
return r.updateAccessLogPolicyStatus(ctx, alp, gwv1alpha2.PolicyReasonInvalid, message)
}

namespace is nullchecked, but then the nil value is reused in string(*alp.Spec.TargetRef.Namespace)

I looked at all other objects and it seems that they do not require the operator to specify target ref namespace. I'm wondering why in this accesslogpolicy we require target ref namespace instead of just defaulting it to the access log policy's namespace if it's missing. This is also the only place that uses k8s.NamespaceOrDefault for now.

I would make a contribution to fix this but I'm not sure if the maintainers would prefer

  • for this NPE to be fixed by not referencing the nil in the log
  • or for the default namespace to be assumed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions