https://pulumi.com logo
#general
Title
# general
b

bitter-dentist-28132

12/19/2019, 8:50 PM
what do i give for the import id for a kubernetes resource?
g

gorgeous-egg-16927

12/19/2019, 9:17 PM
[namespace/]name
e.g., to import a Deployment in the
foo
namespace:
import: "foo/my-deployment"
b

bitter-dentist-28132

12/19/2019, 9:19 PM
huh, i tried that, but it's not working 🤔
g

gorgeous-egg-16927

12/19/2019, 9:20 PM
can you paste in the code snippet that’s not working?
make sure you’re using
.metadata.name
rather than the name you picked for the pulumi resource
b

bitter-dentist-28132

12/19/2019, 9:22 PM
Copy code
const clusterIssuer = new k8s.yaml.ConfigGroup('cluster-issuer', {yaml: CLUSTER_ISSUER_YAML}, {provider, dependsOn, transformations: [asdf]});
function asdf(args: any) {
    return {
        props: args.props,
        opts: pulumi.mergeOptions(args.opts, {import: 'letsencrypt-prod'}),
    };
}
This is just a test resource to see if i could import a single resource.
CLUSTER_ISSUER_YAML
is my cert-manager cluster issuer
g

gorgeous-egg-16927

12/19/2019, 9:35 PM
oh, i think the problem is that you can’t import the
ConfigGroup
directly; import currently only works with the underlying resources, so the import name has to map correctly
b

bitter-dentist-28132

12/19/2019, 9:41 PM
won't the transform apply to the individual resources?
g

gorgeous-egg-16927

12/19/2019, 9:42 PM
it will, but you have to make sure each of those resources is named
letsencrypt-prod
b

bitter-dentist-28132

12/19/2019, 9:42 PM
trying to give
import: whatever
to
ConfigGroup
fails because of the type mismatch (expected), and the transform applies to the cluster issuer (it's a config group but there's only one yaml element), but the import fails with
Preview failed: resource 'letsencrypt-prod' does not exist
g

gorgeous-egg-16927

12/19/2019, 9:43 PM
maybe in a different namespace?
b

bitter-dentist-28132

12/19/2019, 9:43 PM
clusterissuers are namespaceless
unless that's the problem?
g

gorgeous-egg-16927

12/19/2019, 9:44 PM
oh, right
no, that should be fine
it could be the transformation function. i think you need to pass two args
b

bitter-dentist-28132

12/19/2019, 9:46 PM
yeah, i don't know? it seems it changed?
g

gorgeous-egg-16927

12/19/2019, 9:47 PM
from the example i linked:
Copy code
function addImportForHelmChart() {
  return (obj: any, opts: pulumi.CustomResourceOptions): void => {
    if (obj != null && obj.metadata != null && obj.metadata.name) {
      opts.import = obj.metadata.namespace
        ? `${obj.metadata.namespace}/${obj.metadata.name}`
        : obj.metadata.name;
    }
  };
}
b

bitter-dentist-28132

12/19/2019, 9:47 PM
yeah but i get all kinds of errors with that, include type errors i have to suppress with
any
, and the docs say something different now
check "transformations"
g

gorgeous-egg-16927

12/19/2019, 9:49 PM
hmm, i’m fairly sure the k8s transformations support predates this, and may not be identical
i haven’t used it much myself
b

bitter-dentist-28132

12/19/2019, 9:52 PM
mmm, you're probably right that i should have checked that reference. i do indeed get type errors though:
Copy code
src/cluster-bits.ts:99:99 - error TS2345: Argument of type '{ provider: Provider; dependsOn: Output<any>; transformations: (() => (obj: any, opts: CustomResourceOptions) => void)[]; }' is not assignable to parameter of type 'ComponentResourceOptions'.
  Types of property 'transformations' are incompatible.
    Type '(() => (obj: any, opts: CustomResourceOptions) => void)[]' is not assignable to type 'ResourceTransformation[]'.
      Type '() => (obj: any, opts: CustomResourceOptions) => void' is not assignable to type 'ResourceTransformation'.
        Type '(obj: any, opts: CustomResourceOptions) => void' is missing the following properties from type 'ResourceTransformationResult': props, opts

99     const clusterIssuer = new k8s.yaml.ConfigGroup('cluster-issuer', {yaml: CLUSTER_ISSUER_YAML}, {provider, dependsOn, transformations: [addImportForYaml]});
so it seems that, at the very least, it wants the return type that i linked above (
{props, opts}
)
g

gorgeous-egg-16927

12/19/2019, 9:54 PM
hmm, that’s odd. perhaps something changed i’m not aware of. let me look into it
Copy code
new k8s.yaml.ConfigGroup("test",
    {
        yaml: `
apiVersion: v1
kind: Namespace
metadata:
    annotations: {}
    name: foo`,
        transformations: [
            (obj: any, opts: pulumi.CustomResourceOptions) => {
                opts.import = obj.metadata.name
            }
        ]
    }
);
that worked for me to import a namespace
b

bitter-dentist-28132

12/19/2019, 10:05 PM
v1.7.1?
g

gorgeous-egg-16927

12/19/2019, 10:06 PM
yeah, plus 1.4.1 on
pulumi-kubernetes
b

bitter-dentist-28132

12/19/2019, 10:06 PM
my
pulumi-kubernetes
is pretty old, let me try bumping it...
nope still get a type error.
does it matter that this is in a library?
(i.e. i'm running
tsc
so i can then import the code in the actual pulumi stack code)
i guess there is disagreement somewhere that is confusing
tsc
?
g

gorgeous-egg-16927

12/19/2019, 10:39 PM
normally you shouldn’t have to run
tsc
. pulumi will run it as part of the
pulumi up
process
b

bitter-dentist-28132

12/19/2019, 10:40 PM
so it can import typescript from an external library?
g

gorgeous-egg-16927

12/19/2019, 10:42 PM
oh, i think i misunderstood what you were doing
you may need to open an issue to get some more eyes on this. i’m not as familiar with the typescript toolchain in general, so it may be something to do with that
b

bitter-dentist-28132

12/19/2019, 10:43 PM
noted. will do that. thanks for the assistance.
👍 1
should i file it against pulumi or pulumi-kubernetes?
g

gorgeous-egg-16927

12/19/2019, 10:56 PM
pulumi-kubernetes is good
👍 1
b

bitter-dentist-28132

12/19/2019, 11:49 PM
filed at https://github.com/pulumi/pulumi-kubernetes/issues/932 in case anyone comes through
p

prehistoric-account-60014

12/20/2019, 4:22 AM
I don’t know if this helps but I had a monorepo setup and when there are different versions of the same package being hoisted it’s possible to get conflicting types due to difference in instances of the library. Even if you don’t use a monorepo if it’s a library make sure you’re using peerDependecies so there’s not 2 Pulumi instances.
b

bitter-dentist-28132

12/20/2019, 3:21 PM
@prehistoric-account-60014 that's a good point to keep in mind, thanks. i don't think that's the case here, since i get a type error even in the library. and doing an
npm ls | grep pulumi
shows the same pulumi version for everything. but it is something i'll have to watch out for.
p

prehistoric-account-60014

12/20/2019, 3:36 PM
Even same versions that are duplicated would cause an issue. The way I checked myself was by running
yarn why @pulumi/pulumi
and making sure there was only one instance. Also keep in mind there are two transformation properties and each have different signatures. You might be mixing the two. One is in the second positional argument in the constructor, together with other options and the other one is in the third, together with the provider, etc.