Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python ContainerRegistryDockerCredentials doesn't return docker_credentials #127

Closed
davzucky opened this issue Aug 28, 2020 · 2 comments
Closed

Comments

@davzucky
Copy link

I'm trying to reproduced the script from here (in typescript) in python to create a digitalocean container registry credential ContainerRegistryDockerCredentials in python.
pulumi/pulumi-kubernetesx#49 (comment) code look like that

    container_registry = ContainerRegistry.get("source", "hyperwave-research")
    registry_creds = pulumi.Output.secret( ContainerRegistryDockerCredentials(
        "container-registry-creds", registry_name=container_registry.name).docker_credentials)        def encode_base64_dc(dc):
        message_bytes = dc.encode('ascii')
        base64_bytes = base64.b64encode(message_bytes)
        print(f"===> Docker  : {dc}")
        print(f"===> Docker Credential : {base64_bytes.decode('utf-8')}")
        return base64_bytes.decode("utf-8")        dc = registry_creds.apply(encode_base64_dc)        self.secret = Secret(
        "registry-creds-kube-secret",
        type="kubernetes.io/dockerconfigjson",
        metadata={"namespace": "default", "name": f"registry-{do_registry_name}"},
        string_data={".dockerconfigjson": dc},
        opts=opts,
    )

However whatever I tried, the docker.credential is everytime None. I tried other property of the ContainerRegistryDockerCredentials and I can confirm I have value like registry_name

      File "/home/dzucker/git/Hyperwave.Infrastructure/venv/lib/python3.8/site-packages/pulumi/runtime/rpc.py", line 192, in serialize_property
        obj[transformed_key] = await serialize_property(v, deps, input_transformer)
      File "/home/dzucker/git/Hyperwave.Infrastructure/venv/lib/python3.8/site-packages/pulumi/runtime/rpc.py", line 173, in serialize_property
        value = await serialize_property(output.future(), deps, input_transformer)
      File "/home/dzucker/git/Hyperwave.Infrastructure/venv/lib/python3.8/site-packages/pulumi/runtime/rpc.py", line 159, in serialize_property
        future_return = await asyncio.ensure_future(awaitable)
      File "/home/dzucker/git/Hyperwave.Infrastructure/venv/lib/python3.8/site-packages/pulumi/output.py", line 112, in get_value
        val = await self._future
      File "/home/dzucker/git/Hyperwave.Infrastructure/venv/lib/python3.8/site-packages/pulumi/output.py", line 174, in run
        transformed: Input[U] = func(value)
      File "./digitalocean/docker_registry.py", line 42, in print_dc
        message_bytes = dc.encode('ascii')
    AttributeError: 'NoneType' object has no attribute 'encode'
    error: an unhandled error occurred: Program exited with non-zero exit code: 1

I tried other idea that I found from the slack https://pulumi-community.slack.com/archives/C84L4E3N1/p1596457104392200?thread_ts=1596452646.389800&cid=C84L4E3N1 however same result.
Am I doing something ? or could it be they are a mapping error on the python property naming. (edited)

I think I have been able to reproduce the bug with the below unit test. which is failing with the error

FAILED [100%]
venv/lib/python3.8/site-packages/pulumi/runtime/mocks.py:35 (test_can_create_kubernetes)
None != This is my credential

Expected :This is my credential
Actual   :None
from datetime import datetime

import pulumi
from pulumi_digitalocean import ContainerRegistryDockerCredentials

class MyMocks(pulumi.runtime.Mocks):
    def new_resource(self, type_, name, inputs, provider, id_):
        if type == 'digitalocean:index/containerRegistryDockerCredentials:ContainerRegistryDockerCredentials':
            return [
                name,
                {
                    "registryName": inputs["registryName"],
                    "dockerCredentials": "This is my credential"
                },
            ]

        return [name + "_id", inputs]

    def call(self, token, args, provider):
        return {}


pulumi.runtime.set_mocks(MyMocks())


@pulumi.runtime.test
def test_registry_name_set():
    registyr_name = "my-registry"
    kb = ContainerRegistryDockerCredentials("tet", registry_name=registyr_name )

    def check_project_name(args):
        assert args == registyr_name

    return kb.registry_name.apply(check_project_name)

@pulumi.runtime.test
def test_contain_docker_credential():
    registyr_name = "my-registry"
    kb = ContainerRegistryDockerCredentials("tet", registry_name=registyr_name )

    def check_project_name(args):
        assert args == "This is my credential"

    return kb.docker_credentials.apply(check_project_name)
@leezen
Copy link

leezen commented Aug 28, 2020

I think there's a mistake in your unit test:

        if type == 'digitalocean:index/containerRegistryDockerCredentials:ContainerRegistryDockerCredentials':

should be type_ at which point, the test will work.

I believe you're actually running into #124

Can you please try passing in expiry_seconds that's less than 50 years?

@davzucky
Copy link
Author

Thank you @leezen for your reply.
I will check my test again :-)
thank you for the link, Indeed, adding a time on the input solved the problem. I'm able now to publish the token to my kubernetes cluster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants