Skip to content

Unit.set_ports is not a drop-in replacement for KubernetsServicePatch library #238

@Deezzir

Description

@Deezzir

During the migration from PodSpec to Sidecar, a weird behaviour with Unit.set_ports was raised:

  • On fresh deploy, set_ports works fine and the K8s service exposes the right ports.

But:

  • After juju refresh (of the old pattern charm), the service gets recreated (confirmed via kubectl get svc), but juju show-unit doesn’t show any open ports, and the service exposes the placeholder port - 65353
  • Running juju exec "opened_ports" inside the pod shows the ports are open (only with the updated charm).
  • We tried moving set_ports to install, config_changed, even deleting the service manually – no luck, Juju doesn’t seem to reapply the ports.

Other charms currently use the KubernetesServicePatch library, which is scheduled to be deprecated in October 2025. The library recommends switching to the aforementioned Unit.set_ports.

  • The current workaround is the new Reusable Component introduced in feat: migrate to sidecar pattern #233. This component patches the service with the provided ports using similar logic to what the deprecated library included. Note: the Unit.set_ports is still required to expose the ports on the pebble container.

Linked issue: canonical/bundle-kubeflow#1194

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions