-
-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
K8s unstructured
helper?
#137
Comments
Hey @s3rj1k, I'd need some more details about that, but, skimming through this article, it sounds like you want to create a gabs container from a weakly-decoded JSON. Is that correct? If yes, try this: package main
import (
"fmt"
"github.com/Jeffail/gabs/v2"
)
func main() {
newEnvs := []interface{}{
map[string]interface{}{
"name": "NAMESPACE",
"valueFrom": map[string]interface{}{
"fieldRef": map[string]interface{}{
"fieldPath": "metadata.namespace",
},
},
},
map[string]interface{}{
"name": "POD_UID",
"valueFrom": map[string]interface{}{
"fieldRef": map[string]interface{}{
"fieldPath": "metadata.uid",
},
},
},
}
obj := gabs.Wrap(newEnvs)
fmt.Println(obj.Path("*.valueFrom.fieldRef.fieldPath").String())
} |
@mihaitodor hey, thanks for quick response, I just want a helper to convert gabs <-> unstructured Basically unstructured has embedded The flow would be something like this:
(hopefully with minimal memory allocation) |
@s3rj1k Sure, have you tried the package main
import (
"fmt"
"github.com/Jeffail/gabs/v2"
"github.com/davecgh/go-spew/spew"
)
func main() {
newEnvs := []interface{}{
map[string]interface{}{
"name": "NAMESPACE",
"valueFrom": map[string]interface{}{
"fieldRef": map[string]interface{}{
"fieldPath": "metadata.namespace",
},
},
},
map[string]interface{}{
"name": "POD_UID",
"valueFrom": map[string]interface{}{
"fieldRef": map[string]interface{}{
"fieldPath": "metadata.uid",
},
},
},
}
obj := gabs.Wrap(newEnvs)
fmt.Println(obj.Path("*.valueFrom.fieldRef.fieldPath").String())
spew.Dump(obj.Data())
obj.SetP(666, "0.valueFrom.fieldRef.fieldPath")
spew.Dump(obj.Data())
} PS: You should be able to use type assertions to get the actual type from the |
Flow is a bit different, reversed
so what I am after here is basically
a more streamlined version of this ^^^ |
Sure, but that's specific to your use case. Nothing wrong with publishing your own gabs wrapper which exposes a method that returns |
Yea, I was hoping for method similar to |
I am curious would it be possible to add some simple wrapper support for K8s
unstructured
, as it would be really great to use gabs with that object natively.The text was updated successfully, but these errors were encountered: