@@ -37,6 +37,8 @@ import (
3737 "sigs.k8s.io/controller-runtime/pkg/client"
3838)
3939
40+ const Public_Cache_Name = "PUBLIC"
41+
4042type KubeDBClientBuilder struct {
4143 kc client.Client
4244 db * api.Ignite
@@ -79,7 +81,7 @@ func (o *KubeDBClientBuilder) WithTimeout(d time.Duration) *KubeDBClientBuilder
7981 return o
8082}
8183
82- func (o * KubeDBClientBuilder ) GetIgniteBinaryClient () ( * BinaryClient , error ) {
84+ func (o * KubeDBClientBuilder ) GetIgniteConnectionInfo () ignite. ConnInfo {
8385 igniteConnectionInfo := ignite.ConnInfo {
8486 Network : "tcp" ,
8587 Host : o .Address (),
@@ -91,8 +93,14 @@ func (o *KubeDBClientBuilder) GetIgniteBinaryClient() (*BinaryClient, error) {
9193 Timeout : o .timeout ,
9294 },
9395 }
96+ return igniteConnectionInfo
97+ }
98+
99+ func (o * KubeDBClientBuilder ) GetIgniteBinaryClient () (* BinaryClient , error ) {
100+ igniteConnectionInfo := o .GetIgniteConnectionInfo ()
101+
94102 if ! o .db .Spec .DisableSecurity {
95- err , username , password := o .getUsernamePassword ()
103+ err , username , password := o .GetUsernamePassword ()
96104 if err != nil {
97105 return nil , err
98106 }
@@ -123,14 +131,19 @@ func (o *KubeDBClientBuilder) GetIgniteBinaryClient() (*BinaryClient, error) {
123131 }, nil
124132}
125133
126- func (o * KubeDBClientBuilder ) GetIgniteSqlClient () ( * SqlClient , error ) {
134+ func (o * KubeDBClientBuilder ) GetIgniteDataSource () string {
127135 dataSource := fmt .Sprintf (
128136 "tcp://%s:%d/PUBLIC?version=1.1.0" +
129137 "&timeout=%d" ,
130138 o .Address (), kubedb .IgniteThinPort , o .timeout )
139+ return dataSource
140+ }
141+
142+ func (o * KubeDBClientBuilder ) GetIgniteSqlClient () (* SqlClient , error ) {
143+ dataSource := o .GetIgniteDataSource ()
131144
132145 if ! o .db .Spec .DisableSecurity {
133- err , username , password := o .getUsernamePassword ()
146+ err , username , password := o .GetUsernamePassword ()
134147 if err != nil {
135148 return nil , nil
136149 }
@@ -155,7 +168,7 @@ func (o *KubeDBClientBuilder) GetIgniteSqlClient() (*SqlClient, error) {
155168 }, nil
156169}
157170
158- func (o * KubeDBClientBuilder ) getUsernamePassword () (error , string , string ) {
171+ func (o * KubeDBClientBuilder ) GetUsernamePassword () (error , string , string ) {
159172 authSecret := & core.Secret {}
160173
161174 err := o .kc .Get (o .ctx , types.NamespacedName {
@@ -174,7 +187,7 @@ func (o *KubeDBClientBuilder) getUsernamePassword() (error, string, string) {
174187
175188func (igBin * BinaryClient ) CreateCache (cacheName string ) error {
176189 // create cache
177- if err := igBin .CacheCreateWithName (cacheName ); err != nil {
190+ if err := igBin .CacheGetOrCreateWithName (cacheName ); err != nil {
178191 klog .Error (err , "failed to create cache: %v" )
179192 return err
180193 }
0 commit comments