Skip to content

Commit e2f3541

Browse files
authored
fix: ssl use cache (#203)
* fix: ssl use cache * fix: cert failed * add tls update & delete test case * fix: modify image * fix: add license header * fix: build error after merge * fix: unit test failed * fix: review & add dp test case * fix: revert ApisixTls * fix: e2e test failed * fix: build image failed * fix: e2e test failed * fix: e2e-test failed * fix: e2e test failed * fix: remove debug info * fix: remove debug info * fix:typo * fix: remove createResourceWithMethod * fix: http ports
1 parent c786e08 commit e2f3541

File tree

29 files changed

+605
-212
lines changed

29 files changed

+605
-212
lines changed

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
4242
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
4343
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
4444
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
45+
github.com/api7/ingress-controller v0.1.0-rc1 h1:6EjrBu0r+ccVfYTnpGYj1txz1DJCJ/Q/k8pHigRkeu0=
4546
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
4647
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
4748
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=

pkg/apisix/cache/memdb_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,21 @@ func TestMemDBCacheSSL(t *testing.T) {
134134
assert.Nil(t, err, "NewMemDBCache")
135135

136136
s1 := &v1.Ssl{
137-
ID: "abc",
137+
ID: "abc",
138+
FullName: "abc",
138139
}
139140
assert.Nil(t, c.InsertSSL(s1), "inserting ssl 1")
140141

141142
s, err := c.GetSSL("abc")
142143
assert.Equal(t, s1, s)
143144

144145
s2 := &v1.Ssl{
145-
ID: "def",
146+
ID: "def",
147+
FullName: "def",
146148
}
147149
s3 := &v1.Ssl{
148-
ID: "ghi",
150+
ID: "ghi",
151+
FullName: "ghi",
149152
}
150153
assert.Nil(t, c.InsertSSL(s2), "inserting ssl 2")
151154
assert.Nil(t, c.InsertSSL(s3), "inserting ssl 3")

pkg/apisix/cache/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ var (
8787
"id": {
8888
Name: "id",
8989
Unique: true,
90-
Indexer: &memdb.StringFieldIndex{Field: "ID"},
90+
Indexer: &memdb.StringFieldIndex{Field: "FullName"},
9191
},
9292
},
9393
},

pkg/apisix/resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func (i *item) ssl(clusterName string) (*v1.Ssl, error) {
192192
id := list[len(list)-1]
193193
ssl.ID = id
194194
ssl.Group = clusterName
195+
ssl.FullName = id
195196
return &ssl, nil
196197
}
197198

pkg/apisix/ssl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func (s *sslClient) Create(ctx context.Context, obj *v1.Ssl) (*v1.Ssl, error) {
138138
log.Infow("try to create ssl",
139139
zap.String("cluster", s.clusterName),
140140
zap.String("url", s.url),
141+
zap.String("id", obj.ID),
141142
)
142143
if err := s.cluster.HasSynced(ctx); err != nil {
143144
return nil, err
@@ -231,7 +232,6 @@ func (s *sslClient) Update(ctx context.Context, obj *v1.Ssl) (*v1.Ssl, error) {
231232
if err := s.cluster.cache.InsertSSL(ssl); err != nil {
232233
log.Errorf("failed to reflect ssl update to cache: %s", err)
233234
return nil, err
234-
235235
}
236236
return ssl, nil
237237
}

pkg/ingress/apisix/tls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
apisix "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1"
2727
)
2828

29-
type ApisixTLSCRD configv1.ApisixTLS
29+
type ApisixTLSCRD configv1.ApisixTls
3030

3131
// Convert convert to apisix.Ssl from ingress.ApisixTls CRD
3232
func (as *ApisixTLSCRD) Convert(sc Secreter) (*apisix.Ssl, error) {

pkg/ingress/controller/apisix_tls.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ type ApisixTLSController struct {
4040
controller *Controller
4141
kubeclientset kubernetes.Interface
4242
apisixClientset clientset.Interface
43-
apisixTLSList listersv1.ApisixTLSLister
43+
apisixTLSList listersv1.ApisixTlsLister
4444
apisixTLSSynced cache.InformerSynced
4545
workqueue workqueue.RateLimitingInterface
4646
}
4747

4848
type TlsQueueObj struct {
4949
Key string `json:"key"`
50-
OldObj *configv1.ApisixTLS `json:"old_obj"`
50+
OldObj *configv1.ApisixTls `json:"old_obj"`
5151
Ope string `json:"ope"` // add / update / delete
5252
}
5353

5454
func BuildApisixTlsController(
5555
kubeclientset kubernetes.Interface,
5656
apisixTLSClientset clientset.Interface,
57-
apisixTLSInformer informersv1.ApisixTLSInformer,
57+
apisixTLSInformer informersv1.ApisixTlsInformer,
5858
root *Controller) *ApisixTLSController {
5959

6060
runtime.Must(apisixscheme.AddToScheme(scheme.Scheme))
@@ -128,13 +128,13 @@ func (c *ApisixTLSController) syncHandler(tqo *TlsQueueObj) error {
128128
}
129129
apisixTlsYaml := tqo.OldObj
130130
if tqo.Ope == state.Delete {
131-
apisixIngressTls, _ := c.apisixTLSList.ApisixTLSs(namespace).Get(name)
131+
apisixIngressTls, _ := c.apisixTLSList.ApisixTlses(namespace).Get(name)
132132
if apisixIngressTls != nil && apisixIngressTls.ResourceVersion > tqo.OldObj.ResourceVersion {
133133
log.Warnf("TLS %s has been covered when retry", tqo.Key)
134134
return nil
135135
}
136136
} else {
137-
apisixTlsYaml, err = c.apisixTLSList.ApisixTLSs(namespace).Get(name)
137+
apisixTlsYaml, err = c.apisixTLSList.ApisixTlses(namespace).Get(name)
138138
if err != nil {
139139
if errors.IsNotFound(err) {
140140
log.Infof("apisixTls %s is removed", tqo.Key)
@@ -172,8 +172,8 @@ func (c *ApisixTLSController) addFunc(obj interface{}) {
172172
}
173173

174174
func (c *ApisixTLSController) updateFunc(oldObj, newObj interface{}) {
175-
oldTls := oldObj.(*configv1.ApisixTLS)
176-
newTls := newObj.(*configv1.ApisixTLS)
175+
oldTls := oldObj.(*configv1.ApisixTls)
176+
newTls := newObj.(*configv1.ApisixTls)
177177
if oldTls.ResourceVersion == newTls.ResourceVersion {
178178
return
179179
}
@@ -191,13 +191,13 @@ func (c *ApisixTLSController) updateFunc(oldObj, newObj interface{}) {
191191
}
192192

193193
func (c *ApisixTLSController) deleteFunc(obj interface{}) {
194-
oldTls, ok := obj.(*configv1.ApisixTLS)
194+
oldTls, ok := obj.(*configv1.ApisixTls)
195195
if !ok {
196196
oldState, ok := obj.(cache.DeletedFinalStateUnknown)
197197
if !ok {
198198
return
199199
}
200-
oldTls, ok = oldState.Obj.(*configv1.ApisixTLS)
200+
oldTls, ok = oldState.Obj.(*configv1.ApisixTls)
201201
if !ok {
202202
return
203203
}

pkg/ingress/controller/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (api6 *Api6Controller) ApisixTLS(controller *Controller) {
330330
atc := BuildApisixTlsController(
331331
api6.KubeClientSet,
332332
api6.Api6ClientSet,
333-
api6.SharedInformerFactory.Apisix().V1().ApisixTLSs(),
333+
api6.SharedInformerFactory.Apisix().V1().ApisixTlses(),
334334
controller)
335335
if err := atc.Run(api6.Stop); err != nil {
336336
log.Errorf("failed to run ApisixTlsController: %s", err)

pkg/kube/apisix/apis/config/v1/register.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
5050
&ApisixUpstreamList{},
5151
&ApisixService{},
5252
&ApisixServiceList{},
53-
&ApisixTLS{},
54-
&ApisixTLSList{},
53+
&ApisixTls{},
54+
&ApisixTlsList{},
5555
)
5656

5757
// register the type in the scheme

pkg/kube/apisix/apis/config/v1/types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,22 +191,22 @@ func (p *Config) DeepCopy() *Config {
191191
// +genclient:noStatus
192192

193193
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
194-
// ApisixTLS defines SSL resource in APISIX.
195-
type ApisixTLS struct {
194+
// ApisixTls defines SSL resource in APISIX.
195+
type ApisixTls struct {
196196
metav1.TypeMeta `json:",inline" yaml:",inline"`
197197
metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
198-
Spec *ApisixTLSSpec `json:"spec,omitempty" yaml:"spec,omitempty"`
198+
Spec *ApisixTlsSpec `json:"spec,omitempty" yaml:"spec,omitempty"`
199199
}
200200

201201
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
202-
type ApisixTLSList struct {
202+
type ApisixTlsList struct {
203203
metav1.TypeMeta `json:",inline"`
204204
metav1.ListMeta `json:"metadata"`
205-
Items []ApisixTLS `json:"items,omitempty"`
205+
Items []ApisixTls `json:"items,omitempty"`
206206
}
207207

208-
// ApisixTLSSpec is the specification of ApisixSSL.
209-
type ApisixTLSSpec struct {
208+
// ApisixTlsSpec is the specification of ApisixSSL.
209+
type ApisixTlsSpec struct {
210210
Hosts []string `json:"hosts,omitempty"`
211211
Secret ApisixSecret `json:"secret,omitempty"`
212212
}

0 commit comments

Comments
 (0)