-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.go
63 lines (58 loc) · 1.56 KB
/
resource.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
52
53
54
55
56
57
58
59
60
61
62
63
package commands
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/argoproj/argo/workflow/common"
)
func NewResourceCommand() *cobra.Command {
var command = cobra.Command{
Use: "resource (get|create|apply|delete) MANIFEST",
Short: "update a resource and wait for resource conditions",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
err := execResource(args[0])
if err != nil {
log.Fatalf("%+v", err)
}
},
}
return &command
}
func execResource(action string) error {
wfExecutor := initExecutor()
defer wfExecutor.HandleError()
err := wfExecutor.StageFiles()
if err != nil {
wfExecutor.AddError(err)
return err
}
isDelete := action == "delete"
if isDelete && (wfExecutor.Template.Resource.SuccessCondition != "" || wfExecutor.Template.Resource.FailureCondition != "" || len(wfExecutor.Template.Outputs.Parameters) > 0) {
err = fmt.Errorf("successCondition, failureCondition and outputs are not supported for delete action")
wfExecutor.AddError(err)
return err
}
resourceNamespace, resourceName, err := wfExecutor.ExecResource(action, common.ExecutorResourceManifestPath)
if err != nil {
wfExecutor.AddError(err)
return err
}
if !isDelete {
err = wfExecutor.WaitResource(resourceNamespace, resourceName)
if err != nil {
wfExecutor.AddError(err)
return err
}
err = wfExecutor.SaveResourceParameters(resourceNamespace, resourceName)
if err != nil {
wfExecutor.AddError(err)
return err
}
}
return nil
}