This is an automated email from the ASF dual-hosted git repository.
tokers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new 549d67d chore: remove pointer type in types (#208)
549d67d is described below
commit 549d67de388cc35cd49f47a367a8896bf0e320f0
Author: Alex Zhang <[email protected]>
AuthorDate: Mon Jan 25 21:29:04 2021 +0800
chore: remove pointer type in types (#208)
---
pkg/apisix/cache/memdb.go | 4 +-
pkg/apisix/cache/memdb_test.go | 125 ++++++---------
pkg/apisix/cluster.go | 8 +-
pkg/apisix/resource.go | 61 ++++----
pkg/apisix/resource_test.go | 17 ++-
pkg/apisix/route.go | 36 ++---
pkg/apisix/route_test.go | 63 ++++----
pkg/apisix/service.go | 34 ++---
pkg/apisix/service_test.go | 53 +++----
pkg/apisix/ssl.go | 18 +--
pkg/apisix/ssl_test.go | 36 ++---
pkg/apisix/upstream.go | 48 +++---
pkg/apisix/upstream_test.go | 61 ++++----
pkg/ingress/apisix/route.go | 42 ++---
pkg/ingress/apisix/service.go | 34 ++---
pkg/ingress/apisix/tls.go | 14 +-
pkg/ingress/apisix/tls_test.go | 30 ++--
pkg/ingress/apisix/upstream.go | 20 +--
pkg/ingress/apisix/upstream_test.go | 24 +--
pkg/ingress/controller/endpoint.go | 12 +-
pkg/ingress/controller/watch.go | 12 +-
pkg/ingress/endpoint/ep.go | 18 +--
pkg/seven/state/builder.go | 59 ++++---
pkg/seven/state/service_worker.go | 22 +--
pkg/seven/state/solver.go | 36 ++---
pkg/types/apisix/v1/types.go | 82 +++++-----
pkg/types/apisix/v1/zz_generated.deepcopy.go | 220 +--------------------------
27 files changed, 457 insertions(+), 732 deletions(-)
diff --git a/pkg/apisix/cache/memdb.go b/pkg/apisix/cache/memdb.go
index aa7e8f6..a82d087 100644
--- a/pkg/apisix/cache/memdb.go
+++ b/pkg/apisix/cache/memdb.go
@@ -220,7 +220,7 @@ func (c *dbCache) checkServiceReference(s *v1.Service)
error {
// Service is referenced by Route.
txn := c.db.Txn(false)
defer txn.Abort()
- obj, err := txn.First("route", "service_id", *s.FullName)
+ obj, err := txn.First("route", "service_id", s.FullName)
if err != nil {
if err == memdb.ErrNotFound {
return nil
@@ -237,7 +237,7 @@ func (c *dbCache) checkUpstreamReference(u *v1.Upstream)
error {
// Upstream is referenced by Service.
txn := c.db.Txn(false)
defer txn.Abort()
- obj, err := txn.First("service", "upstream_id", *u.FullName)
+ obj, err := txn.First("service", "upstream_id", u.FullName)
if err != nil {
if err == memdb.ErrNotFound {
return nil
diff --git a/pkg/apisix/cache/memdb_test.go b/pkg/apisix/cache/memdb_test.go
index e16bffe..dcf2489 100644
--- a/pkg/apisix/cache/memdb_test.go
+++ b/pkg/apisix/cache/memdb_test.go
@@ -27,31 +27,25 @@ func TestMemDBCacheRoute(t *testing.T) {
c, err := NewMemDBCache()
assert.Nil(t, err, "NewMemDBCache")
- name := "abc"
- sid := "1"
r1 := &v1.Route{
- FullName: &name,
- Name: &name,
- ServiceId: &sid,
+ FullName: "abc",
+ Name: "abc",
+ ServiceId: "1",
}
assert.Nil(t, c.InsertRoute(r1), "inserting route 1")
r, err := c.GetRoute("abc")
assert.Equal(t, r1, r)
- name2 := "def"
- sid2 := "2"
r2 := &v1.Route{
- FullName: &name2,
- Name: &name2,
- ServiceId: &sid2,
+ FullName: "def",
+ Name: "def",
+ ServiceId: "2",
}
- name3 := "ghi"
- sid3 := "3"
r3 := &v1.Route{
- FullName: &name3,
- Name: &name3,
- ServiceId: &sid3,
+ FullName: "ghi",
+ Name: "ghi",
+ ServiceId: "3",
}
assert.Nil(t, c.InsertRoute(r2), "inserting route r2")
assert.Nil(t, c.InsertRoute(r3), "inserting route r3")
@@ -64,18 +58,16 @@ func TestMemDBCacheRoute(t *testing.T) {
routes, err := c.ListRoutes()
assert.Nil(t, err, "listing routes")
- if *routes[0].FullName > *routes[1].FullName {
+ if routes[0].FullName > routes[1].FullName {
routes[0], routes[1] = routes[1], routes[0]
}
assert.Equal(t, routes[0], r1)
assert.Equal(t, routes[1], r2)
- name4 := "name4"
- sid4 := "4"
r4 := &v1.Route{
- FullName: &name4,
- Name: &name4,
- ServiceId: &sid4,
+ FullName: "name4",
+ Name: "name4",
+ ServiceId: "4",
}
assert.Error(t, ErrNotFound, c.DeleteRoute(r4))
}
@@ -84,31 +76,25 @@ func TestMemDBCacheService(t *testing.T) {
c, err := NewMemDBCache()
assert.Nil(t, err, "NewMemDBCache")
- name := "abc"
- uid := "1"
s1 := &v1.Service{
- FullName: &name,
- Name: &name,
- UpstreamId: &uid,
+ FullName: "abc",
+ Name: "abc",
+ UpstreamId: "1",
}
assert.Nil(t, c.InsertService(s1), "inserting service 1")
s, err := c.GetService("abc")
assert.Equal(t, s1, s)
- name2 := "def"
- uid2 := "2"
s2 := &v1.Service{
- FullName: &name2,
- Name: &name2,
- UpstreamId: &uid2,
+ FullName: "def",
+ Name: "def",
+ UpstreamId: "2",
}
- name3 := "ghi"
- uid3 := "3"
s3 := &v1.Service{
- FullName: &name3,
- Name: &name3,
- UpstreamId: &uid3,
+ FullName: "ghi",
+ Name: "ghi",
+ UpstreamId: "3",
}
assert.Nil(t, c.InsertService(s2), "inserting service 2")
assert.Nil(t, c.InsertService(s3), "inserting service 3")
@@ -121,18 +107,16 @@ func TestMemDBCacheService(t *testing.T) {
services, err := c.ListServices()
assert.Nil(t, err, "listing services")
- if *services[0].FullName > *services[1].FullName {
+ if services[0].FullName > services[1].FullName {
services[0], services[1] = services[1], services[0]
}
assert.Equal(t, services[0], s1)
assert.Equal(t, services[1], s2)
- name4 := "name4"
- uid4 := "4"
s4 := &v1.Service{
- FullName: &name4,
- Name: &name4,
- UpstreamId: &uid4,
+ FullName: "name4",
+ Name: "name4",
+ UpstreamId: "4",
}
assert.Error(t, ErrNotFound, c.DeleteService(s4))
}
@@ -141,22 +125,19 @@ func TestMemDBCacheSSL(t *testing.T) {
c, err := NewMemDBCache()
assert.Nil(t, err, "NewMemDBCache")
- id := "abc"
s1 := &v1.Ssl{
- ID: &id,
+ ID: "abc",
}
assert.Nil(t, c.InsertSSL(s1), "inserting ssl 1")
s, err := c.GetSSL("abc")
assert.Equal(t, s1, s)
- id2 := "def"
s2 := &v1.Ssl{
- ID: &id2,
+ ID: "def",
}
- id3 := "ghi"
s3 := &v1.Ssl{
- ID: &id3,
+ ID: "ghi",
}
assert.Nil(t, c.InsertSSL(s2), "inserting ssl 2")
assert.Nil(t, c.InsertSSL(s3), "inserting ssl 3")
@@ -169,15 +150,14 @@ func TestMemDBCacheSSL(t *testing.T) {
ssl, err := c.ListSSL()
assert.Nil(t, err, "listing ssl")
- if *ssl[0].ID > *ssl[1].ID {
+ if ssl[0].ID > ssl[1].ID {
ssl[0], ssl[1] = ssl[1], ssl[0]
}
assert.Equal(t, ssl[0], s1)
assert.Equal(t, ssl[1], s2)
- id4 := "id4"
s4 := &v1.Ssl{
- ID: &id4,
+ ID: "id4",
}
assert.Error(t, ErrNotFound, c.DeleteSSL(s4))
}
@@ -186,25 +166,22 @@ func TestMemDBCacheUpstream(t *testing.T) {
c, err := NewMemDBCache()
assert.Nil(t, err, "NewMemDBCache")
- name := "abc"
u1 := &v1.Upstream{
- FullName: &name,
- Name: &name,
+ FullName: "abc",
+ Name: "abc",
}
assert.Nil(t, c.InsertUpstream(u1), "inserting upstream 1")
u, err := c.GetUpstream("abc")
assert.Equal(t, u1, u)
- name2 := "def"
u2 := &v1.Upstream{
- FullName: &name2,
- Name: &name2,
+ FullName: "def",
+ Name: "def",
}
- name3 := "ghi"
u3 := &v1.Upstream{
- FullName: &name3,
- Name: &name3,
+ FullName: "ghi",
+ Name: "ghi",
}
assert.Nil(t, c.InsertUpstream(u2), "inserting upstream 2")
assert.Nil(t, c.InsertUpstream(u3), "inserting upstream 3")
@@ -217,39 +194,33 @@ func TestMemDBCacheUpstream(t *testing.T) {
upstreams, err := c.ListUpstreams()
assert.Nil(t, err, "listing upstreams")
- if *upstreams[0].FullName > *upstreams[1].FullName {
+ if upstreams[0].FullName > upstreams[1].FullName {
upstreams[0], upstreams[1] = upstreams[1], upstreams[0]
}
assert.Equal(t, upstreams[0], u1)
assert.Equal(t, upstreams[1], u2)
- name4 := "name4"
u4 := &v1.Upstream{
- FullName: &name4,
- Name: &name4,
+ FullName: "name4",
+ Name: "name4",
}
assert.Error(t, ErrNotFound, c.DeleteUpstream(u4))
}
func TestMemDBCacheReference(t *testing.T) {
- rname := "route"
- sid := "service"
r := &v1.Route{
- FullName: &rname,
- Name: &rname,
- ServiceId: &sid,
+ FullName: "route",
+ Name: "route",
+ ServiceId: "service",
}
- sname := "service"
- uid := "upstream"
s := &v1.Service{
- FullName: &sname,
- Name: &sname,
- UpstreamId: &uid,
+ FullName: "service",
+ Name: "service",
+ UpstreamId: "upstream",
}
- uname := "upstream"
u := &v1.Upstream{
- FullName: &uname,
- Name: &uname,
+ FullName: "upstream",
+ Name: "upstream",
}
db, err := NewMemDBCache()
diff --git a/pkg/apisix/cluster.go b/pkg/apisix/cluster.go
index d73a193..b2bfa5d 100644
--- a/pkg/apisix/cluster.go
+++ b/pkg/apisix/cluster.go
@@ -162,7 +162,7 @@ func (c *cluster) syncCacheOnce() (bool, error) {
for _, r := range routes {
if err := c.cache.InsertRoute(r); err != nil {
log.Errorw("failed to insert route to cache",
- zap.String("route", *r.ID),
+ zap.String("route", r.ID),
zap.String("cluster", c.name),
zap.String("error", err.Error()),
)
@@ -172,7 +172,7 @@ func (c *cluster) syncCacheOnce() (bool, error) {
for _, s := range services {
if err := c.cache.InsertService(s); err != nil {
log.Errorw("failed to insert service to cache",
- zap.String("service", *s.ID),
+ zap.String("service", s.ID),
zap.String("cluster", c.name),
zap.String("error", err.Error()),
)
@@ -182,7 +182,7 @@ func (c *cluster) syncCacheOnce() (bool, error) {
for _, u := range upstreams {
if err := c.cache.InsertUpstream(u); err != nil {
log.Errorw("failed to insert upstream to cache",
- zap.String("upstream", *u.ID),
+ zap.String("upstream", u.ID),
zap.String("cluster", c.name),
zap.String("error", err.Error()),
)
@@ -192,7 +192,7 @@ func (c *cluster) syncCacheOnce() (bool, error) {
for _, s := range ssl {
if err := c.cache.InsertSSL(s); err != nil {
log.Errorw("failed to insert ssl to cache",
- zap.String("ssl", *s.ID),
+ zap.String("ssl", s.ID),
zap.String("cluster", c.name),
zap.String("error", err.Error()),
)
diff --git a/pkg/apisix/resource.go b/pkg/apisix/resource.go
index e411bf5..1fe51a7 100644
--- a/pkg/apisix/resource.go
+++ b/pkg/apisix/resource.go
@@ -73,12 +73,12 @@ type item struct {
}
type routeItem struct {
- UpstreamId *string `json:"upstream_id"`
- ServiceId *string `json:"service_id"`
- Host *string `json:"host"`
- URI *string `json:"uri"`
- Desc *string `json:"desc"`
- Methods []*string `json:"methods"`
+ UpstreamId string `json:"upstream_id"`
+ ServiceId string `json:"service_id"`
+ Host string `json:"host"`
+ URI string `json:"uri"`
+ Desc string `json:"desc"`
+ Methods []string `json:"methods"`
Plugins map[string]interface{} `json:"plugins"`
}
@@ -98,16 +98,16 @@ func (i *item) route(clusterName string) (*v1.Route, error)
{
fullName := genFullName(route.Desc, clusterName)
return &v1.Route{
- ID: &list[len(list)-1],
- FullName: &fullName,
- Group: &clusterName,
+ ID: list[len(list)-1],
+ FullName: fullName,
+ Group: clusterName,
Name: route.Desc,
Host: route.Host,
Path: route.URI,
Methods: route.Methods,
UpstreamId: route.UpstreamId,
ServiceId: route.ServiceId,
- Plugins: (*v1.Plugins)(&route.Plugins),
+ Plugins: route.Plugins,
}, nil
}
@@ -129,24 +129,24 @@ func (i *item) upstream(clusterName string)
(*v1.Upstream, error) {
LBType := ups.LBType
key := i.Key
- var nodes []*v1.Node
+ var nodes []v1.Node
for _, node := range ups.Nodes {
- nodes = append(nodes, &v1.Node{
- IP: &node.Host,
- Port: &node.Port,
- Weight: &node.Weight,
+ nodes = append(nodes, v1.Node{
+ IP: node.Host,
+ Port: node.Port,
+ Weight: node.Weight,
})
}
fullName := genFullName(ups.Desc, clusterName)
return &v1.Upstream{
- ID: &id,
- FullName: &fullName,
- Group: &clusterName,
+ ID: id,
+ FullName: fullName,
+ Group: clusterName,
Name: name,
Type: LBType,
- Key: &key,
+ Key: key,
Nodes: nodes,
}, nil
}
@@ -163,20 +163,20 @@ func (i *item) service(clusterName string) (*v1.Service,
error) {
id := list[len(list)-1]
var plugins v1.Plugins
if svc.Plugins != nil {
- plugins := make(v1.Plugins, len(*svc.Plugins))
- for k, v := range *svc.Plugins {
+ plugins := make(v1.Plugins, len(svc.Plugins))
+ for k, v := range svc.Plugins {
plugins[k] = v
}
}
fullName := genFullName(svc.Desc, clusterName)
return &v1.Service{
- ID: &id,
- FullName: &fullName,
- Group: &clusterName,
+ ID: id,
+ FullName: fullName,
+ Group: clusterName,
Name: svc.Desc,
UpstreamId: svc.UpstreamId,
- Plugins: &plugins,
+ Plugins: plugins,
}, nil
}
@@ -190,16 +190,13 @@ func (i *item) ssl(clusterName string) (*v1.Ssl, error) {
list := strings.Split(i.Key, "/")
id := list[len(list)-1]
- ssl.ID = &id
- ssl.Group = &clusterName
+ ssl.ID = id
+ ssl.Group = clusterName
return &ssl, nil
}
-func genFullName(name *string, clusterName string) string {
- fullName := "unknown"
- if name != nil {
- fullName = *name
- }
+func genFullName(name string, clusterName string) string {
+ fullName := name
if clusterName != "" {
fullName = clusterName + "_" + fullName
}
diff --git a/pkg/apisix/resource_test.go b/pkg/apisix/resource_test.go
index 7a625db..571bb88 100644
--- a/pkg/apisix/resource_test.go
+++ b/pkg/apisix/resource_test.go
@@ -60,6 +60,7 @@ func TestItemConvertRoute(t *testing.T) {
"service_id": "14",
"host": "foo.com",
"uri": "/shop/133/details",
+ "desc": "unknown",
"methods": ["GET", "POST"]
}
`),
@@ -67,12 +68,12 @@ func TestItemConvertRoute(t *testing.T) {
r, err := item.route("qa")
assert.Nil(t, err)
- assert.Equal(t, *r.UpstreamId, "13")
- assert.Equal(t, *r.ServiceId, "14")
- assert.Equal(t, *r.Host, "foo.com")
- assert.Equal(t, *r.Path, "/shop/133/details")
- assert.Equal(t, *r.Methods[0], "GET")
- assert.Equal(t, *r.Methods[1], "POST")
- assert.Nil(t, r.Name)
- assert.Equal(t, *r.FullName, "qa_unknown")
+ assert.Equal(t, r.UpstreamId, "13")
+ assert.Equal(t, r.ServiceId, "14")
+ assert.Equal(t, r.Host, "foo.com")
+ assert.Equal(t, r.Path, "/shop/133/details")
+ assert.Equal(t, r.Methods[0], "GET")
+ assert.Equal(t, r.Methods[1], "POST")
+ assert.Equal(t, r.Name, "unknown")
+ assert.Equal(t, r.FullName, "qa_unknown")
}
diff --git a/pkg/apisix/route.go b/pkg/apisix/route.go
index 246f869..8cd704b 100644
--- a/pkg/apisix/route.go
+++ b/pkg/apisix/route.go
@@ -29,11 +29,11 @@ import (
)
type routeReqBody struct {
- Desc *string `json:"desc,omitempty"`
- URI *string `json:"uri,omitempty"`
- Host *string `json:"host,omitempty"`
- ServiceId *string `json:"service_id,omitempty"`
- Plugins *v1.Plugins `json:"plugins,omitempty"`
+ Desc string `json:"desc,omitempty"`
+ URI string `json:"uri,omitempty"`
+ Host string `json:"host,omitempty"`
+ ServiceId string `json:"service_id,omitempty"`
+ Plugins v1.Plugins `json:"plugins,omitempty"`
}
type routeClient struct {
@@ -146,8 +146,8 @@ func (r *routeClient) List(ctx context.Context)
([]*v1.Route, error) {
func (r *routeClient) Create(ctx context.Context, obj *v1.Route) (*v1.Route,
error) {
log.Infow("try to create route",
- zap.String("host", *obj.Host),
- zap.String("fullname", *obj.FullName),
+ zap.String("host", obj.Host),
+ zap.String("fullname", obj.FullName),
zap.String("cluster", r.clusterName),
zap.String("url", r.url),
)
@@ -167,7 +167,7 @@ func (r *routeClient) Create(ctx context.Context, obj
*v1.Route) (*v1.Route, err
return nil, err
}
- url := r.url + "/" + *obj.ID
+ url := r.url + "/" + obj.ID
log.Infow("creating route", zap.ByteString("body", data),
zap.String("url", url))
resp, err := r.cluster.createResource(ctx, url, bytes.NewReader(data))
if err != nil {
@@ -176,8 +176,8 @@ func (r *routeClient) Create(ctx context.Context, obj
*v1.Route) (*v1.Route, err
}
var clusterName string
- if obj.Group != nil {
- clusterName = *obj.Group
+ if obj.Group != "" {
+ clusterName = obj.Group
}
route, err := resp.Item.route(clusterName)
if err != nil {
@@ -192,15 +192,15 @@ func (r *routeClient) Create(ctx context.Context, obj
*v1.Route) (*v1.Route, err
func (r *routeClient) Delete(ctx context.Context, obj *v1.Route) error {
log.Infow("try to delete route",
- zap.String("id", *obj.ID),
- zap.String("fullname", *obj.FullName),
+ zap.String("id", obj.ID),
+ zap.String("fullname", obj.FullName),
zap.String("cluster", r.clusterName),
zap.String("url", r.url),
)
if err := r.cluster.HasSynced(ctx); err != nil {
return err
}
- url := r.url + "/" + *obj.ID
+ url := r.url + "/" + obj.ID
if err := r.cluster.deleteResource(ctx, url); err != nil {
return err
}
@@ -213,8 +213,8 @@ func (r *routeClient) Delete(ctx context.Context, obj
*v1.Route) error {
func (r *routeClient) Update(ctx context.Context, obj *v1.Route) (*v1.Route,
error) {
log.Infow("try to update route",
- zap.String("id", *obj.ID),
- zap.String("fullname", *obj.FullName),
+ zap.String("id", obj.ID),
+ zap.String("fullname", obj.FullName),
zap.String("cluster", r.clusterName),
zap.String("url", r.url),
)
@@ -231,15 +231,15 @@ func (r *routeClient) Update(ctx context.Context, obj
*v1.Route) (*v1.Route, err
if err != nil {
return nil, err
}
- url := r.url + "/" + *obj.ID
+ url := r.url + "/" + obj.ID
log.Infow("updating route", zap.ByteString("body", body),
zap.String("url", r.url))
resp, err := r.cluster.updateResource(ctx, url, bytes.NewReader(body))
if err != nil {
return nil, err
}
var clusterName string
- if obj.Group != nil {
- clusterName = *obj.Group
+ if obj.Group != "" {
+ clusterName = obj.Group
}
route, err := resp.Item.route(clusterName)
if err != nil {
diff --git a/pkg/apisix/route_test.go b/pkg/apisix/route_test.go
index a06a209..d767c6d 100644
--- a/pkg/apisix/route_test.go
+++ b/pkg/apisix/route_test.go
@@ -179,65 +179,58 @@ func TestRouteClient(t *testing.T) {
})
// Create
- id := "1"
- host := "www.foo.com"
- uri := "/bar"
- name := "test"
obj, err := cli.Create(context.Background(), &v1.Route{
- ID: &id,
- Host: &host,
- Path: &uri,
- Name: &name,
- FullName: &name,
- ServiceId: &id,
- UpstreamId: &id,
+ ID: "1",
+ Host: "www.foo.com",
+ Path: "/bar",
+ Name: "test",
+ FullName: "test",
+ ServiceId: "1",
+ UpstreamId: "1",
})
assert.Nil(t, err)
- assert.Equal(t, *obj.ID, "1")
+ assert.Equal(t, obj.ID, "1")
- id2 := "2"
obj, err = cli.Create(context.Background(), &v1.Route{
- ID: &id2,
- Host: &host,
- Path: &uri,
- Name: &name,
- FullName: &name,
- ServiceId: &id,
- UpstreamId: &id,
+ ID: "2",
+ Host: "www.foo.com",
+ Path: "/bar",
+ Name: "test",
+ FullName: "test",
+ ServiceId: "1",
+ UpstreamId: "1",
})
assert.Nil(t, err)
- assert.Equal(t, *obj.ID, "2")
+ assert.Equal(t, obj.ID, "2")
// List
objs, err := cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 2)
- assert.Equal(t, *objs[0].ID, "1")
- assert.Equal(t, *objs[1].ID, "2")
+ assert.Equal(t, objs[0].ID, "1")
+ assert.Equal(t, objs[1].ID, "2")
// Delete then List
assert.Nil(t, cli.Delete(context.Background(), objs[0]))
objs, err = cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 1)
- assert.Equal(t, "2", *objs[0].ID)
+ assert.Equal(t, "2", objs[0].ID)
// Patch then List
- id = "112"
- objId := "2"
_, err = cli.Update(context.Background(), &v1.Route{
- ID: &objId,
- Host: &host,
- Path: &uri,
- Name: &name,
- FullName: &name,
- ServiceId: &id,
- UpstreamId: &id,
+ ID: "2",
+ Host: "www.foo.com",
+ Path: "/bar",
+ Name: "test",
+ FullName: "test",
+ ServiceId: "112",
+ UpstreamId: "112",
})
assert.Nil(t, err)
objs, err = cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 1)
- assert.Equal(t, "2", *objs[0].ID)
- assert.Equal(t, "112", *objs[0].ServiceId)
+ assert.Equal(t, "2", objs[0].ID)
+ assert.Equal(t, "112", objs[0].ServiceId)
}
diff --git a/pkg/apisix/service.go b/pkg/apisix/service.go
index 8d77eb3..6e51a5f 100644
--- a/pkg/apisix/service.go
+++ b/pkg/apisix/service.go
@@ -35,9 +35,9 @@ type serviceClient struct {
}
type serviceItem struct {
- UpstreamId *string `json:"upstream_id,omitempty"`
- Plugins *map[string]interface{} `json:"plugins,omitempty"`
- Desc *string `json:"desc,omitempty"`
+ UpstreamId string `json:"upstream_id,omitempty"`
+ Plugins map[string]interface{} `json:"plugins,omitempty"`
+ Desc string `json:"desc,omitempty"`
}
func newServiceClient(c *cluster) Service {
@@ -141,7 +141,7 @@ func (s *serviceClient) List(ctx context.Context)
([]*v1.Service, error) {
func (s *serviceClient) Create(ctx context.Context, obj *v1.Service)
(*v1.Service, error) {
log.Infow("try to create service",
- zap.String("fullname", *obj.FullName),
+ zap.String("fullname", obj.FullName),
zap.String("cluster", s.clusterName),
zap.String("url", s.url),
)
@@ -151,14 +151,14 @@ func (s *serviceClient) Create(ctx context.Context, obj
*v1.Service) (*v1.Servic
body, err := json.Marshal(serviceItem{
UpstreamId: obj.UpstreamId,
- Plugins: (*map[string]interface{})(obj.Plugins),
+ Plugins: obj.Plugins,
Desc: obj.Name,
})
if err != nil {
return nil, err
}
- url := s.url + "/" + *obj.ID
+ url := s.url + "/" + obj.ID
log.Infow("creating service", zap.ByteString("body", body),
zap.String("url", url))
resp, err := s.cluster.createResource(ctx, url, bytes.NewReader(body))
if err != nil {
@@ -166,8 +166,8 @@ func (s *serviceClient) Create(ctx context.Context, obj
*v1.Service) (*v1.Servic
return nil, err
}
var clusterName string
- if obj.Group != nil {
- clusterName = *obj.Group
+ if obj.Group != "" {
+ clusterName = obj.Group
}
svc, err := resp.Item.service(clusterName)
if err != nil {
@@ -182,15 +182,15 @@ func (s *serviceClient) Create(ctx context.Context, obj
*v1.Service) (*v1.Servic
func (s *serviceClient) Delete(ctx context.Context, obj *v1.Service) error {
log.Infow("try to delete service",
- zap.String("id", *obj.ID),
- zap.String("fullname", *obj.FullName),
+ zap.String("id", obj.ID),
+ zap.String("fullname", obj.FullName),
zap.String("cluster", s.clusterName),
zap.String("url", s.url),
)
if err := s.cluster.HasSynced(ctx); err != nil {
return err
}
- url := s.url + "/" + *obj.ID
+ url := s.url + "/" + obj.ID
if err := s.cluster.deleteResource(ctx, url); err != nil {
return err
}
@@ -203,8 +203,8 @@ func (s *serviceClient) Delete(ctx context.Context, obj
*v1.Service) error {
func (s *serviceClient) Update(ctx context.Context, obj *v1.Service)
(*v1.Service, error) {
log.Infow("try to update service",
- zap.String("id", *obj.ID),
- zap.String("fullname", *obj.FullName),
+ zap.String("id", obj.ID),
+ zap.String("fullname", obj.FullName),
zap.String("cluster", s.clusterName),
zap.String("url", s.url),
)
@@ -215,22 +215,22 @@ func (s *serviceClient) Update(ctx context.Context, obj
*v1.Service) (*v1.Servic
body, err := json.Marshal(serviceItem{
UpstreamId: obj.UpstreamId,
- Plugins: (*map[string]interface{})(obj.Plugins),
+ Plugins: obj.Plugins,
Desc: obj.Name,
})
if err != nil {
return nil, err
}
- url := s.url + "/" + *obj.ID
+ url := s.url + "/" + obj.ID
log.Infow("creating service", zap.ByteString("body", body),
zap.String("url", url))
resp, err := s.cluster.updateResource(ctx, url, bytes.NewReader(body))
if err != nil {
return nil, err
}
var clusterName string
- if obj.Group != nil {
- clusterName = *obj.Group
+ if obj.Group != "" {
+ clusterName = obj.Group
}
svc, err := resp.Item.service(clusterName)
if err != nil {
diff --git a/pkg/apisix/service_test.go b/pkg/apisix/service_test.go
index 41c8078..9e3efa7 100644
--- a/pkg/apisix/service_test.go
+++ b/pkg/apisix/service_test.go
@@ -156,61 +156,52 @@ func TestServiceClient(t *testing.T) {
})
// Create
- group := "default"
- fullName := "default_test"
- name := "test"
- upsId := "13"
-
- id := "1"
obj, err := cli.Create(context.TODO(), &v1.Service{
- ID: &id,
- FullName: &fullName,
- Group: &group,
- Name: &name,
- UpstreamId: &upsId,
+ ID: "1",
+ FullName: "default_test",
+ Group: "default",
+ Name: "test",
+ UpstreamId: "13",
})
assert.Nil(t, err)
- assert.Equal(t, *obj.ID, "1")
+ assert.Equal(t, obj.ID, "1")
- id2 := "2"
obj, err = cli.Create(context.TODO(), &v1.Service{
- ID: &id2,
- FullName: &fullName,
- Group: &group,
- Name: &name,
- UpstreamId: &upsId,
+ ID: "2",
+ FullName: "default_test",
+ Group: "default",
+ Name: "test",
+ UpstreamId: "13",
})
assert.Nil(t, err)
- assert.Equal(t, *obj.ID, "2")
+ assert.Equal(t, obj.ID, "2")
// List
objs, err := cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 2)
- assert.Equal(t, *objs[0].ID, "1")
- assert.Equal(t, *objs[1].ID, "2")
+ assert.Equal(t, objs[0].ID, "1")
+ assert.Equal(t, objs[1].ID, "2")
// Delete then List
assert.Nil(t, cli.Delete(context.Background(), objs[0]))
objs, err = cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 1)
- assert.Equal(t, "2", *objs[0].ID)
+ assert.Equal(t, "2", objs[0].ID)
// Patch then List
- upsId = "14"
- objId := "2"
_, err = cli.Update(context.Background(), &v1.Service{
- ID: &objId,
- FullName: &fullName,
- Group: &group,
- Name: &name,
- UpstreamId: &upsId,
+ ID: "2",
+ FullName: "default_test",
+ Group: "default",
+ Name: "test",
+ UpstreamId: "14",
})
assert.Nil(t, err)
objs, err = cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 1)
- assert.Equal(t, "2", *objs[0].ID)
- assert.Equal(t, upsId, *objs[0].UpstreamId)
+ assert.Equal(t, "2", objs[0].ID)
+ assert.Equal(t, "14", objs[0].UpstreamId)
}
diff --git a/pkg/apisix/ssl.go b/pkg/apisix/ssl.go
index 275933f..90a55c6 100644
--- a/pkg/apisix/ssl.go
+++ b/pkg/apisix/ssl.go
@@ -151,7 +151,7 @@ func (s *sslClient) Create(ctx context.Context, obj
*v1.Ssl) (*v1.Ssl, error) {
if err != nil {
return nil, err
}
- url := s.url + "/" + *obj.ID
+ url := s.url + "/" + obj.ID
log.Infow("creating ssl", zap.ByteString("body", data),
zap.String("url", url))
resp, err := s.cluster.createResource(ctx, url, bytes.NewReader(data))
if err != nil {
@@ -160,8 +160,8 @@ func (s *sslClient) Create(ctx context.Context, obj
*v1.Ssl) (*v1.Ssl, error) {
}
var clusterName string
- if obj.Group != nil {
- clusterName = *obj.Group
+ if obj.Group != "" {
+ clusterName = obj.Group
}
ssl, err := resp.Item.ssl(clusterName)
@@ -177,14 +177,14 @@ func (s *sslClient) Create(ctx context.Context, obj
*v1.Ssl) (*v1.Ssl, error) {
func (s *sslClient) Delete(ctx context.Context, obj *v1.Ssl) error {
log.Infow("try to delete ssl",
- zap.String("id", *obj.ID),
+ zap.String("id", obj.ID),
zap.String("cluster", s.clusterName),
zap.String("url", s.url),
)
if err := s.cluster.HasSynced(ctx); err != nil {
return err
}
- url := s.url + "/" + *obj.ID
+ url := s.url + "/" + obj.ID
if err := s.cluster.deleteResource(ctx, url); err != nil {
return err
}
@@ -197,14 +197,14 @@ func (s *sslClient) Delete(ctx context.Context, obj
*v1.Ssl) error {
func (s *sslClient) Update(ctx context.Context, obj *v1.Ssl) (*v1.Ssl, error) {
log.Infow("try to update ssl",
- zap.String("id", *obj.ID),
+ zap.String("id", obj.ID),
zap.String("cluster", s.clusterName),
zap.String("url", s.url),
)
if err := s.cluster.HasSynced(ctx); err != nil {
return nil, err
}
- url := s.url + "/" + *obj.ID
+ url := s.url + "/" + obj.ID
data, err := json.Marshal(v1.Ssl{
ID: obj.ID,
Snis: obj.Snis,
@@ -221,8 +221,8 @@ func (s *sslClient) Update(ctx context.Context, obj
*v1.Ssl) (*v1.Ssl, error) {
return nil, err
}
var clusterName string
- if obj.Group != nil {
- clusterName = *obj.Group
+ if obj.Group != "" {
+ clusterName = obj.Group
}
ssl, err := resp.Item.ssl(clusterName)
if err != nil {
diff --git a/pkg/apisix/ssl_test.go b/pkg/apisix/ssl_test.go
index 8e4ad2e..649c0ee 100644
--- a/pkg/apisix/ssl_test.go
+++ b/pkg/apisix/ssl_test.go
@@ -157,51 +157,45 @@ func TestSSLClient(t *testing.T) {
})
// Create
- id1 := "1"
- group := "default"
- sni := "bar.com"
obj, err := cli.Create(context.TODO(), &v1.Ssl{
- ID: &id1,
- Group: &group,
- Snis: []*string{&sni},
+ ID: "1",
+ Group: "default",
+ Snis: []string{"bar.com"},
})
assert.Nil(t, err)
- assert.Equal(t, *obj.ID, "1")
+ assert.Equal(t, obj.ID, "1")
- id2 := "2"
obj, err = cli.Create(context.TODO(), &v1.Ssl{
- ID: &id2,
- Group: &group,
- Snis: []*string{&sni},
+ ID: "2",
+ Group: "default",
+ Snis: []string{"bar.com"},
})
assert.Nil(t, err)
- assert.Equal(t, *obj.ID, "2")
+ assert.Equal(t, obj.ID, "2")
// List
objs, err := cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 2)
- assert.Equal(t, *objs[0].ID, "1")
- assert.Equal(t, *objs[1].ID, "2")
+ assert.Equal(t, objs[0].ID, "1")
+ assert.Equal(t, objs[1].ID, "2")
// Delete then List
assert.Nil(t, cli.Delete(context.Background(), objs[0]))
objs, err = cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 1)
- assert.Equal(t, "2", *objs[0].ID)
+ assert.Equal(t, "2", objs[0].ID)
// Patch then List
- objId := "2"
- sni = "foo.com"
_, err = cli.Update(context.Background(), &v1.Ssl{
- ID: &objId,
- Snis: []*string{&sni},
+ ID: "2",
+ Snis: []string{"foo.com"},
})
assert.Nil(t, err)
objs, err = cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 1)
- assert.Equal(t, "2", *objs[0].ID)
- assert.Equal(t, sni, *objs[0].Snis[0])
+ assert.Equal(t, "2", objs[0].ID)
+ assert.Equal(t, "foo.com", objs[0].Snis[0])
}
diff --git a/pkg/apisix/upstream.go b/pkg/apisix/upstream.go
index 3f49b0b..1e635ed 100644
--- a/pkg/apisix/upstream.go
+++ b/pkg/apisix/upstream.go
@@ -62,17 +62,17 @@ func (n *upstreamNodes) UnmarshalJSON(p []byte) error {
}
type upstreamReqBody struct {
- LBType *string `json:"type"`
- HashOn *string `json:"hash_on,omitempty"`
- Key *string `json:"key,omitempty"`
+ LBType string `json:"type"`
+ HashOn string `json:"hash_on,omitempty"`
+ Key string `json:"key,omitempty"`
Nodes upstreamNodes `json:"nodes"`
- Desc *string `json:"desc"`
+ Desc string `json:"desc"`
}
type upstreamItem struct {
Nodes upstreamNodes `json:"nodes"`
- Desc *string `json:"desc"`
- LBType *string `json:"type"`
+ Desc string `json:"desc"`
+ LBType string `json:"type"`
}
func newUpstreamClient(c *cluster) Upstream {
@@ -176,7 +176,7 @@ func (u *upstreamClient) List(ctx context.Context)
([]*v1.Upstream, error) {
func (u *upstreamClient) Create(ctx context.Context, obj *v1.Upstream)
(*v1.Upstream, error) {
log.Infow("try to create upstream",
- zap.String("fullname", *obj.FullName),
+ zap.String("fullname", obj.FullName),
zap.String("url", u.url),
zap.String("cluster", u.clusterName),
)
@@ -188,9 +188,9 @@ func (u *upstreamClient) Create(ctx context.Context, obj
*v1.Upstream) (*v1.Upst
nodes := make(upstreamNodes, 0, len(obj.Nodes))
for _, node := range obj.Nodes {
nodes = append(nodes, upstreamNode{
- Host: *node.IP,
- Port: *node.Port,
- Weight: *node.Weight,
+ Host: node.IP,
+ Port: node.Port,
+ Weight: node.Weight,
})
}
body, err := json.Marshal(upstreamReqBody{
@@ -203,7 +203,7 @@ func (u *upstreamClient) Create(ctx context.Context, obj
*v1.Upstream) (*v1.Upst
if err != nil {
return nil, err
}
- url := u.url + "/" + *obj.ID
+ url := u.url + "/" + obj.ID
log.Infow("creating upstream", zap.ByteString("body", body),
zap.String("url", url))
resp, err := u.cluster.createResource(ctx, url, bytes.NewReader(body))
@@ -212,8 +212,8 @@ func (u *upstreamClient) Create(ctx context.Context, obj
*v1.Upstream) (*v1.Upst
return nil, err
}
var clusterName string
- if obj.Group != nil {
- clusterName = *obj.Group
+ if obj.Group != "" {
+ clusterName = obj.Group
}
ups, err := resp.Item.upstream(clusterName)
if err != nil {
@@ -228,8 +228,8 @@ func (u *upstreamClient) Create(ctx context.Context, obj
*v1.Upstream) (*v1.Upst
func (u *upstreamClient) Delete(ctx context.Context, obj *v1.Upstream) error {
log.Infow("try to delete upstream",
- zap.String("id", *obj.ID),
- zap.String("fullname", *obj.FullName),
+ zap.String("id", obj.ID),
+ zap.String("fullname", obj.FullName),
zap.String("cluster", u.clusterName),
zap.String("url", u.url),
)
@@ -237,7 +237,7 @@ func (u *upstreamClient) Delete(ctx context.Context, obj
*v1.Upstream) error {
if err := u.cluster.HasSynced(ctx); err != nil {
return err
}
- url := u.url + "/" + *obj.ID
+ url := u.url + "/" + obj.ID
if err := u.cluster.deleteResource(ctx, url); err != nil {
return err
}
@@ -250,8 +250,8 @@ func (u *upstreamClient) Delete(ctx context.Context, obj
*v1.Upstream) error {
func (u *upstreamClient) Update(ctx context.Context, obj *v1.Upstream)
(*v1.Upstream, error) {
log.Infow("try to update upstream",
- zap.String("id", *obj.ID),
- zap.String("fullname", *obj.FullName),
+ zap.String("id", obj.ID),
+ zap.String("fullname", obj.FullName),
zap.String("cluster", u.clusterName),
zap.String("url", u.url),
)
@@ -263,9 +263,9 @@ func (u *upstreamClient) Update(ctx context.Context, obj
*v1.Upstream) (*v1.Upst
nodes := make(upstreamNodes, 0, len(obj.Nodes))
for _, node := range obj.Nodes {
nodes = append(nodes, upstreamNode{
- Host: *node.IP,
- Port: *node.Port,
- Weight: *node.Weight,
+ Host: node.IP,
+ Port: node.Port,
+ Weight: node.Weight,
})
}
body, err := json.Marshal(upstreamReqBody{
@@ -279,15 +279,15 @@ func (u *upstreamClient) Update(ctx context.Context, obj
*v1.Upstream) (*v1.Upst
return nil, err
}
- url := u.url + "/" + *obj.ID
+ url := u.url + "/" + obj.ID
log.Infow("updating upstream", zap.ByteString("body", body),
zap.String("url", url))
resp, err := u.cluster.updateResource(ctx, url, bytes.NewReader(body))
if err != nil {
return nil, err
}
var clusterName string
- if obj.Group != nil {
- clusterName = *obj.Group
+ if obj.Group != "" {
+ clusterName = obj.Group
}
ups, err := resp.Item.upstream(clusterName)
if err != nil {
diff --git a/pkg/apisix/upstream_test.go b/pkg/apisix/upstream_test.go
index 5619680..476e9cd 100644
--- a/pkg/apisix/upstream_test.go
+++ b/pkg/apisix/upstream_test.go
@@ -165,70 +165,67 @@ func TestUpstreamClient(t *testing.T) {
ip := "10.0.11.153"
port := 15006
weight := 100
- nodes := []*v1.Node{
+ nodes := []v1.Node{
{
- IP: &ip,
- Port: &port,
- Weight: &weight,
+ IP: ip,
+ Port: port,
+ Weight: weight,
},
}
- id1 := "1"
obj, err := cli.Create(context.TODO(), &v1.Upstream{
- ID: &id1,
- FullName: &fullName,
- Group: &group,
- Name: &name,
- Type: &lbType,
- Key: &key,
+ ID: "1",
+ FullName: fullName,
+ Group: group,
+ Name: name,
+ Type: lbType,
+ Key: key,
Nodes: nodes,
})
assert.Nil(t, err)
- assert.Equal(t, *obj.ID, "1")
+ assert.Equal(t, obj.ID, "1")
id2 := "2"
obj, err = cli.Create(context.TODO(), &v1.Upstream{
- ID: &id2,
- FullName: &fullName,
- Group: &group,
- Name: &name,
- Type: &lbType,
- Key: &key,
+ ID: id2,
+ FullName: fullName,
+ Group: group,
+ Name: name,
+ Type: lbType,
+ Key: key,
Nodes: nodes,
})
assert.Nil(t, err)
- assert.Equal(t, *obj.ID, "2")
+ assert.Equal(t, obj.ID, "2")
// List
objs, err := cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 2)
- assert.Equal(t, *objs[0].ID, "1")
- assert.Equal(t, *objs[1].ID, "2")
+ assert.Equal(t, objs[0].ID, "1")
+ assert.Equal(t, objs[1].ID, "2")
// Delete then List
assert.Nil(t, cli.Delete(context.Background(), objs[0]))
objs, err = cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 1)
- assert.Equal(t, "2", *objs[0].ID)
+ assert.Equal(t, "2", objs[0].ID)
// Patch then List
- lbType = "chash"
- objId := "2"
_, err = cli.Update(context.Background(), &v1.Upstream{
- ID: &objId,
- FullName: &fullName,
- Group: &group,
- Name: &name,
- Type: &lbType,
- Key: &key,
+ ID: "2",
+ FullName: fullName,
+ Group: group,
+ Name: name,
+ Type: "chash",
+ Key: key,
Nodes: nodes,
})
assert.Nil(t, err)
objs, err = cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, 1)
- assert.Equal(t, "2", *objs[0].ID)
- assert.Equal(t, lbType, *objs[0].Type)
+ assert.Equal(t, "2", objs[0].ID)
+ assert.Equal(t, "chash", objs[0].Type)
}
diff --git a/pkg/ingress/apisix/route.go b/pkg/ingress/apisix/route.go
index affbf71..c8d0c14 100644
--- a/pkg/ingress/apisix/route.go
+++ b/pkg/ingress/apisix/route.go
@@ -90,15 +90,15 @@ func (ar *ApisixRoute) Convert() ([]*apisix.Route,
[]*apisix.Service, []*apisix.
// routes
route := &apisix.Route{
- Group: &group,
- FullName: &fullRouteName,
- ResourceVersion: &rv,
- Name: &apisixRouteName,
- Host: &host,
- Path: &uri,
- ServiceName: &apisixSvcName,
- UpstreamName: &apisixUpstreamName,
- Plugins: &pluginRet,
+ Group: group,
+ FullName: fullRouteName,
+ ResourceVersion: rv,
+ Name: apisixRouteName,
+ Host: host,
+ Path: uri,
+ ServiceName: apisixSvcName,
+ UpstreamName: apisixUpstreamName,
+ Plugins: pluginRet,
}
routes = append(routes, route)
// services
@@ -109,13 +109,13 @@ func (ar *ApisixRoute) Convert() ([]*apisix.Route,
[]*apisix.Service, []*apisix.
}
service := &apisix.Service{
- FullName: &fullServiceName,
- Group: &group,
- Name: &apisixSvcName,
- UpstreamName: &apisixUpstreamName,
- ResourceVersion: &rv,
+ FullName: fullServiceName,
+ Group: group,
+ Name: apisixSvcName,
+ UpstreamName: apisixUpstreamName,
+ ResourceVersion: rv,
}
- serviceMap[*service.FullName] = service
+ serviceMap[service.FullName] = service
// upstreams
// fullServiceName
@@ -127,14 +127,14 @@ func (ar *ApisixRoute) Convert() ([]*apisix.Route,
[]*apisix.Service, []*apisix.
port, _ := strconv.Atoi(svcPort)
nodes := endpoint.BuildEps(ns, svcName, port)
upstream := &apisix.Upstream{
- FullName: &fullUpstreamName,
- Group: &group,
- ResourceVersion: &rv,
- Name: &apisixUpstreamName,
- Type: &LBType,
+ FullName: fullUpstreamName,
+ Group: group,
+ ResourceVersion: rv,
+ Name: apisixUpstreamName,
+ Type: LBType,
Nodes: nodes,
}
- upstreamMap[*upstream.FullName] = upstream
+ upstreamMap[upstream.FullName] = upstream
}
}
for _, s := range serviceMap {
diff --git a/pkg/ingress/apisix/service.go b/pkg/ingress/apisix/service.go
index 65ea5b6..b8d9d1a 100644
--- a/pkg/ingress/apisix/service.go
+++ b/pkg/ingress/apisix/service.go
@@ -47,20 +47,20 @@ func (as *ApisixServiceCRD) Convert() ([]*apisix.Service,
[]*apisix.Upstream, er
fromKind := ApisixService
// plugins
plugins := as.Spec.Plugins
- pluginRet := &apisix.Plugins{}
+ pluginRet := apisix.Plugins{}
// 1.from annotations
for k, v := range pluginsInAnnotation {
- (*pluginRet)[k] = v
+ pluginRet[k] = v
}
// 2.from service plugins
for _, p := range plugins {
if p.Enable {
if p.Config != nil {
- (*pluginRet)[p.Name] = p.Config
+ pluginRet[p.Name] = p.Config
} else if p.ConfigSet != nil {
- (*pluginRet)[p.Name] = p.ConfigSet
+ pluginRet[p.Name] = p.ConfigSet
} else {
- (*pluginRet)[p.Name] =
make(map[string]interface{})
+ pluginRet[p.Name] = make(map[string]interface{})
}
}
}
@@ -71,12 +71,12 @@ func (as *ApisixServiceCRD) Convert() ([]*apisix.Service,
[]*apisix.Upstream, er
}
service := &apisix.Service{
- FullName: &fullServiceName,
- Group: &group,
- ResourceVersion: &rv,
- Name: &apisixServiceName,
- UpstreamName: &apisixUpstreamName,
- FromKind: &fromKind,
+ FullName: fullServiceName,
+ Group: group,
+ ResourceVersion: rv,
+ Name: apisixServiceName,
+ UpstreamName: apisixUpstreamName,
+ FromKind: fromKind,
Plugins: pluginRet,
}
services = append(services, service)
@@ -89,13 +89,13 @@ func (as *ApisixServiceCRD) Convert() ([]*apisix.Service,
[]*apisix.Upstream, er
LBType := DefaultLBType
nodes := endpoint.BuildEps(ns, upstreamName, int(port))
upstream := &apisix.Upstream{
- FullName: &fullUpstreamName,
- Group: &group,
- ResourceVersion: &rv,
- Name: &apisixUpstreamName,
- Type: &LBType,
+ FullName: fullUpstreamName,
+ Group: group,
+ ResourceVersion: rv,
+ Name: apisixUpstreamName,
+ Type: LBType,
Nodes: nodes,
- FromKind: &fromKind,
+ FromKind: fromKind,
}
upstreams = append(upstreams, upstream)
return services, upstreams, nil
diff --git a/pkg/ingress/apisix/tls.go b/pkg/ingress/apisix/tls.go
index d9b6c9a..5419beb 100644
--- a/pkg/ingress/apisix/tls.go
+++ b/pkg/ingress/apisix/tls.go
@@ -45,17 +45,17 @@ func (as *ApisixTLSCRD) Convert(sc Secreter) (*apisix.Ssl,
error) {
cert := string(secret.Data["cert"])
key := string(secret.Data["key"])
status := 1
- snis := make([]*string, 0)
+ snis := make([]string, 0)
for _, host := range as.Spec.Hosts {
- snis = append(snis, &host)
+ snis = append(snis, host)
}
ssl := &apisix.Ssl{
- ID: &id,
+ ID: id,
Snis: snis,
- Cert: &cert,
- Key: &key,
- Status: &status,
- Group: &group,
+ Cert: cert,
+ Key: key,
+ Status: status,
+ Group: group,
}
return ssl, nil
}
diff --git a/pkg/ingress/apisix/tls_test.go b/pkg/ingress/apisix/tls_test.go
index 23adc79..0df3569 100644
--- a/pkg/ingress/apisix/tls_test.go
+++ b/pkg/ingress/apisix/tls_test.go
@@ -43,25 +43,25 @@ spec:
namespace: helm
`
id := "helm_foo"
- host := "api6.com"
- snis := []*string{&host}
- status := int(1)
+ snis := []string{"api6.com"}
+ status := 1
cert := "root"
key := "123456"
group := ""
sslExpect := &apisix.Ssl{
- ID: &id,
+ ID: id,
Snis: snis,
- Cert: &cert,
- Key: &key,
- Status: &status,
- Group: &group,
+ Cert: cert,
+ Key: key,
+ Status: status,
+ Group: group,
}
atlsCRD := &ApisixTLSCRD{}
err := yaml.Unmarshal([]byte(atlsStr), atlsCRD)
assert.Nil(t, err, "yaml decode failed")
sc := &SecretClientMock{}
ssl, err := atlsCRD.Convert(sc)
+ assert.Nil(t, err)
assert.EqualValues(t, sslExpect.Key, ssl.Key, "key convert error")
assert.EqualValues(t, sslExpect.ID, ssl.ID, "id convert error")
assert.EqualValues(t, sslExpect.Cert, ssl.Cert, "cert convert error")
@@ -86,19 +86,18 @@ spec:
namespace: helm
`
id := "helm_foo"
- host := "api6.com"
- snis := []*string{&host}
+ snis := []string{"api6.com"}
status := int(1)
cert := "root"
key := "123456"
group := "127.0.0.1:9080"
sslExpect := &apisix.Ssl{
- ID: &id,
+ ID: id,
Snis: snis,
- Cert: &cert,
- Key: &key,
- Status: &status,
- Group: &group,
+ Cert: cert,
+ Key: key,
+ Status: status,
+ Group: group,
}
setDummyApisixClient(t)
atlsCRD := &ApisixTLSCRD{}
@@ -106,6 +105,7 @@ spec:
assert.Nil(t, err, "yaml decode failed")
sc := &SecretClientMock{}
ssl, err := atlsCRD.Convert(sc)
+ assert.Nil(t, err)
assert.EqualValues(t, sslExpect.Group, ssl.Group, "group convert error")
}
diff --git a/pkg/ingress/apisix/upstream.go b/pkg/ingress/apisix/upstream.go
index 0336211..7b0ab3f 100644
--- a/pkg/ingress/apisix/upstream.go
+++ b/pkg/ingress/apisix/upstream.go
@@ -56,7 +56,7 @@ func (aub *ApisixUpstreamBuilder) Convert()
([]*apisix.Upstream, error) {
lb := r.LoadBalancer
//nodes := endpoint.BuildEps(ns, name, int(port))
- nodes := aub.Ep.BuildEps(ns, name, int(port))
+ nodes := aub.Ep.BuildEps(ns, name, port)
fromKind := ApisixUpstream
// fullName
@@ -65,12 +65,12 @@ func (aub *ApisixUpstreamBuilder) Convert()
([]*apisix.Upstream, error) {
fullName = group + "_" + apisixUpstreamName
}
upstream := &apisix.Upstream{
- FullName: &fullName,
- Group: &group,
- ResourceVersion: &rv,
- Name: &apisixUpstreamName,
+ FullName: fullName,
+ Group: group,
+ ResourceVersion: rv,
+ Name: apisixUpstreamName,
Nodes: nodes,
- FromKind: &fromKind,
+ FromKind: fromKind,
}
lbType := RR
if lb != nil {
@@ -78,20 +78,20 @@ func (aub *ApisixUpstreamBuilder) Convert()
([]*apisix.Upstream, error) {
}
switch {
case lbType == CHASH:
- upstream.Type = &lbType
+ upstream.Type = lbType
hashOn := lb["hashOn"]
key := lb["key"]
if hashOn != nil {
ho := hashOn.(string)
- upstream.HashOn = &ho
+ upstream.HashOn = ho
}
if key != nil {
k := key.(string)
- upstream.Key = &k
+ upstream.Key = k
}
default:
lbType = RR
- upstream.Type = &lbType
+ upstream.Type = lbType
}
upstreams = append(upstreams, upstream)
}
diff --git a/pkg/ingress/apisix/upstream_test.go
b/pkg/ingress/apisix/upstream_test.go
index 220c6e7..c2e27f4 100644
--- a/pkg/ingress/apisix/upstream_test.go
+++ b/pkg/ingress/apisix/upstream_test.go
@@ -54,11 +54,11 @@ func TestApisixUpstreamCRD_Convert(t *testing.T) {
}
func equals(s, d *v1.Upstream) bool {
- if *s.Name != *d.Name || *s.FullName != *d.FullName || *s.Group !=
*d.Group {
+ if s.Name != d.Name || s.FullName != d.FullName || s.Group != d.Group {
return false
}
- if *s.FromKind != *d.FromKind || *s.Type != *d.Type || *s.Key != *d.Key
|| *s.HashOn != *d.HashOn {
+ if s.FromKind != d.FromKind || s.Type != d.Type || s.Key != d.Key ||
s.HashOn != d.HashOn {
return false
}
@@ -68,8 +68,8 @@ func equals(s, d *v1.Upstream) bool {
// mock BuildEps
type EndpointRequestTest struct{}
-func (epr *EndpointRequestTest) BuildEps(ns, name string, port int) []*v1.Node
{
- nodes := make([]*v1.Node, 0)
+func (epr *EndpointRequestTest) BuildEps(ns, name string, port int) []v1.Node {
+ nodes := make([]v1.Node, 0)
return nodes
}
@@ -81,14 +81,14 @@ func buildExpectUpstream() *v1.Upstream {
fromKind := "ApisixUpstream"
group := ""
upstreamExpect := &v1.Upstream{
- Group: &group,
- ResourceVersion: &group,
- FullName: &fullName,
- Name: &fullName,
- Type: &LBType,
- HashOn: &HashOn,
- Key: &Key,
- FromKind: &fromKind,
+ Group: group,
+ ResourceVersion: group,
+ FullName: fullName,
+ Name: fullName,
+ Type: LBType,
+ HashOn: HashOn,
+ Key: Key,
+ FromKind: fromKind,
}
return upstreamExpect
}
diff --git a/pkg/ingress/controller/endpoint.go
b/pkg/ingress/controller/endpoint.go
index 6c7a7e1..3d8666f 100644
--- a/pkg/ingress/controller/endpoint.go
+++ b/pkg/ingress/controller/endpoint.go
@@ -185,21 +185,17 @@ func syncWithGroup(group, upstreamName string, ips
[]string, port CoreV1.Endpoin
upstreams, err :=
sevenConf.Client.Cluster(group).Upstream().List(context.TODO())
if err == nil {
for _, upstream := range upstreams {
- if *(upstream.Name) == upstreamName {
- nodes := make([]*apisixv1.Node, 0)
+ if upstream.Name == upstreamName {
+ nodes := make([]apisixv1.Node, 0)
for _, ip := range ips {
- ipAddress := ip
- p := int(port.Port)
- weight := 100
- node := &apisixv1.Node{IP: &ipAddress,
Port: &p, Weight: &weight}
+ node := apisixv1.Node{IP: ip, Port:
int(port.Port), Weight: 100}
nodes = append(nodes, node)
}
upstream.Nodes = nodes
// update upstream nodes
// add to seven solver queue
//apisix.UpdateUpstream(upstream)
- fromKind := WatchFromKind
- upstream.FromKind = &fromKind
+ upstream.FromKind = WatchFromKind
upstreams := []*apisixv1.Upstream{upstream}
comb := state.ApisixCombination{Routes: nil,
Services: nil, Upstreams: upstreams}
if _, err = comb.Solver(); err != nil {
diff --git a/pkg/ingress/controller/watch.go b/pkg/ingress/controller/watch.go
index 4661d94..e2b4c76 100644
--- a/pkg/ingress/controller/watch.go
+++ b/pkg/ingress/controller/watch.go
@@ -74,21 +74,17 @@ func (c *controller) process(obj interface{}) {
upstreams, err :=
cluster.Upstream().List(context.TODO())
if err == nil {
for _, upstream := range
upstreams {
- if *(upstream.Name) ==
upstreamName {
- nodes :=
make([]*apisixv1.Node, 0)
+ if upstream.Name ==
upstreamName {
+ nodes :=
make([]apisixv1.Node, 0)
for _, ip :=
range ips {
-
ipAddress := ip
- p :=
int(port.Port)
- weight
:= 100
- node :=
&apisixv1.Node{IP: &ipAddress, Port: &p, Weight: &weight}
+ node :=
apisixv1.Node{IP: ip, Port: int(port.Port), Weight: 100}
nodes =
append(nodes, node)
}
upstream.Nodes
= nodes
// update
upstream nodes
// add to seven
solver queue
//apisix.UpdateUpstream(upstream)
- fromKind :=
WatchFromKind
-
upstream.FromKind = &fromKind
+
upstream.FromKind = WatchFromKind
upstreams :=
[]*apisixv1.Upstream{upstream}
comb :=
state.ApisixCombination{Routes: nil, Services: nil, Upstreams: upstreams}
if _, err =
comb.Solver(); err != nil {
diff --git a/pkg/ingress/endpoint/ep.go b/pkg/ingress/endpoint/ep.go
index 32eee37..14bf441 100644
--- a/pkg/ingress/endpoint/ep.go
+++ b/pkg/ingress/endpoint/ep.go
@@ -22,22 +22,20 @@ import (
)
type Endpoint interface {
- BuildEps(ns, name string, port int) []*v1.Node
+ BuildEps(ns, name string, port int) []v1.Node
}
type EndpointRequest struct{}
-func (epr *EndpointRequest) BuildEps(ns, name string, port int) []*v1.Node {
- nodes := make([]*v1.Node, 0)
+func (epr *EndpointRequest) BuildEps(ns, name string, port int) []v1.Node {
+ nodes := make([]v1.Node, 0)
epInformers := kube.EndpointsInformer
if ep, err := epInformers.Lister().Endpoints(ns).Get(name); err != nil {
glog.Errorf("find endpoint %s/%s err: %s", ns, name,
err.Error())
} else {
for _, s := range ep.Subsets {
for _, ip := range s.Addresses {
- p := ip.IP
- weight := 100
- node := &v1.Node{IP: &p, Port: &port, Weight:
&weight}
+ node := v1.Node{IP: ip.IP, Port: port, Weight:
100}
nodes = append(nodes, node)
}
}
@@ -46,17 +44,15 @@ func (epr *EndpointRequest) BuildEps(ns, name string, port
int) []*v1.Node {
}
// BuildEps build nodes from endpoints for upstream
-func BuildEps(ns, name string, port int) []*v1.Node {
- nodes := make([]*v1.Node, 0)
+func BuildEps(ns, name string, port int) []v1.Node {
+ nodes := make([]v1.Node, 0)
epInformers := kube.EndpointsInformer
if ep, err := epInformers.Lister().Endpoints(ns).Get(name); err != nil {
glog.Errorf("find endpoint %s/%s err: %s", ns, name,
err.Error())
} else {
for _, s := range ep.Subsets {
for _, ip := range s.Addresses {
- p := ip.IP
- weight := 100
- node := &v1.Node{IP: &p, Port: &port, Weight:
&weight}
+ node := v1.Node{IP: ip.IP, Port: port, Weight:
100}
nodes = append(nodes, node)
}
}
diff --git a/pkg/seven/state/builder.go b/pkg/seven/state/builder.go
index 4861206..683cf0d 100644
--- a/pkg/seven/state/builder.go
+++ b/pkg/seven/state/builder.go
@@ -36,8 +36,7 @@ const (
// value to indicate whether the route is a new created one.
func paddingRoute(route *v1.Route, currentRoute *v1.Route) bool {
if currentRoute == nil {
- rid := id.GenID(*route.FullName)
- route.ID = &rid
+ route.ID = id.GenID(route.FullName)
return true
}
route.ID = currentRoute.ID
@@ -48,8 +47,7 @@ func paddingRoute(route *v1.Route, currentRoute *v1.Route)
bool {
// value to indicate whether the service is a new created one.
func paddingService(service *v1.Service, currentService *v1.Service) bool {
if currentService == nil {
- sid := id.GenID(*service.FullName)
- service.ID = &sid
+ service.ID = id.GenID(service.FullName)
return true
}
service.ID = currentService.ID
@@ -60,8 +58,7 @@ func paddingService(service *v1.Service, currentService
*v1.Service) bool {
// value to indicate whether the upstream is a new created one.
func paddingUpstream(upstream *v1.Upstream, currentUpstream *v1.Upstream) bool
{
if currentUpstream == nil {
- uid := id.GenID(*upstream.FullName)
- upstream.ID = &uid
+ upstream.ID = id.GenID(upstream.FullName)
return true
}
upstream.ID = currentUpstream.ID
@@ -78,7 +75,7 @@ func NewRouteWorkers(ctx context.Context,
for _, r := range routes {
rw := &routeWorker{Route: r, Ctx: ctx, Wg: wg, ErrorChan:
errorChan}
rw.start()
- rwg.Add(*r.ServiceName, rw)
+ rwg.Add(r.ServiceName, rw)
}
return rwg
}
@@ -98,14 +95,14 @@ func (r *routeWorker) trigger(event Event) {
// consumer Event
service := event.Obj.(*v1.Service)
r.ServiceId = service.ID
- log.Infof("trigger routeWorker %s from %s, %s", *r.Name, event.Op,
*service.Name)
+ log.Infof("trigger routeWorker %s from %s, %s", r.Name, event.Op,
service.Name)
// padding
var cluster string
- if r.Route.Group != nil {
- cluster = *r.Route.Group
+ if r.Route.Group != "" {
+ cluster = r.Route.Group
}
- currentRoute, err :=
conf.Client.Cluster(cluster).Route().Get(context.TODO(), *r.Route.FullName)
+ currentRoute, err :=
conf.Client.Cluster(cluster).Route().Get(context.TODO(), r.Route.FullName)
if err != nil && !errors.Is(err, cache.ErrNotFound) {
errNotify = err
return
@@ -134,24 +131,24 @@ func (r *routeWorker) trigger(event Event) {
// sync
func (r *routeWorker) sync(op string) error {
var cluster string
- if r.Group != nil {
- cluster = *r.Group
+ if r.Group != "" {
+ cluster = r.Group
}
if op == Update {
if _, err :=
conf.Client.Cluster(cluster).Route().Update(context.TODO(), r.Route); err !=
nil {
- log.Errorf("failed to update route %s: %s, ", *r.Name,
err)
+ log.Errorf("failed to update route %s: %s, ", r.Name,
err)
return err
}
- log.Infof("update route %s, %s", *r.Name, *r.ServiceId)
+ log.Infof("update route %s, %s", r.Name, r.ServiceId)
} else {
route, err :=
conf.Client.Cluster(cluster).Route().Create(context.TODO(), r.Route)
if err != nil {
log.Errorf("failed to create route: %s", err.Error())
return err
}
- *r.ID = *route.ID
+ r.ID = route.ID
}
- log.Infof("create route %s, %s", *r.Name, *r.ServiceId)
+ log.Infof("create route %s, %s", r.Name, r.ServiceId)
return nil
}
@@ -163,7 +160,7 @@ func NewServiceWorkers(ctx context.Context,
rw := &serviceWorker{Service: s, Ctx: ctx, Wg: wg, ErrorChan:
errorChan}
//rw.Wg.Add(1)
rw.start(rwg)
- swg.Add(*s.UpstreamName, rw)
+ swg.Add(s.UpstreamName, rw)
}
return swg
}
@@ -187,11 +184,11 @@ func SolverSingleUpstream(u *v1.Upstream, swg
ServiceWorkerGroup, wg *sync.WaitG
wg.Done()
}()
var cluster string
- if u.Group != nil {
- cluster = *u.Group
+ if u.Group != "" {
+ cluster = u.Group
}
- if currentUpstream, err :=
conf.Client.Cluster(cluster).Upstream().Get(context.TODO(), *u.FullName); err
!= nil && err != cache.ErrNotFound {
- log.Errorf("failed to find upstream %s: %s", *u.FullName, err)
+ if currentUpstream, err :=
conf.Client.Cluster(cluster).Upstream().Get(context.TODO(), u.FullName); err !=
nil && err != cache.ErrNotFound {
+ log.Errorf("failed to find upstream %s: %s", u.FullName, err)
errNotify = err
return
} else {
@@ -202,13 +199,13 @@ func SolverSingleUpstream(u *v1.Upstream, swg
ServiceWorkerGroup, wg *sync.WaitG
}
if op == Create {
- if u.FromKind != nil && *u.FromKind == WatchFromKind {
+ if u.FromKind == WatchFromKind {
// We don't have a pre-defined upstream and the
current upstream updating from
// endpoints.
return
}
if _, err :=
conf.Client.Cluster(cluster).Upstream().Create(context.TODO(), u); err != nil {
- log.Errorf("failed to create upstream %s: %s",
*u.FullName, err)
+ log.Errorf("failed to create upstream %s: %s",
u.FullName, err)
return
}
} else {
@@ -222,30 +219,30 @@ func SolverSingleUpstream(u *v1.Upstream, swg
ServiceWorkerGroup, wg *sync.WaitG
op = Update
// 0.field check
needToUpdate := true
- if currentUpstream.FromKind != nil &&
*(currentUpstream.FromKind) == ApisixUpstream { // update from ApisixUpstream
- if u.FromKind == nil || (u.FromKind !=
nil && *(u.FromKind) != ApisixUpstream) {
+ if currentUpstream.FromKind == ApisixUpstream {
// update from ApisixUpstream
+ if u.FromKind != ApisixUpstream {
// currentUpstream > u
// set lb && health check
needToUpdate = false
}
}
- if needToUpdate || (u.FromKind != nil &&
*u.FromKind == WatchFromKind) {
- if u.FromKind != nil && *u.FromKind ==
WatchFromKind {
+ if needToUpdate || u.FromKind == WatchFromKind {
+ if u.FromKind == WatchFromKind {
currentUpstream.Nodes = u.Nodes
} else { // due to CRD update
currentUpstream = u
}
if _, err =
conf.Client.Cluster(cluster).Upstream().Update(context.TODO(),
currentUpstream); err != nil {
- log.Errorf("failed to update
upstream %s: %s", *u.FullName, err)
+ log.Errorf("failed to update
upstream %s: %s", u.FullName, err)
return
}
}
}
}
}
- log.Infof("solver upstream %s:%s", op, *u.Name)
+ log.Infof("solver upstream %s:%s", op, u.Name)
// anyway, broadcast to service
- serviceWorkers := swg[*u.Name]
+ serviceWorkers := swg[u.Name]
for _, sw := range serviceWorkers {
event := &Event{Kind: UpstreamKind, Op: op, Obj: u}
sw.Event <- *event
diff --git a/pkg/seven/state/service_worker.go
b/pkg/seven/state/service_worker.go
index 8e19234..d74f351 100644
--- a/pkg/seven/state/service_worker.go
+++ b/pkg/seven/state/service_worker.go
@@ -59,7 +59,7 @@ func (w *serviceWorker) trigger(event Event, rwg
*RouteWorkerGroup) error {
log.Infof("1.service trigger from %s, %s", event.Op, event.Kind)
// consumer Event set upstreamID
upstream := event.Obj.(*v1.Upstream)
- log.Infof("2.service trigger from %s, %s", event.Op, *upstream.Name)
+ log.Infof("2.service trigger from %s, %s", event.Op, upstream.Name)
w.UpstreamId = upstream.ID
// add to queue
@@ -89,10 +89,10 @@ func SolverSingleService(svc *v1.Service, rwg
RouteWorkerGroup, wg *sync.WaitGro
op := Update
// padding
var cluster string
- if svc.Group != nil {
- cluster = *svc.Group
+ if svc.Group != "" {
+ cluster = svc.Group
}
- currentService, _ :=
conf.Client.Cluster(cluster).Service().Get(context.TODO(), *svc.FullName)
+ currentService, _ :=
conf.Client.Cluster(cluster).Service().Get(context.TODO(), svc.FullName)
if paddingService(svc, currentService) {
op = Create
}
@@ -110,11 +110,11 @@ func SolverSingleService(svc *v1.Service, rwg
RouteWorkerGroup, wg *sync.WaitGro
errNotify = err
return
}
- log.Infof("create service %s, %s", *svc.Name,
*svc.UpstreamId)
+ log.Infof("create service %s, %s", svc.Name,
svc.UpstreamId)
} else {
needToUpdate := true
- if currentService.FromKind != nil &&
*(currentService.FromKind) == ApisixService { // update from ApisixUpstream
- if svc.FromKind == nil || (svc.FromKind != nil
&& *(svc.FromKind) != ApisixService) {
+ if currentService.FromKind == ApisixService { // update
from ApisixUpstream
+ if svc.FromKind != ApisixService {
// currentService > svc
// set lb && health check
needToUpdate = false
@@ -123,17 +123,17 @@ func SolverSingleService(svc *v1.Service, rwg
RouteWorkerGroup, wg *sync.WaitGro
if needToUpdate {
if _, err :=
conf.Client.Cluster(cluster).Service().Update(context.TODO(), svc); err != nil {
errNotify = err
- log.Errorf("failed to update service:
%s, id:%s", err, *svc.ID)
+ log.Errorf("failed to update service:
%s, id:%s", err, svc.ID)
} else {
- log.Infof("updated service, id:%s,
upstream_id:%s", *svc.ID, *svc.UpstreamId)
+ log.Infof("updated service, id:%s,
upstream_id:%s", svc.ID, svc.UpstreamId)
}
}
}
}
// broadcast to route
- for _, rw := range rwg[*svc.Name] {
+ for _, rw := range rwg[svc.Name] {
event := &Event{Kind: ServiceKind, Op: op, Obj: svc}
- log.Infof("send event %s, %s, %s", event.Kind, event.Op,
*svc.Name)
+ log.Infof("send event %s, %s, %s", event.Kind, event.Op,
svc.Name)
rw.Event <- *event
}
}
diff --git a/pkg/seven/state/solver.go b/pkg/seven/state/solver.go
index 46b2167..9d1e504 100644
--- a/pkg/seven/state/solver.go
+++ b/pkg/seven/state/solver.go
@@ -58,13 +58,13 @@ func (s *ApisixCombination) Remove() error {
// services
for _, svc := range s.Services {
var cluster string
- if svc.Group != nil {
- cluster = *svc.Group
+ if svc.Group != "" {
+ cluster = svc.Group
}
- svcInCache, err :=
conf.Client.Cluster(cluster).Service().Get(context.TODO(), *svc.FullName)
+ svcInCache, err :=
conf.Client.Cluster(cluster).Service().Get(context.TODO(), svc.FullName)
if err != nil {
if err == cache.ErrNotFound {
- log.Errorf("failed to remove service %s: %s",
*svc.FullName, err)
+ log.Errorf("failed to remove service %s: %s",
svc.FullName, err)
continue
} else {
return err
@@ -74,9 +74,9 @@ func (s *ApisixCombination) Remove() error {
err =
conf.Client.Cluster(cluster).Service().Delete(context.TODO(), svc)
if err != nil {
if err == cache.ErrNotFound {
- log.Errorf("failed to remove service %s: %s",
*svc.FullName, err)
+ log.Errorf("failed to remove service %s: %s",
svc.FullName, err)
} else if err == cache.ErrStillInUse {
- log.Warnf("failed to remove service %s: %s",
*svc.FullName, err)
+ log.Warnf("failed to remove service %s: %s",
svc.FullName, err)
} else {
return err
}
@@ -86,13 +86,13 @@ func (s *ApisixCombination) Remove() error {
// upstreams
for _, ups := range s.Upstreams {
var cluster string
- if ups.Group != nil {
- cluster = *ups.Group
+ if ups.Group != "" {
+ cluster = ups.Group
}
- upsInCache, err :=
conf.Client.Cluster(cluster).Upstream().Get(context.TODO(), *ups.FullName)
+ upsInCache, err :=
conf.Client.Cluster(cluster).Upstream().Get(context.TODO(), ups.FullName)
if err != nil {
if err == cache.ErrNotFound {
- log.Errorf("failed to remove service %s: %s",
*ups.FullName, err)
+ log.Errorf("failed to remove service %s: %s",
ups.FullName, err)
continue
} else {
return err
@@ -101,9 +101,9 @@ func (s *ApisixCombination) Remove() error {
_ = paddingUpstream(ups, upsInCache)
err =
conf.Client.Cluster(cluster).Upstream().Delete(context.TODO(), ups)
if err == cache.ErrNotFound {
- log.Errorf("failed to remove upstream %s: %s",
*ups.FullName, err)
+ log.Errorf("failed to remove upstream %s: %s",
ups.FullName, err)
} else if err == cache.ErrStillInUse {
- log.Warnf("failed to remove upstream %s: %s",
*ups.FullName, err)
+ log.Warnf("failed to remove upstream %s: %s",
ups.FullName, err)
} else {
return err
}
@@ -190,12 +190,12 @@ func (rc *RouteCompare) Sync() error {
}
if needToDel {
var cluster string
- if old.Group != nil {
- cluster = *old.Group
+ if old.Group != "" {
+ cluster = old.Group
}
// old should inject the ID.
- route, err :=
conf.Client.Cluster(cluster).Route().Get(context.TODO(), *old.FullName)
+ route, err :=
conf.Client.Cluster(cluster).Route().Get(context.TODO(), old.FullName)
if err != nil {
if err != cache.ErrNotFound {
merr = multierr.Append(merr, err)
@@ -205,7 +205,7 @@ func (rc *RouteCompare) Sync() error {
_ = paddingRoute(old, route)
if err :=
conf.Client.Cluster(cluster).Route().Delete(context.TODO(), old); err != nil {
- log.Errorf("failed to delete route %s from
APISIX: %s", *old.Name, err)
+ log.Errorf("failed to delete route %s from
APISIX: %s", old.Name, err)
merr = multierr.Append(merr, err)
}
}
@@ -215,8 +215,8 @@ func (rc *RouteCompare) Sync() error {
func SyncSsl(ssl *v1.Ssl, method string) error {
var cluster string
- if ssl.Group != nil {
- cluster = *ssl.Group
+ if ssl.Group != "" {
+ cluster = ssl.Group
}
switch method {
case Create:
diff --git a/pkg/types/apisix/v1/types.go b/pkg/types/apisix/v1/types.go
index 694b9e2..7c78a9b 100644
--- a/pkg/types/apisix/v1/types.go
+++ b/pkg/types/apisix/v1/types.go
@@ -19,19 +19,19 @@ import "encoding/json"
// Route apisix route object
// +k8s:deepcopy-gen=true
type Route struct {
- ID *string `json:"id,omitempty" yaml:"id,omitempty"`
- Group *string `json:"group,omitempty"
yaml:"group,omitempty"`
- FullName *string `json:"full_name,omitempty"
yaml:"full_name,omitempty"`
- ResourceVersion *string `json:"resource_version,omitempty"
yaml:"resource_version,omitempty"`
- Host *string `json:"host,omitempty" yaml:"host,omitempty"`
- Path *string `json:"path,omitempty" yaml:"path,omitempty"`
- Name *string `json:"name,omitempty" yaml:"name,omitempty"`
- Methods []*string `json:"methods,omitempty"
yaml:"methods,omitempty"`
- ServiceId *string `json:"service_id,omitempty"
yaml:"service_id,omitempty"`
- ServiceName *string `json:"service_name,omitempty"
yaml:"service_name,omitempty"`
- UpstreamId *string `json:"upstream_id,omitempty"
yaml:"upstream_id,omitempty"`
- UpstreamName *string `json:"upstream_name,omitempty"
yaml:"upstream_name,omitempty"`
- Plugins *Plugins `json:"plugins,omitempty"
yaml:"plugins,omitempty"`
+ ID string `json:"id,omitempty" yaml:"id,omitempty"`
+ Group string `json:"group,omitempty" yaml:"group,omitempty"`
+ FullName string `json:"full_name,omitempty"
yaml:"full_name,omitempty"`
+ ResourceVersion string `json:"resource_version,omitempty"
yaml:"resource_version,omitempty"`
+ Host string `json:"host,omitempty" yaml:"host,omitempty"`
+ Path string `json:"path,omitempty" yaml:"path,omitempty"`
+ Name string `json:"name,omitempty" yaml:"name,omitempty"`
+ Methods []string `json:"methods,omitempty"
yaml:"methods,omitempty"`
+ ServiceId string `json:"service_id,omitempty"
yaml:"service_id,omitempty"`
+ ServiceName string `json:"service_name,omitempty"
yaml:"service_name,omitempty"`
+ UpstreamId string `json:"upstream_id,omitempty"
yaml:"upstream_id,omitempty"`
+ UpstreamName string `json:"upstream_name,omitempty"
yaml:"upstream_name,omitempty"`
+ Plugins Plugins `json:"plugins,omitempty"
yaml:"plugins,omitempty"`
}
type Plugins map[string]interface{}
@@ -53,47 +53,47 @@ func (p *Plugins) DeepCopy() *Plugins {
// Service apisix service
// +k8s:deepcopy-gen=true
type Service struct {
- ID *string `json:"id,omitempty" yaml:"id,omitempty"`
- FullName *string `json:"full_name,omitempty"
yaml:"full_name,omitempty"`
- Group *string `json:"group,omitempty" yaml:"group,omitempty"`
- ResourceVersion *string `json:"resource_version,omitempty"
yaml:"resource_version,omitempty"`
- Name *string `json:"name,omitempty" yaml:"name,omitempty"`
- UpstreamId *string `json:"upstream_id,omitempty"
yaml:"upstream_id,omitempty"`
- UpstreamName *string `json:"upstream_name,omitempty"
yaml:"upstream_name,omitempty"`
- Plugins *Plugins `json:"plugins,omitempty"
yaml:"plugins,omitempty"`
- FromKind *string `json:"from_kind,omitempty"
yaml:"from_kind,omitempty"`
+ ID string `json:"id,omitempty" yaml:"id,omitempty"`
+ FullName string `json:"full_name,omitempty"
yaml:"full_name,omitempty"`
+ Group string `json:"group,omitempty" yaml:"group,omitempty"`
+ ResourceVersion string `json:"resource_version,omitempty"
yaml:"resource_version,omitempty"`
+ Name string `json:"name,omitempty" yaml:"name,omitempty"`
+ UpstreamId string `json:"upstream_id,omitempty"
yaml:"upstream_id,omitempty"`
+ UpstreamName string `json:"upstream_name,omitempty"
yaml:"upstream_name,omitempty"`
+ Plugins Plugins `json:"plugins,omitempty"
yaml:"plugins,omitempty"`
+ FromKind string `json:"from_kind,omitempty"
yaml:"from_kind,omitempty"`
}
// Upstream apisix upstream
// +k8s:deepcopy-gen=true
type Upstream struct {
- ID *string `json:"id,omitempty" yaml:"id,omitempty"`
- FullName *string `json:"full_name,omitempty"
yaml:"full_name,omitempty"`
- Group *string `json:"group,omitempty" yaml:"group,omitempty"`
- ResourceVersion *string `json:"resource_version,omitempty"
yaml:"resource_version,omitempty"`
- Name *string `json:"name,omitempty" yaml:"name,omitempty"`
- Type *string `json:"type,omitempty" yaml:"type,omitempty"`
- HashOn *string `json:"hash_on,omitemtpy"
yaml:"hash_on,omitempty"`
- Key *string `json:"key,omitempty" yaml:"key,omitempty"`
- Nodes []*Node `json:"nodes,omitempty" yaml:"nodes,omitempty"`
- FromKind *string `json:"from_kind,omitempty"
yaml:"from_kind,omitempty"`
+ ID string `json:"id,omitempty" yaml:"id,omitempty"`
+ FullName string `json:"full_name,omitempty"
yaml:"full_name,omitempty"`
+ Group string `json:"group,omitempty" yaml:"group,omitempty"`
+ ResourceVersion string `json:"resource_version,omitempty"
yaml:"resource_version,omitempty"`
+ Name string `json:"name,omitempty" yaml:"name,omitempty"`
+ Type string `json:"type,omitempty" yaml:"type,omitempty"`
+ HashOn string `json:"hash_on,omitemtpy"
yaml:"hash_on,omitempty"`
+ Key string `json:"key,omitempty" yaml:"key,omitempty"`
+ Nodes []Node `json:"nodes,omitempty" yaml:"nodes,omitempty"`
+ FromKind string `json:"from_kind,omitempty"
yaml:"from_kind,omitempty"`
}
// Node the node in upstream
// +k8s:deepcopy-gen=true
type Node struct {
- IP *string `json:"ip,omitempty" yaml:"ip,omitempty"`
- Port *int `json:"port,omitempty" yaml:"port,omitempty"`
- Weight *int `json:"weight,omitempty" yaml:"weight,omitempty"`
+ IP string `json:"ip,omitempty" yaml:"ip,omitempty"`
+ Port int `json:"port,omitempty" yaml:"port,omitempty"`
+ Weight int `json:"weight,omitempty" yaml:"weight,omitempty"`
}
// Ssl apisix ssl object
// +k8s:deepcopy-gen=true
type Ssl struct {
- ID *string `json:"id,omitempty" yaml:"id,omitempty"`
- Snis []*string `json:"snis,omitempty" yaml:"snis,omitempty"`
- Cert *string `json:"cert,omitempty" yaml:"cert,omitempty"`
- Key *string `json:"key,omitempty" yaml:"key,omitempty"`
- Status *int `json:"status,omitempty" yaml:"status,omitempty"`
- Group *string `json:"group,omitempty" yaml:"group,omitempty"`
+ ID string `json:"id,omitempty" yaml:"id,omitempty"`
+ Snis []string `json:"snis,omitempty" yaml:"snis,omitempty"`
+ Cert string `json:"cert,omitempty" yaml:"cert,omitempty"`
+ Key string `json:"key,omitempty" yaml:"key,omitempty"`
+ Status int `json:"status,omitempty" yaml:"status,omitempty"`
+ Group string `json:"group,omitempty" yaml:"group,omitempty"`
}
diff --git a/pkg/types/apisix/v1/zz_generated.deepcopy.go
b/pkg/types/apisix/v1/zz_generated.deepcopy.go
index 5e7e655..4eedebe 100644
--- a/pkg/types/apisix/v1/zz_generated.deepcopy.go
+++ b/pkg/types/apisix/v1/zz_generated.deepcopy.go
@@ -23,21 +23,6 @@ package v1
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *Node) DeepCopyInto(out *Node) {
*out = *in
- if in.IP != nil {
- in, out := &in.IP, &out.IP
- *out = new(string)
- **out = **in
- }
- if in.Port != nil {
- in, out := &in.Port, &out.Port
- *out = new(int)
- **out = **in
- }
- if in.Weight != nil {
- in, out := &in.Weight, &out.Weight
- *out = new(int)
- **out = **in
- }
return
}
@@ -54,76 +39,12 @@ func (in *Node) DeepCopy() *Node {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *Route) DeepCopyInto(out *Route) {
*out = *in
- if in.ID != nil {
- in, out := &in.ID, &out.ID
- *out = new(string)
- **out = **in
- }
- if in.Group != nil {
- in, out := &in.Group, &out.Group
- *out = new(string)
- **out = **in
- }
- if in.FullName != nil {
- in, out := &in.FullName, &out.FullName
- *out = new(string)
- **out = **in
- }
- if in.ResourceVersion != nil {
- in, out := &in.ResourceVersion, &out.ResourceVersion
- *out = new(string)
- **out = **in
- }
- if in.Host != nil {
- in, out := &in.Host, &out.Host
- *out = new(string)
- **out = **in
- }
- if in.Path != nil {
- in, out := &in.Path, &out.Path
- *out = new(string)
- **out = **in
- }
- if in.Name != nil {
- in, out := &in.Name, &out.Name
- *out = new(string)
- **out = **in
- }
if in.Methods != nil {
in, out := &in.Methods, &out.Methods
- *out = make([]*string, len(*in))
- for i := range *in {
- if (*in)[i] != nil {
- in, out := &(*in)[i], &(*out)[i]
- *out = new(string)
- **out = **in
- }
- }
- }
- if in.ServiceId != nil {
- in, out := &in.ServiceId, &out.ServiceId
- *out = new(string)
- **out = **in
- }
- if in.ServiceName != nil {
- in, out := &in.ServiceName, &out.ServiceName
- *out = new(string)
- **out = **in
- }
- if in.UpstreamId != nil {
- in, out := &in.UpstreamId, &out.UpstreamId
- *out = new(string)
- **out = **in
- }
- if in.UpstreamName != nil {
- in, out := &in.UpstreamName, &out.UpstreamName
- *out = new(string)
- **out = **in
- }
- if in.Plugins != nil {
- in, out := &in.Plugins, &out.Plugins
- *out = (*in).DeepCopy()
+ *out = make([]string, len(*in))
+ copy(*out, *in)
}
+ in.Plugins.DeepCopyInto(&out.Plugins)
return
}
@@ -140,50 +61,7 @@ func (in *Route) DeepCopy() *Route {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *Service) DeepCopyInto(out *Service) {
*out = *in
- if in.ID != nil {
- in, out := &in.ID, &out.ID
- *out = new(string)
- **out = **in
- }
- if in.FullName != nil {
- in, out := &in.FullName, &out.FullName
- *out = new(string)
- **out = **in
- }
- if in.Group != nil {
- in, out := &in.Group, &out.Group
- *out = new(string)
- **out = **in
- }
- if in.ResourceVersion != nil {
- in, out := &in.ResourceVersion, &out.ResourceVersion
- *out = new(string)
- **out = **in
- }
- if in.Name != nil {
- in, out := &in.Name, &out.Name
- *out = new(string)
- **out = **in
- }
- if in.UpstreamId != nil {
- in, out := &in.UpstreamId, &out.UpstreamId
- *out = new(string)
- **out = **in
- }
- if in.UpstreamName != nil {
- in, out := &in.UpstreamName, &out.UpstreamName
- *out = new(string)
- **out = **in
- }
- if in.Plugins != nil {
- in, out := &in.Plugins, &out.Plugins
- *out = (*in).DeepCopy()
- }
- if in.FromKind != nil {
- in, out := &in.FromKind, &out.FromKind
- *out = new(string)
- **out = **in
- }
+ in.Plugins.DeepCopyInto(&out.Plugins)
return
}
@@ -200,41 +78,10 @@ func (in *Service) DeepCopy() *Service {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *Ssl) DeepCopyInto(out *Ssl) {
*out = *in
- if in.ID != nil {
- in, out := &in.ID, &out.ID
- *out = new(string)
- **out = **in
- }
if in.Snis != nil {
in, out := &in.Snis, &out.Snis
- *out = make([]*string, len(*in))
- for i := range *in {
- if (*in)[i] != nil {
- in, out := &(*in)[i], &(*out)[i]
- *out = new(string)
- **out = **in
- }
- }
- }
- if in.Cert != nil {
- in, out := &in.Cert, &out.Cert
- *out = new(string)
- **out = **in
- }
- if in.Key != nil {
- in, out := &in.Key, &out.Key
- *out = new(string)
- **out = **in
- }
- if in.Status != nil {
- in, out := &in.Status, &out.Status
- *out = new(int)
- **out = **in
- }
- if in.Group != nil {
- in, out := &in.Group, &out.Group
- *out = new(string)
- **out = **in
+ *out = make([]string, len(*in))
+ copy(*out, *in)
}
return
}
@@ -252,61 +99,10 @@ func (in *Ssl) DeepCopy() *Ssl {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver,
writing into out. in must be non-nil.
func (in *Upstream) DeepCopyInto(out *Upstream) {
*out = *in
- if in.ID != nil {
- in, out := &in.ID, &out.ID
- *out = new(string)
- **out = **in
- }
- if in.FullName != nil {
- in, out := &in.FullName, &out.FullName
- *out = new(string)
- **out = **in
- }
- if in.Group != nil {
- in, out := &in.Group, &out.Group
- *out = new(string)
- **out = **in
- }
- if in.ResourceVersion != nil {
- in, out := &in.ResourceVersion, &out.ResourceVersion
- *out = new(string)
- **out = **in
- }
- if in.Name != nil {
- in, out := &in.Name, &out.Name
- *out = new(string)
- **out = **in
- }
- if in.Type != nil {
- in, out := &in.Type, &out.Type
- *out = new(string)
- **out = **in
- }
- if in.HashOn != nil {
- in, out := &in.HashOn, &out.HashOn
- *out = new(string)
- **out = **in
- }
- if in.Key != nil {
- in, out := &in.Key, &out.Key
- *out = new(string)
- **out = **in
- }
if in.Nodes != nil {
in, out := &in.Nodes, &out.Nodes
- *out = make([]*Node, len(*in))
- for i := range *in {
- if (*in)[i] != nil {
- in, out := &(*in)[i], &(*out)[i]
- *out = new(Node)
- (*in).DeepCopyInto(*out)
- }
- }
- }
- if in.FromKind != nil {
- in, out := &in.FromKind, &out.FromKind
- *out = new(string)
- **out = **in
+ *out = make([]Node, len(*in))
+ copy(*out, *in)
}
return
}