Skip to content

Commit aa3e7d8

Browse files
authored
add status message when attempting to attach to headless service (#12918)
If the `parent_ref` of an HTTPRoute resource is set to a headless service, the policy controller gives the HTTPRoute a status of NoMatchingParent: ``` - conditions: - lastTransitionTime: "2024-07-30T22:52:24Z" message: "" reason: NoMatchingParent status: "False" type: Accepted ``` However, this can be misleading because the parent does exist, but is not a valid parent because it does not have a cluster IP. We make this error easier to understand by adding a message to the status condition in this case: ``` - lastTransitionTime: "2024-07-30T22:51:29Z" message: parent service must have a ClusterIP reason: NoMatchingParent status: "False" type: Accepted ``` Signed-off-by: Alex Leong <[email protected]>
1 parent 7bccd05 commit aa3e7d8

File tree

1 file changed

+26
-17
lines changed
  • policy-controller/k8s/status/src

1 file changed

+26
-17
lines changed

policy-controller/k8s/status/src/index.rs

+26-17
Original file line numberDiff line numberDiff line change
@@ -397,24 +397,22 @@ impl Index {
397397
}
398398
routes::ParentReference::Service(service, port) => {
399399
// service is a valid parent if it exists and it has a cluster_ip.
400-
let condition = if self
401-
.services
402-
.get(service)
403-
.map_or(false, |svc| svc.valid_parent_service())
404-
{
405-
// If this route is an HTTPRoute and there exists a GRPCRoute
406-
// with the same parent, the HTTPRoute should not be accepted
407-
// because it is less specific.
408-
// https://gateway-api.sigs.k8s.io/geps/gep-1426/#route-types
409-
if id.gkn.kind == k8s_gateway_api::HttpRoute::kind(&())
410-
&& self.parent_has_grpcroute_children(parent_ref)
411-
{
412-
route_conflicted()
413-
} else {
414-
accepted()
400+
let condition = match self.services.get(service) {
401+
Some(svc) if svc.valid_parent_service() => {
402+
// If this route is an HTTPRoute and there exists a GRPCRoute
403+
// with the same parent, the HTTPRoute should not be accepted
404+
// because it is less specific.
405+
// https://gateway-api.sigs.k8s.io/geps/gep-1426/#route-types
406+
if id.gkn.kind == k8s_gateway_api::HttpRoute::kind(&())
407+
&& self.parent_has_grpcroute_children(parent_ref)
408+
{
409+
route_conflicted()
410+
} else {
411+
accepted()
412+
}
415413
}
416-
} else {
417-
no_matching_parent()
414+
Some(_svc) => headless_parent(),
415+
None => no_matching_parent(),
418416
};
419417

420418
Some(k8s_gateway_api::RouteParentStatus {
@@ -861,6 +859,17 @@ fn no_matching_parent() -> k8s_core_api::Condition {
861859
}
862860
}
863861

862+
fn headless_parent() -> k8s_core_api::Condition {
863+
k8s_core_api::Condition {
864+
last_transition_time: k8s_core_api::Time(now()),
865+
message: "parent service must have a ClusterIP".to_string(),
866+
observed_generation: None,
867+
reason: reasons::NO_MATCHING_PARENT.to_string(),
868+
status: cond_statuses::STATUS_FALSE.to_string(),
869+
type_: conditions::ACCEPTED.to_string(),
870+
}
871+
}
872+
864873
fn route_conflicted() -> k8s_core_api::Condition {
865874
k8s_core_api::Condition {
866875
last_transition_time: k8s_core_api::Time(now()),

0 commit comments

Comments
 (0)