forked from kptdev/krm-functions-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
50 lines (38 loc) · 1.74 KB
/
Copy pathdoc.go
File metadata and controls
50 lines (38 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
/*
Package krmfn.provides an SDK for writing KRM functions in Go. The function
specification is defined at:
https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/docs/api-conventions/functions-spec.md
Note: this package is an krmfn.package.
A KRM functions can generate, mutate or validate Kubernetes resources in a
ResourceList.
The ResourceList type and the KubeObject type are the core part of this package.
The ResourceList type maps to the ResourceList in the function spec. The
KubeObject represent a kubernetes resource in a ResourceList, and it's the basic
unit to perform most CRUD operations.
A KRM function does the following things:
1. read yaml bytes from stdin and convert it to a ResourceList
2. perform mutation and validation on the resources in the ResourceList
3. write the updated ResourceList out to stdout in yaml format
4. Any diagnostic messages should be written to stderr
ResourceListProcessor
In most cases, you only need to do #2 which is implementing a
ResourceListProcessor and then pass it to AsMain. In the following example, we
use ResourceListProcessorFunc that implements the ResourceListProcessor
interface.
func main() {
if err := krmfn.AsMain(krmfn.ResourceListProcessorFunc(myfn)); err != nil {
os.Exit(1)
}
}
func myfn(rl *krmfn.ResourceList) error {
krmfn.Log("log something")
// mutate or validate the ResourceList
}
KubeObject
KubeObject hides all the details about yaml.Node and yaml.RNode. It is always
recommended converting a KubeObject to a strong typed object or getting a field
as a strong typed object. Then do the CRUD operation on the strong typed objects.
*/
package krmfn