Skip to content

Crossplane Spin PoC - #641

Closed
marcelovilla wants to merge 43 commits into
mainfrom
poc/crossplane-spin
Closed

marcelovilla wants to merge 43 commits into
mainfrom
poc/crossplane-spin

Conversation

@marcelovilla

@marcelovilla marcelovilla commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

Closes

Part of #551

Description

This PR implements a data science spin PoC using Crossplane composition via a control plane project. The spin consists of the following software packs:

This PoC aims to showcase composition at three different levels:

  • Render time: wire all values known before deploying the software packs. In this case, we derive all hostnames from the single domain field and inject each pack's info (namespace, release name, service URLs) into the siblings that need them, referenced by the same variables in a single place (i.e., the composition).
  • Run time: read cluster state from resources created after deploying the software packs. In this case, z2jh, part of the data science pack, creates an API token stored in the hub secret, which is then read and injected as part of the helm values passed in the dask gateway pack as gateway.auth.jupyterhub.apiToken.
  • New resources: create new resources that are needed for the interoperability between software packs. In this case, two NetworkPolicies are created so that user pods can communicate with the dask scheduler, and so pods from dask gateway can hit the hub API.

The composition logic is written in templated yaml (see examples/crossplane/datascience-spin/functions/render-applications/01-compose.yaml.gotmpl) but could also be written in Python, Go, or KCL.

The control plane project was built and pushed to quay.io using the crossplane CLI via:

crossplane project build
crossplane project push --tag v0.1.0

The repo is specified in examples/crossplane/datascience-spin/crossplane-project.yaml

How to Test

  1. Build nic off this branch
  2. Deploy a local cluster via nic deploy
  3. Add examples/crossplane/spin.yaml to the gitops repo and commit
  4. Wait a couple minutes for ArgoCD to pick up the changes
  5. Run the temporary setup bash script outlined below
  6. Create a Keycloak user
  7. Go to the landing page, access Jupyterhub, and launch a small server
  8. Launch Nebi within Jupyterlab and create + install the following environment:
    [workspace]
    name = "dask"
    channels = ["conda-forge"]
    platforms = ["osx-arm64", "linux-64", "linux-aarch64"]
    
    [dependencies]
    python = "3.13.*"
    dask-gateway = "2026.3.*"
    distributed = "2026.3.*"
    msgpack-python = "1.1.*"
    tornado = "6.5.*"
    ipykernel = ">=6.0"
  9. Create a new notebook and select the newly created dask environment as kernel
  10. Run the following Python snippet:
from dask_gateway import Gateway

gw = Gateway()

for c in gw.list_clusters():
    gw.stop_cluster(c.name)

with gw.new_cluster(shutdown_on_close=True) as cluster:
    cluster.scale(1)
    with cluster.get_client() as client:
        print(client.submit(lambda x: x + 1, 41).result())

You should see a 42, the result of the submitted lambda, ran by a worker.

Temporary setup script

While deploying this locally, I hit some hiccups that are not related to the spin itself, but rather to some of the different components interacting here. To make sure the software packs not only deploy but are also usable, you'll need to:

  1. Setup in-cluster DNS for the platform domain (tracked by [EXPLORE] NIC should resolve external Nebari hostnames in-cluster for server-side OIDC  #607)
  2. Add a trust bundle for the self-signed certificates (tracked by Gateway certificate: add a wildcard SAN and/or a proper root CA for a stable downstream trust anchor #447)
  3. Setup gateway OIDC for nebi (tracked by SecurityPolicy OIDC issuer uses the internal Keycloak URL which is rejected by Envoy Gateway's v1.9.1 issuer validation nebari-operator#186)

Until those issues have been addressed, you can run the following script (assuming your domain is nebari.lvh.me):

#!/usr/bin/env bash
set -euo pipefail

DOMAIN="${1:-nebari.lvh.me}"
GATEWAY_SVC=$(kubectl get svc -n envoy-gateway-system -o name | grep -E 'envoy-.*nebari-gateway' | head -1 | cut -d/ -f2)
TMP=$(mktemp -d) && trap 'rm -rf "$TMP"' EXIT

# 1. In-cluster DNS
ESCAPED_DOMAIN=$(printf '%s' "${DOMAIN}" | sed 's/\./\\./g')
COREFILE=$(kubectl get cm coredns -n kube-system -o jsonpath='{.data.Corefile}')
if ! grep -qF "${ESCAPED_DOMAIN}" <<<"${COREFILE}"; then
  REWRITE="    rewrite name regex (.*)\\.${ESCAPED_DOMAIN} ${GATEWAY_SVC}.envoy-gateway-system.svc.cluster.local answer auto"
  NEW_COREFILE=$(sed "s|    kubernetes cluster.local|${REWRITE}\n    kubernetes cluster.local|" <<<"${COREFILE}")
  kubectl create cm coredns -n kube-system --from-literal=Corefile="${NEW_COREFILE}" --dry-run=client -o yaml | kubectl apply -f -
  kubectl rollout restart deploy/coredns -n kube-system
fi

# 2. Trust bundle
kubectl create ns nebi --dry-run=client -o yaml | kubectl apply -f -
kubectl create ns data-science --dry-run=client -o yaml | kubectl apply -f -
docker exec "$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')" cat /etc/ssl/certs/ca-certificates.crt > "$TMP/bundle.crt"
for s in $(kubectl get secrets -n envoy-gateway-system -o name | grep 'tls$'); do
  kubectl get "$s" -n envoy-gateway-system -o jsonpath='{.data.ca\.crt}' | base64 -d >> "$TMP/bundle.crt"; echo >> "$TMP/bundle.crt"
done
kubectl create configmap nebari-trust-bundle \
  --from-file=ca-bundle.crt="$TMP/bundle.crt" --from-file=ca-certificates.crt="$TMP/bundle.crt" \
  --dry-run=client -o yaml > "$TMP/trust-bundle.yaml"
kubectl apply --server-side --force-conflicts -n nebi -f "$TMP/trust-bundle.yaml"
kubectl apply --server-side --force-conflicts -n data-science -f "$TMP/trust-bundle.yaml"
kubectl rollout restart deploy/nebi-pack-nebari-nebi-pack -n nebi 2>/dev/null || true

# 3. Gateway OIDC for nebi
kubectl apply -f - <<EOF
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
  name: nebi-gateway-auth-stopgap
  namespace: nebi
spec:
  targetRefs:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      name: nebi-pack-nebari-nebi-pack-route
  oidc:
    provider:
      issuer: https://keycloak.${DOMAIN}/realms/nebari
      authorizationEndpoint: https://keycloak.${DOMAIN}/realms/nebari/protocol/openid-connect/auth
      tokenEndpoint: http://keycloak-keycloakx-http.keycloak.svc.cluster.local:8080/realms/nebari/protocol/openid-connect/token
    clientID: nebi-nebi-pack-nebari-nebi-pack
    clientSecret:
      name: nebi-pack-nebari-nebi-pack-oidc-client
    redirectURL: https://nebi.${DOMAIN}/oauth2/callback
    logoutPath: /oauth2/sign_out
    scopes: ["openid", "profile", "email", "groups"]
EOF

@marcelovilla
marcelovilla changed the base branch from main to fix/metallb-address-derivation August 28, 2026 14:00
Base automatically changed from fix/metallb-address-derivation to main September 3, 2026 14:44
@dcmcand

dcmcand commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Hey Marcelo,
I looked into your workarounds to see if they needed issues. Two of the four in spin.yaml don't look like they do. The nebi-pack sha-256da80 override is fixed upstream: chart 0.1.4 and main pin sha-5ca877a, which is multi-arch (amd64 + arm64), so bumping off 0.1.3 drops that override. The dask-gateway cluster image is a documented pre-release placeholder in the pack's own values.yaml rather than a bug, with dask-gateway-pack#5 covering the publish failure behind it.

The hub NetworkPolicy one does look like a real DSP bug and doesn't look like it is filed yet. I confirmed the mechanism statically against z2jh 4.4.0: the hub netpol admits http only from pods labelled hub.jupyter.org/network-access-hub: "true" (templates/hub/netpol.yaml:39-46), and the hub pod itself only carries network-access-proxy-api, network-access-proxy-http and network-access-singleuser (templates/hub/deployment.yaml:22-24), so jhub-apps calling the hub API through the Service is an unlabelled source. What I could not check without a cluster is the runtime behavior, since CNIs vary on whether pod-to-self hairpin traffic is policy-evaluated at all. You have the kindnetd repro, so would you file it against data-science-pack?

@marcelovilla

Copy link
Copy Markdown
Member Author

Hey @dcmcand, thanks for looking into it. Yes, the multi-arch images are already in place for both packs and I'm just waiting on a release to upgrade them and get rid of the overrides.

Regarding the hub network workaround, I did not file a bug because I realized nebari-dev/data-science-pack#205 was already addressing it to be able to deploy locally for the previews. See this comment for more context: nebari-dev/data-science-pack#205 (comment)

@dcmcand

dcmcand commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Marcelo, thanks for this PoC. I know you put a lot of work into it, and I personally learned a lot from it. I've opened #670 proposing a different approach, based on your work here and James's work in #549. We can discuss it in our team meeting and see which way we want to go.

Nothing here closes this PR.

@github-actions

Copy link
Copy Markdown

This pull request has had no activity for 30 days, so it has been labeled status: inactive 💤.

It will close automatically in 7 days unless something happens. A comment or a push resets the clock.

If this pull request should stay open regardless, for example long-running design work or something blocked upstream, add the status: keep open 📌 label and this bot will skip it permanently.

Closing is not final. The branch is kept, and the pull request can be reopened.

@github-actions github-actions Bot added the status: inactive 💤 No activity for 30 days; will auto-close at 37 unless updated label Oct 15, 2026
@marcelovilla marcelovilla added status: keep open 📌 Exempt from stale auto-close; this PR stays open indefinitely and removed status: inactive 💤 No activity for 30 days; will auto-close at 37 unless updated labels Oct 15, 2026
@marcelovilla

Copy link
Copy Markdown
Member Author

Closing given the consensus reached on #670 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: keep open 📌 Exempt from stale auto-close; this PR stays open indefinitely

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants