Documentation ¶
Overview ¶
Example (Full) ¶
package main import ( "embed" "os" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" testlog "knative.dev/reconciler-test/pkg/logging" "knative.dev/reconciler-test/pkg/manifest" "knative.dev/reconciler-test/pkg/resources/service" ) //go:embed *.yaml var templates embed.FS func main() { ctx := testlog.NewContext() images := map[string]string{} cfg := map[string]interface{}{ "name": "foo", "namespace": "bar", } opts := []manifest.CfgFn{ service.WithLabels(map[string]string{ "color": "green", }), service.WithAnnotations(map[string]interface{}{ "app.kubernetes.io/name": "app", }), service.WithType(corev1.ServiceTypeClusterIP), service.WithSelectors(map[string]string{ "app.kubernetes.io/name": "foobar", }), service.WithExternalName("my-external.name"), service.WithPorts([]corev1.ServicePort{{ Port: 1234, TargetPort: intstr.FromInt(5678), }}), } for _, opt := range opts { opt(cfg) } files, err := manifest.ExecuteYAML(ctx, templates, images, cfg) if err != nil { panic(err) } manifest.OutputYAML(os.Stdout, files) }
Output: apiVersion: v1 kind: Service metadata: name: foo namespace: bar annotations: app.kubernetes.io/name: "app" labels: color: "green" spec: selector: app.kubernetes.io/name: "foobar" ports: - protocol: TCP port: 1234 targetPort: 5678 type: ClusterIP externalName: my-external.name
Example (Min) ¶
package main import ( "embed" "os" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" testlog "knative.dev/reconciler-test/pkg/logging" "knative.dev/reconciler-test/pkg/manifest" ) //go:embed *.yaml var templates embed.FS func main() { ctx := testlog.NewContext() images := map[string]string{} cfg := map[string]interface{}{ "name": "foo", "namespace": "bar", "ports": []corev1.ServicePort{{ Port: 80, TargetPort: intstr.FromInt(8080), }}, } files, err := manifest.ExecuteYAML(ctx, templates, images, cfg) if err != nil { panic(err) } manifest.OutputYAML(os.Stdout, files) }
Output: apiVersion: v1 kind: Service metadata: name: foo namespace: bar spec: ports: - protocol: TCP port: 80 targetPort: 8080
Index ¶
- Variables
- func Address(ctx context.Context, name string) (*duckv1.Addressable, error)
- func AsDestinationRef(name string) *duckv1.Destination
- func AsKReference(name string) *duckv1.KReference
- func AsTrackerReference(name string) *tracker.Reference
- func GVR() schema.GroupVersionResource
- func Install(name string, opts ...manifest.CfgFn) feature.StepFn
- func WithExternalName(externalName string) manifest.CfgFn
- func WithPorts(ports []corev1.ServicePort) manifest.CfgFn
- func WithSelectors(selectors map[string]string) manifest.CfgFn
- func WithType(serviceType corev1.ServiceType) manifest.CfgFn
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var WithAnnotations = manifest.WithAnnotations
View Source
var WithLabels = manifest.WithLabels
Functions ¶
func AsDestinationRef ¶
func AsDestinationRef(name string) *duckv1.Destination
func AsKReference ¶
func AsKReference(name string) *duckv1.KReference
AsKReference returns a KReference for a Service without namespace.
func AsTrackerReference ¶
func GVR ¶
func GVR() schema.GroupVersionResource
func Install ¶
Install will create a Service resource. If no ports where defined via the WithPorts option, a default mapping 80:8080 will be used.
func WithExternalName ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.