Documentation ¶
Overview ¶
Example (Full) ¶
package main import ( "embed" "os" v1 "k8s.io/api/core/v1" testlog "knative.dev/reconciler-test/pkg/logging" "knative.dev/reconciler-test/pkg/manifest" "knative.dev/reconciler-test/pkg/resources/pod" ) //go:embed *.yaml var yaml embed.FS func main() { ctx := testlog.NewContext() images := map[string]string{} cfg := map[string]interface{}{ "name": "foo", "image": "baz", } opts := []manifest.CfgFn{ pod.WithLabels(map[string]string{ "color": "green", }), pod.WithAnnotations(map[string]interface{}{ "app.kubernetes.io/name": "app", }), pod.WithNamespace("bar"), pod.WithCommand([]string{"sh"}), pod.WithArgs([]string{"-c", "echo \"Hello, Kubernetes!\""}), pod.WithImagePullPolicy(v1.PullNever), pod.WithEnvs(map[string]string{ "VAR": "VAL", }), pod.WithPort(8080), } for _, opt := range opts { opt(cfg) } files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg) if err != nil { panic(err) } manifest.OutputYAML(os.Stdout, files) }
Output: apiVersion: v1 kind: Pod metadata: name: foo namespace: bar annotations: app.kubernetes.io/name: "app" labels: color: "green" spec: containers: - name: user-container image: baz command: - "sh" args: - "-c" - "echo \"Hello, Kubernetes!\"" ports: - containerPort: 8080 env: - name: "VAR" value: "VAL" imagePullPolicy: Never
Example (Min) ¶
package main import ( "embed" "os" testlog "knative.dev/reconciler-test/pkg/logging" "knative.dev/reconciler-test/pkg/manifest" ) //go:embed *.yaml var yaml embed.FS func main() { ctx := testlog.NewContext() images := map[string]string{} cfg := map[string]interface{}{ "name": "foo", "namespace": "bar", "image": "baz", } files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg) if err != nil { panic(err) } manifest.OutputYAML(os.Stdout, files) }
Output: apiVersion: v1 kind: Pod metadata: name: foo namespace: bar spec: containers: - name: user-container image: baz
Example (WithArgs) ¶
package main import ( "embed" "os" testlog "knative.dev/reconciler-test/pkg/logging" "knative.dev/reconciler-test/pkg/manifest" "knative.dev/reconciler-test/pkg/resources/pod" ) //go:embed *.yaml var yaml embed.FS func main() { ctx := testlog.NewContext() images := map[string]string{} cfg := map[string]interface{}{ "name": "foo", "namespace": "bar", "image": "baz", } pod.WithArgs([]string{"-c", "echo \"Hello, Kubernetes!\""})(cfg) files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg) if err != nil { panic(err) } manifest.OutputYAML(os.Stdout, files) }
Output: apiVersion: v1 kind: Pod metadata: name: foo namespace: bar spec: containers: - name: user-container image: baz args: - "-c" - "echo \"Hello, Kubernetes!\""
Example (WithCommand) ¶
package main import ( "embed" "os" testlog "knative.dev/reconciler-test/pkg/logging" "knative.dev/reconciler-test/pkg/manifest" "knative.dev/reconciler-test/pkg/resources/pod" ) //go:embed *.yaml var yaml embed.FS func main() { ctx := testlog.NewContext() images := map[string]string{} cfg := map[string]interface{}{ "name": "foo", "namespace": "bar", "image": "baz", } pod.WithCommand([]string{"sh", "-c", "echo \"Hello, Kubernetes!\""})(cfg) files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg) if err != nil { panic(err) } manifest.OutputYAML(os.Stdout, files) }
Output: apiVersion: v1 kind: Pod metadata: name: foo namespace: bar spec: containers: - name: user-container image: baz command: - "sh" - "-c" - "echo \"Hello, Kubernetes!\""
Example (WithNamespace) ¶
package main import ( "embed" "os" testlog "knative.dev/reconciler-test/pkg/logging" "knative.dev/reconciler-test/pkg/manifest" "knative.dev/reconciler-test/pkg/resources/pod" ) //go:embed *.yaml var yaml embed.FS func main() { ctx := testlog.NewContext() images := map[string]string{} cfg := map[string]interface{}{ "name": "foo", "namespace": "bar", "image": "baz", } pod.WithNamespace("new-namespace")(cfg) files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg) if err != nil { panic(err) } manifest.OutputYAML(os.Stdout, files) }
Output: apiVersion: v1 kind: Pod metadata: name: foo namespace: new-namespace spec: containers: - name: user-container image: baz
Example (WithPort) ¶
package main import ( "embed" "os" testlog "knative.dev/reconciler-test/pkg/logging" "knative.dev/reconciler-test/pkg/manifest" "knative.dev/reconciler-test/pkg/resources/pod" ) //go:embed *.yaml var yaml embed.FS func main() { ctx := testlog.NewContext() images := map[string]string{} cfg := map[string]interface{}{ "name": "foo", "namespace": "bar", "image": "baz", } pod.WithPort(8888)(cfg) files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg) if err != nil { panic(err) } manifest.OutputYAML(os.Stdout, files) }
Output: apiVersion: v1 kind: Pod metadata: name: foo namespace: bar spec: containers: - name: user-container image: baz ports: - containerPort: 8888
Index ¶
- Variables
- func Install(name string, image string, opts ...manifest.CfgFn) feature.StepFn
- func WithArgs(args []string) manifest.CfgFn
- func WithCommand(cmd []string) manifest.CfgFn
- func WithEnvs(envs map[string]string) manifest.CfgFn
- func WithImagePullPolicy(ipp corev1.PullPolicy) manifest.CfgFn
- func WithNamespace(ns string) manifest.CfgFn
- func WithPort(port int) manifest.CfgFn
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var WithAnnotations = manifest.WithAnnotations
View Source
var WithLabels = manifest.WithLabels
Functions ¶
func WithCommand ¶
func WithImagePullPolicy ¶
func WithImagePullPolicy(ipp corev1.PullPolicy) manifest.CfgFn
func WithNamespace ¶
WithOverriddenNamespace will modify the namespace of the pod from the specs to the provided one
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.