I don't have a good grasp on providers; I use (typ...
# general
c
I don't have a good grasp on providers; I use (typescript)
@pulumi/kubernetes
and
@pulumi/command
to delete some CRDs when a specific helm chart is deleted. I'd like to be able to write:
Copy code
new local.Command("name", {
  delete: "kubectl delete thing"
}, { provider: k8sProvider});
However that yields:
unrecognized resource type: "command:local:Command" for this provider
The error message suggests that somehow makeKubeProvider can be made aware of other providers - but it's really opaque to me as to how this happens. I'm also pulling a blank searching for docs on how this works. Does anyone have any pointers?
Also, it occurred to me that perhaps providers aren't typically cross compatible this way? It would introduce a layer of dependency for example which may make updating pulumi-kubernetes harder. What sort of guidance exists in terms of understanding whether this sort of cross-package dependence is acceptable or not.
FWIW, this is my current strategy:
Copy code
pulumi.all([clusterCore.kubeconfig]).apply(([config]) => {
    // this leaves some trash around; gitignore manages this.
    // not clear if this is nasty; but without updating k8sProvider
    // to understand local.Command
    const filename = `kubeconfig.${hash(stack)}.json`;
    writeFileSync(filename, JSON.stringify(config));
    [
      "<http://alertmanagerconfigs.monitoring.coreos.com|alertmanagerconfigs.monitoring.coreos.com>",
      "<http://alertmanagers.monitoring.coreos.com|alertmanagers.monitoring.coreos.com>",
      "<http://podmonitors.monitoring.coreos.com|podmonitors.monitoring.coreos.com>",
      "<http://probes.monitoring.coreos.com|probes.monitoring.coreos.com>",
      "<http://prometheuses.monitoring.coreos.com|prometheuses.monitoring.coreos.com>",
      "<http://prometheusrules.monitoring.coreos.com|prometheusrules.monitoring.coreos.com>",
      "<http://servicemonitors.monitoring.coreos.com|servicemonitors.monitoring.coreos.com>",
      "<http://thanosrulers.monitoring.coreos.com|thanosrulers.monitoring.coreos.com>",
    ].forEach(
      (crd) =>
        new local.Command(
          `${stack}-cleanupcrd-${hash(crd)}`,
          {
            delete: `kubectl delete crd ${crd}`,
            environment: {
              KUBECONFIG: filename,
            },
          }
        )
    );
  });
clusterCore is an
eks.ClusterCore
type from the
@pulumi/eks
package.
s
When you specify an explicit provider (which you usually do not need to do), it needs to be of the same type that that resource belongs to.
command.local.Command
can only take an explicit CommandProvider, not a K8s provider.
If you want to deploy a K8s resource after creating a K8s cluster in the same program, you'll need to create an explicit K8s provider with the kubeconfig of the cluster you just provisioned.
c
👋🏼 @stocky-restaurant-98004 - thanks for your thoughts. Good to know that cross provider isn't a thing. The error message definitely led me astray a little there.
s
Feel free to submit an issue to https://github.com/pulumi/pulumi if you'd like that error message improved.
c
I mean.. I think it would just say "RTFM, don't imagine what the software could do" 😅 The message as interpreted by my brain made me think there was some ability to "magically" interpret provider abilities. The docs for command do a solid job of illustrating using the env to set the kubeconfig and in my case I just need to write a temp file to reference. RE: specifying explicit providers "which you usually do not need to do" I do it because it's possible, in a dev context, for my system config to be referencing a different cluster than what I have pulumi operating on. So I'm explicit about the k8s cluster to interact with.