This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
delete.go
51 lines (42 loc) · 1.47 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package bundle
import (
"github.com/caos/orbos/internal/operator/boom/application"
"github.com/caos/orbos/internal/utils/clientgo"
"github.com/caos/orbos/internal/utils/helper"
"github.com/caos/orbos/internal/utils/kubectl"
"github.com/caos/orbos/mntr"
"github.com/pkg/errors"
)
func deleteWithCurrentState(monitor mntr.Monitor, currentResourceList []*clientgo.Resource, app application.Application) func(resultFilePath, namespace string) error {
logFields := map[string]interface{}{
"application": app.GetName().String,
"command": "delete",
}
delMonitor := monitor.WithFields(logFields)
resultFunc := func(resultFilePath, namespace string) error {
for _, resource := range currentResourceList {
if err := clientgo.DeleteResource(resource); err != nil {
err := errors.Wrap(err, "Failed to delete resource")
delMonitor.Error(err)
return err
}
}
return nil
}
return resultFunc
}
func delete(monitor mntr.Monitor) func(resultFilePath, namespace string) error {
logFields := map[string]interface{}{
"command": "delete",
}
delMonitor := monitor.WithFields(logFields)
resultFunc := func(resultFilePath, namespace string) error {
kubectlCmd := kubectl.New("delete").AddParameter("-f", resultFilePath).AddFlag("--ignore-not-found")
if namespace != "" {
kubectlCmd.AddParameter("-n", namespace)
}
err := helper.Run(delMonitor, kubectlCmd.Build())
return errors.Wrapf(err, "Failed to delete with file %s", resultFilePath)
}
return resultFunc
}