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

DiffConfig fails when provider's kubeconfig is set to file path #2663

Closed
mikhailshilkov opened this issue Nov 10, 2023 · 0 comments · Fixed by #2771
Closed

DiffConfig fails when provider's kubeconfig is set to file path #2663

mikhailshilkov opened this issue Nov 10, 2023 · 0 comments · Fixed by #2771
Assignees
Labels
area/providers kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@mikhailshilkov
Copy link
Member

mikhailshilkov commented Nov 10, 2023

What happened?

Reported in pulumi/pulumi#14529

A CLI version that doesn't ignore errors returned from DiffConfig fails with

error: rpc error: code = Unknown desc = failed to parse kubeconfig: couldn't get version/kind; json parse error: json: cannot unmarshal string into Go value of type struct { APIVersion string "json:"apiVersion,omitempty""; Kind string "json:"kind,omitempty"" }

when an explicit kubernetes provider points to a kubeconfig via its path.

I reproduced that the error is returned from this line:

Example

import { Provider } from '@pulumi/kubernetes'

export const provider = new Provider('***', {
  kubeconfig: join(__dirname, 'kubeconfig.yaml')
})

Output of pulumi about

CLI          
Version      3.92.0
Go Version   go1.21.3
Go Compiler  gc

Plugins
NAME            VERSION
aws             5.4.0
aws             4.38.1
aws             4.38.1
aws-apigateway  0.0.6
aws-native      0.16.1
command         0.1.0
docker          3.1.0
eks             0.36.0
kubernetes      3.12.1
nodejs          unknown
random          4.3.1

Host     
OS       darwin
Version  14.1
Arch     arm64

This project is written in nodejs: executable='/usr/local/bin/node' version='v18.17.0'

Dependencies:
NAME                              VERSION
@types/node                       17.0.5
husky                             7.0.4
deepmerge                         4.2.2
lodash                            4.17.21
@aws-sdk/client-sts               3.45.0
@pulumi/aws-apigateway            0.0.6
@pulumi/aws-native                0.16.1
@pulumi/eks                       0.36.0
@pulumi/kubernetes                3.12.1
@pulumi/pulumi                    3.18.0
eslint                            8.12.0
typescript                        4.6.3
@aws-sdk/client-kms               3.45.0
@pulumi/aws                       5.4.0
@pulumi/awsx                      0.40.0
@pulumi/command                   0.1.0
@pulumi/random                    4.3.1
@typescript-eslint/eslint-plugin  5.18.0
@types/js-yaml                    4.0.5
@types/lodash                     4.14.178
@typescript-eslint/parser         5.18.0
js-yaml                           4.1.0

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@mikhailshilkov mikhailshilkov added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team area/providers and removed needs-triage Needs attention from the triage team labels Nov 10, 2023
@EronWright EronWright self-assigned this Jan 24, 2024
@mjeffryes mjeffryes added this to the 0.99 milestone Jan 26, 2024
EronWright added a commit that referenced this issue Jan 27, 2024
…2771)

<!--Thanks for your contribution. See [CONTRIBUTING](CONTRIBUTING.md)
    for Pulumi's contribution guidelines.

    Help us merge your changes more quickly by adding more details such
    as labels, milestones, and reviewers.-->

### Proposed changes

<!--Give us a brief description of what you've done and what it solves.
-->

This PR refactors the kubeconfig loading code to be more consistent
between `DiffConfig` and `Configure`. Previously the `DiffConfig` method
did not support file-based kubeconfigs, and would throw a spurious
parser error.

`DiffConfig` loads the kubeconfig to be able to detect cluster
replacement, by comparing the active cluster info. Unlike `Configure`,
it doesn't have support for ambient kubeconfigs. When an ambient config
is in use, or the config is invalid (e.g. the `context` or `cluster`
properties refer to a non-existent entry), then the replacement logic is
skipped.

This PR also fixes a panic in `DiffConfig` that would occur if `cluster`
or `context` is a computed value; the provider will conservatively
suggest replacement as it does when `kubeconfig` is a computed value.

### Testing
New test cases were added for cluster change detection.

New tests were added for the parsing code that was consolidated into
`utils.go`. The tests now cover file-, string-, and object-based
resource property values for `kubeconfig`.

### Related issues (optional)

<!--Refer to related PRs or issues: #1234, or 'Fixes #1234' or 'Closes
#1234'.
Or link to full URLs to issues or pull requests in other GitHub
repositories. -->
Closes: #2663 
Related: #1032
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/providers kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants