diff --git a/pkg/kapp/clusterapply/add_or_update_change.go b/pkg/kapp/clusterapply/add_or_update_change.go index cdadc4221..e31114c08 100644 --- a/pkg/kapp/clusterapply/add_or_update_change.go +++ b/pkg/kapp/clusterapply/add_or_update_change.go @@ -202,6 +202,7 @@ func (c AddOrUpdateChange) isResourceDoneApplying(res ctlres.Resource, isParent // It's rare that Pod is directly created func(res ctlres.Resource) SpecificResource { return ctlresm.NewPodvX(res) }, func(res ctlres.Resource) SpecificResource { return ctlresm.NewServicev1(res) }, + func(res ctlres.Resource) SpecificResource { return ctlresm.NewDeploymentv1(res) }, } for _, f := range specificResFactories { diff --git a/pkg/kapp/resourcesmisc/deploymentv1.go b/pkg/kapp/resourcesmisc/deploymentv1.go new file mode 100644 index 000000000..93eda4ce5 --- /dev/null +++ b/pkg/kapp/resourcesmisc/deploymentv1.go @@ -0,0 +1,44 @@ +package resourcesmisc + +import ( + "fmt" + + ctlres "github.com/k14s/kapp/pkg/kapp/resources" + appsv1 "k8s.io/api/apps/v1" +) + +type Deploymentv1 struct { + resource ctlres.Resource +} + +func NewDeploymentv1(resource ctlres.Resource) *Deploymentv1 { + matcher := ctlres.APIVersionKindMatcher{ + APIVersion: "apps/v1", + Kind: "Deployment", + } + if matcher.Matches(resource) { + return &Deploymentv1{resource} + } + return nil +} + +func (s Deploymentv1) IsDoneApplying() DoneApplyState { + dep := appsv1.Deployment{} + + err := s.resource.AsTypedObj(&dep) + if err != nil { + return DoneApplyState{Done: true, Successful: false, Message: fmt.Sprintf("Error: Failed obj conversion: %s", err)} + } + + if dep.Generation != dep.Status.ObservedGeneration { + return DoneApplyState{Done: false, Message: fmt.Sprintf( + "Waiting for generation %d to be observed", dep.Generation)} + } + + if dep.Status.UnavailableReplicas > 0 { + return DoneApplyState{Done: false, Message: fmt.Sprintf( + "Waiting for unavailable replicas to go from %d to 0", dep.Status.UnavailableReplicas)} + } + + return DoneApplyState{Done: true, Successful: true} +}