-
Notifications
You must be signed in to change notification settings - Fork 75
/
exec_steps.go
80 lines (69 loc) · 2.98 KB
/
exec_steps.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
78
79
80
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
//
// SPDX-License-Identifier: Apache-2.0
package migration
import (
"fmt"
"github.com/pkg/errors"
)
func (pg *PlanGenerator) stepBackupAllResources() {
pg.stepBackupManagedResources()
pg.stepBackupCompositeResources()
pg.stepBackupClaims()
}
func (pg *PlanGenerator) stepBackupManagedResources() {
s := pg.stepConfiguration(stepBackupMRs)
s.Exec.Args = []string{"-c", "kubectl get managed -o yaml > backup/managed-resources.yaml"}
}
func (pg *PlanGenerator) stepBackupCompositeResources() {
s := pg.stepConfiguration(stepBackupComposites)
s.Exec.Args = []string{"-c", "kubectl get composite -o yaml > backup/composite-resources.yaml"}
}
func (pg *PlanGenerator) stepBackupClaims() {
s := pg.stepConfiguration(stepBackupClaims)
s.Exec.Args = []string{"-c", "kubectl get claim --all-namespaces -o yaml > backup/claim-resources.yaml"}
}
func (pg *PlanGenerator) stepCheckHealthOfNewProvider(source UnstructuredWithMetadata, targets []*UnstructuredWithMetadata) error {
for _, t := range targets {
var s *Step
isFamilyConfig, err := checkContainsFamilyConfigProvider(targets)
if err != nil {
return errors.Wrapf(err, "could not decide whether the provider family config")
}
if isFamilyConfig {
s = pg.stepConfigurationWithSubStep(stepCheckHealthFamilyProvider, true)
} else {
s = pg.stepConfigurationWithSubStep(stepCheckHealthNewServiceScopedProvider, true)
}
s.Exec.Args = []string{"-c", fmt.Sprintf("kubectl wait provider.pkg %s --for condition=Healthy", t.Object.GetName())}
t.Object.Object = addGVK(source.Object, t.Object.Object)
t.Metadata.Path = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(t.Object))
}
return nil
}
func (pg *PlanGenerator) stepCheckInstallationOfNewProvider(source UnstructuredWithMetadata, targets []*UnstructuredWithMetadata) error {
for _, t := range targets {
var s *Step
isFamilyConfig, err := checkContainsFamilyConfigProvider(targets)
if err != nil {
return errors.Wrapf(err, "could not decide whether the provider family config")
}
if isFamilyConfig {
s = pg.stepConfigurationWithSubStep(stepCheckInstallationFamilyProviderRevision, true)
} else {
s = pg.stepConfigurationWithSubStep(stepCheckInstallationServiceScopedProviderRevision, true)
}
s.Exec.Args = []string{"-c", fmt.Sprintf("kubectl wait provider.pkg %s --for condition=Installed", t.Object.GetName())}
t.Object.Object = addGVK(source.Object, t.Object.Object)
t.Metadata.Path = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(t.Object))
}
return nil
}
func (pg *PlanGenerator) stepBuildConfiguration() {
s := pg.stepConfiguration(stepBuildConfiguration)
s.Exec.Args = []string{"-c", "up xpkg build --package-root={{PKG_ROOT}} --examples-root={{EXAMPLES_ROOT}} -o {{PKG_PATH}}"}
}
func (pg *PlanGenerator) stepPushConfiguration() {
s := pg.stepConfiguration(stepPushConfiguration)
s.Exec.Args = []string{"-c", "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}"}
}