@@ -13,8 +13,12 @@ import (
13
13
cmdapp "github.com/vmware-tanzu/carvel-kapp-controller/cli/pkg/kctrl/cmd/app"
14
14
cmdcore "github.com/vmware-tanzu/carvel-kapp-controller/cli/pkg/kctrl/cmd/core"
15
15
"github.com/vmware-tanzu/carvel-kapp-controller/cli/pkg/kctrl/logger"
16
+ kcv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
16
17
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/client/clientset/versioned"
18
+ corev1 "k8s.io/api/core/v1"
19
+ "k8s.io/apimachinery/pkg/api/errors"
17
20
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21
+ "k8s.io/apimachinery/pkg/util/wait"
18
22
)
19
23
20
24
type DeleteOptions struct {
@@ -104,12 +108,56 @@ func (o *DeleteOptions) Run(args []string) error {
104
108
105
109
func (o * DeleteOptions ) waitForDeletion (client versioned.Interface ) error {
106
110
o .statusUI .PrintMessagef ("Waiting for package repository reconciliation for '%s'" , o .Name )
107
- repoWatcher := NewRepoTailer (o .NamespaceFlags .Name , o .Name , o .ui , client , RepoTailerOpts {})
108
111
109
- err := repoWatcher .TailRepoStatus ()
110
- if err != nil {
111
- return err
112
+ msgsUI := cmdcore .NewDedupingMessagesUI (cmdcore .NewPlainMessagesUI (o .ui ))
113
+ description := getPackageRepositoryDescription (o .Name , o .NamespaceFlags .Name )
114
+
115
+ repoStatusTailErrored := false
116
+ tailRepoStatusOutput := func (tailErrored * bool ) {
117
+ repoWatcher := NewRepoTailer (o .NamespaceFlags .Name , o .Name , o .ui , client , RepoTailerOpts {})
118
+
119
+ err := repoWatcher .TailRepoStatus ()
120
+ if err != nil {
121
+ o .statusUI .PrintMessagef ("Error tailing or reconciling Package Repository: %s" , err .Error ())
122
+ * tailErrored = true
123
+ }
112
124
}
113
125
126
+ go tailRepoStatusOutput (& repoStatusTailErrored )
127
+
128
+ if err := wait .Poll (o .WaitFlags .CheckInterval , o .WaitFlags .Timeout , func () (bool , error ) {
129
+ resource , err := client .PackagingV1alpha1 ().PackageRepositories (o .NamespaceFlags .Name ).Get (context .Background (), o .Name , metav1.GetOptions {})
130
+ if err != nil {
131
+ if ! (errors .IsNotFound (err )) {
132
+ return true , nil
133
+ }
134
+ }
135
+ if err != nil {
136
+ if errors .IsNotFound (err ) {
137
+ msgsUI .NotifySection ("%s: DeletionSucceeded" , description )
138
+ return true , nil
139
+ }
140
+ return false , err
141
+ }
142
+
143
+ if resource .Generation != resource .Status .ObservedGeneration {
144
+ // Should wait for generation to be observed before checking the reconciliation status so that we know we are checking the new spec
145
+ return false , nil
146
+ }
147
+ status := resource .Status .GenericStatus
148
+
149
+ for _ , cond := range status .Conditions {
150
+ if repoStatusTailErrored {
151
+ msgsUI .NotifySection ("%s: %s" , description , cond .Type )
152
+ }
153
+
154
+ if cond .Type == kcv1alpha1 .DeleteFailed && cond .Status == corev1 .ConditionTrue {
155
+ return false , fmt .Errorf ("%s: Deleting: %s. %s" , description , status .UsefulErrorMessage , status .FriendlyDescription )
156
+ }
157
+ }
158
+ return false , nil
159
+ }); err != nil {
160
+ return fmt .Errorf ("%s: Deleting: %s" , description , err )
161
+ }
114
162
return nil
115
163
}
0 commit comments