@@ -2,9 +2,10 @@ use std::time::Duration;
2
2
3
3
use k8s_openapi:: api:: core:: v1:: Node ;
4
4
use kube:: api:: { Api , ListParams } ;
5
+ use kube:: error:: ErrorResponse ;
5
6
use kube:: { Client , ResourceExt } ;
6
7
use kube_runtime:: controller:: Action ;
7
- use tracing:: { event, info, instrument, Level } ;
8
+ use tracing:: { event, info, instrument, warn , Level } ;
8
9
9
10
use eip_operator_shared:: Error ;
10
11
@@ -88,7 +89,9 @@ impl k8s_controller::Context for Context {
88
89
if eip_description. network_interface_id != Some ( eni_id. to_owned ( ) )
89
90
|| eip_description. private_ip_address != Some ( node_ip. to_owned ( ) )
90
91
{
91
- match crate :: eip:: set_status_attached ( & eip_api, & eip, & eni_id, node_ip, & name) . await {
92
+ match crate :: eip:: set_status_should_attach ( & eip_api, & eip, & eni_id, node_ip, & name)
93
+ . await
94
+ {
92
95
Ok ( _) => {
93
96
info ! ( "Found matching Eip, attaching it" ) ;
94
97
let association_id = crate :: aws:: associate_eip (
@@ -103,16 +106,14 @@ impl k8s_controller::Context for Context {
103
106
crate :: eip:: set_status_association_id ( & eip_api, & eip_name, & association_id)
104
107
. await ?;
105
108
}
106
- Err ( err)
107
- if err
108
- . to_string ( )
109
- . contains ( "Operation cannot be fulfilled on eips.materialize.cloud" ) =>
110
- {
111
- info ! (
109
+ Err ( Error :: Kube {
110
+ source : kube:: Error :: Api ( ErrorResponse { reason, .. } ) ,
111
+ } ) if reason == "Conflict" => {
112
+ warn ! (
112
113
"Node {} failed to claim eip {}, rescheduling to try another" ,
113
114
name, eip_name
114
115
) ;
115
- return Ok ( Some ( Action :: requeue ( Duration :: from_secs ( 1 ) ) ) ) ;
116
+ return Ok ( Some ( Action :: requeue ( Duration :: from_secs ( 3 ) ) ) ) ;
116
117
}
117
118
Err ( e) => return Err ( e) ,
118
119
} ;
@@ -132,17 +133,15 @@ impl k8s_controller::Context for Context {
132
133
) ;
133
134
let node_labels = node. labels ( ) ;
134
135
let matched_eips = eip_api. list ( & ListParams :: default ( ) ) . await ?. items ;
135
- let eip = matched_eips
136
- . into_iter ( )
137
- . filter ( |eip| eip. attached ( ) )
138
- . find ( |eip| {
139
- eip. matches_node ( node_labels)
140
- && eip
141
- . status
142
- . as_ref ( )
143
- . is_some_and ( |s| s. resource_id == Some ( node. name_unchecked ( ) . clone ( ) ) )
144
- } ) ;
145
- if let Some ( eip) = eip {
136
+ // find all eips that match (there should be one, but lets not lean on that)
137
+ let eips = matched_eips. into_iter ( ) . filter ( |eip| {
138
+ eip. matches_node ( node_labels)
139
+ && eip
140
+ . status
141
+ . as_ref ( )
142
+ . is_some_and ( |s| s. resource_id == Some ( node. name_unchecked ( ) . clone ( ) ) )
143
+ } ) ;
144
+ for eip in eips {
146
145
let allocation_id = eip. allocation_id ( ) . ok_or ( Error :: MissingAllocationId ) ?;
147
146
let addresses = crate :: aws:: describe_address ( & self . ec2_client , allocation_id)
148
147
. await ?
0 commit comments