Skip to content

Commit

Permalink
wait for deployment explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
cppforlife committed May 24, 2019
1 parent 2418448 commit 9f528e8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/kapp/clusterapply/add_or_update_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
44 changes: 44 additions & 0 deletions pkg/kapp/resourcesmisc/deploymentv1.go
Original file line number Diff line number Diff line change
@@ -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}
}

0 comments on commit 9f528e8

Please sign in to comment.