Ability to apply objects from custom reader #1670
Labels
kind/feature
Categorizes issue or PR as related to a new feature.
needs-triage
Indicates an issue or PR lacks a `triage/foo` label and requires one.
What would you like to be added:
Hello 👋 ,
I was trying to make use of the
"k8s.io/kubectl/pkg/cmd/apply"
package in order to applyunstructured.Unstructured
objects we read from in memory or from CRs.By doing that I needed to configure a custom reader ( thus not using
stdin
nor filesystem ), and I'm facing some issues. In other words, unless I've missed something this doesn't seem to be possible right now.Following are my attempts:
1. Configure the apply command with custom reader using cobra command
SetIn
method:RESULT:
2. Configure both the
IOStreams
and the cobra command with the custom reader:RESULT:
3. Configure the
resource.Builder
with the customer reader from the pipeRESULT:
4. Configure the
resource.Builder
with the customer reader from the pipe without the mapper:import (
"io"
"testing"
)
func TestCmdApply(t *testing.T) {
// a random Unstructured object
sa := &unstructured.Unstructured{
Object: map[string]interface{}{
"kind": "ServiceAccount",
"metadata": map[string]interface{}{
"name": "test1",
"namespace": "test",
},
"apiVersion": "v1",
},
}
jsonContent, err := sa.MarshalJSON()
require.NoError(t, err)
// create a pipe with a reader and a writer for the above object
r, w := io.Pipe()
go func() {
defer w.Close()
w.Write(jsonContent)
}()
}
RESULT:
In short: unless I've missed something, it doesn't seem to be possible to configure a custom reader with the current
apply
package implementation. Thanks in advance for your help.Why is this needed:
We would love to be able to integrate the
apply
package into our components and be able to leverage features like 3WayMergePatch and ServerSide Apply when provisioning objects to kubernetes.As anticipated we do not read those objects from files nor
os.Stdin
, instead we get those objects from other CRs,embed.FS
, other sources that implement theio.Reader
interface. And we would really like to avoid writing those objects to temporary files and read those from there , mainly because of performance issues and other constraints ( we are potentially handling thousands of objects and we need to provision those for the user in a timely manner ).It would be nice if we could configure the
resource.Builder
upfront and skip the creation here which doesn't seem to be configurable with a customStream
property, or any other way which could allow for really leveraging the stream based builder:o.Builder.Stream(r, "input")
.Any feedback/help is highly appreciated 🙏
The text was updated successfully, but these errors were encountered: