This message was deleted.
# general
s
This message was deleted.
p
I’d need to check that but I guess there might be another Ingress class in from
pulumi_kubernetes.networking.v1.outputs
basically, the error looks pretty self-explaining:
Copy code
TypeError: __init__() takes 1 positional argument but 2 positional arguments (and 2 keyword-only arguments) were given
However, your Ingress object creation looks pretty good to me (without looking at the docs/source code) so I’m guessing it’s not the Ingress you are looking for 😄
Copy code
import pulumi
from pulumi_kubernetes.apps.v1 import Deployment, DeploymentSpecArgs
from pulumi_kubernetes.core.v1 import (
    ContainerArgs,
    PodSpecArgs,
    PodTemplateSpecArgs,
    Service,
    ServicePortArgs,
    ServiceSpecArgs,
)
from pulumi_kubernetes.meta.v1 import LabelSelectorArgs, ObjectMetaArgs
from pulumi_kubernetes.networking.v1 import (
    HTTPIngressPathArgs,
    HTTPIngressRuleValueArgs,
    Ingress,
    IngressBackendArgs,
    IngressRuleArgs,
    IngressServiceBackendArgs,
    IngressSpecArgs,
    ServiceBackendPortArgs,
)

app_labels = {"app": "strapi"}

deployment = Deployment(
    "strapi",
    spec=DeploymentSpecArgs(
        selector=LabelSelectorArgs(match_labels=app_labels),
        replicas=2,
        template=PodTemplateSpecArgs(
            metadata=ObjectMetaArgs(labels=app_labels),
            spec=PodSpecArgs(
                containers=[ContainerArgs(name="nginx", image="strapi/strapi")]
            ),
        ),
    ),
)

pulumi.export("name", deployment.metadata["name"])

strapiService = Service(
    "strapiService",
    api_version="v1",
    kind="Service",
    metadata=ObjectMetaArgs(
        name="strapi",
    ),
    spec=ServiceSpecArgs(
        selector=app_labels,
        ports=[
            ServicePortArgs(
                protocol="TCP",
                port=80,
                target_port=1337,
            )
        ],
    ),
)

ingress = Ingress(
    "strapi",
    metadata=ObjectMetaArgs(
        name="strapi",
    ),
    spec=IngressSpecArgs(
        ingress_class_name="nginx",
        rules=[
            IngressRuleArgs(
                host="strapi.test.cluster",
                http=HTTPIngressRuleValueArgs(
                    paths=[
                        HTTPIngressPathArgs(
                            backend=IngressBackendArgs(
                                service=IngressServiceBackendArgs(
                                    name="strapi",
                                    port=ServiceBackendPortArgs(
                                        name="http", number="80"
                                    ),
                                )
                            ),
                            path_type="Prefix",
                            path="/",
                        )
                    ]
                ),
            )
        ],
    ),
)
try the above
to sum up: • try not to use
from X import *
, it might be evil as you’ve already checked • you had 2 small extra issues: ◦
rules
definition; it’s supposed to be a list, not a single object ◦ same for
paths
b
I'm totally with Jakub on not using the
from X import *
syntax, I prefer to use the more canonical imports, see here: https://github.com/jaxxstorm/pulumi-nginx-demo/blob/main/nginx-ingress/app.py
👍 2
p
@billowy-army-68599 it looks like copy’n’paste from my pulumi files 😄
even the alias is the same:
Copy code
import pulumi_kubernetes as k8s
b
great minds thank alike 😄
p
could not agree more 😄
b
I submitted a talk to PyCon about the python type system based entirely on these lessons learned, hope it gets accepted 😄
p
nice 🙂
@red-kangaroo-44125 the fixed code above tries to create some k8s resources. I haven’t run it against the real cluster but I guess it should be fine.
r
Thanks @prehistoric-activity-61023 I'll try that for my cluster and see if that works.