@@ -2,19 +2,21 @@ package controllers
22
33import (
44 "context"
5+ "testing"
6+ "time"
7+
58 "github.com/kalmhq/kalm/controller/api/v1alpha1"
69 "github.com/stretchr/testify/assert"
710 "github.com/stretchr/testify/suite"
811 corev1 "k8s.io/api/core/v1"
912 "k8s.io/apimachinery/pkg/api/errors"
1013 v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1114 "k8s.io/apimachinery/pkg/types"
12- "testing"
13- "time"
1415)
1516
1617type HttpsCertControllerSuite struct {
1718 BasicSuite
19+ * v1alpha1.Tenant
1820}
1921
2022func TestHttpsCertControllerSuite (t * testing.T ) {
@@ -23,14 +25,17 @@ func TestHttpsCertControllerSuite(t *testing.T) {
2325
2426func (suite * HttpsCertControllerSuite ) SetupSuite () {
2527 suite .BasicSuite .SetupSuite ()
28+
29+ tenant := suite .SetupTenant ()
30+ suite .Tenant = tenant
2631}
2732
2833func (suite * HttpsCertControllerSuite ) TearDownSuite () {
2934 suite .BasicSuite .TearDownSuite ()
3035}
3136
3237func (suite * HttpsCertControllerSuite ) TestSelfManagedCertWithAbsentSecret () {
33- httpsCert := genSelfManagedHttpsCert ()
38+ httpsCert := genSelfManagedHttpsCert (suite . Tenant . Name )
3439 suite .createHttpsCert (httpsCert )
3540
3641 //get
@@ -50,7 +55,7 @@ func (suite *HttpsCertControllerSuite) TestSelfManagedCertWithAbsentSecret() {
5055}
5156
5257func (suite * HttpsCertControllerSuite ) TestSelfManagedCertWithSecret () {
53- httpsCert := genSelfManagedHttpsCert ()
58+ httpsCert := genSelfManagedHttpsCert (suite . Tenant . Name )
5459
5560 //prepare secret for httpsCert first
5661 suite .createObject (& corev1.Secret {
@@ -80,12 +85,8 @@ func (suite *HttpsCertControllerSuite) TestSelfManagedCertWithSecret() {
8085
8186func (suite * HttpsCertControllerSuite ) TestBasicCRUD () {
8287
83- // prepare httpsCertIssuer
84- issuer := genEmptyCAHttpsCertIssuer ()
85- suite .createHttpsCertIssuer (issuer )
86-
8788 //create
88- httpsCert := genHttpsCert (issuer .Name )
89+ httpsCert := genHttpsCert (v1alpha1 . DefaultCAIssuerName , suite . Tenant .Name )
8990 suite .createHttpsCert (httpsCert )
9091
9192 //get
@@ -101,25 +102,6 @@ func (suite *HttpsCertControllerSuite) TestBasicCRUD() {
101102 return err == nil
102103 })
103104
104- // secret with prvKey & cert should be generated too
105- //suite.Eventually(func() bool {
106- // var sec corev1.Secret
107- // err := suite.K8sClient.Get(context.Background(), types.NamespacedName{
108- // Name: httpsCert.Name,
109- // Namespace: "istio-system",
110- // }, &sec)
111- //
112- // if err != nil {
113- // fmt.Println("fail get sec", err)
114- // }
115- //
116- // return err == nil
117- // //_, keyExist := sec.Data["tls.key"]
118- // //_, crtExist := sec.Data["tls.crt"]
119- // //_, caCrtExist := sec.Data["ca.crt"]
120- // //return keyExist && crtExist && caCrtExist
121- //})
122-
123105 // delete
124106 suite .reloadHttpsCert (& httpsCert )
125107 suite .Nil (suite .K8sClient .Delete (context .Background (), & httpsCert ))
@@ -150,7 +132,7 @@ func (suite *HttpsCertControllerSuite) reloadHttpsCert(httpsCert *v1alpha1.Https
150132 suite .Nil (err )
151133}
152134
153- func genSelfManagedHttpsCert (certNameOpt ... string ) v1alpha1.HttpsCert {
135+ func genSelfManagedHttpsCert (tenant string , certNameOpt ... string ) v1alpha1.HttpsCert {
154136 var certName string
155137 if len (certNameOpt ) > 0 {
156138 certName = certNameOpt [0 ]
@@ -161,6 +143,9 @@ func genSelfManagedHttpsCert(certNameOpt ...string) v1alpha1.HttpsCert {
161143 return v1alpha1.HttpsCert {
162144 ObjectMeta : v1.ObjectMeta {
163145 Name : certName ,
146+ Labels : map [string ]string {
147+ v1alpha1 .TenantNameLabelKey : tenant ,
148+ },
164149 },
165150 Spec : v1alpha1.HttpsCertSpec {
166151 IsSelfManaged : true ,
@@ -169,7 +154,7 @@ func genSelfManagedHttpsCert(certNameOpt ...string) v1alpha1.HttpsCert {
169154 },
170155 }
171156}
172- func genHttpsCert (issuer string , certNameOpt ... string ) v1alpha1.HttpsCert {
157+ func genHttpsCert (issuer string , tenant string , certNameOpt ... string ) v1alpha1.HttpsCert {
173158 var certName string
174159 if len (certNameOpt ) > 0 {
175160 certName = certNameOpt [0 ]
@@ -180,6 +165,9 @@ func genHttpsCert(issuer string, certNameOpt ...string) v1alpha1.HttpsCert {
180165 return v1alpha1.HttpsCert {
181166 ObjectMeta : v1.ObjectMeta {
182167 Name : certName ,
168+ Labels : map [string ]string {
169+ v1alpha1 .TenantNameLabelKey : tenant ,
170+ },
183171 },
184172 Spec : v1alpha1.HttpsCertSpec {
185173 HttpsCertIssuer : issuer ,
0 commit comments