@@ -69,7 +69,9 @@ func (h *IPPoolHandler) DeleteIPPool(netAttachDef string, podCIDR string) error
69
69
name := h .GetIPPoolName (netAttachDef , podCIDR )
70
70
instance , err := h .GetIPPool (name )
71
71
if err == nil {
72
- err = h .Client .Delete (context .TODO (), instance )
72
+ ctx , cancel := context .WithTimeout (context .Background (), vars .ContextTimeout )
73
+ defer cancel ()
74
+ err = h .Client .Delete (ctx , instance )
73
75
}
74
76
return err
75
77
}
@@ -132,7 +134,9 @@ func (h *IPPoolHandler) UpdateIPPool(netAttachDef string, podCIDR string, vlanCI
132
134
ippool .Spec = spec
133
135
ippool .Spec .Allocations = prevSpec .Allocations
134
136
ippool .ObjectMeta .Labels = labels
135
- err = h .Client .Update (context .TODO (), ippool )
137
+ ctx , cancel := context .WithTimeout (context .Background (), vars .ContextTimeout )
138
+ defer cancel ()
139
+ err = h .Client .Update (ctx , ippool )
136
140
if ! reflect .DeepEqual (prevSpec .Excludes , excludesInterface ) {
137
141
// report if allocated ip addresses have conflicts with the new IPPool (for example, in exclude list)
138
142
invalidAllocations := h .checkPoolValidity (excludesInterface , prevSpec .Allocations )
@@ -154,7 +158,9 @@ func (h *IPPoolHandler) UpdateIPPool(netAttachDef string, podCIDR string, vlanCI
154
158
},
155
159
Spec : spec ,
156
160
}
157
- err = h .Client .Create (context .Background (), newIPPool )
161
+ ctx , cancel := context .WithTimeout (context .Background (), vars .ContextTimeout )
162
+ defer cancel ()
163
+ err = h .Client .Create (ctx , newIPPool )
158
164
vars .IPPoolLog .V (5 ).Info (fmt .Sprintf ("New IPPool %s: %v, %v" , ippoolName , newIPPool , err ))
159
165
}
160
166
return err
@@ -192,7 +198,9 @@ func (h *IPPoolHandler) PatchIPPoolAllocations(ippoolName string, newAllocations
192
198
}
193
199
patch := client .MergeFrom (ippool .DeepCopy ())
194
200
ippool .Spec .Allocations = newAllocations
195
- return h .Client .Patch (context .Background (), ippool , patch )
201
+ ctx , cancel := context .WithTimeout (context .Background (), vars .ContextTimeout )
202
+ defer cancel ()
203
+ return h .Client .Patch (ctx , ippool , patch )
196
204
}
197
205
198
206
func (h * IPPoolHandler ) UpdateIPPools (defName string , entries []multinicv1.CIDREntry , excludes []compute.IPValue ) {
@@ -234,6 +242,8 @@ func (h *IPPoolHandler) AddLabel(ippool *multinicv1.IPPool) error {
234
242
labels := map [string ]string {vars .HostNameLabel : hostName , vars .DefNameLabel : netAttachDef }
235
243
patch := client .MergeFrom (ippool .DeepCopy ())
236
244
ippool .ObjectMeta .Labels = labels
237
- err := h .Client .Patch (context .Background (), ippool , patch )
245
+ ctx , cancel := context .WithTimeout (context .Background (), vars .ContextTimeout )
246
+ defer cancel ()
247
+ err := h .Client .Patch (ctx , ippool , patch )
238
248
return err
239
249
}
0 commit comments