Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit a905f68

Browse files
committed
fix: lint issues
Signed-off-by: Shane Utt <shaneutt@linux.com>
1 parent 18e2bc8 commit a905f68

File tree

4 files changed

+75
-95
lines changed

4 files changed

+75
-95
lines changed

controlplane/src/gateway_utils.rs

Lines changed: 68 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@ use tracing::*;
5555
pub fn set_gateway_status_addresses(gateway: &mut Gateway, svc_status: &ServiceStatus) {
5656
let mut gw_addrs: Vec<GatewayStatusAddresses> = vec![];
5757

58-
if let Some(load_balancer) = &svc_status.load_balancer {
59-
if let Some(ingress) = &load_balancer.ingress {
60-
for addr in ingress {
61-
if let Some(ip) = &addr.ip {
62-
gw_addrs.push(GatewayStatusAddresses {
63-
r#type: Some("IPAddress".to_string()),
64-
value: ip.clone(),
65-
});
66-
}
58+
if let Some(load_balancer) = &svc_status.load_balancer
59+
&& let Some(ingress) = &load_balancer.ingress {
60+
for addr in ingress {
61+
if let Some(ip) = &addr.ip {
62+
gw_addrs.push(GatewayStatusAddresses {
63+
r#type: Some("IPAddress".to_string()),
64+
value: ip.clone(),
65+
});
6766
}
6867
}
6968
}
@@ -111,60 +110,57 @@ pub async fn create_endpoint_if_not_exists(
111110

112111
let endpoints_api: Api<Endpoints> = Api::namespaced(ctx.client.clone(), &key.namespace);
113112

114-
if let Some(err) = endpoints_api.get(&key.name).await.err() {
115-
if check_if_not_found_err(err) {
116-
let mut ep_ports: Vec<EndpointPort> = vec![];
117-
if let Some(ports) = &svc_spec.ports {
118-
for port in ports {
119-
let mut ep_port = EndpointPort::default();
120-
ep_port.port = port.port;
121-
ep_port.protocol.clone_from(&port.protocol);
122-
ep_ports.push(ep_port);
123-
}
113+
if let Some(err) = endpoints_api.get(&key.name).await.err()
114+
&& check_if_not_found_err(err) {
115+
let mut ep_ports: Vec<EndpointPort> = vec![];
116+
if let Some(ports) = &svc_spec.ports {
117+
for port in ports {
118+
let mut ep_port = EndpointPort::default();
119+
ep_port.port = port.port;
120+
ep_port.protocol.clone_from(&port.protocol);
121+
ep_ports.push(ep_port);
124122
}
125-
126-
let mut obj_meta = ObjectMeta::default();
127-
obj_meta.name = Some(key.name.clone());
128-
obj_meta.namespace = Some(key.namespace.clone());
129-
130-
let mut ep_addr = EndpointAddress::default();
131-
ep_addr.ip = lb_addr_ip;
132-
133-
let endpoints = Endpoints {
134-
metadata: obj_meta,
135-
subsets: Some(vec![EndpointSubset {
136-
addresses: Some(vec![ep_addr]),
137-
not_ready_addresses: None,
138-
ports: Some(ep_ports),
139-
}]),
140-
};
141-
let ep = endpoints_api
142-
.create(&PostParams::default(), &endpoints)
143-
.await
144-
.map_err(Error::KubeError)?;
145-
info!("created Endpoints object {}", ep.name_any());
146123
}
124+
125+
let mut obj_meta = ObjectMeta::default();
126+
obj_meta.name = Some(key.name.clone());
127+
obj_meta.namespace = Some(key.namespace.clone());
128+
129+
let mut ep_addr = EndpointAddress::default();
130+
ep_addr.ip = lb_addr_ip;
131+
132+
let endpoints = Endpoints {
133+
metadata: obj_meta,
134+
subsets: Some(vec![EndpointSubset {
135+
addresses: Some(vec![ep_addr]),
136+
not_ready_addresses: None,
137+
ports: Some(ep_ports),
138+
}]),
139+
};
140+
let ep = endpoints_api
141+
.create(&PostParams::default(), &endpoints)
142+
.await
143+
.map_err(Error::KubeError)?;
144+
info!("created Endpoints object {}", ep.name_any());
147145
}
148146

149147
Ok(())
150148
}
151149

152150
// Returns true if the provided error is a not found error.
153151
pub fn check_if_not_found_err(error: kube::Error) -> bool {
154-
if let kube::Error::Api(response) = error {
155-
if response.code == 404 {
156-
return true;
157-
}
152+
if let kube::Error::Api(response) = error
153+
&& response.code == 404 {
154+
return true;
158155
}
159156
false
160157
}
161158

162159
// Returns the number of ingresses set on the LoadBalancer Service.
163160
pub fn get_ingress_ip_len(svc_status: &ServiceStatus) -> usize {
164-
if let Some(lb) = &svc_status.load_balancer {
165-
if let Some(ingress) = &lb.ingress {
166-
return ingress.len();
167-
}
161+
if let Some(lb) = &svc_status.load_balancer
162+
&& let Some(ingress) = &lb.ingress {
163+
return ingress.len();
168164
}
169165
0
170166
}
@@ -223,10 +219,9 @@ pub fn update_service_for_gateway(gateway: &Gateway, svc: &mut Service) -> Resul
223219
if let Some(addresses) = &gateway.spec.addresses {
224220
if !addresses.is_empty() {
225221
let addr = addresses[0].clone();
226-
if let Some(t) = addr.r#type {
227-
if t != "IPAddress" {
228-
return Err(Error::InvalidConfigError(format!("addresses of type {t} are not supported; only type IPAddress is supported").to_string()));
229-
}
222+
if let Some(t) = addr.r#type
223+
&& t != "IPAddress" {
224+
return Err(Error::InvalidConfigError(format!("addresses of type {t} are not supported; only type IPAddress is supported").to_string()));
230225
}
231226
address = Some(addresses[0].clone());
232227
}
@@ -239,11 +234,10 @@ pub fn update_service_for_gateway(gateway: &Gateway, svc: &mut Service) -> Resul
239234
))?;
240235

241236
let lb_ip: Option<String> = svc_spec.load_balancer_ip.clone();
242-
if let Some((addr, ip)) = address.clone().zip(lb_ip.clone()) {
243-
if ip != addr.value {
244-
svc_spec.load_balancer_ip = Some(addr.value.clone());
245-
updated = true;
246-
}
237+
if let Some((addr, ip)) = address.clone().zip(lb_ip.clone())
238+
&& ip != addr.value {
239+
svc_spec.load_balancer_ip = Some(addr.value.clone());
240+
updated = true;
247241
}
248242
if address.is_none() && lb_ip.is_some() {
249243
svc_spec.load_balancer_ip = None;
@@ -332,8 +326,8 @@ pub fn get_accepted_condition(gateway: &Gateway) -> metav1::Condition {
332326
};
333327
let gateway_spec: &GatewaySpec = &gateway.spec;
334328

335-
if let Some(status) = &gateway.status {
336-
if let Some(listeners) = &status.listeners {
329+
if let Some(status) = &gateway.status
330+
&& let Some(listeners) = &status.listeners {
337331
for listener in listeners {
338332
for conditon in &listener.conditions {
339333
if conditon.status == "False" {
@@ -344,20 +338,18 @@ pub fn get_accepted_condition(gateway: &Gateway) -> metav1::Condition {
344338
}
345339
}
346340
}
347-
}
348341

349342
if let Some(addresses) = &gateway_spec.addresses {
350343
for addr in addresses {
351-
if let Some(addr_type) = &addr.r#type {
352-
if addr_type.as_str() != "IPAddress" {
344+
if let Some(addr_type) = &addr.r#type
345+
&& addr_type.as_str() != "IPAddress" {
353346
accepted.status = String::from("False");
354347
accepted.reason = GatewayConditionReason::UnsupportedAddress.to_string();
355348
accepted.message = format!(
356349
"found an addres of type {addr_type}, only type IPAddress is supported"
357350
);
358351
break;
359352
}
360-
}
361353
}
362354
}
363355
accepted
@@ -369,13 +361,12 @@ pub fn set_listener_status(gateway: &mut Gateway) -> Result<()> {
369361
let mut statuses: Vec<GatewayStatusListeners> = vec![];
370362
let mut current_listener_statuses: HashMap<String, GatewayStatusListeners> = HashMap::new();
371363

372-
if let Some(gw_status) = &gateway.status {
373-
if let Some(listeners) = &gw_status.listeners {
364+
if let Some(gw_status) = &gateway.status
365+
&& let Some(listeners) = &gw_status.listeners {
374366
for listener in listeners {
375367
current_listener_statuses.insert(listener.name.clone(), listener.clone());
376368
}
377369
}
378-
}
379370

380371
let generation = gateway
381372
.metadata
@@ -489,9 +480,9 @@ fn get_listener_status(
489480
group: Some("gateway.networking.k8s.io".to_string()),
490481
kind: "TCPRoute".to_string(),
491482
});
492-
if let Some(routes) = &listener.allowed_routes {
493-
if let Some(rgks) = &routes.kinds {
494-
if let Some(msg) = check_route_kinds(Some("TCPRoute"), rgks) {
483+
if let Some(routes) = &listener.allowed_routes
484+
&& let Some(rgks) = &routes.kinds
485+
&& let Some(msg) = check_route_kinds(Some("TCPRoute"), rgks) {
495486
update_listener_condition(
496487
String::from("False"),
497488
ListenerConditionReason::InvalidRouteKinds.to_string(),
@@ -511,17 +502,15 @@ fn get_listener_status(
511502
2,
512503
);
513504
}
514-
}
515-
}
516505
}
517506
"UDP" => {
518507
supported_kinds.push(GatewayStatusListenersSupportedKinds {
519508
group: Some("gateway.networking.k8s.io".to_string()),
520509
kind: "UDPRoute".to_string(),
521510
});
522-
if let Some(routes) = &listener.allowed_routes {
523-
if let Some(rgks) = &routes.kinds {
524-
if let Some(msg) = check_route_kinds(Some("UDPRoute"), rgks) {
511+
if let Some(routes) = &listener.allowed_routes
512+
&& let Some(rgks) = &routes.kinds
513+
&& let Some(msg) = check_route_kinds(Some("UDPRoute"), rgks) {
525514
update_listener_condition(
526515
String::from("False"),
527516
ListenerConditionReason::InvalidRouteKinds.to_string(),
@@ -541,8 +530,6 @@ fn get_listener_status(
541530
2,
542531
);
543532
}
544-
}
545-
}
546533
}
547534
_ => {
548535
update_listener_condition(
@@ -555,18 +542,16 @@ fn get_listener_status(
555542
1,
556543
);
557544

558-
if let Some(routes) = &listener.allowed_routes {
559-
if let Some(rgks) = &routes.kinds {
560-
if let Some(msg) = check_route_kinds(Some("UDPRoute"), rgks) {
545+
if let Some(routes) = &listener.allowed_routes
546+
&& let Some(rgks) = &routes.kinds
547+
&& let Some(msg) = check_route_kinds(Some("UDPRoute"), rgks) {
561548
update_listener_condition(
562549
String::from("False"),
563550
ListenerConditionReason::InvalidRouteKinds.to_string(),
564551
msg.clone(),
565552
0,
566553
);
567554
}
568-
}
569-
}
570555

571556
update_listener_condition(
572557
String::from("False"),
@@ -612,10 +597,9 @@ fn check_route_kinds(
612597
));
613598
}
614599

615-
if let Some(group) = &rgk.group {
616-
if group.as_str() != "gateway.networking.k8s.io" {
600+
if let Some(group) = &rgk.group
601+
&& group.as_str() != "gateway.networking.k8s.io" {
617602
return Some(format!("Unsupported API group: {group}"));
618603
}
619-
}
620604
None
621605
}

controlplane/src/gatewayclass_utils.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ use serde_json::json;
2828

2929
pub fn is_accepted(gateway_class: &GatewayClass) -> bool {
3030
let mut accepted = false;
31-
if let Some(status) = &gateway_class.status {
32-
if let Some(conditions) = &status.conditions {
31+
if let Some(status) = &gateway_class.status
32+
&& let Some(conditions) = &status.conditions {
3333
for condition in conditions {
3434
accepted = condition.type_ == GatewayConditionType::Accepted.to_string()
3535
&& condition.status == "True"
3636
}
3737
}
38-
}
3938
accepted
4039
}
4140

controlplane/src/route_utils.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,15 @@ pub async fn is_route_managed(
5858
continue;
5959
}
6060

61-
if let Some(port) = parent_ref.port {
62-
if !gateway
61+
if let Some(port) = parent_ref.port
62+
&& !gateway
6363
.spec
6464
.listeners
6565
.iter()
6666
.any(|listener| listener.port == port && listener.protocol == "TCP")
6767
{
6868
continue;
6969
}
70-
}
7170

7271
return Ok(Some(gateway));
7372
}

dataplane/api-server/src/netutils.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,12 @@ pub fn if_index_for_routing_ip(ip_addr: Ipv4Addr) -> Result<u32, Error> {
6363
// extract returned RouteNetLinkMessage
6464
if let NetlinkPayload::InnerMessage(RouteNetlinkMessage::NewRoute(message)) =
6565
recv_route_message.payload
66-
{
67-
if let Some(RouteAttribute::Oif(idex_if)) = message
66+
&& let Some(RouteAttribute::Oif(idex_if)) = message
6867
.attributes
6968
.iter()
7069
.find(|attr| matches!(attr, RouteAttribute::Oif(_)))
71-
{
72-
return Ok(*idex_if);
73-
}
70+
{
71+
return Ok(*idex_if);
7472
}
7573
Err(Error::msg(format!("{ERR_NO_IFINDEX} {ip_addr}")))
7674
}

0 commit comments

Comments
 (0)