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 unexpected end of JSON input during planning #221

Closed

Conversation

nazarewk
Copy link
Contributor

github.com/kbst/terraform-provider-kustomize/kustomize.kustomizationResourceDiff: github.com/kbst/terraform-provider-kustomize/kustomize.(*kManifest).load: json error: unexpected end of JSON input

not sure if it's the right way to go, but my workday is now over and i still want to share the findings

fixes #219

@nazarewk nazarewk force-pushed the bugfix/unexpected_end_of_JSON_input branch from 3ca524d to 84a1c22 Compare February 17, 2023 09:57
@nazarewk nazarewk marked this pull request as ready for review February 17, 2023 09:57
@nazarewk
Copy link
Contributor Author

nazarewk commented Feb 17, 2023

I've tried refactoring to see if there would be any code left after IF-ing everything depending on new value, but there wasn't anything left except loading old manifest, so it's mostly just improved error message and returning early without errors.

can I get a review @pst ?

Comment on lines +188 to +191
// dm will always be empty if it's known after apply
if tm == "" {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

I will have to look into this to fully understand it before I can merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can quite easily replicate the issue by creating something like:

  1. resource "random_id"
  2. data "kustomization_overlay" "prerender"
  3. data "kustomization_overlay" "source" - make this depend on the random_id
  4. resource "kustomization_resource" depending on ids from prerender and manifests from source

if err != nil {
return logError(err)
return logError(fmt.Errorf("failed to parse new manifest: %s [body=%#v]", err, tm))
Copy link
Member

Choose a reason for hiding this comment

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

You can not print the manifest to the log. The resource may be a secret, and now you printed that to the CI/CD log. Please remove this part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, I'll stick to the length of the body so there is at least some indicator of issues

@nazarewk nazarewk force-pushed the bugfix/unexpected_end_of_JSON_input branch from 84a1c22 to 9e2d87e Compare February 20, 2023 14:55
@nazarewk nazarewk requested a review from pst February 20, 2023 14:59
@nazarewk
Copy link
Contributor Author

nazarewk commented Feb 22, 2023

I've noticed the same error happens during update after I delete last-applied config from a resource

@wpbeckwith
Copy link

What's the status on this issue? I can see it's being worked, more so trying to get an idea if we need to actually do something or wait for an imminent fix.

github.com/kbst/terraform-provider-kustomize/kustomize.kustomizationResourceDiff: github.com/kbst/terraform-provider-kustomize/kustomize.(*kManifest).load: json error: unexpected end of JSON input
@nazarewk nazarewk force-pushed the bugfix/unexpected_end_of_JSON_input branch from c5c4f90 to ab4126a Compare April 17, 2023 12:25
@pst
Copy link
Member

pst commented May 30, 2023

I finally found the time to look into this, and I unfortunately have to tell you that I have decided to not merge this.

I don't see any real world situation where this is an issue, your prerender "hack" to work around the for_each limitation with known after apply values is not a valid use in my opinion. If you depend on values that are known after apply, avoid the for_each by having one kustomization_resource per K8s resource. Or fall back to the apply --target as suggested by Terraform.

If there are valid uses where the provider crashes because of such an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

json error during kustomizationResourceDiff
3 participants