mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Better support for writing functions in go
This commit is contained in:
12
kyaml/fn/framework/example/Dockerfile
Normal file
12
kyaml/fn/framework/example/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright 2019 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
FROM golang:1.13-stretch
|
||||
ENV CGO_ENABLED=0
|
||||
WORKDIR /go/src/
|
||||
COPY . .
|
||||
RUN go build -v -o /usr/local/bin/function ./
|
||||
|
||||
FROM alpine:latest
|
||||
COPY --from=0 /usr/local/bin/function /usr/local/bin/function
|
||||
CMD ["function"]
|
||||
9
kyaml/fn/framework/example/doc.go
Normal file
9
kyaml/fn/framework/example/doc.go
Normal file
@@ -0,0 +1,9 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package main contains an example using the the framework.
|
||||
//
|
||||
// To generate the Dockerfile for the function image run:
|
||||
//
|
||||
// $ go run ./main.go .
|
||||
package main
|
||||
29
kyaml/fn/framework/example/main.go
Normal file
29
kyaml/fn/framework/example/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/fn/framework"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var value string
|
||||
cmd := framework.Command(nil, func(items []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||
for i := range items {
|
||||
// set the annotation on each resource item
|
||||
if err := items[i].PipeE(yaml.SetAnnotation("value", value)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return items, nil
|
||||
})
|
||||
cmd.Flags().StringVar(&value, "value", "", "annotation value")
|
||||
|
||||
if err := cmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user