describe

package
v2.11.23 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package describe contains describers similar to Kubectl's describe package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppSpecAutoscaling

func AppSpecAutoscaling(w io.Writer, autoscalingSpec *kfv1alpha1.AppSpecAutoscaling)

AppSpecAutoscaling describes the autoscaling features of the app.

Example
package main

import (
	"os"

	kfv1alpha1 "github.com/google/kf/v2/pkg/apis/kf/v1alpha1"
	"github.com/google/kf/v2/pkg/kf/describe"
	"knative.dev/pkg/ptr"
)

func main() {
	autoscalingSpec := &kfv1alpha1.AppSpecAutoscaling{
		Enabled:     true,
		MinReplicas: ptr.Int32(1),
		MaxReplicas: ptr.Int32(3),

		Rules: []kfv1alpha1.AppAutoscalingRule{
			{
				RuleType: kfv1alpha1.CPURuleType,
				Target:   ptr.Int32(80),
			},
		},
	}

	describe.AppSpecAutoscaling(os.Stdout, autoscalingSpec)

}
Output:

Autoscaling:
  Enabled?:     true
  MaxReplicas:  3
  MinReplicas:  1
  Rules:
    RuleType  Target
    CPU       80

func AppSpecInstances

func AppSpecInstances(w io.Writer, instances kfv1alpha1.AppSpecInstances)

AppSpecInstances describes the scaling features of the app.

Example (Exactly)
package main

import (
	"os"

	kfv1alpha1 "github.com/google/kf/v2/pkg/apis/kf/v1alpha1"
	"github.com/google/kf/v2/pkg/kf/describe"
	"knative.dev/pkg/ptr"
)

func main() {
	instances := kfv1alpha1.AppSpecInstances{}
	instances.Stopped = true
	instances.Replicas = ptr.Int32(3)

	describe.AppSpecInstances(os.Stdout, instances)

}
Output:

Scale:
  Stopped?:  true
  Replicas:  3

func DuckStatus

func DuckStatus(w io.Writer, duck duckv1beta1.Status)

DuckStatus prints a table of status info based on the duck status.

Example (Ready)
package main

import (
	"os"

	"github.com/google/kf/v2/pkg/kf/describe"

	v1 "k8s.io/api/core/v1"
	"knative.dev/pkg/apis"

	duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
)

func main() {
	status := duckv1beta1.Status{
		Conditions: duckv1beta1.Conditions{
			{Status: v1.ConditionTrue, Type: "SecretReady"},
			{Status: v1.ConditionUnknown, Type: apis.ConditionReady, Reason: "NamespaceErr", Message: "problem with namespace"},
			{Status: v1.ConditionFalse, Type: "NamespaceReady", Reason: "NotOwned", Message: "couldn't create"},
		},
	}

	describe.DuckStatus(os.Stdout, status)

}
Output:

Status:
  Ready:
    Ready:    Unknown
    Message:  problem with namespace
    Reason:   NamespaceErr
  Conditions:
    Type            Status  Updated    Message          Reason
    NamespaceReady  False   <unknown>  couldn't create  NotOwned
    SecretReady     True    <unknown>
Example (Succeeded)
package main

import (
	"os"

	"github.com/google/kf/v2/pkg/kf/describe"

	v1 "k8s.io/api/core/v1"
	"knative.dev/pkg/apis"

	duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
)

func main() {
	status := duckv1beta1.Status{
		Conditions: duckv1beta1.Conditions{
			{Status: v1.ConditionUnknown, Type: apis.ConditionSucceeded, Reason: "NamespaceErr", Message: "problem with namespace"},
			{Status: v1.ConditionFalse, Type: "NamespaceReady", Reason: "NotOwned", Message: "couldn't create"},
		},
	}

	describe.DuckStatus(os.Stdout, status)

}
Output:

Status:
  Succeeded:
    Ready:    Unknown
    Message:  problem with namespace
    Reason:   NamespaceErr
  Conditions:
    Type            Status  Updated    Message          Reason
    NamespaceReady  False   <unknown>  couldn't create  NotOwned

func IndentWriter

func IndentWriter(w io.Writer, f func(io.Writer))

IndentWriter creates a new writer that indents all lines passing through it by two spaces.

Example
w := os.Stdout
fmt.Fprintln(w, "Level0")
IndentWriter(w, func(w io.Writer) {
	fmt.Fprintln(w, "Level1")
	IndentWriter(w, func(w io.Writer) {
		fmt.Fprintln(w, "Level2")
	})
})
Output:

Level0
  Level1
    Level2

func JSONKeyToTitleCase

func JSONKeyToTitleCase(name string) string

JSONKeyToTitleCase converts a JSON key to a human friendly casing.

func Labels

func Labels(w io.Writer, labels map[string]string)

Labels prints a label map by the alphanumeric sorting of the keys.

func MetaV1Beta1Table

func MetaV1Beta1Table(w io.Writer, table *metav1beta1.Table) error

MetaV1Beta1Table can print Kubernetes server-side rendered tables.

Example
package main

import (
	"os"

	"github.com/google/kf/v2/pkg/kf/describe"

	metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
)

func main() {
	describe.MetaV1Beta1Table(os.Stdout, &metav1beta1.Table{
		ColumnDefinitions: []metav1beta1.TableColumnDefinition{
			{Name: "Name"},
			{Name: "Age"},
			{Name: "Instances"},
		},

		Rows: []metav1beta1.TableRow{
			{Cells: []interface{}{"First", "12d", 12}},
			{Cells: []interface{}{"Second", "3h", 1}},
			{Cells: []interface{}{"Third", "9s", 0}},
		},
	})

}
Output:

Name    Age  Instances
First   12d  12
Second  3h   1
Third   9s   0

func PrefixWriter

func PrefixWriter(w io.Writer, prefix string, f func(io.Writer))

PrefixWriter creates a new writer that indents all lines passing through it with a given prefix.

func SectionWriter

func SectionWriter(w io.Writer, name string, f func(io.Writer))

SectionWriter writes a section heading with the given name then calls f with a tab aligning indenting writer to format the contents of the section.

Example (Empty)
SectionWriter(os.Stdout, "SectionName", func(_ io.Writer) {
	// No output
})
Output:

SectionName: <empty>
Example (Populated)
SectionWriter(os.Stdout, "OperatingSystems", func(w io.Writer) {
	fmt.Fprintln(w, "Linux:\tOSS")
	fmt.Fprintln(w, "DOS:\tPaid")
	fmt.Fprintln(w, "BeOS:\tDead")
})
Output:

OperatingSystems:
  Linux:  OSS
  DOS:    Paid
  BeOS:   Dead

func TabbedWriter

func TabbedWriter(w io.Writer, f func(io.Writer))

TabbedWriter indents all tabbed output to be aligned.

Example
TabbedWriter(os.Stdout, func(w io.Writer) {
	fmt.Fprintln(w, "OS\tAGE")
	fmt.Fprintln(w, "Linux\t20y")
	fmt.Fprintln(w, "DOS\t40y")
	fmt.Fprintln(w, "BeOS\t20y")
})
Output:

OS     AGE
Linux  20y
DOS    40y
BeOS   20y

func Unstructured

func Unstructured(w io.Writer, resource *unstructured.Unstructured)

Unstructured prints information about an unstructured Kubernetes object.

Example
// example adapted from
// https://github.com/kubernetes/kubectl/blob/master/pkg/describe/versioned/describe_test.go

resource := &unstructured.Unstructured{
	Object: map[string]interface{}{
		"apiVersion":           "v1",
		"kind":                 "Test",
		"sampleSample":         "present",
		"sample/sample":        "present",
		"sample-sample@sample": "present",
		"sample-sample":        "present",
		"sample1":              "present",
		"sample2":              "present",
		"metadata": map[string]interface{}{
			"name":              "MyName",
			"namespace":         "MyNamespace",
			"creationTimestamp": "2017-04-01T00:00:00Z",
			"resourceVersion":   123,
			"uid":               "00000000-0000-0000-0000-000000000001",
			"sample3":           "present",
		},
		"items": []interface{}{
			map[string]interface{}{
				"itemBool": true,
				"itemInt":  42,
			},
		},
		"url":    "http://localhost",
		"status": "ok",
	},
}

Unstructured(os.Stdout, resource)
Output:

API Version:  v1
Items:
  Item Bool:  true
  Item Int:   42
Kind:  Test
Metadata:
  Creation Timestamp:  2017-04-01T00:00:00Z
  Name:                MyName
  Namespace:           MyNamespace
  Resource Version:    123
  Sample 3:            present
  UID:                 00000000-0000-0000-0000-000000000001
sample-sample:         present
sample-sample@sample:  present
sample/sample:         present
Sample 1:              present
Sample 2:              present
Sample Sample:         present
Status:                ok
URL:                   http://localhost

func UnstructuredArray

func UnstructuredArray(w io.Writer, anArray []interface{})

UnstructuredArray formats and writes an array to the output.

func UnstructuredMap

func UnstructuredMap(w io.Writer, obj map[string]interface{})

UnstructuredMap writes information about a JSON style unstructured object.

func UnstructuredStruct

func UnstructuredStruct(w io.Writer, obj interface{}) error

UnstructuredStruct converts the object to and from JSON then writes it, similar to what would happen when sent through the Kubernetes API.

Example
example := struct {
	IntField int            `json:"intField"`
	StrField string         `json:"strField"`
	ArrField []string       `json:"arrField"`
	MapField map[string]int `json:"strToInt"`
}{
	IntField: 10,
	StrField: "some string",
	ArrField: []string{"one", "two", "three"},
	MapField: map[string]int{
		"a": 1,
		"b": 2,
		"c": 3,
	},
}

UnstructuredStruct(os.Stdout, example)
Output:

Arr Field:
  one
  two
  three
Int Field:  10
Str Field:  some string
Str To Int:
  A:  1
  B:  2
  C:  3
Example (Nil)
UnstructuredStruct(os.Stdout, nil)
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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