Documentation
¶
Overview ¶
Package describe contains describers similar to Kubectl's describe package.
Index ¶
- func AppSpecInstances(w io.Writer, instances kfv1alpha1.AppSpecInstances)
- func AppSpecTemplate(w io.Writer, template kfv1alpha1.AppSpecTemplate)
- func DuckStatus(w io.Writer, duck duckv1beta1.Status)
- func EnvVars(w io.Writer, vars []corev1.EnvVar)
- func HealthCheck(w io.Writer, healthCheck *corev1.Probe)
- func IndentWriter(w io.Writer, f func(io.Writer))
- func Labels(w io.Writer, labels map[string]string)
- func ObjectMeta(w io.Writer, meta metav1.ObjectMeta)
- func RouteSpecFieldsList(w io.Writer, routes []kfv1alpha1.RouteSpecFields)
- func SectionWriter(w io.Writer, name string, f func(io.Writer))
- func ServiceInstance(w io.Writer, service *v1beta1.ServiceInstance)
- func SourceSpec(w io.Writer, spec kfv1alpha1.SourceSpec)
- func TabbedWriter(w io.Writer, f func(io.Writer))
- func TypeMeta(w io.Writer, meta metav1.TypeMeta)
Examples ¶
- AppSpecInstances (Exactly)
- AppSpecInstances (MinMax)
- AppSpecInstances (MinOnly)
- AppSpecTemplate (ResourceRequests)
- DuckStatus (Ready)
- DuckStatus (Succeeded)
- EnvVars (Empty)
- EnvVars (Populated)
- HealthCheck (Http)
- HealthCheck (Nil)
- HealthCheck (Tcp)
- IndentWriter
- SectionWriter (Empty)
- SectionWriter (Populated)
- ServiceInstance
- ServiceInstance (Nil)
- SourceSpec (Buildpack)
- SourceSpec (Docker)
- SourceSpec (Dockerfile)
- TabbedWriter
- TypeMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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/pkg/apis/kf/v1alpha1" "github.com/google/kf/pkg/kf/describe" ) func main() { exactly := 3 instances := kfv1alpha1.AppSpecInstances{} instances.Stopped = true instances.Exactly = &exactly describe.AppSpecInstances(os.Stdout, instances) }
Output: Scale: Stopped?: true Exactly: 3
Example (MinMax) ¶
package main import ( "os" kfv1alpha1 "github.com/google/kf/pkg/apis/kf/v1alpha1" "github.com/google/kf/pkg/kf/describe" ) func main() { min := 3 max := 5 instances := kfv1alpha1.AppSpecInstances{} instances.Min = &min instances.Max = &max describe.AppSpecInstances(os.Stdout, instances) }
Output: Scale: Stopped?: false Min: 3 Max: 5
Example (MinOnly) ¶
package main import ( "os" kfv1alpha1 "github.com/google/kf/pkg/apis/kf/v1alpha1" "github.com/google/kf/pkg/kf/describe" ) func main() { min := 3 instances := kfv1alpha1.AppSpecInstances{} instances.Min = &min describe.AppSpecInstances(os.Stdout, instances) }
Output: Scale: Stopped?: false Min: 3 Max: ∞
func AppSpecTemplate ¶
func AppSpecTemplate(w io.Writer, template kfv1alpha1.AppSpecTemplate)
AppSpecTemplate describes the runtime configurations of the app.
Example (ResourceRequests) ¶
package main import ( "os" kfv1alpha1 "github.com/google/kf/pkg/apis/kf/v1alpha1" "github.com/google/kf/pkg/kf/describe" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) func main() { wantMem := resource.MustParse("2Gi") wantStorage := resource.MustParse("2Gi") wantCPU := resource.MustParse("2") spec := kfv1alpha1.AppSpecTemplate{ Spec: corev1.PodSpec{ Containers: []corev1.Container{{ Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{ corev1.ResourceMemory: wantMem, corev1.ResourceEphemeralStorage: wantStorage, corev1.ResourceCPU: wantCPU, }, }, }}, }, } describe.AppSpecTemplate(os.Stdout, spec) }
Output: Resource requests: Memory: 2Gi Storage: 2Gi CPU: 2
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/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/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 EnvVars ¶
EnvVars prints out environment variables.
Example (Empty) ¶
package main import ( "os" "github.com/google/kf/pkg/kf/describe" ) func main() { describe.EnvVars(os.Stdout, nil) }
Output: Environment: <empty>
Example (Populated) ¶
package main import ( "os" "github.com/google/kf/pkg/kf/describe" corev1 "k8s.io/api/core/v1" ) func main() { env := []corev1.EnvVar{ {Name: "FIRST", Value: "first-value"}, {Name: "SECOND", Value: "second-value"}, } describe.EnvVars(os.Stdout, env) }
Output: Environment: FIRST: first-value SECOND: second-value
func HealthCheck ¶
HealthCheck prints a Readiness Probe in a friendly manner
Example (Http) ¶
package main import ( "os" "github.com/google/kf/pkg/kf/describe" corev1 "k8s.io/api/core/v1" ) func main() { describe.HealthCheck(os.Stdout, &corev1.Probe{ TimeoutSeconds: 42, Handler: corev1.Handler{ HTTPGet: &corev1.HTTPGetAction{Path: "/healthz"}, }, }) }
Output: Health Check: Timeout: 42s Type: http Endpoint: /healthz
Example (Nil) ¶
package main import ( "os" "github.com/google/kf/pkg/kf/describe" ) func main() { describe.HealthCheck(os.Stdout, nil) }
Output: Health Check: <empty>
Example (Tcp) ¶
package main import ( "os" "github.com/google/kf/pkg/kf/describe" corev1 "k8s.io/api/core/v1" ) func main() { describe.HealthCheck(os.Stdout, &corev1.Probe{ TimeoutSeconds: 42, Handler: corev1.Handler{ TCPSocket: &corev1.TCPSocketAction{}, }, }) }
Output: Health Check: Timeout: 42s Type: port (tcp)
func IndentWriter ¶
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 ObjectMeta ¶
func ObjectMeta(w io.Writer, meta metav1.ObjectMeta)
ObjectMeta prints the normal object metadata associated with standard K8s objects.
func RouteSpecFieldsList ¶
func RouteSpecFieldsList(w io.Writer, routes []kfv1alpha1.RouteSpecFields)
RouteSpecFieldsList prints a list of routes
func SectionWriter ¶
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 ServiceInstance ¶
func ServiceInstance(w io.Writer, service *v1beta1.ServiceInstance)
ServiceInstance
Example ¶
package main import ( "os" "time" "github.com/google/kf/pkg/kf/describe" "github.com/poy/service-catalog/pkg/apis/servicecatalog/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) func main() { describe.ServiceInstance(os.Stdout, &v1beta1.ServiceInstance{ ObjectMeta: metav1.ObjectMeta{ Name: "myservice-instance", }, Spec: v1beta1.ServiceInstanceSpec{ PlanReference: v1beta1.PlanReference{ ClusterServiceClassExternalName: "myclass", ClusterServicePlanExternalName: "myplan", }, Parameters: &runtime.RawExtension{ Raw: []byte(`{"some":"params"}`), }, }, Status: v1beta1.ServiceInstanceStatus{ Conditions: []v1beta1.ServiceInstanceCondition{ {Status: "Wrong"}, {LastTransitionTime: metav1.Time{Time: time.Now()}, Reason: "Ready"}, }, }, }) }
Output: Service Instance: Name: myservice-instance Service: myclass Plan: myplan Parameters: some: params Status: Ready
Example (Nil) ¶
package main import ( "os" "github.com/google/kf/pkg/kf/describe" ) func main() { describe.ServiceInstance(os.Stdout, nil) }
Output: Service Instance: <empty>
func SourceSpec ¶
func SourceSpec(w io.Writer, spec kfv1alpha1.SourceSpec)
SourceSpec describes the source of an application and the build process it will undergo.
Example (Buildpack) ¶
package main import ( "os" kfv1alpha1 "github.com/google/kf/pkg/apis/kf/v1alpha1" "github.com/google/kf/pkg/kf/describe" ) func main() { spec := kfv1alpha1.SourceSpec{ ServiceAccount: "builder-account", BuildpackBuild: kfv1alpha1.SourceSpecBuildpackBuild{ Source: "gcr.io/my-registry/src-mysource", Stack: "cflinuxfs3", BuildpackBuilder: "gcr.io/my-registry/my-builder:latest", Image: "gcr.io/my-registry/my-image:latest", }, } describe.SourceSpec(os.Stdout, spec) }
Output: Source: Build Type: buildpack Service Account: builder-account Buildpack Build: Source: gcr.io/my-registry/src-mysource Stack: cflinuxfs3 Bulider: gcr.io/my-registry/my-builder:latest Destination: gcr.io/my-registry/my-image:latest Environment: <empty>
Example (Docker) ¶
package main import ( "os" kfv1alpha1 "github.com/google/kf/pkg/apis/kf/v1alpha1" "github.com/google/kf/pkg/kf/describe" ) func main() { spec := kfv1alpha1.SourceSpec{ ServiceAccount: "builder-account", ContainerImage: kfv1alpha1.SourceSpecContainerImage{ Image: "mysql/mysql", }, } describe.SourceSpec(os.Stdout, spec) }
Output: Source: Build Type: container Service Account: builder-account Container Image: Image: mysql/mysql
Example (Dockerfile) ¶
package main import ( "os" kfv1alpha1 "github.com/google/kf/pkg/apis/kf/v1alpha1" "github.com/google/kf/pkg/kf/describe" ) func main() { spec := kfv1alpha1.SourceSpec{ ServiceAccount: "builder-account", Dockerfile: kfv1alpha1.SourceSpecDockerfile{ Source: "gcr.io/my-registry/src-mysource", Path: "path/to/build/Dockerfile", Image: "gcr.io/my-registry/my-image:latest", }, } describe.SourceSpec(os.Stdout, spec) }
Output: Source: Build Type: dockerfile Service Account: builder-account Dockerfile Build: Source: gcr.io/my-registry/src-mysource Dockerfile Path: path/to/build/Dockerfile Destination: gcr.io/my-registry/my-image:latest
func TabbedWriter ¶
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 TypeMeta ¶
TypeMeta prints information about the type.
Example ¶
package main import ( "os" "github.com/google/kf/pkg/kf/describe" v1 "k8s.io/api/core/v1" ) func main() { s := &v1.Secret{} s.Kind = "Secret" s.APIVersion = "v1" describe.TypeMeta(os.Stdout, s.TypeMeta) }
Output: API Version: v1 Kind: Secret
Types ¶
This section is empty.