9
9
"k8s.io/apimachinery/pkg/runtime/schema"
10
10
"k8s.io/apiserver/pkg/registry/generic"
11
11
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
12
+ "k8s.io/apiserver/pkg/storage/storagebackend"
12
13
builderrest "sigs.k8s.io/apiserver-runtime/pkg/builder/rest"
13
14
)
14
15
@@ -25,38 +26,41 @@ import (
25
26
// )).Build()
26
27
//
27
28
func NewMysqlStorageProvider (host string , port int32 , username , password , database string ) builderrest.StoreFn {
29
+ dsn := fmt .Sprintf ("mysql://%s:%s@tcp(%s:%d)/%s" ,
30
+ username ,
31
+ password ,
32
+ host ,
33
+ port ,
34
+ database )
35
+
28
36
return func (s * genericregistry.Store , options * generic.StoreOptions ) {
29
37
options .RESTOptions = & kineProxiedRESTOptionsGetter {
30
- delegate : options . RESTOptions ,
38
+ dsn : dsn ,
31
39
}
32
40
}
33
41
}
34
42
35
43
type kineProxiedRESTOptionsGetter struct {
36
- delegate generic. RESTOptionsGetter
44
+ dsn string
37
45
}
38
46
39
47
// GetRESTOptions implements RESTOptionsGetter interface.
40
48
func (g * kineProxiedRESTOptionsGetter ) GetRESTOptions (resource schema.GroupResource ) (generic.RESTOptions , error ) {
41
- restOptions , err := g .delegate .GetRESTOptions (resource )
42
- if err != nil {
43
- return generic.RESTOptions {}, err
44
- }
45
-
46
- if len (restOptions .StorageConfig .Transport .ServerList ) != 1 {
47
- return generic.RESTOptions {}, fmt .Errorf ("no valid mysql dsn found" )
48
- }
49
-
50
49
etcdConfig , err := endpoint .Listen (context .TODO (), endpoint.Config {
51
- Endpoint : restOptions . StorageConfig . Transport . ServerList [ 0 ] ,
50
+ Endpoint : g . dsn ,
52
51
})
53
52
if err != nil {
54
53
return generic.RESTOptions {}, err
55
54
}
56
-
57
- restOptions .StorageConfig .Transport .ServerList = etcdConfig .Endpoints
58
- restOptions .StorageConfig .Transport .TrustedCAFile = etcdConfig .TLSConfig .CAFile
59
- restOptions .StorageConfig .Transport .CertFile = etcdConfig .TLSConfig .CertFile
60
- restOptions .StorageConfig .Transport .KeyFile = etcdConfig .TLSConfig .KeyFile
55
+ restOptions := generic.RESTOptions {
56
+ StorageConfig : & storagebackend.Config {
57
+ Transport : storagebackend.TransportConfig {
58
+ ServerList : etcdConfig .Endpoints ,
59
+ TrustedCAFile : etcdConfig .TLSConfig .CAFile ,
60
+ CertFile : etcdConfig .TLSConfig .CertFile ,
61
+ KeyFile : etcdConfig .TLSConfig .KeyFile ,
62
+ },
63
+ },
64
+ }
61
65
return restOptions , nil
62
66
}
0 commit comments