-
Notifications
You must be signed in to change notification settings - Fork 62
diff: Add --no-error-on-diff flag #282
base: main
Are you sure you want to change the base?
Conversation
Not sure if I should have raised an issue to discuss this feature first, but this is the third time I've needed this (with a TODO in my Makefiles to do it). I find this feature useful as I can run |
Add a `--no-error-on-diff` flag to the `diff` subcommand so as to not exit with an error when there are diffs present. It will still exit with an error if the configs are not valid, so `kubecfg diff` can be a useful command to run on a branch of a CI system to show diffs and still validate the configs.
aa27319
to
5b6d6de
Compare
Not sure how to get a passing build. Travis is saying:
|
that's weird, I ran this 3 days ago and it worked: https://travis-ci.org/bitnami/kubecfg/jobs/648533819?utm_medium=notification&utm_source=github_status probably a transient issue, restarting the job |
Not sure kubecfg needs to have a special feature of that.
? |
I covered that partly in the commit message - that shell construct will hide errors that are not due to a diff. But the other reason is that you may not have a shell because you have kubecfg in a distroless image or similar. Also I avoid running things with the shell as much as possible because it introduces quoting problems and changes argv from a vector to a single string ( But the other reason I'd like this patch to be merged is I don't think kubecfg doing exactly what you ask it to do should result in an error. At least how I use it. I think it should be the default not to exit with an error but it's too late for that. |
I wonder how many people are actually depending on that behavior. I'm all for not breaking backward compatibility, but what if a behavior is objectively wrong? That would be a bug and bugs should be fixed, right? What does kubectl diff do? |
I'm not sure. I haven't used that. And I can't run it now because we have "security" in my cluster:
As for whether bugs should be fixed that change behaviour, i think it comes down to pragmatism. If people have built scripts that depend on this behaviour, you'll be breaking them if you change this. I can see |
|
Makes sense. So, there are two main reasons why one would want to run k* diff:
If I understood correctly, the current behaviour (consistent with kubectl and good old unix diff) works well out of the box in the second use case but poorly in the first use case, because if all you do is to look whether the exit code is non 0 you may misinterpret unrelated failures (e.g. transient networking, configuration) as "there are differences". Technically, the exit code can encode such difference, by using the value 1 for "there are differences" and 2 for actual errors, as unix diff and grep utilities do (Not sure if kubecfg already does that, consistently. I think it should). But that means that users of kubecfg diff would need to have a more complicated exit status check, e.g. when using it in shell scripts they should use What if instead of adding a flag that forces found differences to be reported as exit code 0, we explicitly address the first use case and add a Perhaps to could even ask for interactive confirmation before continuing (overrideable with --yes). (It's been a long time since the last time I used borgcfg ; I think it worked that way although I forgot the details )
|
That would work for me - in my CI/CD I do the
As long as it can be overridden, I'm fine with that. I don't know whether it makes more sense to have We would also need to add the |
I don't have strong feelings for whether to default to interactive or not. On one hand I do agree with you that "do what I tell you" would more naturally follow the principle of least surprise. On the other hand I don't know of there are some precedents set by sister tools. As for diff strategy: I agree. I always wondered the same. @anguslees? |
The These leads me to the concern that if |
Add a
--no-error-on-diff
flag to thediff
subcommand so as to notexit with an error when there are diffs present. It will still exit with
an error if the configs are not valid, so
kubecfg diff
can be a usefulcommand to run on a branch of a CI system to show diffs and still
validate the configs.