Skip to content

Commit 050ba8a

Browse files
authored
Add missing package condition while waiting for app pause (#944)
When a package install for which the installed package version is now removed from the cluster, the app cr is never paused and so we need to check for the failing condition in package install
1 parent f54408f commit 050ba8a

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

cli/pkg/kctrl/cmd/package/installed/create_or_update.go

+14
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,8 @@ func (o *CreateOrUpdateOptions) unpauseReconciliation(client kcclient.Interface)
901901
}
902902

903903
// Waits for the App CR created by the package installation to pick up it's paused status
904+
// TODO: Have common place for waiting logic and refactor based on
905+
// https://github.com/vmware-tanzu/carvel-kapp-controller/issues/639
904906
func (o *CreateOrUpdateOptions) waitForAppPause(client kcclient.Interface) error {
905907
if err := wait.Poll(o.WaitFlags.CheckInterval, o.WaitFlags.Timeout, func() (done bool, err error) {
906908
appResource, err := client.KappctrlV1alpha1().Apps(o.NamespaceFlags.Name).Get(context.Background(), o.Name, metav1.GetOptions{})
@@ -913,6 +915,18 @@ func (o *CreateOrUpdateOptions) waitForAppPause(client kcclient.Interface) error
913915
if appResource.Status.FriendlyDescription == "Canceled/paused" {
914916
return true, nil
915917
}
918+
pkgi, err := client.PackagingV1alpha1().PackageInstalls(o.NamespaceFlags.Name).Get(context.Background(), o.Name, metav1.GetOptions{})
919+
if err != nil {
920+
return false, err
921+
}
922+
if pkgi.Generation != pkgi.Status.ObservedGeneration {
923+
return false, nil
924+
}
925+
for _, condition := range pkgi.Status.Conditions {
926+
if condition.Type == "ReconcileFailed" && strings.Contains(condition.Message, "Expected to find at least one version") {
927+
return true, nil
928+
}
929+
}
916930
return false, nil
917931
}); err != nil {
918932
return fmt.Errorf("Waiting for app '%s' in namespace '%s' to be paused: %s", o.Name, o.NamespaceFlags.Name, err)

cli/pkg/kctrl/cmd/package/installed/pause_or_kick.go

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"encoding/json"
99
"fmt"
10+
"strings"
1011
"time"
1112

1213
"github.com/cppforlife/go-cli-ui/ui"
@@ -234,6 +235,18 @@ func (o *PauseOrKickOptions) waitForAppPause(client kcclient.Interface) error {
234235
if appResource.Status.FriendlyDescription == "Canceled/paused" {
235236
return true, nil
236237
}
238+
pkgi, err := client.PackagingV1alpha1().PackageInstalls(o.NamespaceFlags.Name).Get(context.Background(), o.Name, metav1.GetOptions{})
239+
if err != nil {
240+
return false, err
241+
}
242+
if pkgi.Generation != pkgi.Status.ObservedGeneration {
243+
return false, nil
244+
}
245+
for _, condition := range pkgi.Status.Conditions {
246+
if condition.Type == "ReconcileFailed" && strings.Contains(condition.Message, "Expected to find at least one version") {
247+
return true, nil
248+
}
249+
}
237250
return false, nil
238251
}); err != nil {
239252
return fmt.Errorf("Waiting for app '%s' in namespace '%s' to be paused: %s", o.Name, o.NamespaceFlags.Name, err)

cli/test/e2e/package_install_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,17 @@ key2: value2
255255
})
256256
require.Contains(t, err.Error(), "not found")
257257
})
258+
259+
logger.Section("package installed update with missing old version", func() {
260+
kappCtrl.RunWithOpts([]string{"package", "installed", "create", "--package-install", pkgiName,
261+
"-p", packageMetadataName, "--version", packageVersion1,
262+
"--values-file", "-"}, RunOpts{StdinReader: strings.NewReader(valuesFile1)})
263+
264+
kapp.RunWithOpts([]string{"deploy", "-a", appName, "-f", "-"}, RunOpts{
265+
StdinReader: strings.NewReader(packageMetadata + "\n" + packageCR2)})
266+
267+
kappCtrl.RunWithOpts([]string{"package", "installed", "update", "--package-install", pkgiName,
268+
"-p", packageMetadataName, "--version", packageVersion2,
269+
"--values-file", "-"}, RunOpts{StdinReader: strings.NewReader(valuesFile2)})
270+
})
258271
}

0 commit comments

Comments
 (0)