mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 09:49:13 +00:00
Merge pull request #1937 from mortent/FixStatusRules
Fix issues with rules for Deployment and ReplicaSet
This commit is contained in:
@@ -5,6 +5,7 @@ package status
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
@@ -23,8 +24,11 @@ var legacyTypes = map[string]GetConditionsFn{
|
|||||||
"PersistentVolumeClaim": pvcConditions,
|
"PersistentVolumeClaim": pvcConditions,
|
||||||
"apps/StatefulSet": stsConditions,
|
"apps/StatefulSet": stsConditions,
|
||||||
"apps/DaemonSet": daemonsetConditions,
|
"apps/DaemonSet": daemonsetConditions,
|
||||||
|
"extensions/DaemonSet": daemonsetConditions,
|
||||||
"apps/Deployment": deploymentConditions,
|
"apps/Deployment": deploymentConditions,
|
||||||
|
"extensions/Deployment": deploymentConditions,
|
||||||
"apps/ReplicaSet": replicasetConditions,
|
"apps/ReplicaSet": replicasetConditions,
|
||||||
|
"extensions/ReplicaSet": replicasetConditions,
|
||||||
"policy/PodDisruptionBudget": pdbConditions,
|
"policy/PodDisruptionBudget": pdbConditions,
|
||||||
"batch/CronJob": alwaysReady,
|
"batch/CronJob": alwaysReady,
|
||||||
"ConfigMap": alwaysReady,
|
"ConfigMap": alwaysReady,
|
||||||
@@ -142,6 +146,17 @@ func deploymentConditions(u *unstructured.Unstructured) (*Result, error) {
|
|||||||
obj := u.UnstructuredContent()
|
obj := u.UnstructuredContent()
|
||||||
|
|
||||||
progressing := false
|
progressing := false
|
||||||
|
|
||||||
|
// Check if progressDeadlineSeconds is set. If not, the controller will not set
|
||||||
|
// the `Progressing` condition, so it will always consider a deployment to be
|
||||||
|
// progressing. The use of math.MaxInt32 is due to special handling in the
|
||||||
|
// controller:
|
||||||
|
// https://github.com/kubernetes/kubernetes/blob/a3ccea9d8743f2ff82e41b6c2af6dc2c41dc7b10/pkg/controller/deployment/util/deployment_util.go#L886
|
||||||
|
progressDeadline := GetIntField(obj, ".spec.progressDeadlineSeconds", math.MaxInt32)
|
||||||
|
if progressDeadline == math.MaxInt32 {
|
||||||
|
progressing = true
|
||||||
|
}
|
||||||
|
|
||||||
available := false
|
available := false
|
||||||
|
|
||||||
objc, err := GetObjectWithConditions(obj)
|
objc, err := GetObjectWithConditions(obj)
|
||||||
@@ -171,7 +186,7 @@ func deploymentConditions(u *unstructured.Unstructured) (*Result, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replicas
|
// replicas
|
||||||
specReplicas := GetIntField(obj, ".spec.replicas", 1)
|
specReplicas := GetIntField(obj, ".spec.replicas", 1) // Controller uses 1 as default if not specified.
|
||||||
statusReplicas := GetIntField(obj, ".status.replicas", 0)
|
statusReplicas := GetIntField(obj, ".status.replicas", 0)
|
||||||
updatedReplicas := GetIntField(obj, ".status.updatedReplicas", 0)
|
updatedReplicas := GetIntField(obj, ".status.updatedReplicas", 0)
|
||||||
readyReplicas := GetIntField(obj, ".status.readyReplicas", 0)
|
readyReplicas := GetIntField(obj, ".status.readyReplicas", 0)
|
||||||
@@ -240,19 +255,14 @@ func replicasetConditions(u *unstructured.Unstructured) (*Result, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Replicas
|
// Replicas
|
||||||
specReplicas := GetIntField(obj, ".spec.replicas", 1)
|
specReplicas := GetIntField(obj, ".spec.replicas", 1) // Controller uses 1 as default if not specified.
|
||||||
statusReplicas := GetIntField(obj, ".status.replicas", 0)
|
statusReplicas := GetIntField(obj, ".status.replicas", 0)
|
||||||
readyReplicas := GetIntField(obj, ".status.readyReplicas", 0)
|
readyReplicas := GetIntField(obj, ".status.readyReplicas", 0)
|
||||||
availableReplicas := GetIntField(obj, ".status.availableReplicas", 0)
|
availableReplicas := GetIntField(obj, ".status.availableReplicas", 0)
|
||||||
labelledReplicas := GetIntField(obj, ".status.labelledReplicas", 0)
|
fullyLabelledReplicas := GetIntField(obj, ".status.fullyLabeledReplicas", 0)
|
||||||
|
|
||||||
if specReplicas == 0 && labelledReplicas == 0 && availableReplicas == 0 && readyReplicas == 0 {
|
if specReplicas > fullyLabelledReplicas {
|
||||||
message := ".spec.replica is 0"
|
message := fmt.Sprintf("Labelled: %d/%d", fullyLabelledReplicas, specReplicas)
|
||||||
return newInProgressStatus("ZeroReplicas", message), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if specReplicas > labelledReplicas {
|
|
||||||
message := fmt.Sprintf("Labelled: %d/%d", labelledReplicas, specReplicas)
|
|
||||||
return newInProgressStatus("LessLabelled", message), nil
|
return newInProgressStatus("LessLabelled", message), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -521,6 +521,8 @@ metadata:
|
|||||||
name: test
|
name: test
|
||||||
generation: 1
|
generation: 1
|
||||||
namespace: qual
|
namespace: qual
|
||||||
|
spec:
|
||||||
|
progressDeadlineSeconds: 45
|
||||||
status:
|
status:
|
||||||
observedGeneration: 1
|
observedGeneration: 1
|
||||||
updatedReplicas: 1
|
updatedReplicas: 1
|
||||||
@@ -536,6 +538,25 @@ status:
|
|||||||
status: "True"
|
status: "True"
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var depNoProgressDeadlineSeconds = `
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: test
|
||||||
|
generation: 1
|
||||||
|
namespace: qual
|
||||||
|
status:
|
||||||
|
observedGeneration: 1
|
||||||
|
updatedReplicas: 1
|
||||||
|
readyReplicas: 1
|
||||||
|
availableReplicas: 1
|
||||||
|
replicas: 1
|
||||||
|
observedGeneration: 1
|
||||||
|
conditions:
|
||||||
|
- type: Available
|
||||||
|
status: "True"
|
||||||
|
`
|
||||||
|
|
||||||
var depNotAvailable = `
|
var depNotAvailable = `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -593,6 +614,15 @@ func TestDeploymentStatus(t *testing.T) {
|
|||||||
ConditionFailed,
|
ConditionFailed,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"depNoProgressDeadlineSeconds": {
|
||||||
|
spec: depNoProgressDeadlineSeconds,
|
||||||
|
expectedStatus: CurrentStatus,
|
||||||
|
expectedConditions: []Condition{},
|
||||||
|
absentConditionTypes: []ConditionType{
|
||||||
|
ConditionFailed,
|
||||||
|
ConditionInProgress,
|
||||||
|
},
|
||||||
|
},
|
||||||
"depNotAvailable": {
|
"depNotAvailable": {
|
||||||
spec: depNotAvailable,
|
spec: depNotAvailable,
|
||||||
expectedStatus: InProgressStatus,
|
expectedStatus: InProgressStatus,
|
||||||
@@ -637,7 +667,7 @@ status:
|
|||||||
replicas: 2
|
replicas: 2
|
||||||
readyReplicas: 2
|
readyReplicas: 2
|
||||||
availableReplicas: 2
|
availableReplicas: 2
|
||||||
labelledReplicas: 2
|
fullyLabeledReplicas: 2
|
||||||
conditions:
|
conditions:
|
||||||
- type: ReplicaFailure
|
- type: ReplicaFailure
|
||||||
status: "False"
|
status: "False"
|
||||||
@@ -654,7 +684,7 @@ spec:
|
|||||||
replicas: 2
|
replicas: 2
|
||||||
status:
|
status:
|
||||||
observedGeneration: 1
|
observedGeneration: 1
|
||||||
labelledReplicas: 2
|
fullyLabeledReplicas: 2
|
||||||
replicas: 2
|
replicas: 2
|
||||||
readyReplicas: 2
|
readyReplicas: 2
|
||||||
availableReplicas: 2
|
availableReplicas: 2
|
||||||
@@ -674,7 +704,7 @@ status:
|
|||||||
replicas: 4
|
replicas: 4
|
||||||
readyReplicas: 2
|
readyReplicas: 2
|
||||||
availableReplicas: 4
|
availableReplicas: 4
|
||||||
labelledReplicas: 4
|
fullyLabeledReplicas: 4
|
||||||
`
|
`
|
||||||
|
|
||||||
var rsLessAvailable = `
|
var rsLessAvailable = `
|
||||||
@@ -691,7 +721,7 @@ status:
|
|||||||
replicas: 4
|
replicas: 4
|
||||||
readyReplicas: 4
|
readyReplicas: 4
|
||||||
availableReplicas: 2
|
availableReplicas: 2
|
||||||
labelledReplicas: 4
|
fullyLabeledReplicas: 4
|
||||||
`
|
`
|
||||||
|
|
||||||
var rsReplicaFailure = `
|
var rsReplicaFailure = `
|
||||||
@@ -707,7 +737,7 @@ status:
|
|||||||
observedGeneration: 1
|
observedGeneration: 1
|
||||||
replicas: 4
|
replicas: 4
|
||||||
readyReplicas: 4
|
readyReplicas: 4
|
||||||
labelledReplicas: 4
|
fullyLabeledReplicas: 4
|
||||||
availableReplicas: 4
|
availableReplicas: 4
|
||||||
conditions:
|
conditions:
|
||||||
- type: ReplicaFailure
|
- type: ReplicaFailure
|
||||||
|
|||||||
Reference in New Issue
Block a user