what do i give for the import id for a kubernetes ...
# general
b
what do i give for the import id for a kubernetes resource?
g
[namespace/]name
e.g., to import a Deployment in the
foo
namespace:
import: "foo/my-deployment"
b
huh, i tried that, but it's not working 🤔
g
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
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
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
won't the transform apply to the individual resources?
g
it will, but you have to make sure each of those resources is named
letsencrypt-prod
b
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
maybe in a different namespace?
b
clusterissuers are namespaceless
unless that's the problem?
g
oh, right
no, that should be fine
it could be the transformation function. i think you need to pass two args
b
yeah, i don't know? it seems it changed?
g
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
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
hmm, i’m fairly sure the k8s transformations support predates this, and may not be identical
i haven’t used it much myself
b
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
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
v1.7.1?
g
yeah, plus 1.4.1 on
pulumi-kubernetes
b
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
normally you shouldn’t have to run
tsc
. pulumi will run it as part of the
pulumi up
process
b
so it can import typescript from an external library?
g
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
noted. will do that. thanks for the assistance.
👍 1
should i file it against pulumi or pulumi-kubernetes?
g
pulumi-kubernetes is good
👍 1
b
filed at https://github.com/pulumi/pulumi-kubernetes/issues/932 in case anyone comes through
p
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
@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
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.