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 import handling for Helm Release #1818

Merged
merged 9 commits into from
Dec 8, 2021
Merged

Fix import handling for Helm Release #1818

merged 9 commits into from
Dec 8, 2021

Conversation

viveklak
Copy link
Contributor

@viveklak viveklak commented Dec 3, 2021

Proposed changes

Adds ability to import releases.

Note - since releases don't themselves record information about the chart used, repository information is omitted from the code generated.

Related issues (optional)

#1698

@viveklak
Copy link
Contributor Author

viveklak commented Dec 3, 2021

I have manually verified this. Working on an integration test for this.

@github-actions
Copy link

github-actions bot commented Dec 3, 2021

Does the PR have any schema changes?

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

1 similar comment
@github-actions
Copy link

github-actions bot commented Dec 3, 2021

Does the PR have any schema changes?

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

@lblackstone
Copy link
Member

I think this looks good, but it will likely have a merge conflict with #1809

Not sure which would be easier to merge first

@silphid
Copy link

silphid commented Dec 3, 2021

We tried out that PR with the release we're trying to import and we get a warning during preview:

Diagnostics:
  kubernetes:helm.sh/v3:Release (ingress-nginx-controller):
    warning: inputs to import do not match the existing resource; importing this resource will fail

and equivalent error during the actual import:

  kubernetes:helm.sh/v3:Release (ingress-nginx-controller):
    error: inputs to import do not match the existing resource

Is there anything we should do to make that work?

Our resource looks like this in TS:

    new k8s.helm.v3.Release(
      model.name,
      {
        chart: 'ingress-nginx',
        repositoryOpts: {
          repo: 'https://kubernetes.github.io/ingress-nginx',
        },
        values: values,
        version: model.repoVersion,
        namespace: 'nginx-ingress-controller',
        keyring: '~/.gpg/pubring.gpg',
      },
      {
        parent: this,
        import: 'nginx-ingress-controller/release-kl2buwnx',
        provider: cluster.provider,
      }
    );

@viveklak
Copy link
Contributor Author

viveklak commented Dec 4, 2021

We tried out that PR with the release we're trying to import and we get a warning during preview:

Diagnostics:
  kubernetes:helm.sh/v3:Release (ingress-nginx-controller):
    warning: inputs to import do not match the existing resource; importing this resource will fail

and equivalent error during the actual import:

  kubernetes:helm.sh/v3:Release (ingress-nginx-controller):
    error: inputs to import do not match the existing resource

Is there anything we should do to make that work?

Our resource looks like this in TS:

    new k8s.helm.v3.Release(
      model.name,
      {
        chart: 'ingress-nginx',
        repositoryOpts: {
          repo: 'https://kubernetes.github.io/ingress-nginx',
        },
        values: values,
        version: model.repoVersion,
        namespace: 'nginx-ingress-controller',
        keyring: '~/.gpg/pubring.gpg',
      },
      {
        parent: this,
        import: 'nginx-ingress-controller/release-kl2buwnx',
        provider: cluster.provider,
      }
    );

Thanks for testing this out already! I discovered this and a couple of similar issues in my tests as well. Essentially we need to drop some computed items from the inputs which are being detected as conflicts. In addition, we set certain fields as defaults which are conflicting with the import. I will have fixes for both in the PR shortly.

@github-actions
Copy link

github-actions bot commented Dec 7, 2021

Does the PR have any schema changes?

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

@github-actions
Copy link

github-actions bot commented Dec 8, 2021

Does the PR have any schema changes?

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

1 similar comment
@github-actions
Copy link

github-actions bot commented Dec 8, 2021

Does the PR have any schema changes?

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

@@ -647,21 +647,19 @@ func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequ
// Attempt to load the configuration from the provided kubeconfig. If this fails, mark the cluster as unreachable.
if !k.clusterUnreachable {
config, err := kubeconfig.ClientConfig()

if kubeClientSettings.Burst != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran into some panics here in tests which this change fixed.

@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same as the chart in the local chart example. Its a lot easier to refer to a local chart with the manual chart install and figured its best to copy it. Let me know if we should consolidate instead.

Copy link
Member

Choose a reason for hiding this comment

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

Fine by me

@github-actions
Copy link

github-actions bot commented Dec 8, 2021

Does the PR have any schema changes?

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

@viveklak
Copy link
Contributor Author

viveklak commented Dec 8, 2021

@lblackstone I think this is ready for another look now.

@github-actions
Copy link

github-actions bot commented Dec 8, 2021

Does the PR have any schema changes?

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

tests/sdk/go/go_test.go Outdated Show resolved Hide resolved
tests/sdk/go/go_test.go Outdated Show resolved Hide resolved
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
Copy link
Member

Choose a reason for hiding this comment

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

Fine by me

tests/sdk/go/manual.go Outdated Show resolved Hide resolved
tests/sdk/go/manual.go Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Dec 8, 2021

Does the PR have any schema changes?

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

@viveklak viveklak merged commit 96ad041 into master Dec 8, 2021
@pulumi-bot pulumi-bot deleted the vl/HelmReleaseImport branch December 8, 2021 21:24
@nestobot
Copy link

nestobot commented Dec 8, 2021

First, thank you so much @viveklak for taking the time to add support for imports, that's deeply appreciated! 👍

Now, I have tried to import our release again with a build of the master branch right after the merge of this PR, however we are still getting the same issue as mentioned above, this time with the resourceNames input:

Previewing update (nesto/dev)

View Live: https://app.pulumi.com/nesto/host/dev/previews/78043fca-7342-4c60-bb86-f92386b20443

     Type                                 Name                      Plan       Info
     pulumi:pulumi:Stack                  host-dev                             
     ├─ nesto:cert-manager                cert-manager                         
     │  └─ kubernetes:helm.sh/v3:Release  cert-manager                         
     └─ nesto:ingress-nginx               ingress-nginx-controller             
 =      └─ kubernetes:helm.sh/v3:Release  ingress-nginx-controller  import     [diff: +repositoryOpts~resour
 
Diagnostics:
  kubernetes:helm.sh/v3:Release (ingress-nginx-controller):
    warning: inputs to import do not match the existing resource; importing this resource will fail
 

Do you want to perform this update? details
  pulumi:pulumi:Stack: (same)
    [urn=urn:pulumi:dev::host::pulumi:pulumi:Stack::host-dev]
            > kubernetes:core/v1:Secret: (read)
                [id=kube-system/codefresh-token-tx9tj]
                [urn=urn:pulumi:dev::host::nesto:kubernetes$nesto:infra:CodefreshCluster$kubernetes:core/v1:Secret::codefresh]
                [provider=urn:pulumi:dev::host::pulumi:providers:kubernetes::k8s-provider::94f630e8-5f8e-4f99-a362-ba5e6a17ce57]
        = kubernetes:helm.sh/v3:Release: (import)
            [id=nginx-ingress-controller/release-kl2buwnx]
            [urn=urn:pulumi:dev::host::nesto:ingress-nginx$kubernetes:helm.sh/v3:Release::ingress-nginx-controller]
            [provider=urn:pulumi:dev::host::pulumi:providers:kubernetes::k8s-provider::94f630e8-5f8e-4f99-a362-ba5e6a17ce57]
          + repositoryOpts: {
              + repo    : "https://kubernetes.github.io/ingress-nginx"
            }
          ~ resourceNames : {
              ~ ClusterRole.rbac.authorization.k8s.io/rbac.authorization.k8s.io/v1       : [
                  + [1]: "release-kl2buwnx-ingress-nginx-admission"
                ]
              ~ ClusterRoleBinding.rbac.authorization.k8s.io/rbac.authorization.k8s.io/v1: [
                  + [1]: "release-kl2buwnx-ingress-nginx-admission"
                ]
              + Job.batch/batch/v1                                                       : [
              +     [0]: "nginx-ingress-controller/release-kl2buwnx-ingress-nginx-admission-create"
              +     [1]: "nginx-ingress-controller/release-kl2buwnx-ingress-nginx-admission-patch"
                ]
              ~ Role.rbac.authorization.k8s.io/rbac.authorization.k8s.io/v1              : [
                  + [1]: "nginx-ingress-controller/release-kl2buwnx-ingress-nginx-admission"
                ]
              ~ RoleBinding.rbac.authorization.k8s.io/rbac.authorization.k8s.io/v1       : [
                  + [1]: "nginx-ingress-controller/release-kl2buwnx-ingress-nginx-admission"
                ]
              ~ ServiceAccount/v1                                                        : [
                  + [1]: "nginx-ingress-controller/release-kl2buwnx-ingress-nginx-admission"
                ]
            }

Do you want to perform this update? yes
Updating (nesto/dev)

View Live: https://app.pulumi.com/nesto/host/dev/updates/17

     Type                                 Name                      Status                   Info
     pulumi:pulumi:Stack                  host-dev                  **failed**               1 error
     ├─ nesto:cert-manager                cert-manager                                       
     │  └─ kubernetes:helm.sh/v3:Release  cert-manager                                       
     └─ nesto:ingress-nginx               ingress-nginx-controller                           
 =      └─ kubernetes:helm.sh/v3:Release  ingress-nginx-controller  **importing failed**     1 error
 
Diagnostics:
  pulumi:pulumi:Stack (host-dev):
    error: update failed
 
  kubernetes:helm.sh/v3:Release (ingress-nginx-controller):
    error: inputs to import do not match the existing resource

Is there anything we're not doing correctly on our end or is it just yet another computed input that would need to be dropped by the provider?

@silphid
Copy link

silphid commented Dec 8, 2021

(Sorry, that was me above, just logged as our bot account! 😉)

@silphid
Copy link

silphid commented Dec 8, 2021

Another input that seems to be computed dynamically and which should maybe be dropped is keyring. On my machine, it computes to /Users/mathieu/.gnupg/pubring.gpg, which obviously won't be the same on my colleague's machine (and thus always require an update). What do you think? 🤔

@viveklak
Copy link
Contributor Author

viveklak commented Dec 8, 2021

@silphid thanks for that. You might want to disable the following from the resource during the import.

repositoryOpts: {
          repo: 'https://kubernetes.github.io/ingress-nginx',
},

The reason for this is that helm doesn't seem to persist the repository information on the release. You may want to add repositoryOpts after the import and run a pulumi up so subsequent chart updates/upgrades work.

You can also drop keyring: '~/.gpg/pubring.gpg',.

Happy to chat over slack if you run into further issues with the above and huge thanks for taking this out for a spin so quickly!

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.

None yet

4 participants