pod

package
v0.36.7 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Example (Full)
package main

import (
	"embed"
	"os"

	"knative.dev/eventing/test/rekt/resources/pod"
	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",
		"port":      "8080",
		"labels":    map[string]string{"app": "bla"},
	}

	pod.WithLabels(map[string]string{"overwrite": "yes"})(cfg)
	pod.WithImage("myimage")(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
  labels:
    overwrite: yes
spec:
  containers:
    - name: user-container
      image: myimage
      ports:
        - containerPort: 8080
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",
		"port":      "8080",
		"labels":    map[string]string{"app": "bla"},
	}

	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
  labels:
    app: bla
spec:
  containers:
    - name: user-container
      image: baz
      ports:
        - containerPort: 8080
Example (WithImage)
package main

import (
	"embed"
	"os"

	"knative.dev/eventing/test/rekt/resources/pod"
	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",
		"port":      "8080",
		"labels":    map[string]string{"app": "bla"},
	}

	pod.WithImage("myimage")(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
  labels:
    app: bla
spec:
  containers:
    - name: user-container
      image: myimage
      ports:
        - containerPort: 8080
Example (WithLabels)
package main

import (
	"embed"
	"os"

	"knative.dev/eventing/test/rekt/resources/pod"
	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",
		"port":      "8080",
		"labels":    map[string]string{"app": "bla"},
	}

	pod.WithLabels(map[string]string{"overwrite": "yes"})(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
  labels:
    overwrite: yes
spec:
  containers:
    - name: user-container
      image: baz
      ports:
        - containerPort: 8080
Example (WithNamespace)
package main

import (
	"embed"
	"os"

	"knative.dev/eventing/test/rekt/resources/pod"
	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",
		"port":      "8080",
		"labels":    map[string]string{"app": "bla"},
	}

	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
  labels:
    app: bla
spec:
  containers:
    - name: user-container
      image: baz
      ports:
        - containerPort: 8080

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Install

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

Install will create a Pod with defaults that can be overwritten by the With* methods.

func WithImage

func WithImage(image string) manifest.CfgFn

WithImage sets the given image on the Pod spec.

func WithLabels

func WithLabels(labels map[string]string) manifest.CfgFn

WithLabels sets the given labels on the Pod.

func WithNamespace added in v0.36.0

func WithNamespace(ns string) manifest.CfgFn

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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