-
Notifications
You must be signed in to change notification settings - Fork 99
/
app_deploy.go
77 lines (60 loc) · 2.14 KB
/
app_deploy.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2021 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
package pkgrepository
import (
"fmt"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
ctldep "github.com/vmware-tanzu/carvel-kapp-controller/pkg/deploy"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/exec"
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/kubeconfig"
)
func (a *App) deploy(tplOutput string) exec.CmdRunResult {
err := a.blockDeletion()
if err != nil {
return exec.NewCmdRunResultWithErr(fmt.Errorf("Blocking for deploy: %s", err))
}
if len(a.app.Spec.Deploy) != 1 {
return exec.NewCmdRunResultWithErr(fmt.Errorf("Expected exactly one deploy option"))
}
dep := a.app.Spec.Deploy[0]
switch {
case dep.Kapp != nil:
kapp, err := a.newKapp(*dep.Kapp, make(chan struct{}))
if err != nil {
return exec.NewCmdRunResultWithErr(fmt.Errorf("Preparing kapp: %s", err))
}
return kapp.Deploy(tplOutput, a.startFlushingAllStatusUpdates, func(exec.CmdRunResult) {})
default:
return exec.NewCmdRunResultWithErr(fmt.Errorf("Unsupported way to deploy"))
}
}
func (a *App) delete() exec.CmdRunResult {
if len(a.app.Spec.Deploy) != 1 {
return exec.NewCmdRunResultWithErr(fmt.Errorf("Expected exactly one deploy option"))
}
var result exec.CmdRunResult
if !a.app.Spec.NoopDelete {
dep := a.app.Spec.Deploy[0]
switch {
case dep.Kapp != nil:
kapp, err := a.newKapp(*dep.Kapp, make(chan struct{}))
if err != nil {
return exec.NewCmdRunResultWithErr(fmt.Errorf("Preparing kapp: %s", err))
}
result = kapp.Delete(a.startFlushingAllStatusUpdates, func(exec.CmdRunResult) {})
default:
result.AttachErrorf("%s", fmt.Errorf("Unsupported way to delete"))
}
}
if result.Error == nil {
err := a.unblockDeletion()
if err != nil {
return exec.NewCmdRunResultWithErr(fmt.Errorf("Unblocking for deploy: %s", err))
}
}
return result
}
func (a *App) newKapp(kapp v1alpha1.AppDeployKapp, cancelCh chan struct{}) (*ctldep.Kapp, error) {
genericOpts := kubeconfig.AccessInfo{Name: a.app.Name, Namespace: a.app.Namespace}
return a.deployFactory.NewKappPrivilegedForPackageRepository(kapp, genericOpts, cancelCh)
}