How can I run kubectl apply commands from go via client-go? e.g.: I'm having a file called crds.yaml and I want to run it via client-go
I can't find any examples about how to do so can someone please help?
CodePudding user response:
You need to decode your .yaml file
Here it's the complete answer (with code example)
CodePudding user response:
I ended up having this type of call based on what is on the link you provided
yamlFile, err := ioutil.ReadFile("custom.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
var ctx context.Context
var c client.Client
var actionFn ForEachObjectInYAMLActionFunc
err = ForEachObjectInYAML(ctx, c, yamlFile, "default", actionFn)
if err != nil {
fmt.Println(err)
}
But it is failing with
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10ac5cc]
goroutine 1 [running]:
main.ForEachObjectInYAML({0x0, 0x0}, {0x0, 0x0}, {0xc000880000?, 0xc0000021a0?, 0x200000003?}, {0x12bf20f, 0x7}, 0x0)
apply.go:125 0x12c
main.main()
apply.go:34 0xc5
exit status 2
And there is:
if err := actionFn(ctx, c, obj); err != nil {
return err
}
Any idea what I'm doing wrong?