pod

package
v0.0.0-...-96258be Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 6 Imported by: 1

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

Examples

Constants

This section is empty.

Variables

View Source
var WithAnnotations = manifest.WithAnnotations
View Source
var WithLabels = manifest.WithLabels

Functions

func Install

func Install(name string, image string, opts ...manifest.CfgFn) feature.StepFn

func WithArgs

func WithArgs(args []string) manifest.CfgFn

func WithCommand

func WithCommand(cmd []string) manifest.CfgFn

func WithEnvs

func WithEnvs(envs map[string]string) manifest.CfgFn

func WithImagePullPolicy

func WithImagePullPolicy(ipp corev1.PullPolicy) manifest.CfgFn

func WithNamespace

func WithNamespace(ns string) manifest.CfgFn

WithOverriddenNamespace will modify the namespace of the pod from the specs to the provided one

func WithPort

func WithPort(port int) manifest.CfgFn

Types

This section is empty.

Jump to

Keyboard shortcuts

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