Pulumi-kubernetes: Importing custom resource fails with unknown resource type error

Created on 25 Mar 2021  路  5Comments  路  Source: pulumi/pulumi-kubernetes


While trying to import a redis custom resource to pulumi I'm getting an unknown resource type error.

Expected behavior

Importing the resource should work

Current behavior

Trying to import the resource via the cli or json file always results in error and failure to import.

Steps to reproduce

  1. Install amaizfinance/redis-operator - download the deploy directory and run kubectl apply -k deploy/
  2. Create an example redis instance - kubectl apply -f https://raw.githubusercontent.com/amaizfinance/redis-operator/master/example/k8s_v1alpha1_redis_cr.yaml
  3. Try to import to pulumi - pulumi import kubernetes:k8s.amaiz.com/v1alpha1:Redis example example

Always throws the same error:

Previewing import (dev):
     Type                                        Name       Plan       Info
     pulumi:pulumi:Stack                         redis-dev             1 error
 =   鈹斺攢 kubernetes:k8s.amaiz.com/v1alpha1:Redis  example    import     1 error

Diagnostics:
  kubernetes:k8s.amaiz.com/v1alpha1:Redis (example):
    error: Preview failed: unknown resource type 'kubernetes:k8s.amaiz.com/v1alpha1:Redis'

  pulumi:pulumi:Stack (redis-dev):
    error: preview failed

This seems to happen just on import. While using crd2pulumi and creating a programmatic instance of redis, pulumi is able to create and manage the resource just fine.

pulumi version - v2.23.1
pulumi-kubernetes - 2.8.3
go - 1.16.2

kinbug

Most helpful comment

Can confirm that using that using the import option on the resource allows to import the resource properly to pulumi. Thanks for the help @lblackstone.

I would still love to see it working using the cli but programmatic import is a good solution as well

All 5 comments

@lblackstone any quick ideas what might be going on here? Is it that import can only import resources defined within the pulumi schema?

Is it that import can only import resources defined within the pulumi schema?

That would be my guess. I can't think a reason it shouldn't work in theory, but it would require extra logic for k8s CustomResources. I expect the part that's failing is the code-generation since the k8s provider doesn't have knowledge about the custom schema. This case seems fairly tricky to support, but the crd2pulumi tool includes most of the logic that would be required.

@lblackstone if this is caused by the code generation preview, is it possible to skip it during import? For example in the form of some flag for the import command

As far as I know, this isn't possible currently. I think you could still manually import the resource using the import option on the resource rather than using the pulumi import command. This blog post gives an example of this for a different resource type.

Can confirm that using that using the import option on the resource allows to import the resource properly to pulumi. Thanks for the help @lblackstone.

I would still love to see it working using the cli but programmatic import is a good solution as well

Was this page helpful?
0 / 5 - 0 ratings