Skip to content

Commit f49a3fa

Browse files
committed
Fix binding image fetch and add test
1 parent c65edc9 commit f49a3fa

7 files changed

Lines changed: 119 additions & 7 deletions

File tree

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ fullrelease: ## Tag+push openrun, pkg/binding and all bindings under one version
180180
> echo "Error: bindings tags for v$$version already exist:" $$(git -C ../bindings tag -l "*/v$$version")
181181
> exit 1
182182
> fi
183-
> # openrun server + pkg/binding SDK: tag and push. The SDK tag must be on the
184-
> # remote before the bindings release, whose go mod tidy resolves it.
183+
> # openrun server + pkg/binding SDK: tag, then push the current branch and
184+
> # both tags. The SDK tag must be on the remote before the bindings release,
185+
> # whose go mod tidy resolves it.
185186
> git tag -a "v$$version" -m "Release v$$version"
186187
> git tag -a "pkg/binding/v$$version" -m "Release pkg/binding/v$$version"
187-
> git push origin "v$$version" "pkg/binding/v$$version"
188+
> git push origin HEAD "v$$version" "pkg/binding/v$$version"
188189
> # Bindings: update every provider module to the new SDK version, tag each
189190
> # module and push; the bindings release workflow builds and publishes each
190191
> # provider (binaries + OCI image) from its pushed tag

deploy/obs/update_obs.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# OBS_PROJECT target OBS project (default: home:ajayvk:openrun)
1111
# DRY_RUN=1 prepare everything and show the pending change, skip commit
1212
#
13-
# Requires: osc with credentials configured, go >= version in go.mod, git.
13+
# Requires: osc with credentials configured, the Go minor version in go.mod, git.
1414

1515
set -euo pipefail
1616

@@ -54,10 +54,14 @@ mv "$WORK/embed.go" internal/server/list_apps/embed.go
5454
rm -rf apps
5555

5656
# Distro toolchains lag behind Go patch releases; the minor version is what
57-
# actually gates the language level, so drop the patch from the go directive.
57+
# actually gates the language level, so drop the patch from the main module and
58+
# local module dependencies before creating vendor metadata.
5859
echo "==> Relaxing go.mod patch version and vendoring modules"
59-
sed -E 's/^go ([0-9]+\.[0-9]+)\.[0-9]+$/go \1/' go.mod > go.mod.new && mv go.mod.new go.mod
60-
go mod vendor
60+
for mod_file in go.mod pkg/binding/go.mod; do
61+
sed -E 's/^go ([0-9]+\.[0-9]+)\.[0-9]+$/go \1/' "$mod_file" > "$mod_file.new"
62+
mv "$mod_file.new" "$mod_file"
63+
done
64+
GOTOOLCHAIN=local go mod vendor
6165
CGO_ENABLED=0 GOTOOLCHAIN=local go build -mod=vendor -o /dev/null ./cmd/openrun
6266

6367
echo "==> Creating source tarball"

tests/kube_bindings/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM scratch
2+
COPY openrun-binding-fixture-linux /openrun-binding-fixture
3+
ENTRYPOINT ["/openrun-binding-fixture"]
17.5 MB
Binary file not shown.
18.1 MB
Binary file not shown.

tests/run_cli_tests.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,29 @@ if [[ -n "$KUBE_REGISTRY_URL" ]] && contains_any "test_kubernetes.yaml"; then
748748
kubectl create namespace "$KUBE_TEST_NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -
749749
kubectl create namespace "${KUBE_TEST_NAMESPACE}-apps" --dry-run=client -o yaml | kubectl apply -f -
750750

751+
# OCI binding provider distribution test setup: the fixture provider is
752+
# built once for the host (registered with the local server through
753+
# bindings.preinstalled_dir, as the chart's shared volume would be) and once
754+
# for the cluster platform, packaged as a FROM scratch image and pushed to
755+
# the test registry (pulled by the init container in test_kubernetes.yaml).
756+
KUBE_BINDINGS_DIR="$(pwd)/kube_bindings"
757+
rm -rf "$KUBE_BINDINGS_DIR"
758+
mkdir -p "$KUBE_BINDINGS_DIR/preinstalled"
759+
(cd ../internal/bindings/testdata/fixtureprovider && \
760+
GOWORK=off CGO_ENABLED=0 go build -o "$KUBE_BINDINGS_DIR/preinstalled/openrun-binding-fixture" .)
761+
KUBE_NODE_ARCH=$(kubectl get nodes -o jsonpath='{.items[0].status.nodeInfo.architecture}')
762+
(cd ../internal/bindings/testdata/fixtureprovider && \
763+
GOWORK=off CGO_ENABLED=0 GOOS=linux GOARCH="$KUBE_NODE_ARCH" go build -o "$KUBE_BINDINGS_DIR/openrun-binding-fixture-linux" .)
764+
cat <<EOF > "$KUBE_BINDINGS_DIR/Dockerfile"
765+
FROM scratch
766+
COPY openrun-binding-fixture-linux /openrun-binding-fixture
767+
ENTRYPOINT ["/openrun-binding-fixture"]
768+
EOF
769+
export KUBE_BINDING_IMAGE="$KUBE_REGISTRY_URL/openrun-binding-fixture:cli-test"
770+
$CONTAINER_TOOL build --platform "linux/$KUBE_NODE_ARCH" -q -t "$KUBE_BINDING_IMAGE" "$KUBE_BINDINGS_DIR"
771+
$CONTAINER_TOOL push "$KUBE_BINDING_IMAGE"
772+
export KUBE_TEST_NAMESPACE
773+
751774
cat <<EOF > config_k8s.toml
752775
[http]
753776
port = $K8S_HTTP_PORT
@@ -762,6 +785,9 @@ use_node_port = true
762785
[registry]
763786
url="$KUBE_REGISTRY_URL"
764787
insecure = true
788+
[bindings]
789+
preinstalled_dir = "$KUBE_BINDINGS_DIR/preinstalled"
790+
disable_install = true
765791
[app_config]
766792
container.health_attempts_after_startup = 20
767793
container.health_timeout_secs = 1
@@ -774,6 +800,12 @@ container.status_check_interval_secs = 60
774800
EOF
775801

776802
rm -rf metadata run/openrun.sock
803+
# The CLI commands in test_kubernetes.yaml run with CL_CONFIG_FILE=openrun.toml
804+
# (commander replaces the environment with the yaml env map). In a full run the
805+
# main test block has already written openrun.toml; create an empty one for
806+
# standalone runs (`run_cli_tests.sh --kube-registry ... test_kubernetes.yaml`)
807+
# so the CLI does not fail parsing a missing config file.
808+
[[ -f openrun.toml ]] || : > openrun.toml
777809
CL_CONFIG_FILE=config_k8s.toml GOCOVERDIR=$GOCOVERDIR ../openrun server start &
778810
wait_for_http "$K8S_HTTP_PORT"
779811
wait_for_socket

tests/test_kubernetes.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
config:
22
env:
33
CL_CONFIG_FILE: openrun.toml
4+
# commander replaces the process environment with this map; OPENRUN_HOME
5+
# anchors the CLI's socket/config resolution to the tests dir, and
6+
# PATH/HOME are needed for kubectl (binary lookup + kubeconfig)
7+
OPENRUN_HOME: .
8+
PATH: ${PATH}
9+
HOME: ${HOME}
410
HTTP_PORT: ${HTTP_PORT}
511
GOCOVERDIR: ${GOCOVERDIR}/../client
12+
KUBE_BINDING_IMAGE: ${KUBE_BINDING_IMAGE}
13+
KUBE_TEST_NAMESPACE: ${KUBE_TEST_NAMESPACE}
614
tests:
715
kubernetes010: # setup flask app
816
command: rm -rf ./flaskapp && mkdir flaskapp && cp flask.py flaskapp/app.py
@@ -127,3 +135,67 @@ tests:
127135
kubernetes823: # health endpoint still serves the old, working version
128136
command: curl -sS localhost:${HTTP_PORT}/kube_verify
129137
stdout: "ok"
138+
139+
# Out-of-process binding providers, OCI distribution path: the harness built
140+
# the fixture provider into bindings.preinstalled_dir (as the Helm chart's
141+
# init containers populate the shared volume) and pushed it as a FROM
142+
# scratch image to the test registry.
143+
kubernetes900: # preinstalled provider is registered: its service type works
144+
command: ../openrun service create --config url=fixture://kube fixture/kfx1
145+
stdout: "Service fixture/kfx1 created"
146+
kubernetes901: # binding create goes through the preinstalled provider
147+
command: ../openrun binding create fixture/kfx1 /kube_fx1
148+
stdout: "Binding /kube_fx1 created"
149+
kubernetes902: # run-command round trip through the provider process
150+
command: ../openrun binding run-command /kube_fx1 "echo:oci-ok" | jq -r '.echo'
151+
stdout: "oci-ok"
152+
kubernetes903: # disable_install rejects imperative provider install
153+
command: ../openrun provider install fixture --version v0.1.0
154+
stderr: "provider install is disabled"
155+
exit-code: 1
156+
kubernetes904: # disable_install rejects imperative provider uninstall
157+
command: ../openrun provider uninstall fixture
158+
stderr: "provider uninstall is disabled"
159+
exit-code: 1
160+
kubernetes910: # in-cluster export: init container copies the provider out of the scratch image
161+
command: |
162+
kubectl apply -n ${KUBE_TEST_NAMESPACE} -f - <<EOF
163+
apiVersion: v1
164+
kind: Pod
165+
metadata:
166+
name: binding-export-test
167+
spec:
168+
restartPolicy: Never
169+
initContainers:
170+
- name: binding-provider-fixture
171+
image: ${KUBE_BINDING_IMAGE}
172+
command: ["/openrun-binding-fixture", "export", "/providers"]
173+
volumeMounts:
174+
- name: providers
175+
mountPath: /providers
176+
containers:
177+
- name: check
178+
image: busybox:1.36
179+
command: ["sh", "-c", "test -x /providers/openrun-binding-fixture && echo EXPORT_OK"]
180+
volumeMounts:
181+
- name: providers
182+
mountPath: /providers
183+
volumes:
184+
- name: providers
185+
emptyDir: {}
186+
EOF
187+
stdout: "pod/binding-export-test created"
188+
kubernetes911: # exported binary is present and executable in the shared volume
189+
command: kubectl wait -n ${KUBE_TEST_NAMESPACE} --for=jsonpath='{.status.phase}'=Succeeded pod/binding-export-test --timeout=120s && kubectl logs -n ${KUBE_TEST_NAMESPACE} binding-export-test -c check
190+
stdout: "EXPORT_OK"
191+
kubernetes912: # init container logged the export
192+
command: kubectl logs -n ${KUBE_TEST_NAMESPACE} binding-export-test -c binding-provider-fixture
193+
stdout: "exported /providers/openrun-binding-fixture"
194+
kubernetes913: # cleanup export test pod
195+
command: kubectl delete pod binding-export-test -n ${KUBE_TEST_NAMESPACE} --ignore-not-found
196+
kubernetes920: # binding delete through the provider
197+
command: ../openrun binding delete /kube_fx1
198+
stdout: "Binding /kube_fx1 deleted"
199+
kubernetes921: # service delete
200+
command: ../openrun service delete fixture/kfx1
201+
stdout: "Service fixture/kfx1 deleted"

0 commit comments

Comments
 (0)