-
Notifications
You must be signed in to change notification settings - Fork 0
/
features_patch.go
32 lines (27 loc) · 1.08 KB
/
features_patch.go
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
package kubernetes_ctx
import (
"k8s.io/apimachinery/pkg/types"
"github.com/xunleii/godog-kubernetes/helpers"
)
// PatchResourceWith implements the GoDoc step
// - `Kubernetes patches <ApiGroupVersionKind> '<NamespacedName>' with <YAML>`
// It patches a specific resource with the given patch (it use StrategicMergePatchType...
// see https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md
// for more information).
func PatchResourceWith(ctx *FeatureContext, s ScenarioContext) {
s.Step(
`^Kubernetes patches (`+RxGroupVersionKind+`) '(`+RxNamespacedName+`)' with$`,
func(groupVersionKindStr, resourceName string, content helpers.YamlDocString) error {
groupVersionKind, err := helpers.GroupVersionKindFrom(groupVersionKindStr)
if err != nil {
return err
}
namespacedName, _ := helpers.NamespacedNameFrom(resourceName)
patch, err := helpers.YamlToJson(content.Content)
if err != nil {
return err
}
return ctx.Patch(groupVersionKind, namespacedName, types.StrategicMergePatchType, patch)
},
)
}