bergerx/kubectl-status

View on GitHub
pkg/plugin/templates/Deployment.tmpl

Summary

Maintainability
Test Coverage
{{- define "Deployment" }}
    {{- /*gotype: github.com/bergerx/kubectl-status/pkg/plugin.RenderableObject*/ -}}
    {{- template "status_summary_line" . }}{{- with index .Annotations "deployment.kubernetes.io/revision" }} rev:{{.}}{{ end }}
    {{- template "kstatus_summary" . }}
    {{- template "finalizer_details_on_termination" . }}
    {{- template "observed_generation_summary" . }}
    {{- template "application_details" . }}
    {{- $injectedStatus := .Status | default dict }}
    {{- $_ := set $injectedStatus "replicas" ( $injectedStatus.replicas | default 0 ) }}
    {{- $_ := set $injectedStatus "readyReplicas" ( $injectedStatus.readyReplicas | default 0) }}
    {{- $_ := set $injectedStatus "availableReplicas" ( $injectedStatus.availableReplicas | default 0 ) }}
    {{- $_ := set $injectedStatus "updatedReplicas" ( $injectedStatus.updatedReplicas | default 0 ) }}
    {{- $_ := set .Object "status" $injectedStatus }}
    {{- template "replicas_status" . }}
    {{- template "conditions_summary" . }}
    {{- template "suspended" . }}
    {{- $rolloutStatus := .RolloutStatus . }}
    {{- if not $rolloutStatus.done }}
        {{- "Ongoing Rollout" | yellow | bold | redBoldIf $rolloutStatus.error | nindent 2 }}
        {{- with $rolloutStatus.message }}: {{ . | yellow }}{{ end }}
        {{- with $rolloutStatus.error }}: Error: {{ . | red }}{{ end }}
    {{- end }}
    {{- if not .Status.readyReplicas }}
        {{- "Outage" | red | bold | nindent 2 }}: Deployment has no Ready replicas.
    {{- else if ne .Status.replicas .Status.readyReplicas }}
        {{- if $rolloutStatus.done }}
            {{- "Not Ready Replicas" | yellow | bold | nindent 2 }}: {{ sub .Status.replicas .Status.readyReplicas }} replicas are not Ready.
        {{- end }}
    {{- else if .Status.unavailableReplicas }}
        {{- if $rolloutStatus.done }}
            {{- "Unavailable Replicas" | yellow | bold | nindent 2 }}: {{ .status.unavailableReplicas }} replicas are not Available.
        {{- end }}
    {{- end }}
    {{- template "recent_deployment_rollouts" . }}
    {{- template "recent_updates" . }}
    {{- template "events" . }}
    {{- template "owners" . }}
{{- end }}

{{- define "recent_deployment_rollouts" }}
    {{- /*gotype: github.com/bergerx/kubectl-status/pkg/plugin.RenderableObject*/ -}}
    {{- $deploymentRevision := index .Annotations "deployment.kubernetes.io/revision" }}
    {{- $sectionHeader := false }}
    {{- $previousReplicaSet := "" }}
    {{- range .KubeGet .Namespace "ReplicaSets" }}
        {{- /*gotype: github.com/bergerx/kubectl-status/pkg/plugin.RenderableObject*/ -}}
        {{- if eq (index .Metadata.ownerReferences 0).name $.Name }}
            {{- if not $sectionHeader }}
                {{- "Rollouts:" | nindent 2}}
                {{- template "rollout_diffs_flag_help" $ }}
                {{- $sectionHeader = true }}
            {{- end }}
            {{- with .Metadata.creationTimestamp }}{{ . | colorAgo | nindent 4 }} ago{{ end }}, managed by {{ .Kind | bold }}/{{ .Name }}
            {{- $replicationSetRevision := index .Annotations "deployment.kubernetes.io/revision" }}
            {{- $activeReplicaSet := eq $deploymentRevision $replicationSetRevision }}
            {{- if .Status.replicas }}, has {{ .Status.replicas }} replicas
                {{- if not $activeReplicaSet }}, {{ "abandoning" | red }}{{ end }}
            {{- else }}
                {{- if $activeReplicaSet }}, {{ "current revision but doesn't yet have any replicas" | red }}{{ end }}
            {{- end }}
            {{- with index .Annotations "deployment.kubernetes.io/revision-history" }}
                {{- "" | nindent 6 }} Used at revisions: {{ . }},{{ $replicationSetRevision}}
                {{- if $activeReplicaSet }} ({{ "current revision" | green }}) {{ end }}
            {{- end }}
            {{- if and $previousReplicaSet ($.Config.GetBool "include-rollout-diffs") }}
                {{- with $.KubeGetUnifiedDiffString "ReplicaSet" $.Namespace $previousReplicaSet.Name .Name }}
                    {{- "Diff" | bold | nindent 6 }}:
                    {{- . | markRed "^-.*" | markGreen "^\\+.*" | nindent 6 }}
                {{- end }}
            {{- end }}
            {{- $previousReplicaSet = . }}
        {{- end }}
    {{- end }}
{{- end }}