Displays resources that are being deleted as "Progressing". Closes #1410 (#1426)

This commit is contained in:
Alex Collins 2019-04-11 07:47:59 -07:00 committed by GitHub
parent e4b8a9d895
commit 3c4b42de75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 6 deletions

View file

@ -49,10 +49,15 @@ func SetApplicationHealth(resStatuses []appv1.ResourceStatus, liveObjs []*unstru
// GetResourceHealth returns the health of a k8s resource
func GetResourceHealth(obj *unstructured.Unstructured, resourceOverrides map[string]appv1.ResourceOverride) (*appv1.HealthStatus, error) {
var err error
var health *appv1.HealthStatus
health, err = getResourceHealthFromLuaScript(obj, resourceOverrides)
if obj.GetDeletionTimestamp() != nil {
return &appv1.HealthStatus{
Status: appv1.HealthStatusProgressing,
Message: "Pending deletion",
}, nil
}
health, err := getResourceHealthFromLuaScript(obj, resourceOverrides)
if err != nil {
health = &appv1.HealthStatus{
Status: appv1.HealthStatusUnknown,

View file

@ -13,12 +13,12 @@ import (
)
func assertAppHealth(t *testing.T, yamlPath string, expectedStatus appv1.HealthStatusCode) {
health := getHealtStatus(yamlPath, t)
health := getHealthStatus(yamlPath, t)
assert.NotNil(t, health)
assert.Equal(t, expectedStatus, health.Status)
}
func getHealtStatus(yamlPath string, t *testing.T) *appv1.HealthStatus {
func getHealthStatus(yamlPath string, t *testing.T) *appv1.HealthStatus {
yamlBytes, err := ioutil.ReadFile(yamlPath)
assert.Nil(t, err)
var obj unstructured.Unstructured
@ -59,7 +59,7 @@ func TestIngressHealth(t *testing.T) {
}
func TestCRD(t *testing.T) {
assert.Nil(t, getHealtStatus("./testdata/knative-service.yaml", t))
assert.Nil(t, getHealthStatus("./testdata/knative-service.yaml", t))
}
func TestJob(t *testing.T) {
@ -79,6 +79,7 @@ func TestPod(t *testing.T) {
assertAppHealth(t, "./testdata/pod-running-restart-onfailure.yaml", appv1.HealthStatusProgressing)
assertAppHealth(t, "./testdata/pod-failed.yaml", appv1.HealthStatusDegraded)
assertAppHealth(t, "./testdata/pod-succeeded.yaml", appv1.HealthStatusHealthy)
assertAppHealth(t, "./testdata/pod-deletion.yaml", appv1.HealthStatusProgressing)
}
func TestSetApplicationHealth(t *testing.T) {

75
util/health/testdata/pod-deletion.yaml vendored Normal file
View file

@ -0,0 +1,75 @@
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: 2018-12-02T10:16:04Z
name: image-pull-backoff
namespace: argocd
resourceVersion: "155333"
selfLink: /api/v1/namespaces/argocd/pods/image-pull-backoff
uid: 46c1e8de-f61b-11e8-a057-fe5f49266390
deletionTimestamp: 2018-12-03T10:16:04Z
spec:
containers:
- image: doesnt-exist
imagePullPolicy: Always
name: main
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-f9jvj
readOnly: true
dnsPolicy: ClusterFirst
nodeName: minikube
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: default-token-f9jvj
secret:
defaultMode: 420
secretName: default-token-f9jvj
status:
conditions:
- lastProbeTime: null
lastTransitionTime: 2018-12-02T10:16:04Z
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: 2018-12-02T10:16:04Z
message: 'containers with unready status: [main]'
reason: ContainersNotReady
status: "False"
type: Ready
- lastProbeTime: null
lastTransitionTime: 2018-12-02T10:16:04Z
status: "True"
type: PodScheduled
containerStatuses:
- image: doesnt-exist
imageID: ""
lastState: {}
name: main
ready: false
restartCount: 0
state:
waiting:
reason: PodInitializing
hostIP: 192.168.64.41
phase: Pending
podIP: 172.17.0.9
qosClass: BestEffort
startTime: 2018-12-02T10:16:04Z