@@ -238,17 +238,19 @@ func (n *NGINXController) syncServices(ingressCfg *ingress.Configuration) (bool,
238
238
port = 443
239
239
}
240
240
241
- _ , res := client .Services ().Get (name )
241
+ s , res := client .Services ().Get (name )
242
242
if res .StatusCode == http .StatusNotFound {
243
- s : = & kongadminv1.Service {
243
+ s = & kongadminv1.Service {
244
244
Name : name ,
245
245
Path : "/" ,
246
246
Protocol : proto ,
247
247
Host : name ,
248
248
Port : port ,
249
249
Retries : 5 ,
250
250
}
251
+ }
251
252
253
+ if s != nil {
252
254
if kongIngress != nil && kongIngress .Proxy != nil {
253
255
if kongIngress .Proxy .Path != "" {
254
256
s .Path = kongIngress .Proxy .Path
@@ -271,11 +273,20 @@ func (n *NGINXController) syncServices(ingressCfg *ingress.Configuration) (bool,
271
273
}
272
274
}
273
275
274
- glog .Infof ("creating Kong Service name %v" , name )
275
- _ , res := client .Services ().Create (s )
276
- if res .StatusCode != http .StatusCreated {
277
- glog .Errorf ("Unexpected error creating Kong Service: %v" , res )
278
- return false , res .Error ()
276
+ if res .StatusCode == http .StatusNotFound {
277
+ glog .Infof ("Creating Kong Service name %v" , name )
278
+ _ , res := client .Services ().Create (s )
279
+ if res .StatusCode != http .StatusCreated {
280
+ glog .Errorf ("Unexpected error creating Kong Service: %v" , res )
281
+ return false , res .Error ()
282
+ }
283
+ } else {
284
+ glog .Infof ("Patching Kong Service name %v" , name )
285
+ _ , res := client .Services ().Patch (s .ID , s )
286
+ if res .StatusCode != http .StatusOK {
287
+ glog .Errorf ("Unexpected error patching Kong Service: %v" , res )
288
+ return false , res .Error ()
289
+ }
279
290
}
280
291
}
281
292
0 commit comments