Skip to content
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

Fix invalid revision in IOP #28784

Closed
wants to merge 6 commits into from
Closed

Conversation

shamsher31
Copy link
Member

@shamsher31 shamsher31 commented Nov 11, 2020

To fix #24819

# iop.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  namespace: istio-system
spec:
  profile: default
  revision: 18  # All of these values will fail:  18, 1.8, 1.8.0, "18", "1.8", "1.8.0"
$ ./out/linux_amd64/istioctl install -f iop.yaml --set hub=gcr.io/istio-testing -d manifests/

Error: failed to get profile, namespace or enabled components: failed to read profile:
invalid revision specified: 18. revision must be a string eg: "1-9-0"

Related:
#28745
#28778

@shamsher31 shamsher31 added area/environments/operator Issues related to Operator or installation release-notes-none Indicates a PR that does not require release notes. labels Nov 11, 2020
@shamsher31 shamsher31 added this to the 1.9 milestone Nov 11, 2020
@shamsher31 shamsher31 requested a review from a team as a code owner November 11, 2020 09:22
@shamsher31 shamsher31 self-assigned this Nov 11, 2020
@google-cla google-cla bot added the cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. label Nov 11, 2020
@istio-testing istio-testing added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 11, 2020
@shamsher31
Copy link
Member Author

/test integ-helm-tests_istio

@istio-testing istio-testing added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 11, 2020
@shamsher31
Copy link
Member Author

/test integ-security-k8s-tests_istio

@istio-testing istio-testing added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 12, 2020
@shamsher31
Copy link
Member Author

@howardjohn PTAL.

@su225
Copy link
Contributor

su225 commented Nov 17, 2020

@shamsher31 - I think #24819 is more generic than fixing bad revision. So I think we should still keep it open even if this PR is merged. Probably we should convert it to an umbrella issue to track these kind of stuff?

@shamsher31 shamsher31 requested review from a team, richardwxn and ostromart November 18, 2020 15:11
@shamsher31
Copy link
Member Author

@esnible PTAL and provide your feedback on this.

Copy link
Contributor

@esnible esnible left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way this is headed.

@howardjohn has a good point that it is strange to validate inside UnmarshalIOP(). My first idea was that UnmarshallIOP should change non-String Revision to a string, but that the revision itself should be validated elsewhere.

However, this might be too much flexibility. Perhaps UnmarshallIOP() should reject non-strings. It is unclear if the message when a non-string YAML arrives should be "revision must be a string" or the better message you have that requires calling validate inside unmarshal. For Istio developers rejecting non-string is the most helpful, as it keeps the unmarshal method generic. Users might prefer to get a good error message the first time, rather than a generic message. Whichever approach you take, make sure the call to validate the version is inside the function that validates the IOP even if it is already called when unmarshalling.

operator/pkg/validate/validate.go Outdated Show resolved Hide resolved
@shamsher31
Copy link
Member Author

Perhaps UnmarshallIOP() should reject non-strings.

For Istio developers rejecting non-string is the most helpful, as it keeps the unmarshal method generic

Agree. Updated to check just non-string revision in UnmarshallIOP().

but that the revision itself should be validated elsewhere.

make sure the call to validate the version is inside the function that validates the IOP even if it is already called when unmarshalling.

Invalid string revision is checked in the validation step here #28745

Users might prefer to get a good error message the first time, rather than a generic message.

$ ./out/linux_amd64/istioctl install -f iop.yaml --set hub=gcr.io/istio-testing -d manifests/

Error: failed to get profile, namespace or enabled components: failed to read profile:
invalid revision specified: false. revision must be a string eg: "1-9-0"

@esnible Please take another look.

@shamsher31 shamsher31 requested a review from esnible November 24, 2020 06:20
operator/pkg/validate/validate.go Outdated Show resolved Hide resolved
operator/pkg/validate/validate.go Outdated Show resolved Hide resolved
@shamsher31 shamsher31 requested a review from esnible November 24, 2020 13:53
@shamsher31
Copy link
Member Author

@esnible PTAL.

@@ -284,6 +284,11 @@ func UnmarshalIOP(iopYAML string) (*v1alpha1.IstioOperator, error) {
un.SetCreationTimestamp(meta_v1.Time{}) // UnmarshalIstioOperator chokes on these
iopYAML = util.ToYAML(un)
}
// TODO: find a better way to validate all the invalid values in IOP YAML
// before it is unmarshal into IstioOperator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the code has changed or I am just repeating myself, but I still don't think this is right.

First, this method is extremely inefficient. First we take a yaml string, then marshal to a map, then back to yaml, then marshal to a map again, then marshal to IstioOperator. This feels very wrong and contributes to massive memory allocations (it may seem like speed doesn't matter much since its a one-shot CLI tool, and it doesn't, but the amount of allocations we do is so high it makes our unit tests noticeably slow)

Second, why is revision special? Don't we have the same problem with every other field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had problems in the past with IOPs with creation timestamps. (e.g. istioctl/pkg/install/pre-check.go, istioctl/pkg/verifier/verifier.go and already in operator/pkg/validate/common.go.). However, I have retested by removing the clearing of creation time from istioctl x precheck and I see no problems. Let's stop introducing the clearing of Time fields until we can identify a way to reproduce.

@shamsher31
Copy link
Member Author

shamsher31 commented Dec 10, 2020

@howardjohn @esnible Does it make sense to merge this PR or we are ok with invalid revision in IOP?

@esnible
Copy link
Contributor

esnible commented Dec 11, 2020

@shamsher31 I suggest we merge this. I approved it. @howardjohn What do you think?

@howardjohn
Copy link
Member

I will repeat my comment:

@shamsher31 I understand why you put it here, but it doesn't feel correct to me. However, I also do not know a better place, as I don't work on this code base often.

Maybe @ostromart or @richardwxn can give a better review, I don't feel comfortable approving since I am not familiar and it isn't obviously correct to me. Thanks

@shamsher31
Copy link
Member Author

@ostromart @richardwxn WDYT about this fix?

@istio-policy-bot istio-policy-bot added the lifecycle/stale Indicates a PR or issue hasn't been manipulated by an Istio team member for a while label Jan 11, 2021
@shamsher31
Copy link
Member Author

@istio/wg-environments-maintainers ping.

@istio-policy-bot istio-policy-bot removed the lifecycle/stale Indicates a PR or issue hasn't been manipulated by an Istio team member for a while label Jan 12, 2021
@ostromart
Copy link
Contributor

my initial reaction to the code is are we sure this is conceptually the right fix?
afaict the issue with some characters in revision is orthogonal to what a field unmarshals to. these issues should be solved separately. the issue of illegal character stems from revision being used in some k8s resource fields where some chars are illegal per k8s naming rules. that used to be a problem, not sure if it is anymore but that's the first thing to sort out.
once we are clear on what chars are legal/illegal, we should type the field in IstioOperator appropriately so that it unmarshals whatever inputs we support (can use intorstring or interface types and make this change in istio/api). then, validate the unmarshaled value only to ensure it is legal wrt k8s naming (the first step).

@shamsher31
Copy link
Member Author

Closing as this is not a valid solution.

@shamsher31 shamsher31 closed this Feb 10, 2021
@shamsher31 shamsher31 deleted the fix-bad-rev branch February 10, 2021 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/environments/operator Issues related to Operator or installation cla: yes Set by the Google CLA bot to indicate the author of a PR has signed the Google CLA. release-notes-none Indicates a PR that does not require release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No visibility into bad IOP yaml
7 participants