mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 09:24:23 +00:00
Implement new rules for status for PDBs
This commit is contained in:
@@ -395,26 +395,21 @@ func podConditions(u *unstructured.Unstructured) (*Result, error) {
|
|||||||
return newInProgressStatus("PodNotReady", message), nil
|
return newInProgressStatus("PodNotReady", message), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// pdbConditions return standardized Conditions for Deployment
|
// pdbConditions computes the status for PodDisruptionBudgets. A PDB
|
||||||
|
// is currently considered Current if the disruption controller has
|
||||||
|
// observed the latest version of the PDB resource and has computed
|
||||||
|
// the AllowedDisruptions. PDBs do have ObservedGeneration in the
|
||||||
|
// Status object, so if this function gets called we know that
|
||||||
|
// the controller has observed the latest changes.
|
||||||
|
// The disruption controller does not set any conditions if
|
||||||
|
// computing the AllowedDisruptions fails (and there are many ways
|
||||||
|
// it can fail), but there is PR against OSS Kubernetes to address
|
||||||
|
// this: https://github.com/kubernetes/kubernetes/pull/86929
|
||||||
func pdbConditions(u *unstructured.Unstructured) (*Result, error) {
|
func pdbConditions(u *unstructured.Unstructured) (*Result, error) {
|
||||||
obj := u.UnstructuredContent()
|
|
||||||
|
|
||||||
// replicas
|
|
||||||
currentHealthy := GetIntField(obj, ".status.currentHealthy", 0)
|
|
||||||
desiredHealthy := GetIntField(obj, ".status.desiredHealthy", 0)
|
|
||||||
if desiredHealthy == 0 {
|
|
||||||
message := "Missing or zero .status.desiredHealthy"
|
|
||||||
return newInProgressStatus("ZeroDesiredHealthy", message), nil
|
|
||||||
}
|
|
||||||
if desiredHealthy > currentHealthy {
|
|
||||||
message := fmt.Sprintf("Budget not met. healthy replicas: %d/%d", currentHealthy, desiredHealthy)
|
|
||||||
return newInProgressStatus("BudgetNotMet", message), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// All ok
|
// All ok
|
||||||
return &Result{
|
return &Result{
|
||||||
Status: CurrentStatus,
|
Status: CurrentStatus,
|
||||||
Message: fmt.Sprintf("Budget is met. Replicas: %d/%d", currentHealthy, desiredHealthy),
|
Message: "AllowedDisruptions has been computed.",
|
||||||
Conditions: []Condition{},
|
Conditions: []Condition{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Statuses = []Status{InProgressStatus, FailedStatus, CurrentStatus, TerminatingStatus, UnknownStatus}
|
Statuses = []Status{InProgressStatus, FailedStatus, CurrentStatus, TerminatingStatus, UnknownStatus}
|
||||||
ConditionTypes = []ConditionType{ConditionFailed, ConditionInProgress}
|
ConditionTypes = []ConditionType{ConditionFailed, ConditionInProgress}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -822,66 +822,44 @@ func TestReplicasetStatus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pdbNoStatus = `
|
var pdbNotObserved = `
|
||||||
apiVersion: policy/v1
|
apiVersion: policy/v1beta1
|
||||||
kind: PodDisruptionBudget
|
kind: PodDisruptionBudget
|
||||||
metadata:
|
metadata:
|
||||||
generation: 1
|
generation: 2
|
||||||
name: test
|
name: test
|
||||||
|
namespace: qual
|
||||||
|
status:
|
||||||
|
observedGeneration: 1
|
||||||
`
|
`
|
||||||
|
|
||||||
var pdbOK1 = `
|
var pdbObserved = `
|
||||||
apiVersion: policy/v1
|
apiVersion: policy/v1beta1
|
||||||
kind: PodDisruptionBudget
|
kind: PodDisruptionBudget
|
||||||
metadata:
|
metadata:
|
||||||
generation: 1
|
generation: 1
|
||||||
name: test
|
name: test
|
||||||
namespace: qual
|
namespace: qual
|
||||||
status:
|
status:
|
||||||
currentHealthy: 2
|
observedGeneration: 1
|
||||||
desiredHealthy: 2
|
|
||||||
`
|
|
||||||
|
|
||||||
var pdbMoreHealthy = `
|
|
||||||
apiVersion: policy/v1
|
|
||||||
kind: PodDisruptionBudget
|
|
||||||
metadata:
|
|
||||||
generation: 1
|
|
||||||
name: test
|
|
||||||
namespace: qual
|
|
||||||
status:
|
|
||||||
currentHealthy: 4
|
|
||||||
desiredHealthy: 2
|
|
||||||
`
|
|
||||||
|
|
||||||
var pdbLessHealthy = `
|
|
||||||
apiVersion: policy/v1
|
|
||||||
kind: PodDisruptionBudget
|
|
||||||
metadata:
|
|
||||||
generation: 1
|
|
||||||
name: test
|
|
||||||
namespace: qual
|
|
||||||
status:
|
|
||||||
currentHealthy: 2
|
|
||||||
desiredHealthy: 4
|
|
||||||
`
|
`
|
||||||
|
|
||||||
func TestPDBStatus(t *testing.T) {
|
func TestPDBStatus(t *testing.T) {
|
||||||
testCases := map[string]testSpec{
|
testCases := map[string]testSpec{
|
||||||
"pdbNoStatus": {
|
"pdbNotObserved": {
|
||||||
spec: pdbNoStatus,
|
spec: pdbNotObserved,
|
||||||
expectedStatus: InProgressStatus,
|
expectedStatus: InProgressStatus,
|
||||||
expectedConditions: []Condition{{
|
expectedConditions: []Condition{{
|
||||||
Type: ConditionInProgress,
|
Type: ConditionInProgress,
|
||||||
Status: corev1.ConditionTrue,
|
Status: corev1.ConditionTrue,
|
||||||
Reason: "ZeroDesiredHealthy",
|
Reason: "LatestGenerationNotObserved",
|
||||||
}},
|
}},
|
||||||
absentConditionTypes: []ConditionType{
|
absentConditionTypes: []ConditionType{
|
||||||
ConditionFailed,
|
ConditionFailed,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"pdbOK1": {
|
"pdbObserved": {
|
||||||
spec: pdbOK1,
|
spec: pdbObserved,
|
||||||
expectedStatus: CurrentStatus,
|
expectedStatus: CurrentStatus,
|
||||||
expectedConditions: []Condition{},
|
expectedConditions: []Condition{},
|
||||||
absentConditionTypes: []ConditionType{
|
absentConditionTypes: []ConditionType{
|
||||||
@@ -889,27 +867,6 @@ func TestPDBStatus(t *testing.T) {
|
|||||||
ConditionInProgress,
|
ConditionInProgress,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"pdbMoreHealthy": {
|
|
||||||
spec: pdbMoreHealthy,
|
|
||||||
expectedStatus: CurrentStatus,
|
|
||||||
expectedConditions: []Condition{},
|
|
||||||
absentConditionTypes: []ConditionType{
|
|
||||||
ConditionFailed,
|
|
||||||
ConditionInProgress,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"pdbLessHealthy": {
|
|
||||||
spec: pdbLessHealthy,
|
|
||||||
expectedStatus: InProgressStatus,
|
|
||||||
expectedConditions: []Condition{{
|
|
||||||
Type: ConditionInProgress,
|
|
||||||
Status: corev1.ConditionTrue,
|
|
||||||
Reason: "BudgetNotMet",
|
|
||||||
}},
|
|
||||||
absentConditionTypes: []ConditionType{
|
|
||||||
ConditionFailed,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for tn, tc := range testCases {
|
for tn, tc := range testCases {
|
||||||
|
|||||||
Reference in New Issue
Block a user