Commit 43758c8f authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #32117 from nebril/petset-count

Automatic merge from submit-queue PetSet returns valid replica count in status **What this PR does / why we need it**: It prevents the PetSet replica count to be invalid regardless of pods not being created due to **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #31965 **Special notes for your reviewer**: **Release note**: ```release-note ```
parents c1e8c6d8 0bec5882
...@@ -81,6 +81,15 @@ type petSyncer struct { ...@@ -81,6 +81,15 @@ type petSyncer struct {
blockingPet *pcb blockingPet *pcb
} }
// errUnhealthyPet is returned when a we either know for sure a pet is unhealthy,
// or don't know its state but assume it is unhealthy. It's used as a signal to the caller for further operations like updating status.replicas.
// This is not a fatal error.
type errUnhealthyPet string
func (e errUnhealthyPet) Error() string {
return string(e)
}
// Sync syncs the given pet. // Sync syncs the given pet.
func (p *petSyncer) Sync(pet *pcb) error { func (p *petSyncer) Sync(pet *pcb) error {
if pet == nil { if pet == nil {
...@@ -103,8 +112,9 @@ func (p *petSyncer) Sync(pet *pcb) error { ...@@ -103,8 +112,9 @@ func (p *petSyncer) Sync(pet *pcb) error {
return p.Update(realPet, pet) return p.Update(realPet, pet)
} }
if p.blockingPet != nil { if p.blockingPet != nil {
glog.Infof("Create of %v in PetSet %v blocked by unhealthy pet %v", pet.pod.Name, pet.parent.Name, p.blockingPet.pod.Name) message := errUnhealthyPet(fmt.Sprintf("Create of %v in PetSet %v blocked by unhealthy pet %v", pet.pod.Name, pet.parent.Name, p.blockingPet.pod.Name))
return nil glog.Info(message)
return message
} }
// This is counted as a create, even if it fails. We can't skip indices // This is counted as a create, even if it fails. We can't skip indices
// because some pets might allocate a special role to earlier indices. // because some pets might allocate a special role to earlier indices.
......
...@@ -348,7 +348,14 @@ func (psc *PetSetController) syncPetSet(ps *apps.PetSet, pets []*api.Pod) (int, ...@@ -348,7 +348,14 @@ func (psc *PetSetController) syncPetSet(ps *apps.PetSet, pets []*api.Pod) (int,
case deletePet: case deletePet:
err = petManager.Delete(pet) err = petManager.Delete(pet)
} }
if err != nil { switch err.(type) {
case errUnhealthyPet:
// We are not passing this error up, but we don't increment numPets if we encounter it,
// since numPets directly translates to petset.status.replicas
continue
case nil:
continue
default:
it.errs = append(it.errs, err) it.errs = append(it.errs, err)
} }
} }
......
...@@ -267,3 +267,13 @@ func TestPetSetBlockingPetIsCleared(t *testing.T) { ...@@ -267,3 +267,13 @@ func TestPetSetBlockingPetIsCleared(t *testing.T) {
t.Errorf("Unexpected blocking pet, err %v: %+v", err, p) t.Errorf("Unexpected blocking pet, err %v: %+v", err, p)
} }
} }
// TODO(mkwiek): test if the petset.Status.Replicas is actually correct
func TestPetSetReplicaCount(t *testing.T) {
psc, fc := newFakePetSetController()
ps := newPetSet(3)
i, _ := psc.syncPetSet(ps, fc.getPodList())
if i != len(fc.getPodList()) {
t.Errorf("syncPetSet should return actual amount of pods")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment