Skip to content

Commit 62f4940

Browse files
Revolyssupnic-6443
andauthored
fix: missing hosts field from service (#30)
* fix absent Hosts --------- Signed-off-by: Ashish Tiwari <[email protected]> Signed-off-by: Nic <[email protected]> Co-authored-by: Nic <[email protected]>
1 parent b324df7 commit 62f4940

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

pkg/apisix/upstream.go renamed to pkg/apisix/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (u *serviceClient) Create(ctx context.Context, obj *v1.Service, shouldCompa
125125
return nil, err
126126
}
127127
url := u.url + "/" + obj.ID
128-
log.Debugw("creating upstream", zap.ByteString("body", body), zap.String("url", url))
128+
log.Debugw("creating service", zap.ByteString("body", body), zap.String("url", url))
129129
resp, err := u.cluster.createResource(ctx, url, "service", body)
130130
if err != nil {
131131
log.Errorf("failed to create upstream: %s", err)

pkg/providers/apisix/translation/apisix_route.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,12 @@ func (t *translator) translateHTTPRouteV2(ctx *translation.TranslateContext, ar
221221
route.Plugins["traffic-split"] = plugin
222222
}
223223
if !ctx.CheckServiceExist(upstreamName) {
224-
ups, err := t.translateService(ar.Namespace, backend.ServiceName, backend.Subset, backend.ResolveGranularity, svcClusterIP, svcPort)
224+
svc, err := t.translateService(ar.Namespace, backend.ServiceName, backend.Subset, backend.ResolveGranularity, svcClusterIP, svcPort)
225225
if err != nil {
226226
return err
227227
}
228-
ctx.AddService(ups)
228+
svc.Hosts = part.Match.Hosts
229+
ctx.AddService(svc)
229230
}
230231
}
231232

@@ -330,6 +331,7 @@ func (t *translator) translateHTTPRouteV2(ctx *translation.TranslateContext, ar
330331
}
331332

332333
for _, svc := range svcs {
334+
svc.Hosts = part.Match.Hosts
333335
ctx.AddService(svc)
334336
}
335337
}
@@ -493,6 +495,7 @@ func (t *translator) generateHTTPRouteV2DeleteMark(ctx *translation.TranslateCon
493495
if err != nil {
494496
return err
495497
}
498+
ups.Hosts = part.Match.Hosts
496499
ctx.AddService(ups)
497500
}
498501
}
@@ -504,6 +507,7 @@ func (t *translator) generateHTTPRouteV2DeleteMark(ctx *translation.TranslateCon
504507
ups := &apisixv1.Service{}
505508
ups.Name = upstreamName
506509
ups.ID = id.GenID(ups.Name)
510+
ups.Hosts = part.Match.Hosts
507511
ctx.AddService(ups)
508512
}
509513
}

pkg/types/apisix/v1/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ type Service struct {
140140
Metadata `json:",inline" yaml:",inline"`
141141
Type ServiceType `json:"type,omitempty" yaml:"type,omitempty"`
142142
Upstream Upstream `json:"upstream,omitempty" yaml:"upstream,omitempty"`
143+
Hosts []string `json:"hosts,omitempty" yaml:"hosts,omitempty"`
143144
}
144145

145146
// Route apisix route object

0 commit comments

Comments
 (0)