@@ -26,7 +26,13 @@ func GetNetworkPolicies(cfg types.ConfigDB, cluster, namespace, status, nwtype,
26
26
return results
27
27
}
28
28
results = docs
29
- }
29
+ } else if cfg .DBDriver == "sqlite3" {
30
+ docs , err := GetNetworkPoliciesFromSQLite (cfg , cluster , namespace , status )
31
+ if err != nil {
32
+ return results
33
+ }
34
+ results = docs
35
+ }
30
36
31
37
return results
32
38
}
@@ -40,7 +46,13 @@ func GetNetworkPoliciesBySelector(cfg types.ConfigDB, cluster, namespace, status
40
46
return nil , err
41
47
}
42
48
results = docs
43
- } else {
49
+ } else if cfg .DBDriver == "sqlite3" {
50
+ docs , err := GetNetworkPoliciesFromSQLite (cfg , cluster , namespace , status )
51
+ if err != nil {
52
+ return nil , err
53
+ }
54
+ results = docs
55
+ } else {
44
56
return results , nil
45
57
}
46
58
@@ -68,15 +80,24 @@ func UpdateOutdatedNetworkPolicy(cfg types.ConfigDB, outdatedPolicy string, late
68
80
if err := UpdateOutdatedNetworkPolicyFromMySQL (cfg , outdatedPolicy , latestPolicy ); err != nil {
69
81
log .Error ().Msg (err .Error ())
70
82
}
71
- }
83
+ } else if cfg .DBDriver == "sqlite3" {
84
+ if err := UpdateOutdatedNetworkPolicyFromSQLite (cfg , outdatedPolicy , latestPolicy ); err != nil {
85
+ log .Error ().Msg (err .Error ())
86
+ }
87
+ }
72
88
}
73
89
74
90
func InsertNetworkPolicies (cfg types.ConfigDB , policies []types.KnoxNetworkPolicy ) {
75
91
if cfg .DBDriver == "mysql" {
76
92
if err := InsertNetworkPoliciesToMySQL (cfg , policies ); err != nil {
77
93
log .Error ().Msg (err .Error ())
78
94
}
79
- }
95
+ } else if cfg .DBDriver == "sqlite3" {
96
+ if err := InsertNetworkPoliciesToSQLite (cfg , policies ); err != nil {
97
+ log .Error ().Msg (err .Error ())
98
+ }
99
+ }
100
+
80
101
}
81
102
82
103
// ================ //
@@ -102,7 +123,11 @@ func UpdateOutdatedSystemPolicy(cfg types.ConfigDB, outdatedPolicy string, lates
102
123
if err := UpdateOutdatedNetworkPolicyFromMySQL (cfg , outdatedPolicy , latestPolicy ); err != nil {
103
124
log .Error ().Msg (err .Error ())
104
125
}
105
- }
126
+ } else if cfg .DBDriver == "sqlite3" {
127
+ if err := UpdateOutdatedNetworkPolicyFromSQLite (cfg , outdatedPolicy , latestPolicy ); err != nil {
128
+ log .Error ().Msg (err .Error ())
129
+ }
130
+ }
106
131
}
107
132
108
133
func GetSystemPolicies (cfg types.ConfigDB , namespace , status string ) []types.KnoxSystemPolicy {
@@ -114,7 +139,13 @@ func GetSystemPolicies(cfg types.ConfigDB, namespace, status string) []types.Kno
114
139
return results
115
140
}
116
141
results = docs
117
- }
142
+ } else if cfg .DBDriver == "sqlite3" {
143
+ docs , err := GetSystemPoliciesFromSQLite (cfg , namespace , status )
144
+ if err != nil {
145
+ return results
146
+ }
147
+ results = docs
148
+ }
118
149
119
150
return results
120
151
}
@@ -124,15 +155,24 @@ func InsertSystemPolicies(cfg types.ConfigDB, policies []types.KnoxSystemPolicy)
124
155
if err := InsertSystemPoliciesToMySQL (cfg , policies ); err != nil {
125
156
log .Error ().Msg (err .Error ())
126
157
}
127
- }
158
+ } else if cfg .DBDriver == "sqlite3" {
159
+ if err := InsertSystemPoliciesToSQLite (cfg , policies ); err != nil {
160
+ log .Error ().Msg (err .Error ())
161
+ }
162
+ }
128
163
}
129
164
130
165
func UpdateSystemPolicy (cfg types.ConfigDB , policy types.KnoxSystemPolicy ) {
131
166
if cfg .DBDriver == "mysql" {
132
167
if err := UpdateSystemPolicyToMySQL (cfg , policy ); err != nil {
133
168
log .Error ().Msg (err .Error ())
134
169
}
135
- }
170
+ } else if cfg .DBDriver == "sqlite3" {
171
+ if err := UpdateSystemPolicyToSQLite (cfg , policy ); err != nil {
172
+ log .Error ().Msg (err .Error ())
173
+ }
174
+ }
175
+
136
176
}
137
177
138
178
func GetWorkloadProcessFileSet (cfg types.ConfigDB , wpfs types.WorkloadProcessFileSet ) (map [types.WorkloadProcessFileSet ][]string , types.PolicyNameMap , error ) {
@@ -142,21 +182,31 @@ func GetWorkloadProcessFileSet(cfg types.ConfigDB, wpfs types.WorkloadProcessFil
142
182
log .Error ().Msg (err .Error ())
143
183
}
144
184
return res , pnMap , err
145
- }
185
+ } else if cfg .DBDriver == "sqlite3" {
186
+ res , pnMap , err := GetWorkloadProcessFileSetSQLite (cfg , wpfs )
187
+ if err != nil {
188
+ log .Error ().Msg (err .Error ())
189
+ }
190
+ return res , pnMap , err
191
+ }
146
192
return nil , nil , errors .New ("no db driver" )
147
193
}
148
194
149
195
func InsertWorkloadProcessFileSet (cfg types.ConfigDB , wpfs types.WorkloadProcessFileSet , fs []string ) error {
150
196
if cfg .DBDriver == "mysql" {
151
197
return InsertWorkloadProcessFileSetMySQL (cfg , wpfs , fs )
152
- }
198
+ } else if cfg .DBDriver == "sqlite3" {
199
+ return InsertWorkloadProcessFileSetSQLite (cfg , wpfs , fs )
200
+ }
153
201
return errors .New ("no db driver" )
154
202
}
155
203
156
204
func ClearWPFSDb (cfg types.ConfigDB , wpfs types.WorkloadProcessFileSet , duration int64 ) error {
157
205
if cfg .DBDriver == "mysql" {
158
206
return ClearWPFSDbMySQL (cfg , wpfs , duration )
159
- }
207
+ } else if cfg .DBDriver == "sqlite3" {
208
+ return ClearWPFSDbSQLite (cfg , wpfs , duration )
209
+ }
160
210
return errors .New ("no db driver" )
161
211
}
162
212
@@ -169,7 +219,11 @@ func ClearDBTables(cfg types.ConfigDB) {
169
219
if err := ClearDBTablesMySQL (cfg ); err != nil {
170
220
log .Error ().Msg (err .Error ())
171
221
}
172
- }
222
+ } else if cfg .DBDriver == "sqlite3" {
223
+ if err := ClearDBTablesSQLite (cfg ); err != nil {
224
+ log .Error ().Msg (err .Error ())
225
+ }
226
+ }
173
227
}
174
228
175
229
func ClearNetworkDBTable (cfg types.ConfigDB ) {
@@ -191,5 +245,15 @@ func CreateTablesIfNotExist(cfg types.ConfigDB) {
191
245
if err := CreateTableWorkLoadProcessFileSetMySQL (cfg ); err != nil {
192
246
log .Error ().Msg (err .Error ())
193
247
}
194
- }
248
+ } else if cfg .DBDriver == "sqlite3" {
249
+ if err := CreateTableNetworkPolicySQLite (cfg ); err != nil {
250
+ log .Error ().Msg (err .Error ())
251
+ }
252
+ if err := CreateTableSystemPolicySQLite (cfg ); err != nil {
253
+ log .Error ().Msg (err .Error ())
254
+ }
255
+ if err := CreateTableWorkLoadProcessFileSetSQLite (cfg ); err != nil {
256
+ log .Error ().Msg (err .Error ())
257
+ }
258
+ }
195
259
}
0 commit comments