Skip to content

Commit d70bae6

Browse files
authored
Merge pull request #42 from subicura/support-patch-service
Support patch service
2 parents 6125207 + 9020c3e commit d70bae6

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

internal/apis/admin/service.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type ServiceInterface interface {
1515
List(url.Values) (*adminv1.ServiceList, error)
1616
Get(string) (*adminv1.Service, *APIResponse)
1717
Create(*adminv1.Service) (*adminv1.Service, *APIResponse)
18+
Patch(string, *adminv1.Service) (*adminv1.Service, *APIResponse)
1819
Delete(string) error
1920
}
2021

@@ -28,6 +29,12 @@ func (a *serviceAPI) Create(service *adminv1.Service) (*adminv1.Service, *APIRes
2829
return out, err
2930
}
3031

32+
func (a *serviceAPI) Patch(id string, service *adminv1.Service) (*adminv1.Service, *APIResponse) {
33+
out := &adminv1.Service{}
34+
err := a.client.Patch(id, service, out)
35+
return out, err
36+
}
37+
3138
func (a *serviceAPI) Get(name string) (*adminv1.Service, *APIResponse) {
3239
out := &adminv1.Service{}
3340
err := a.client.Get(name, out)

internal/ingress/controller/kong.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,19 @@ func (n *NGINXController) syncServices(ingressCfg *ingress.Configuration) (bool,
238238
port = 443
239239
}
240240

241-
_, res := client.Services().Get(name)
241+
s, res := client.Services().Get(name)
242242
if res.StatusCode == http.StatusNotFound {
243-
s := &kongadminv1.Service{
243+
s = &kongadminv1.Service{
244244
Name: name,
245245
Path: "/",
246246
Protocol: proto,
247247
Host: name,
248248
Port: port,
249249
Retries: 5,
250250
}
251+
}
251252

253+
if s != nil {
252254
if kongIngress != nil && kongIngress.Proxy != nil {
253255
if kongIngress.Proxy.Path != "" {
254256
s.Path = kongIngress.Proxy.Path
@@ -271,11 +273,20 @@ func (n *NGINXController) syncServices(ingressCfg *ingress.Configuration) (bool,
271273
}
272274
}
273275

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+
}
279290
}
280291
}
281292

0 commit comments

Comments
 (0)