-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Ability to apply objects from custom reader #1670
Comments
I think, you can use stdin in |
Hi @ardaguclu , thanks for your help. |
ah, sorry I didn't check point 2. Yes I was suggesting the same. If it doesn't work, this means this is not supported. |
Thank you for the steps and detailed descriptions about the issue. That really helped me to investigate. As stated above, simply changing here with; r := o.Builder.
Unstructured().
Schema(o.Validator).
Stream(o.In, "input").
ContinueOnError().
NamespaceParam(o.Namespace).DefaultNamespace().
LabelSelectorParam(o.Selector).
Flatten().
Do() resolves the problem (with additional note that And I tried to find a elegant way for the users can easily use custom input instead of file or stdin. Unfortunately, there is none at least without introducing a new flag or a decorator function which may eventually cause more trouble in the future due to the incorrect usages. I'm sorry to say this but I'd recommend using tmp file or directly stdin, I think we can close this issue as rejected. |
I see, @ardaguclu thanks for taking a look at it 🙏
Yeah , as I suspected, we discarded the tmp file option since it might turn out to be slow and extra work to be done for our controllers ( dumping ~100K objects per cluster to files/cleaning those up, and the number could grow ), as per the |
Although it may require several changes, this request looks reasonable. In case anyone opens a PR /triage accepted |
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: