-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0aae58
commit 97a7fd4
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
pkg/kapp/resourcesmisc/packaging_carvel_dev_v1alpha1_packageinstall.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |