Skip to content

Commit 1c5e222

Browse files
author
Zijun Wang
committed
address PR comments
1 parent f78925e commit 1c5e222

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

controllers/eventhandlers/mapper.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,17 @@ func policyToTargetRefObj[T client.Object](r *resourceMapper, ctx context.Contex
8686
"policyName", policyNamespacedName)
8787
return null
8888
}
89-
expectedGroup, expectedKind, err := k8sResourceTypeToGroupNameAndKindName(retObj)
89+
expectedGroup, expectedKind, err := k8sResourceTypeToGroupAndKind(retObj)
9090
if err != nil {
91-
r.log.Errorw("Failed to get expected GroupVersion of targetRefObj",
92-
"policyName", policyNamespacedName, "reason", err.Error())
91+
r.log.Errorw("Failed to get expected GroupKind for targetRefObj",
92+
"policyName", policyNamespacedName,
93+
"targetRef", targetRef,
94+
"reason", err.Error())
9395
return null
9496
}
9597

96-
if targetRef.Group != gateway_api.Group(expectedGroup) || targetRef.Kind != gateway_api.Kind(expectedKind) {
97-
r.log.Infow("Detected targetRef GroupVersion and expected retObj GroupVersion are different, skipping",
98+
if targetRef.Group != expectedGroup || targetRef.Kind != expectedKind {
99+
r.log.Infow("Detected targetRef GroupKind and expected retObj GroupKind are different, skipping",
98100
"policyName", policyNamespacedName,
99101
"targetRef", targetRef,
100102
"expectedGroup", expectedGroup,
@@ -103,8 +105,9 @@ func policyToTargetRefObj[T client.Object](r *resourceMapper, ctx context.Contex
103105
}
104106
if targetRef.Namespace != nil && policyNamespacedName.Namespace != string(*targetRef.Namespace) {
105107
r.log.Infow("Detected Policy and TargetRef namespace are different, skipping",
106-
"policyName", policyNamespacedName, "targetRef", targetRef,
107-
"policyNamespace", policyNamespacedName.Namespace)
108+
"policyNamespacedName", policyNamespacedName, "targetRef", targetRef,
109+
"targetRef.Namespace", targetRef.Namespace,
110+
"policyNamespacedName.Namespace", policyNamespacedName.Namespace)
108111
return null
109112
}
110113

@@ -129,7 +132,7 @@ func policyToTargetRefObj[T client.Object](r *resourceMapper, ctx context.Contex
129132
return retObj
130133
}
131134

132-
func k8sResourceTypeToGroupNameAndKindName(obj client.Object) (string, string, error) {
135+
func k8sResourceTypeToGroupAndKind(obj client.Object) (gateway_api.Group, gateway_api.Kind, error) {
133136
switch obj.(type) {
134137
case *corev1.Service:
135138
return corev1.GroupName, serviceKind, nil

0 commit comments

Comments
 (0)