Skip to content

Commit

Permalink
waiting behavior for packageinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash Sethiya authored and danielhelfand committed Jul 9, 2021
1 parent f0aae58 commit 97a7fd4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/kapp/clusterapply/converged_resource_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func (f ConvergedResourceFactory) New(res ctlres.Resource,
func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) {
return ctlresm.NewKappctrlK14sIoV1alpha1App(res), nil
},
func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) {
return ctlresm.NewPackagingCarvelDevV1alpha1PackageInstall(res), nil
},
func(res ctlres.Resource, _ []ctlres.Resource) (SpecificResource, []ctlres.ResourceRef) {
return ctlresm.NewPackagingCarvelDevV1alpha1PackageRepo(res), nil
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package resourcesmisc

import (
"fmt"
ctlres "github.com/k14s/kapp/pkg/kapp/resources"
appv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"
pkgv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/packaging/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes/scheme"
)

func init() {
pkgv1alpha1.AddToScheme(scheme.Scheme)
}

type PackagingCarvelDevV1alpha1PackageInstall struct {
resource ctlres.Resource
}

func NewPackagingCarvelDevV1alpha1PackageInstall(resource ctlres.Resource) *PackagingCarvelDevV1alpha1PackageInstall {
matcher := ctlres.APIVersionKindMatcher{
APIVersion: pkgv1alpha1.SchemeGroupVersion.String(),
Kind: "PackageInstall",
}
if matcher.Matches(resource) {
return &PackagingCarvelDevV1alpha1PackageInstall{resource}
}
return nil
}

func (s PackagingCarvelDevV1alpha1PackageInstall) IsDoneApplying() DoneApplyState {
pkgInstall := pkgv1alpha1.PackageInstall{}

err := s.resource.AsTypedObj(&pkgInstall)
if err != nil {
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Error: Failed obj conversion: %s", err)}
}

if pkgInstall.Generation != pkgInstall.Status.ObservedGeneration {
return DoneApplyState{Done: false, Message: fmt.Sprintf(
"Waiting for generation %d to be observed", pkgInstall.Generation)}
}

for _, cond := range pkgInstall.Status.Conditions {
switch {
case cond.Type == appv1alpha1.Reconciling && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: false, Message: "Reconciling"}

case cond.Type == appv1alpha1.ReconcileFailed && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Reconcile failed: %s (message: %s)", cond.Reason, cond.Message)}

case cond.Type == appv1alpha1.DeleteFailed && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf(
"Delete failed: %s (message: %s)", cond.Reason, cond.Message)}
}
}

deletingRes := NewDeleting(s.resource)
if deletingRes != nil {
return deletingRes.IsDoneApplying()
}

return DoneApplyState{Done: true, Successful: true}
}

0 comments on commit 97a7fd4

Please sign in to comment.