/
apply.go
35 lines (30 loc) · 914 Bytes
/
apply.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
33
34
35
package k8sutil
import (
"bytes"
"context"
"embed"
"os/exec"
"github.com/replicatedhq/plumber/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
kustomizetypes "sigs.k8s.io/kustomize/api/types"
)
func KubectlApply(ctx context.Context, cli client.Client, resources embed.FS, overlay string, opts ...plumber.Option) error {
options := append([]plumber.Option{
plumber.WithKustomizeMutator(
func(ctx context.Context, k *kustomizetypes.Kustomization) error {
k.CommonLabels = AppendKurlLabels(k.CommonLabels)
return nil
},
),
}, opts...)
err := plumber.NewRenderer(cli, resources, options...).Apply(
ctx, overlay,
)
return err
}
func KubectlDelete(ctx context.Context, b []byte, args ...string) ([]byte, error) {
args = append([]string{"delete", "-f", "-"}, args...)
cmd := exec.CommandContext(ctx, "kubectl", args...)
cmd.Stdin = bytes.NewReader(b)
return cmd.CombinedOutput()
}