kopf icon indicating copy to clipboard operation
kopf copied to clipboard

Python 3.7.7 fails creating validating Webhooks

Open tjwilliams-bell-labs opened this issue 2 years ago • 0 comments

Long story short

When trying to configure Webhooks we get an exception: "ValueError: reuse_port not supported by socket module". After a bit of searching we came across that port re-use is only in Python 3.8 and later. We switched the image for the operator to use python 3.8.13 and the Webhook succeeds. This is just FYI as on PyPI kopf is said to run on python 3.7 and this is one part of the framework that has issues.

Kopf version

1.35

Kubernetes version

1.18

Python version

3.7.7

Code

@kopf.on.startup()
def configure(logger: kopf.ObjectLogger, settings: kopf.OperatorSettings, **_):
    """Configure validating webhook server

    kwargs = ['activity', 'logger', 'memo', 'param', 'retry', 'runtime', 'settings', 'started']
    """
    fname = f"{configure.__name__}()"
    namespace = os.getenv("NAMESPACE", "blis")
    addr = '0.0.0.0'
    port = 9443
    host = f"isi-operator.{namespace}.svc.cluster.local"
    logger.info(
        f"{fname}: Setting up kopf.WebhookAutoServer(addr={addr}, port={port}, host={host})")
    settings.admission.server = kopf.WebhookAutoServer(
        addr=addr, port=port, host=host
    )
    settings.admission.managed = 'auto.kopf.dev'

Logs

[2022-08-08 14:48:57,359] kopf._kits.webhooks  [DEBUG   ] Cluster detection failed, running a simple local server.

[2022-08-08 14:48:57,359] kopf._kits.webhooks  [DEBUG   ] Generating a self-signed certificate for HTTPS.

[2022-08-08 14:48:57,483] kopf._core.reactor.r [ERROR   ] Admission webhook server has failed: reuse_port not supported by socket module

Traceback (most recent call last):

  File "/root/miniconda3/lib/python3.7/site-packages/kopf/_cogs/aiokits/aiotasks.py", line 107, in guard

    await coro

  File "/root/miniconda3/lib/python3.7/site-packages/kopf/_core/engines/admission.py", line 259, in admission_webhook_server

    async for client_config in settings.admission.server(webhookfn):

  File "/root/miniconda3/lib/python3.7/site-packages/kopf/_kits/webhooks.py", line 611, in __call__

    async for client_config in super().__call__(fn):

  File "/root/miniconda3/lib/python3.7/site-packages/kopf/_kits/webhooks.py", line 168, in __call__

    await site.start()

  File "/root/miniconda3/lib/python3.7/site-packages/aiohttp/web_runner.py", line 128, in start

    reuse_port=self._reuse_port,

  File "/root/miniconda3/lib/python3.7/asyncio/base_events.py", line 1374, in create_server

    _set_reuseport(sock)

  File "/root/miniconda3/lib/python3.7/asyncio/base_events.py", line 89, in _set_reuseport

    raise ValueError('reuse_port not supported by socket module')

ValueError: reuse_port not supported by socket module

[2022-08-08 14:48:57,487] kopf._core.reactor.r [DEBUG   ] Credentials retriever is cancelled.

[2022-08-08 14:48:57,487] kopf._core.reactor.r [DEBUG   ] Admission validating configuration manager is cancelled.

[2022-08-08 14:48:57,488] kopf._cogs.clients.w [DEBUG   ] Stopping the watch-stream for customresourcedefinitions.v1.apiextensions.k8s.io cluster-wide.

[2022-08-08 14:48:57,488] kopf._core.reactor.r [DEBUG   ] Poster of events is cancelled.

[2022-08-08 14:48:57,488] kopf._core.reactor.r [DEBUG   ] Admission mutating configuration manager is cancelled.

Additional information

No response

tjwilliams-bell-labs avatar Aug 09 '22 15:08 tjwilliams-bell-labs