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 diff panic for malformed kubeconfig #1581

Merged
merged 2 commits into from
May 19, 2021

Conversation

lblackstone
Copy link
Member

Proposed changes

If the kubeconfig context name was not indented
properly, it could lead to a map lookup failing, and
then a subsequent unchecked nil value.

Related issues (optional)

Fix #1543

If the kubeconfig context name was not indented
properly, it could lead to a map lookup failing, and
then a subsequent unchecked nil value.
@github-actions
Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

Copy link
Member

@lukehoban lukehoban left a comment

Choose a reason for hiding this comment

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

Can we add test coverage for these failure cases?

if activeContext == nil {
return &clientapi.Cluster{}
}
activeClusterName := activeContext.Cluster

activeCluster := config.Clusters[activeClusterName]
Copy link
Member

Choose a reason for hiding this comment

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

Can the same issue occur here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like it. Good catch.

activeClusterName := config.Contexts[currentContext].Cluster
activeContext := config.Contexts[currentContext]
if activeContext == nil {
return &clientapi.Cluster{}
Copy link
Member

Choose a reason for hiding this comment

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

This means we don't report up a useful error about what caused this. Should this function return a useful error?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure it's possible to tell if this is actually an error since this runs during preview and Outputs may not yet be fully resolved. I suspect that it might lead to erroneous warnings.

This particular case was a bit odd because the outdented YAML still parsed cleanly, but changed the semantics of the configuration. This change fixes the panic, and now correctly shows a replacement in the preview. This should be sufficient for a user to notice that something is going wrong if they weren't expecting a change.

@github-actions
Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

1 similar comment
@github-actions
Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

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.

Panic when diffing an invalid kubeconfig
2 participants