template

package
v0.0.0-...-b830f6f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTemplates = map[string]string{

	"pod_row":                `{{ .Name }}	{{ template "pod-status" .Pod }}	{{ template "pod-ready" .Pod }}	{{ .Restarts }}	{{ ago .Age }}`,
	"pod_row_with_namespace": `{{ .Namespace }}	{{ .Name }}	{{ template "pod-status" .Pod }}	{{ template "pod-ready" .Pod }}	{{ .Restarts }}	{{ ago .Age }}`,

	"deployment_row":                `{{ .Name }}	{{ .Ready }}	{{ .UpToDate }}	{{ .Available }}	{{ ago .Age }}`,
	"deployment_row_with_namespace": `{{ .Namespace }}	{{ .Name }}	{{ .Ready }}	{{ .UpToDate }}	{{ .Available }}	{{ ago .Age }}`,

	"service_row":                `{{ .Name }}	{{ .Type }}	{{ .ClusterIP }}	{{ .ExternalIP }}	{{ .Ports }}	{{ ago .Age }}`,
	"service_row_with_namespace": `{{ .Namespace }}	{{ .Name }}	{{ .Type }}	{{ .ClusterIP }}	{{ .ExternalIP }}	{{ .Ports }}	{{ ago .Age }}`,

	"statefulset_row":                `{{ .Name }}	{{ .Ready }}	{{ ago .Age }}`,
	"statefulset_row_with_namespace": `{{ .Namespace }}	{{ .Name }}	{{ .Ready }}	{{ ago .Age }}`,

	"ingress_row":                `{{ .Name }}	{{ .Class }}	{{ .Hosts }}	{{ .Address }}	{{ .Ports }}	{{ ago .Age }}`,
	"ingress_row_with_namespace": `{{ .Namespace }}	{{ .Name }}	{{ .Class }}	{{ .Hosts }}	{{ .Address }}	{{ .Ports }}	{{ ago .Age }}`,

	"configmap_row":                `{{ .Name }}	{{ .Data }}	{{ ago .Age }}`,
	"configmap_row_with_namespace": `{{ .Namespace }}	{{ .Name }}	{{ .Data }}	{{ ago .Age }}`,

	"secret_row":                `{{ .Name }}	{{ .Type }}	{{ .Data }}	{{ ago .Age }}`,
	"secret_row_with_namespace": `{{ .Namespace }}	{{ .Name }}	{{ .Type }}	{{ .Data }}	{{ ago .Age }}`,
	"pod-status": `{{- /* Pod Status Formatter - Shows status with appropriate icon and color */ -}}
{{- $status := .Status.Phase -}}
{{- $reason := "" -}}

{{- /* Check for more specific status from conditions */ -}}
{{- range .Status.Conditions -}}
  {{- if and (eq .Type "Ready") (ne .Status "True") .Reason -}}
    {{- $reason = .Reason -}}
  {{- end -}}
{{- end -}}

{{- /* Check container statuses for waiting/terminated states */ -}}
{{- range .Status.ContainerStatuses -}}
  {{- if .State.Waiting -}}
    {{- $status = .State.Waiting.Reason -}}
  {{- else if .State.Terminated -}}
    {{- $status = .State.Terminated.Reason -}}
  {{- end -}}
{{- end -}}

{{- /* Apply appropriate styling based on status */ -}}
{{- if eq $status "Running" -}}
  {{- color "green" "●" }} {{ color "green" "Running" -}}
{{- else if eq $status "Succeeded" -}}
  {{- color "green" "✓" }} {{ color "green" "Succeeded" -}}
{{- else if eq $status "Pending" -}}
  {{- color "yellow" "◐" }} {{ color "yellow" "Pending" -}}
{{- else if eq $status "ContainerCreating" -}}
  {{- color "yellow" "◑" }} {{ color "yellow" "Creating" -}}
{{- else if eq $status "Terminating" -}}
  {{- color "magenta" "◉" }} {{ color "magenta" "Terminating" -}}
{{- else if or (eq $status "Failed") (eq $status "Error") -}}
  {{- color "red" "✗" }} {{ color "red" $status -}}
{{- else if eq $status "CrashLoopBackOff" -}}
  {{- color "red" "↻" }} {{ color "red" "CrashLoop" -}}
{{- else if eq $status "ImagePullBackOff" -}}
  {{- color "red" "⬇" }} {{ color "red" "ImagePull" -}}
{{- else if eq $status "ErrImagePull" -}}
  {{- color "red" "⬇" }} {{ color "red" "ImageErr" -}}
{{- else if eq $status "Completed" -}}
  {{- color "blue" "☐" }} {{ color "blue" "Completed" -}}
{{- else if eq $status "Evicted" -}}
  {{- color "yellow" "⚠" }} {{ color "yellow" "Evicted" -}}
{{- else -}}
  {{- color "gray" "○" }} {{ color "gray" $status -}}
{{- end -}}`,

	"cpu": `{{- /* CPU Formatter - Shows CPU usage with appropriate coloring */ -}}
{{- $cpu := .Metrics.CPU | default 0 -}}
{{- $cpuMilli := $cpu | toMillicores -}}
{{- $requested := 0 -}}
{{- $limit := 0 -}}

{{- /* Get request and limit if available */ -}}
{{- if .Spec.Containers -}}
  {{- range .Spec.Containers -}}
    {{- $requested = add $requested (.Resources.Requests.cpu | toMillicores | default 0) -}}
    {{- $limit = add $limit (.Resources.Limits.cpu | toMillicores | default 0) -}}
  {{- end -}}
{{- end -}}

{{- /* Calculate percentage if request is set */ -}}
{{- $percent := 0 -}}
{{- if gt $requested 0 -}}
  {{- $percent = div (mul $cpuMilli 100) $requested -}}
{{- end -}}

{{- /* Format based on value */ -}}
{{- if eq $cpuMilli 0 -}}
  {{- color "gray" "-" -}}
{{- else if lt $cpuMilli 1000 -}}
  {{- /* Show millicores for small values */ -}}
  {{- if and (gt $percent 0) (gt $percent 90) -}}
    {{- color "red" (printf "%dm" $cpuMilli) -}}
  {{- else if and (gt $percent 0) (gt $percent 70) -}}
    {{- color "yellow" (printf "%dm" $cpuMilli) -}}
  {{- else -}}
    {{- color "green" (printf "%dm" $cpuMilli) -}}
  {{- end -}}
{{- else -}}
  {{- /* Show cores for large values */ -}}
  {{- $cores := div $cpuMilli 1000.0 -}}
  {{- if and (gt $percent 0) (gt $percent 90) -}}
    {{- color "red" (printf "%.2f" $cores) -}}
  {{- else if and (gt $percent 0) (gt $percent 70) -}}
    {{- color "yellow" (printf "%.2f" $cores) -}}
  {{- else -}}
    {{- color "green" (printf "%.2f" $cores) -}}
  {{- end -}}
{{- end -}}`,

	"memory": `{{- /* Memory Formatter - Shows memory with appropriate units and coloring */ -}}
{{- $memory := .Metrics.Memory | default 0 -}}
{{- $memoryMB := $memory | toMB -}}
{{- $requested := 0 -}}
{{- $limit := 0 -}}

{{- /* Get request and limit if available */ -}}
{{- if .Spec.Containers -}}
  {{- range .Spec.Containers -}}
    {{- $requested = add $requested (.Resources.Requests.memory | toMB | default 0) -}}
    {{- $limit = add $limit (.Resources.Limits.memory | toMB | default 0) -}}
  {{- end -}}
{{- end -}}

{{- /* Calculate percentage if request is set */ -}}
{{- $percent := 0 -}}
{{- if gt $requested 0 -}}
  {{- $percent = div (mul $memoryMB 100) $requested -}}
{{- end -}}

{{- /* Format with appropriate units */ -}}
{{- if eq $memoryMB 0 -}}
  {{- color "gray" "-" -}}
{{- else -}}
  {{- $formatted := $memory | humanizeBytes -}}
  {{- if and (gt $percent 0) (gt $percent 90) -}}
    {{- color "red" $formatted -}}
  {{- else if and (gt $percent 0) (gt $percent 70) -}}
    {{- color "yellow" $formatted -}}
  {{- else if lt $memoryMB 128 -}}
    {{- color "green" $formatted -}}
  {{- else if lt $memoryMB 512 -}}
    {{- color "yellow" $formatted -}}
  {{- else -}}
    {{- color "red" $formatted -}}
  {{- end -}}
{{- end -}}`,

	"ready": `{{- /* Ready Formatter - Shows ready/total with coloring */ -}}
{{- $ready := 0 -}}
{{- $total := 0 -}}

{{- /* Handle different resource types */ -}}
{{- if .Status.ContainerStatuses -}}
  {{- /* Pod */ -}}
  {{- $total = len .Status.ContainerStatuses -}}
  {{- range .Status.ContainerStatuses -}}
    {{- if .Ready -}}{{- $ready = add $ready 1 -}}{{- end -}}
  {{- end -}}
{{- else if .Status.ReadyReplicas -}}
  {{- /* Deployment/StatefulSet */ -}}
  {{- $ready = .Status.ReadyReplicas | default 0 -}}
  {{- $total = .Spec.Replicas | default 1 -}}
{{- end -}}

{{- /* Format with color based on readiness */ -}}
{{- $text := printf "%d/%d" $ready $total -}}
{{- if eq $ready $total -}}
  {{- color "green" $text -}}
{{- else if eq $ready 0 -}}
  {{- color "red" $text -}}
{{- else -}}
  {{- color "yellow" $text -}}
{{- end -}}`,

	"restarts": `{{- /* Restart Formatter - Shows restart count with last restart time */ -}}
{{- $restarts := 0 -}}
{{- $lastRestart := "" -}}

{{- /* Sum up all container restarts */ -}}
{{- range .Status.ContainerStatuses -}}
  {{- $restarts = add $restarts .RestartCount -}}
  {{- if .LastTerminationState.Terminated -}}
    {{- $lastRestart = .LastTerminationState.Terminated.FinishedAt | ago -}}
  {{- end -}}
{{- end -}}

{{- /* Format based on restart count */ -}}
{{- if eq $restarts 0 -}}
  {{- color "gray" "0" -}}
{{- else -}}
  {{- $text := toString $restarts -}}
  {{- if $lastRestart -}}
    {{- $text = printf "%d (%s)" $restarts $lastRestart -}}
  {{- end -}}
  
  {{- if lt $restarts 3 -}}
    {{- color "yellow" $text -}}
  {{- else if lt $restarts 10 -}}
    {{- color "orange" (printf "⚠ %s" $text) -}}
  {{- else -}}
    {{- color "red" (printf "‼ %s" $text) -}}
  {{- end -}}
{{- end -}}`,

	"age": `{{- /* Age Formatter - Shows age with optional coloring */ -}}
{{- $age := .Metadata.CreationTimestamp | ago -}}
{{- $ageSeconds := .Metadata.CreationTimestamp | ageInSeconds -}}

{{- /* Color based on age (optional) */ -}}
{{- if lt $ageSeconds 300 -}}
  {{- /* Less than 5 minutes - new */ -}}
  {{- color "cyan" (printf "✨ %s" $age) -}}
{{- else if lt $ageSeconds 3600 -}}
  {{- /* Less than 1 hour */ -}}
  {{- color "green" $age -}}
{{- else if lt $ageSeconds 86400 -}}
  {{- /* Less than 1 day */ -}}
  {{- color "white" $age -}}
{{- else if lt $ageSeconds 604800 -}}
  {{- /* Less than 1 week */ -}}
  {{- color "gray" $age -}}
{{- else -}}
  {{- /* Older than 1 week */ -}}
  {{- color "darkgray" $age -}}
{{- end -}}`,

	"service-type": `{{- /* Service Type Formatter */ -}}
{{- if eq .Spec.Type "LoadBalancer" -}}
  {{- color "blue" "🌐" }} {{ .Spec.Type -}}
{{- else if eq .Spec.Type "NodePort" -}}
  {{- color "cyan" "📡" }} {{ .Spec.Type -}}
{{- else if eq .Spec.Type "ClusterIP" -}}
  {{- color "green" "🔒" }} {{ .Spec.Type -}}
{{- else if eq .Spec.Type "ExternalName" -}}
  {{- color "magenta" "🔗" }} {{ .Spec.Type -}}
{{- else -}}
  {{- color "gray" .Spec.Type -}}
{{- end -}}`,

	"namespace": `{{- /* Namespace Formatter */ -}}
{{- if hasPrefix .Namespace "kube-" -}}
  {{- color "blue" (printf "⚙ %s" .Namespace) -}}
{{- else if eq .Namespace "default" -}}
  {{- color "gray" .Namespace -}}
{{- else if contains .Namespace "prod" -}}
  {{- color "red" (printf "🔴 %s" .Namespace) -}}
{{- else if contains .Namespace "staging" -}}
  {{- color "yellow" (printf "🟡 %s" .Namespace) -}}
{{- else if contains .Namespace "dev" -}}
  {{- color "green" (printf "🟢 %s" .Namespace) -}}
{{- else -}}
  {{- .Namespace -}}
{{- end -}}`,

	"deployment-status": `{{- /* Deployment Status Formatter */ -}}
{{- $desired := .Spec.Replicas | default 1 -}}
{{- $ready := .Status.ReadyReplicas | default 0 -}}
{{- $available := .Status.AvailableReplicas | default 0 -}}
{{- $updated := .Status.UpdatedReplicas | default 0 -}}

{{- if eq $ready $desired -}}
  {{- color "green" "●" }} {{ color "green" "Ready" -}}
{{- else if eq $ready 0 -}}
  {{- color "red" "✗" }} {{ color "red" "NotReady" -}}
{{- else if lt $updated $desired -}}
  {{- color "yellow" "◐" }} {{ color "yellow" "Updating" -}}
{{- else -}}
  {{- color "yellow" "◑" }} {{ color "yellow" "Progressing" -}}
{{- end -}}`,

	"ingress-status": `{{- /* Ingress Status Formatter */ -}}
{{- $hasAddress := false -}}
{{- range .Status.LoadBalancer.Ingress -}}
  {{- if or .IP .Hostname -}}
    {{- $hasAddress = true -}}
  {{- end -}}
{{- end -}}

{{- if $hasAddress -}}
  {{- color "green" "●" }} {{ color "green" "Ready" -}}
{{- else -}}
  {{- color "yellow" "◐" }} {{ color "yellow" "Pending" -}}
{{- end -}}`,

	"configmap-data": `{{- /* ConfigMap Data Count Formatter */ -}}
{{- $dataCount := add (len .Data) (len .BinaryData) -}}
{{- if eq $dataCount 0 -}}
  {{- color "gray" "0" -}}
{{- else if eq $dataCount 1 -}}
  {{- color "green" "1" -}}
{{- else if lt $dataCount 10 -}}
  {{- color "blue" (toString $dataCount) -}}
{{- else -}}
  {{- color "yellow" (toString $dataCount) -}}
{{- end -}}`,

	"secret-type": `{{- /* Secret Type Formatter */ -}}
{{- $type := .Type | toString -}}
{{- if eq $type "Opaque" -}}
  {{- color "blue" "📄" }} {{ color "blue" "Opaque" -}}
{{- else if eq $type "kubernetes.io/tls" -}}
  {{- color "green" "🔐" }} {{ color "green" "TLS" -}}
{{- else if contains $type "dockercfg" -}}
  {{- color "cyan" "🐳" }} {{ color "cyan" "Docker" -}}
{{- else if contains $type "service-account" -}}
  {{- color "purple" "👤" }} {{ color "purple" "ServiceAccount" -}}
{{- else -}}
  {{- color "gray" $type -}}
{{- end -}}`,

	"node-status": `{{- /* Node Status Formatter */ -}}
{{- $ready := false -}}
{{- range .Status.Conditions -}}
  {{- if and (eq .Type "Ready") (eq .Status "True") -}}
    {{- $ready = true -}}
  {{- end -}}
{{- end -}}

{{- if $ready -}}
  {{- color "green" "●" }} {{ color "green" "Ready" -}}
{{- else -}}
  {{- color "red" "✗" }} {{ color "red" "NotReady" -}}
{{- end -}}`,

	"pv-status": `{{- /* PersistentVolume Status Formatter */ -}}
{{- if eq .Status.Phase "Available" -}}
  {{- color "green" "●" }} {{ color "green" "Available" -}}
{{- else if eq .Status.Phase "Bound" -}}
  {{- color "blue" "◉" }} {{ color "blue" "Bound" -}}
{{- else if eq .Status.Phase "Released" -}}
  {{- color "yellow" "◐" }} {{ color "yellow" "Released" -}}
{{- else if eq .Status.Phase "Failed" -}}
  {{- color "red" "✗" }} {{ color "red" "Failed" -}}
{{- else -}}
  {{- color "gray" "○" }} {{ color "gray" .Status.Phase -}}
{{- end -}}`,

	"pvc-status": `{{- /* PersistentVolumeClaim Status Formatter */ -}}
{{- if eq .Status.Phase "Bound" -}}
  {{- color "green" "●" }} {{ color "green" "Bound" -}}
{{- else if eq .Status.Phase "Pending" -}}
  {{- color "yellow" "◐" }} {{ color "yellow" "Pending" -}}
{{- else if eq .Status.Phase "Lost" -}}
  {{- color "red" "✗" }} {{ color "red" "Lost" -}}
{{- else -}}
  {{- color "gray" "○" }} {{ color "gray" .Status.Phase -}}
{{- end -}}`,

	"job-status": `{{- /* Job Status Formatter */ -}}
{{- $succeeded := .Status.Succeeded | default 0 -}}
{{- $failed := .Status.Failed | default 0 -}}
{{- $active := .Status.Active | default 0 -}}

{{- if gt $succeeded 0 -}}
  {{- color "green" "✓" }} {{ color "green" "Completed" -}}
{{- else if gt $failed 0 -}}
  {{- color "red" "✗" }} {{ color "red" "Failed" -}}
{{- else if gt $active 0 -}}
  {{- color "yellow" "◐" }} {{ color "yellow" "Running" -}}
{{- else -}}
  {{- color "gray" "○" }} {{ color "gray" "Pending" -}}
{{- end -}}`,

	"cronjob-status": `{{- /* CronJob Status Formatter */ -}}
{{- $suspended := .Spec.Suspend | default false -}}
{{- $lastSchedule := .Status.LastScheduleTime -}}

{{- if $suspended -}}
  {{- color "gray" "⏸" }} {{ color "gray" "Suspended" -}}
{{- else if $lastSchedule -}}
  {{- color "green" "●" }} {{ color "green" "Active" -}}
{{- else -}}
  {{- color "yellow" "◐" }} {{ color "yellow" "Waiting" -}}
{{- end -}}`,

	"event-type": `{{- /* Event Type Formatter */ -}}
{{- if eq .Type "Normal" -}}
  {{- color "green" "ℹ" }} {{ color "green" .Reason -}}
{{- else if eq .Type "Warning" -}}
  {{- color "yellow" "⚠" }} {{ color "yellow" .Reason -}}
{{- else -}}
  {{- color "red" "✗" }} {{ color "red" .Reason -}}
{{- end -}}`,

	"resource-version": `{{- /* Resource Version Formatter */ -}}
{{- $version := .Metadata.ResourceVersion -}}
{{- if $version -}}
  {{- color "blue" $version -}}
{{- else -}}
  {{- color "gray" "-" -}}
{{- end -}}`,

	"labels": `{{- /* Labels Formatter - Shows important labels */ -}}
{{- $important := list "app" "version" "env" "tier" "component" -}}
{{- $labels := list -}}
{{- range $key, $value := .Metadata.Labels -}}
  {{- if has $key $important -}}
    {{- $labels = append $labels (printf "%s=%s" $key $value) -}}
  {{- end -}}
{{- end -}}
{{- if gt (len $labels) 3 -}}
  {{- join (slice $labels 0 3) ", " }}...
{{- else -}}
  {{- join $labels ", " -}}
{{- end -}}`,

	"annotations": `{{- /* Annotations Formatter - Shows count */ -}}
{{- $count := len .Metadata.Annotations -}}
{{- if eq $count 0 -}}
  {{- color "gray" "0" -}}
{{- else if lt $count 5 -}}
  {{- color "green" (toString $count) -}}
{{- else if lt $count 15 -}}
  {{- color "yellow" (toString $count) -}}
{{- else -}}
  {{- color "red" (toString $count) -}}
{{- end -}}`,

	"uniq_key_default": `{{ .Metadata.Name }}`,

	"uniq_key_pod": `{{ .Metadata.Name }}`,

	"uniq_key_deployment": `{{ .Metadata.Name }}_{{ join .ImageList ";" }}`,

	"uniq_key_statefulset": `{{ .Metadata.Name }}_{{ join .ImageList ";" }}`,

	"uniq_key_service": `{{ .Metadata.Name }}`,

	"uniq_key_ingress": `{{ .Metadata.Name }}`,

	"uniq_key_configmap": `{{ .Metadata.Name }}`,

	"uniq_key_secret": `{{ .Metadata.Name }}`,

	"pod_describe": `{{ bold "Name:" }}             {{ .Name }}
{{ bold "Namespace:" }}        {{ .Namespace }}
{{ bold "Priority:" }}         {{ .Priority | default 0 }}
{{ bold "Service Account:" }}  {{ .Spec.ServiceAccount | default "default" }}
{{ bold "Node:" }}             {{ .Spec.NodeName }}/{{ .Status.HostIP }}
{{ bold "Start Time:" }}       {{ .Status.StartTime | timestamp }}
{{ bold "Labels:" }}           {{ range $k, $v := .Labels }}{{ $k }}={{ $v }}
                  {{ end }}
{{ bold "Annotations:" }}      {{ range $k, $v := .Annotations }}{{ $k }}: {{ $v }}
                  {{ end }}
{{ bold "Status:" }}           {{ .Status.Phase }}
{{ bold "IP:" }}               {{ .Status.PodIP }}
{{ bold "IPs:" }}
  {{ bold "IP:" }}             {{ .Status.PodIP }}
{{ bold "Controlled By:" }}    ReplicaSet/{{ .Name }}-abc123

{{ bold "Containers:" }}
{{ range .Spec.Containers }}  {{ bold .Name }}:
    {{ bold "Container ID:" }}   containerd://abc123def456...
    {{ bold "Image:" }}          {{ .Image }}
    {{ bold "Image ID:" }}       {{ .Image }}@sha256:b3590f10cafc8a250f24b54d49a26a5e88863671c15cb15c417322b8eff6f186
    {{ bold "Port:" }}           {{ range .Ports }}{{ .ContainerPort }}/{{ .Protocol }}{{ end }}
    {{ bold "Host Port:" }}      0/TCP
    {{ bold "State:" }}          Running
      {{ bold "Started:" }}      {{ $.Status.StartTime | timestamp }}
    {{ bold "Ready:" }}          True
    {{ bold "Restart Count:" }}  0
    {{ bold "Limits:" }}
{{ range $k, $v := .Resources.Limits }}      {{ $k }}:     {{ $v }}
{{ end }}    {{ bold "Requests:" }}
{{ range $k, $v := .Resources.Requests }}      {{ $k }}:     {{ $v }}
{{ end }}{{ if .LivenessProbe }}    {{ bold "Liveness:" }}  http-get http://:{{ .LivenessProbe.HttpGet.Port }}{{ .LivenessProbe.HttpGet.Path }} delay={{ .LivenessProbe.InitialDelaySeconds }}s timeout={{ .LivenessProbe.TimeoutSeconds }}s period={{ .LivenessProbe.PeriodSeconds }}s #success={{ .LivenessProbe.SuccessThreshold }} #failure={{ .LivenessProbe.FailureThreshold }}{{ end }}
    {{ bold "Environment:" }}
      {{ bold "K8S_POD_NAME:" }}  {{ $.Name }} (v1:metadata.name)
    {{ bold "Mounts:" }}
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-token (ro)
{{ end }}

{{ bold "Conditions:" }}
  {{ bold "Type" | printf "%-27s" }} {{ bold "Status" }}
{{ range .Status.Conditions }}  {{ .Type | printf "%-27s" }} {{ .Status }}
{{ end }}

{{ bold "Volumes:" }}
{{ range .Spec.Volumes }}  {{ bold .Name }}:
    {{ bold "Type:" }}                    Projected (a volume that contains injected data from multiple sources)
    {{ bold "TokenExpirationSeconds:" }}  3607
    {{ bold "ConfigMapName:" }}           kube-root-ca.crt
    {{ bold "ConfigMapOptional:" }}       <nil>
    {{ bold "DownwardAPI:" }}             true
{{ end }}
{{ bold "QoS Class:" }}                   Burstable
{{ bold "Node-Selectors:" }}              <none>
{{ bold "Tolerations:" }}                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s

{{ bold "Events:" }}
  {{ bold "Type" | printf "%-6s" }}  {{ bold "Reason" | printf "%-10s" }}  {{ bold "Age" | printf "%-4s" }}  {{ bold "From" | printf "%-17s" }}  {{ bold "Message" }}
  ----  ------  ----  ----               -------
{{ range .Events }}  {{ .Type | printf "%-6s" }}  {{ .Reason | printf "%-10s" }}  {{ .Age | printf "%-4s" }}  {{ .From | printf "%-17s" }}  {{ .Message }}
{{ end }}`,

	"deployment_describe": `{{ bold "Name:" }}                   {{ .Name }}
{{ bold "Namespace:" }}              {{ .Namespace }}
{{ bold "CreationTimestamp:" }}      {{ .CreationTimestamp | timestamp }}
{{ bold "Labels:" }}                 {{ range $k, $v := .Labels }}{{ $k }}={{ $v }}
                        {{ end }}
{{ bold "Annotations:" }}            {{ range $k, $v := .Annotations }}{{ $k }}: {{ $v }}
                        {{ end }}
{{ bold "Selector:" }}               {{ range $k, $v := .Spec.Selector.MatchLabels }}{{ $k }}={{ $v }}{{ end }}
{{ bold "Replicas:" }}               {{ .Status.Replicas }} desired | {{ .Status.UpdatedReplicas }} updated | {{ .Status.Replicas }} total | {{ .Status.AvailableReplicas }} available | {{ sub .Status.Replicas .Status.AvailableReplicas }} unavailable
{{ bold "StrategyType:" }}           {{ .Spec.Strategy.Type }}
{{ bold "MinReadySeconds:" }}        0
{{ bold "RollingUpdateStrategy:" }}  {{ .Spec.Strategy.RollingUpdate.MaxUnavailable }} max unavailable, {{ .Spec.Strategy.RollingUpdate.MaxSurge }} max surge
{{ bold "Pod Template:" }}
  {{ bold "Labels:" }}  {{ range $k, $v := .Labels }}{{ $k }}={{ $v }} {{ end }}
  {{ bold "Containers:" }}
{{ range .Spec.Containers }}   {{ bold .Name }}:
    {{ bold "Image:" }}      {{ .Image }}
    {{ bold "Port:" }}       {{ range .Ports }}{{ .ContainerPort }}/{{ .Protocol }}{{ end }}
    {{ bold "Host Port:" }}  0/TCP
{{ if .Resources.Limits }}    {{ bold "Limits:" }}
{{ range $k, $v := .Resources.Limits }}      {{ $k }}:     {{ $v }}
{{ end }}{{ end }}{{ if .Resources.Requests }}    {{ bold "Requests:" }}
{{ range $k, $v := .Resources.Requests }}      {{ $k }}:     {{ $v }}
{{ end }}{{ end }}    {{ bold "Environment:" }}  <none>
    {{ bold "Mounts:" }}       <none>
{{ end }}  {{ bold "Volumes:" }}        <none>

{{ bold "Conditions:" }}
  {{ bold "Type" | printf "%-11s" }}  {{ bold "Status" | printf "%-6s" }}  {{ bold "Reason" }}
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable

{{ bold "Events:" }}
  {{ bold "Type" | printf "%-6s" }}  {{ bold "Reason" | printf "%-10s" }}  {{ bold "Age" | printf "%-4s" }}  {{ bold "From" | printf "%-17s" }}  {{ bold "Message" }}
  ----  ------  ----  ----               -------
{{ range .Events }}  {{ .Type | printf "%-6s" }}  {{ .Reason | printf "%-10s" }}  {{ .Age | printf "%-4s" }}  {{ .From | printf "%-17s" }}  {{ .Message }}
{{ end }}`,

	"service_describe": `{{ bold "Name:" }}                     {{ .Name }}
{{ bold "Namespace:" }}                {{ .Namespace }}
{{ bold "Labels:" }}                   {{ range $k, $v := .Labels }}{{ $k }}={{ $v }}
                          {{ end }}
{{ bold "Annotations:" }}              {{ range $k, $v := .Annotations }}{{ $k }}: {{ $v }}
                          {{ end }}
{{ bold "Selector:" }}                 {{ range $k, $v := .Spec.Selector }}{{ $k }}={{ $v }}{{ end }}
{{ bold "Type:" }}                     {{ .Spec.Type }}
{{ bold "IP Family Policy:" }}         SingleStack
{{ bold "IP Families:" }}              IPv4
{{ bold "IP:" }}                       {{ .Spec.ClusterIP }}
{{ bold "IPs:" }}                      {{ .Spec.ClusterIP }}
{{ bold "Port:" }}                     {{ range .Spec.Ports }}{{ .Name }}  {{ .Port }}/{{ .Protocol }}{{ end }}
{{ bold "TargetPort:" }}               {{ range .Spec.Ports }}{{ .TargetPort }}/{{ .Protocol }}{{ end }}
{{ bold "Endpoints:" }}                10.244.1.5:80,10.244.1.6:80,10.244.1.7:80
{{ bold "Session Affinity:" }}         None
{{ bold "Internal Traffic Policy:" }}  Cluster

{{ bold "Events:" }}
  {{ bold "Type" | printf "%-6s" }}  {{ bold "Reason" | printf "%-10s" }}  {{ bold "Age" | printf "%-4s" }}  {{ bold "From" | printf "%-17s" }}  {{ bold "Message" }}
  ----  ------  ----  ----               -------
{{ range .Events }}  {{ .Type | printf "%-6s" }}  {{ .Reason | printf "%-10s" }}  {{ .Age | printf "%-4s" }}  {{ .From | printf "%-17s" }}  {{ .Message }}
{{ end }}`,

	"ingress_describe": `{{ bold "Name:" }}             {{ .Name }}
{{ bold "Namespace:" }}        {{ .Namespace }}
{{ bold "Address:" }}          {{ range .Status.LoadBalancer.Ingress }}{{ .IP }}{{ end }}
{{ bold "Ingress Class:" }}    {{ .Spec.IngressClassName }}
{{ bold "Default backend:" }}  <default>
{{ bold "Rules:" }}
  {{ bold "Host" | printf "%-22s" }}  {{ bold "Path" | printf "%-4s" }}  {{ bold "Backends" }}
  ----                    ----  --------
{{ range .Spec.Rules }}  {{ .Host | printf "%-22s" }}  {{ range .HTTP.Paths }}{{ .Path }}     {{ .Backend.Service.Name }}:{{ .Backend.Service.Port.Number }}{{ end }}
{{ end }}

{{ bold "Events:" }}
  {{ bold "Type" | printf "%-6s" }}  {{ bold "Reason" | printf "%-10s" }}  {{ bold "Age" | printf "%-4s" }}  {{ bold "From" | printf "%-17s" }}  {{ bold "Message" }}
  ----  ------  ----  ----               -------
{{ range .Events }}  {{ .Type | printf "%-6s" }}  {{ .Reason | printf "%-10s" }}  {{ .Age | printf "%-4s" }}  {{ .From | printf "%-17s" }}  {{ .Message }}
{{ end }}`,

	"configmap_describe": `{{ bold "Name:" }}         {{ .Name }}
{{ bold "Namespace:" }}    {{ .Namespace }}
{{ bold "Labels:" }}       {{ range $k, $v := .Labels }}{{ $k }}={{ $v }}
              {{ end }}
{{ bold "Annotations:" }}  {{ range $k, $v := .Annotations }}{{ $k }}: {{ $v }}
              {{ end }}

{{ bold "Data" }}
====
{{ range $k, $v := .Data }}{{ bold $k }}:
----
{{ $v }}

{{ end }}
{{ bold "BinaryData" }}
==========
<none>

{{ bold "Events:" }}
  {{ bold "Type" | printf "%-6s" }}  {{ bold "Reason" | printf "%-10s" }}  {{ bold "Age" | printf "%-4s" }}  {{ bold "From" | printf "%-17s" }}  {{ bold "Message" }}
  ----  ------  ----  ----               -------
{{ range .Events }}  {{ .Type | printf "%-6s" }}  {{ .Reason | printf "%-10s" }}  {{ .Age | printf "%-4s" }}  {{ .From | printf "%-17s" }}  {{ .Message }}
{{ end }}`,

	"secret_describe": `{{ bold "Name:" }}         {{ .Name }}
{{ bold "Namespace:" }}    {{ .Namespace }}
{{ bold "Labels:" }}       {{ range $k, $v := .Labels }}{{ $k }}={{ $v }}
              {{ end }}
{{ bold "Annotations:" }}  {{ range $k, $v := .Annotations }}{{ $k }}: {{ $v }}
              {{ end }}

{{ bold "Type:" }}  {{ .Type }}

{{ bold "Data" }}
====
{{ range $k, $v := .Data }}{{ $k }}:  {{ len $v }} bytes
{{ end }}

{{ bold "Events:" }}
  {{ bold "Type" | printf "%-6s" }}  {{ bold "Reason" | printf "%-10s" }}  {{ bold "Age" | printf "%-4s" }}  {{ bold "From" | printf "%-17s" }}  {{ bold "Message" }}
  ----  ------  ----  ----               -------
{{ range .Events }}  {{ .Type | printf "%-6s" }}  {{ .Reason | printf "%-10s" }}  {{ .Age | printf "%-4s" }}  {{ .From | printf "%-17s" }}  {{ .Message }}
{{ end }}`,
}

DefaultTemplates contains all built-in formatting templates

Functions

func GetAllDefaultTemplates

func GetAllDefaultTemplates() []string

GetAllDefaultTemplates returns all default template names

func GetDefaultTemplate

func GetDefaultTemplate(name string) (string, bool)

GetDefaultTemplate returns a default template by name

func IsDefaultTemplate

func IsDefaultTemplate(name string) bool

IsDefaultTemplate checks if a template name is a built-in default

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provides LRU caching for template execution results

func NewCache

func NewCache(maxSize int) *Cache

NewCache creates a new cache with the specified max size

func (*Cache) Clear

func (c *Cache) Clear()

Clear empties the cache

func (*Cache) Get

func (c *Cache) Get(template string, data interface{}) (string, bool)

Get retrieves a cached result

func (*Cache) Set

func (c *Cache) Set(template string, data interface{}, result string)

Set stores a result in the cache

type CustomizationManager

type CustomizationManager struct {
	// contains filtered or unexported fields
}

CustomizationManager handles user template customization

func NewCustomizationManager

func NewCustomizationManager(engine *Engine, configDir string) *CustomizationManager

NewCustomizationManager creates a new template customization manager

func (*CustomizationManager) CreateDefaultTemplates

func (cm *CustomizationManager) CreateDefaultTemplates() error

CreateDefaultTemplates creates default templates for common resource types

func (*CustomizationManager) DeleteUserTemplate

func (cm *CustomizationManager) DeleteUserTemplate(name string) error

DeleteUserTemplate removes a user template

func (*CustomizationManager) DisableHotReload

func (cm *CustomizationManager) DisableHotReload()

DisableHotReload disables hot-reloading

func (*CustomizationManager) EnableHotReload

func (cm *CustomizationManager) EnableHotReload() error

EnableHotReload enables hot-reloading of templates for development

func (*CustomizationManager) ExportTemplate

func (cm *CustomizationManager) ExportTemplate(name, path string) error

ExportTemplate exports a template to a file

func (*CustomizationManager) GetUserTemplate

func (cm *CustomizationManager) GetUserTemplate(name string) (*UserTemplate, bool)

GetUserTemplate retrieves a user template by name

func (*CustomizationManager) ImportTemplate

func (cm *CustomizationManager) ImportTemplate(path string) error

ImportTemplate imports a template from a file

func (*CustomizationManager) ListUserTemplates

func (cm *CustomizationManager) ListUserTemplates() map[string]*UserTemplate

ListUserTemplates returns all user templates

func (*CustomizationManager) LoadUserTemplates

func (cm *CustomizationManager) LoadUserTemplates() error

LoadUserTemplates loads all user templates from the config directory

func (*CustomizationManager) OnTemplateChange

func (cm *CustomizationManager) OnTemplateChange(callback func(string, *UserTemplate))

OnTemplateChange registers a callback for template changes

func (*CustomizationManager) SaveUserTemplate

func (cm *CustomizationManager) SaveUserTemplate(template *UserTemplate) error

SaveUserTemplate saves a user template to disk

func (*CustomizationManager) ValidateTemplate

func (cm *CustomizationManager) ValidateTemplate(template *UserTemplate) error

ValidateTemplate validates a template for syntax and function usage

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine provides template execution with custom K8s formatting functions

func NewEngine

func NewEngine() *Engine

NewEngine creates a new template engine with K8s-specific functions

func (*Engine) Execute

func (e *Engine) Execute(tmplStr string, data interface{}) (string, error)

Execute runs a template with the given data

func (*Engine) ExecuteNamed

func (e *Engine) ExecuteNamed(name string, data interface{}) (string, error)

ExecuteNamed executes a named template

func (*Engine) LoadTemplate

func (e *Engine) LoadTemplate(name, tmplStr string) error

LoadTemplate loads a named template

func (*Engine) Validate

func (e *Engine) Validate(tmplStr string) error

Validate checks if a template is valid

type FormattedValue

type FormattedValue struct {
	Text      string
	Color     string
	Bold      bool
	Italic    bool
	Underline bool
}

FormattedValue represents a formatted output with styling hints

type TemplateValidationError

type TemplateValidationError struct {
	Template string
	Line     int
	Column   int
	Message  string
}

TemplateValidationError represents a template validation error

func (*TemplateValidationError) Error

func (e *TemplateValidationError) Error() string

type UserTemplate

type UserTemplate struct {
	Name         string            `yaml:"name"`
	ResourceType string            `yaml:"resourceType"`
	Description  string            `yaml:"description"`
	Template     string            `yaml:"template"`
	Columns      []string          `yaml:"columns"`
	Variables    map[string]string `yaml:"variables"`
	CreatedAt    time.Time         `yaml:"createdAt"`
	UpdatedAt    time.Time         `yaml:"updatedAt"`
	Version      string            `yaml:"version"`
	Author       string            `yaml:"author"`
	Tags         []string          `yaml:"tags"`
}

UserTemplate represents a user-customizable template

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL