6
6
7
7
"github.com/footprintai/multikf/pkg/machine"
8
8
kubeflowplugin "github.com/footprintai/multikf/pkg/machine/plugins/kubeflow"
9
+ "github.com/footprintai/multikf/pkg/template"
9
10
templatefs "github.com/footprintai/multikf/pkg/template/fs"
10
11
)
11
12
@@ -21,21 +22,26 @@ func (t TypePluginVersion) String() string {
21
22
return string (t )
22
23
}
23
24
24
- type kubeflowTemplateMakerFunc func () * kubeflowplugin.KubeflowFileTemplate
25
+ var (
26
+ TypePluginVersionKF14 = NewTypePluginVersion ("v1.4" )
27
+ TypePluginVersionKF151 = NewTypePluginVersion ("v1.5.1" )
28
+ )
29
+
30
+ type templateMakerFunc func () template.TemplateExecutor
25
31
26
32
var (
27
33
noVersion = NewTypePluginVersion ("v0.0.0" )
28
- availableVersions = map [TypePluginVersion ]kubeflowTemplateMakerFunc {
29
- NewTypePluginVersion ( "v1.4" ): kubeflowplugin .NewKubeflow14Template ,
30
- NewTypePluginVersion ( "v1.5.1" ) : kubeflowplugin .NewKubeflow15Template ,
34
+ availableVersions = map [TypePluginVersion ]templateMakerFunc {
35
+ TypePluginVersionKF14 : kubeflowplugin .NewKubeflow14Template ,
36
+ TypePluginVersionKF151 : kubeflowplugin .NewKubeflow15Template ,
31
37
}
32
38
)
33
39
34
40
func NewTypePluginVersion (s string ) TypePluginVersion {
35
41
return TypePluginVersion (s )
36
42
}
37
43
38
- func KubeflowPluginVersionTemplate (s TypePluginVersion ) (TypePluginVersion , * kubeflowplugin. KubeflowFileTemplate ) {
44
+ func KubeflowPluginVersionTemplate (s TypePluginVersion ) (TypePluginVersion , template. TemplateExecutor ) {
39
45
templateMaker , hasVersion := availableVersions [s ]
40
46
if ! hasVersion {
41
47
return noVersion , nil
@@ -48,35 +54,60 @@ type Plugin interface {
48
54
PluginVersion () TypePluginVersion
49
55
}
50
56
51
- func AddPlugins (m machine.MachineCURD , plugins ... Plugin ) error {
52
- pluginAndFiles := map [TypePlugin ]string {}
57
+ type TypeHostFilePath string
58
+
59
+ func (t TypeHostFilePath ) String () string {
60
+ return string (t )
61
+ }
53
62
54
- memFs := templatefs .NewMemoryFilesFs ()
63
+ func NewTypeHostFilePath (s string ) TypeHostFilePath {
64
+ return TypeHostFilePath (s )
65
+ }
66
+
67
+ func generatePluginsManifestsMapping (m machine.MachineCURD , dumpToFile bool , plugins ... Plugin ) (map [Plugin ]template.TemplateExecutor , error ) {
68
+ pluginAndTmpls := map [Plugin ]template.TemplateExecutor {}
55
69
for _ , plugin := range plugins {
56
70
switch plugin .PluginType () {
57
71
case TypePluginKubeflow :
58
72
// handle kubeflow plugins
59
73
_ , tmpl := KubeflowPluginVersionTemplate (plugin .PluginVersion ())
60
74
if tmpl == nil {
61
- return errors .New ("plugins: no version found" )
62
- }
63
- if err := memFs .Generate (plugin , tmpl ); err != nil {
64
- return err
75
+ return nil , errors .New ("plugins: no version found" )
65
76
}
66
- pluginAndFiles [plugin . PluginType () ] = tmpl . Filename ()
77
+ pluginAndTmpls [plugin ] = tmpl
67
78
default :
68
- return errors .New ("plugins: no available plugins" )
79
+ return nil , errors .New ("plugins: no available plugins" )
69
80
}
70
81
}
71
- if err := templatefs .NewFolder (m .HostDir ()).DumpFiles (true , memFs .FS ()); err != nil {
72
- return err
82
+ if dumpToFile {
83
+ memFs := templatefs .NewMemoryFilesFs ()
84
+ for plugin , tmpl := range pluginAndTmpls {
85
+ if err := memFs .Generate (plugin , tmpl ); err != nil {
86
+ return nil , err
87
+ }
88
+ }
89
+ // TODO: check whether we want to overwrite exsiting or not
90
+ if err := templatefs .NewFolder (m .HostDir ()).DumpFiles (true , memFs .FS ()); err != nil {
91
+ return nil , err
92
+ }
73
93
}
94
+ return pluginAndTmpls , nil
95
+ }
96
+
97
+ func AddPlugins (m machine.MachineCURD , plugins ... Plugin ) error {
74
98
var err error
75
- _ , hasKf := pluginAndFiles [TypePluginKubeflow ]
76
- if hasKf {
77
- err = m .GetKubeCli ().InstallKubeflow (m .GetKubeConfig (), filepath .Join (m .HostDir (), pluginAndFiles [TypePluginKubeflow ]))
78
- if err == nil {
79
- err = m .GetKubeCli ().PatchKubeflow (m .GetKubeConfig ())
99
+ pluginAndTmpls , err := generatePluginsManifestsMapping (m , true , plugins ... )
100
+ if err != nil {
101
+ return nil
102
+ }
103
+ for plugin , tmpl := range pluginAndTmpls {
104
+ if plugin .PluginType () == TypePluginKubeflow {
105
+ err = m .GetKubeCli ().InstallKubeflow (m .GetKubeConfig (), filepath .Join (m .HostDir (), tmpl .Filename ()))
106
+ if err == nil {
107
+ if plugin .PluginVersion () == TypePluginVersionKF14 {
108
+ err = m .GetKubeCli ().PatchKubeflow (m .GetKubeConfig ())
109
+ }
110
+ }
80
111
}
81
112
}
82
113
if err != nil {
@@ -86,6 +117,16 @@ func AddPlugins(m machine.MachineCURD, plugins ...Plugin) error {
86
117
}
87
118
88
119
func RemovePlugins (m machine.MachineCURD , plugins ... Plugin ) error {
89
- return errors .New ("plugins: not imp" )
120
+ var err error
121
+ pluginAndTmpls , err := generatePluginsManifestsMapping (m , false , plugins ... )
122
+ if err != nil {
123
+ return err
124
+ }
125
+ for plugin , tmpl := range pluginAndTmpls {
126
+ if plugin .PluginType () == TypePluginKubeflow {
127
+ err = m .GetKubeCli ().RemoveKubeflow (m .GetKubeConfig (), filepath .Join (m .HostDir (), tmpl .Filename ()))
128
+ }
129
+ }
130
+ return err
90
131
91
132
}
0 commit comments