Hello everyone. I'm having a problem using the .ge...
# kubernetes
h
Hello everyone. I'm having a problem using the .get() function from the k8s provider. Apparently depends_on seems to be not working with .get() functions. I create a k8s secret in one place indirectly (operator creates it) and in another place (component resource that depends on the oher CR with the creation) i use the .get() function to read it. But I am getting this error during the plan phase (even if i only target the first CR):
Copy code
error: Preview failed: resource 'rabbitmq/telegraf-user-credentials' does not exist
I appreciate any recommendations on how do depends_on with get(). Thanks 🙂
d
Might be helpful to show more of the code pertaining to depends_on. The trick might come down to the
id
that you pass into `get()`; make the id value be dependent on the other CR.
h
hi and thank you for your answer. Here are my related files. Will try to keep it minimal: main.py
Copy code
rabbitMQ = RabbitMQ(
    name,
    namespace="rabbitmq",
    opts=child_opts,
)

telegraf = TelegrafDeployment(
    name,
    opts=ResourceOptions.merge(
        child_opts,
        ResourceOptions(
            depends_on=[
                rabbitMQ,
            ]
        )
    )
)
inside the RabbitMQ class:
Copy code
self.telegraf_user = kubernetes.apiextensions.CustomResource(
            "telegraf",
            api_version="rabbitmq.com/v1beta1",
            kind="User",
            metadata={
                "name": "telegraf",
                "namespace": namespace,
            },
            opts=child_opts,
            spec={
                "tags": [
                    "management"
                ],
                "rabbitmqClusterReference": {
                    "name": "rabbitmq",
                },
                "importCredentialsSecret": {
                    "name": telegraf_credentials.metadata["name"]
                },
            }
        )
telegraf.py:
Copy code
class TelegrafDeployment(ComponentResource):

    def __init__(self,
                 name: str,
                 args: TelegrafDeploymentArgs,
                 opts: ResourceOptions = None):
        super().__init__("idm:tools:TelegrafDeployment", name, {}, opts)

        child_opts = ResourceOptions(
            parent=self,
        )

        user_secret = Secret.get(
            "telegraf-user-credentials",
            "rabbitmq/telegraf-user-credentials",
            opts=child_opts,
        )
I'm not sure what you mean with: > make the id value be dependent on the other CR. How would i make my id value dependent? Do you mean making an output out of:
telegraf_user.id
and pass it into the Telegraf CR? Or only make the Telegraf CR depend on that output? The operator might take a little time to create the secret itself from the custom resource. Would that work in that case? Thanks
d
I was thinking about making the constant value
"rabbitmq/telegraf-user-credentials"
be an output, that is based on the expression
telegraf_credentials.metadata["name"]
.
It could be problematic that the secret isn't immediately available, because Pulumi doesn't have logic to wait for an object to come into existence, aside from some ordinary retry logic. I would guess that you could create the secret explicitly before installing RabbitMQ, in your Pulumi code, rather than relying on the RabbitMQ operator to do it. That is, change your strategy so that you control the secret directly using Pulumi. Is that possible?
h
I see. I will have to put some password generation into my code but it should be possible. Thank you 🙏