Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix await logic for extensions/v1beta1/Deployment #794

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

### Bug fixes

- Fix await logic for extensions/v1beta1/Deployment
(https://github.com/pulumi/pulumi-kubernetes/pull/794).
- Fix error reporting
(https://github.com/pulumi/pulumi-kubernetes/pull/782).

Expand Down
53 changes: 24 additions & 29 deletions pkg/await/apps_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package await
import (
"fmt"
"reflect"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -98,7 +97,7 @@ type deploymentInitAwaiter struct {
replicaSetAvailable bool
pvcsAvailable bool
updatedReplicaSetReady bool
currentGeneration string
replicaSetGeneration string

deploymentErrors map[string]string

Expand All @@ -115,7 +114,7 @@ func makeDeploymentInitAwaiter(c updateAwaitConfig) *deploymentInitAwaiter {
replicaSetAvailable: false,
updatedReplicaSetReady: false,
// NOTE: Generation 0 is invalid, so this is a good sentinel value.
currentGeneration: "0",
replicaSetGeneration: "0",

deploymentErrors: map[string]string{},

Expand Down Expand Up @@ -340,7 +339,7 @@ func (dia *deploymentInitAwaiter) isEveryPVCReady() bool {
}

func (dia *deploymentInitAwaiter) checkAndLogStatus() bool {
if dia.currentGeneration == "1" {
if dia.replicaSetGeneration == "1" {
if dia.deploymentAvailable && dia.updatedReplicaSetReady {
if !dia.isEveryPVCReady() {
return false
Expand Down Expand Up @@ -396,28 +395,24 @@ func (dia *deploymentInitAwaiter) processDeploymentEvent(event watch.Event) {
// regardless of what the Event apiVersion says.
extensionsV1Beta1API := dia.config.createAwaitConfig.currentInputs.GetAPIVersion() == "extensions/v1beta1"

// Get current generation of the Deployment.
dia.currentGeneration = deployment.GetAnnotations()[revision]
if dia.currentGeneration == "" {
// Get generation of the Deployment's ReplicaSet.
dia.replicaSetGeneration = deployment.GetAnnotations()[revision]
if dia.replicaSetGeneration == "" {
// No current generation, Deployment controller has not yet created a ReplicaSet. Do
// nothing.
return
} else if extensionsV1Beta1API {
if currentGenerationInt, err := strconv.Atoi(dia.currentGeneration); err == nil {
if int64(currentGenerationInt) != dia.deployment.GetGeneration() {
// If the generation is set, make sure it matches the revision annotation, otherwise, ignore this
// event because the status we care about may not be set yet.
if rawObservedGeneration, ok := openapi.Pluck(
deployment.Object, "status", "observedGeneration"); ok {
observedGeneration, _ := rawObservedGeneration.(int64)
if deployment.GetGeneration() != observedGeneration {
// If the generation is set, make sure it matches the .status.observedGeneration, otherwise,
// ignore this event because the status we care about may not be set yet.
return
}
if rawObservedGeneration, ok := openapi.Pluck(
deployment.Object, "status", "observedGeneration"); ok {
observedGeneration, _ := rawObservedGeneration.(int64)
if int64(currentGenerationInt) != observedGeneration {
// If the generation is set, make sure it matches the .status.observedGeneration, otherwise,
// ignore this event because the status we care about may not be set yet.
return
}
}
} else {
// Observed generation status not set yet. Do nothing.
return
}
}

Expand All @@ -430,7 +425,7 @@ func (dia *deploymentInitAwaiter) processDeploymentEvent(event watch.Event) {
return
}

// Success occurs when the ReplicaSet of the `currentGeneration` is marked as available, and
// Success occurs when the ReplicaSet of the `replicaSetGeneration` is marked as available, and
// when the deployment is available.
for _, rawCondition := range conditions {
condition, isMap := rawCondition.(map[string]interface{})
Expand Down Expand Up @@ -518,13 +513,13 @@ func (dia *deploymentInitAwaiter) checkReplicaSetStatus() {

glog.V(3).Infof("Checking ReplicaSet status for Deployment %q", inputs.GetName())

rs, updatedReplicaSetCreated := dia.replicaSets[dia.currentGeneration]
if dia.currentGeneration == "0" || !updatedReplicaSetCreated {
rs, updatedReplicaSetCreated := dia.replicaSets[dia.replicaSetGeneration]
if dia.replicaSetGeneration == "0" || !updatedReplicaSetCreated {
return
}

glog.V(3).Infof("Deployment %q has generation %q, which corresponds to ReplicaSet %q",
inputs.GetName(), dia.currentGeneration, rs.GetName())
inputs.GetName(), dia.replicaSetGeneration, rs.GetName())

var lastGeneration string
if outputs := dia.config.lastOutputs; outputs != nil {
Expand Down Expand Up @@ -590,7 +585,7 @@ func (dia *deploymentInitAwaiter) checkReplicaSetStatus() {
}

if dia.changeTriggeredRollout() {
dia.updatedReplicaSetReady = lastGeneration != dia.currentGeneration && updatedReplicaSetCreated &&
dia.updatedReplicaSetReady = lastGeneration != dia.replicaSetGeneration && updatedReplicaSetCreated &&
doneWaitingOnReplicas() && !unavailableReplicasPresent && !tooManyReplicas &&
expectedNumberOfUpdatedReplicas
} else {
Expand All @@ -612,7 +607,7 @@ func (dia *deploymentInitAwaiter) checkReplicaSetStatus() {
rs.GetName(), specReplicas, readyReplicas)

if dia.changeTriggeredRollout() {
dia.updatedReplicaSetReady = lastGeneration != dia.currentGeneration && updatedReplicaSetCreated &&
dia.updatedReplicaSetReady = lastGeneration != dia.replicaSetGeneration && updatedReplicaSetCreated &&
doneWaitingOnReplicas()
} else {
dia.updatedReplicaSetReady = updatedReplicaSetCreated &&
Expand Down Expand Up @@ -687,7 +682,7 @@ func (dia *deploymentInitAwaiter) processPodEvent(event watch.Event) {
}

// Check whether this Pod was created by our Deployment.
currentReplicaSet := dia.replicaSets[dia.currentGeneration]
currentReplicaSet := dia.replicaSets[dia.replicaSetGeneration]
if !isOwnedBy(pod, currentReplicaSet) {
return
}
Expand Down Expand Up @@ -739,7 +734,7 @@ func (dia *deploymentInitAwaiter) processPersistentVolumeClaimsEvent(event watch
}

func (dia *deploymentInitAwaiter) aggregatePodErrors() logging.Messages {
rs, exists := dia.replicaSets[dia.currentGeneration]
rs, exists := dia.replicaSets[dia.replicaSetGeneration]
if !exists {
return nil
}
Expand Down Expand Up @@ -785,7 +780,7 @@ func (dia *deploymentInitAwaiter) errorMessages() []string {
messages = append(messages, message)
}

if dia.currentGeneration == "1" {
if dia.replicaSetGeneration == "1" {
if !dia.isEveryPVCReady() {
failed := dia.getFailedPersistentValueClaims()
msg := fmt.Sprintf("Failed to bind PersistentVolumeClaim(s): %q", strings.Join(failed, ","))
Expand Down