Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
with:
go-version: v1.24.0
- run: make test-e2e
- run: make test-e2e-contribs

go-test:
name: go-test
Expand Down
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ LDFLAGS := \
-X k8s.io/component-base/version.gitMajor=${KUBE_MAJOR_VERSION} \
-X k8s.io/component-base/version.gitMinor=${KUBE_MINOR_VERSION} \
-X k8s.io/component-base/version.buildDate=${BUILD_DATE}

CONTRIBS ?= $(patsubst contrib/%,%,$(wildcard contrib/*))

all: build
.PHONY: all

check: verify lint test test-e2e
check: verify lint test test-e2e test-e2e-contribs
.PHONY: check

GOMODS := $(shell find . -name 'go.mod' -exec dirname {} \; | grep -v hack/tools)
Expand All @@ -123,7 +126,7 @@ ldflags:
require-%:
@if ! command -v $* 1> /dev/null 2>&1; then echo "$* not found in \$$PATH"; exit 1; fi

build: WHAT ?= ./cmd/... ./cli/cmd/... ./kcp/cmd/kcp-init/...
build: WHAT ?= ./cmd/... ./cli/cmd/... ./contrib/kcp/cmd/kcp-init/...
build: require-jq require-go require-git verify-go-versions ## Build the project
mkdir -p $(GOBIN_DIR)
set -x; for W in $(WHAT); do \
Expand Down Expand Up @@ -278,6 +281,14 @@ test-e2e: $(KCP) $(DEX) build ## Run e2e tests
echo "Waiting for kcp to be ready (check .kcp/kcp.log)." && while ! KUBECONFIG=.kcp/admin.kubeconfig kubectl get --raw /readyz &>/dev/null; do sleep 1; echo -n "."; done && echo && \
KUBECONFIG=$$PWD/.kcp/admin.kubeconfig GOOS=$(OS) GOARCH=$(ARCH) $(GO_TEST) -race -count $(COUNT) -p $(E2E_PARALLELISM) -parallel $(E2E_PARALLELISM) $(WHAT) $(TEST_ARGS)

CONTRIBS_E2E := $(patsubst %,test-e2e-contrib-%,$(CONTRIBS))

.PHONY: test-e2e-contribs $(CONTRIBS_E2E)
test-e2e-contribs: $(CONTRIBS_E2E) ## Run e2e tests for external integrations
test-e2e-contrib-kcp: build $(KCP)
$(CONTRIBS_E2E):
cd contrib/$(patsubst test-e2e-contrib-%,%,$@) && $(GO_TEST) -race -count $(COUNT) -p $(E2E_PARALLELISM) -parallel $(E2E_PARALLELISM) ./test/e2e/...

.PHONY: test
ifdef USE_GOTESTSUM
test: $(GOTESTSUM)
Expand Down Expand Up @@ -314,7 +325,7 @@ modules: ## Run go mod tidy to ensure modules are up to date
.PHONY: verify-modules
verify-modules: modules # Verify go modules are up to date
@for MOD in $(GOMODS); do \
(cd $$MOD; echo "Verifying $$MOD"; if ! git diff --quiet HEAD -- go.mod go.sum; then echo "[$$MOD] go modules are out of date, please run 'make modules'"; exit 1; fi; ) \
(cd $$MOD; echo "Verifying $$MOD"; if ! git diff --quiet HEAD -- go.mod go.sum; then git diff -- go.mod go.sum; echo "[$$MOD] go modules are out of date, please run 'make modules'"; exit 1; fi; ) \

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this because a verify CI job failed without any indication what is different. This way we'll at least see why the modules are different.

done

.PHONY: verify
Expand Down
11 changes: 4 additions & 7 deletions kcp/Makefile → contrib/kcp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@
# We need bash for some conditional logic below.
SHELL := /usr/bin/env bash -e

GO_INSTALL = ../hack/go-install.sh

ROOT_DIR=$(abspath ..)
TOOLS_DIR=../hack/tools
TOOLS_GOBIN_DIR := $(abspath $(TOOLS_DIR))
GOBIN_DIR=$(abspath ../bin )
ROOT_DIR=$(abspath ../..)
GO_INSTALL = $(ROOT_DIR)/hack/go-install.sh
TOOLS_GOBIN_DIR = $(ROOT_DIR)/hack/tools
GOBIN_DIR = $(ROOT_DIR)/bin
PATH := $(GOBIN_DIR):$(TOOLS_GOBIN_DIR):$(PATH)
TMPDIR := $(shell mktemp -d)

Expand Down Expand Up @@ -48,7 +46,6 @@ require-%:
$(KCP_APIGEN_GEN):
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/kcp-dev/kcp/sdk/cmd/apigen $(KCP_APIGEN_BIN) $(KCP_APIGEN_VER)


# KCP runtime targets
run-kcp: $(KCP) ## Start KCP server
$(KCP) start -v=8
Expand Down
38 changes: 20 additions & 18 deletions kcp/README.md → contrib/kcp/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# kcp
# kcp

kcp folder contains isolated set of tooling to bootstrap the kube-bind to allow it to work with kcp instance.
kcp folder contains isolated set of tooling to bootstrap the kube-bind to allow it to work with kcp instance.
It is split into separate package to avoid vendoring pollution.

kcp requires initial setup to be run before it can be used.
kcp requires initial setup to be run before it can be used.
This includes setting up workspace/provider and setting up all the APIResourceSchemas and APIExports.

It was its own GO module to avoid kcp dependencies in the main kube-bind module.
Expand All @@ -23,18 +23,19 @@ It will do the following:

# How to run

1. Start kcp
2. Bootstrap kcp:
1. Start dex
2. Start kcp
3. Bootstrap kcp:
```bash
cp .kcp/admin.kubeconfig .kcp/backend.kubeconfig
export KUBECONFIG=.kcp/backend.kubeconfig
./bin/kcp-init --kcp-kubeconfig $KUBECONFIG
```
3. Run the backend:
4. Run the backend:
```
k ws use :root:kube-bind

bin/backend \
./bin/backend \
--multicluster-runtime-provider kcp \
--server-url=$(kubectl get apiexportendpointslice kube-bind.io -o jsonpath="{.status.endpoints[0].url}") \
--oidc-issuer-client-secret=ZXhhbXBsZS1hcHAtc2VjcmV0 \
Expand All @@ -49,15 +50,15 @@ bin/backend \
```


4. Copy the kubeconfig to the provider and create provider workspace:
5. Copy the kubeconfig to the provider and create provider workspace:
```bash
cp .kcp/admin.kubeconfig .kcp/provider.kubeconfig
export KUBECONFIG=.kcp/provider.kubeconfig
k ws use :root
kubectl ws create provider --enter
```

5. Bind the APIExport to the workspace
6. Bind the APIExport to the provider workspace
```bash
kubectl kcp bind apiexport root:kube-bind:kube-bind.io --accept-permission-claim clusterrolebindings.rbac.authorization.k8s.io \
--accept-permission-claim clusterroles.rbac.authorization.k8s.io \
Expand All @@ -68,13 +69,14 @@ kubectl kcp bind apiexport root:kube-bind:kube-bind.io --accept-permission-claim
--accept-permission-claim namespaces.core \
--accept-permission-claim roles.rbac.authorization.k8s.io \
--accept-permission-claim rolebindings.rbac.authorization.k8s.io \
--accept-permission-claim apiresourceschemas.apis.kcp.io
--accept-permission-claim apiresourceschemas.apis.kcp.io
```

7. Create CRD:
7. Create CRD in provider:
```bash
kubectl create -f kcp/deploy/examples/apiexport.yaml
kubectl create -f kcp/deploy/examples/apiresourceschema.yaml
kubectl create -f kcp/deploy/examples/apiexport.yaml
kubectl create -f kcp/deploy/examples/apiresourceschema-cowboys.yaml
kubectl create -f kcp/deploy/examples/apiresourceschema-sheriffs.yaml
# recursive bind
kubectl kcp bind apiexport root:provider:cowboys-stable
```
Expand All @@ -84,7 +86,7 @@ kubectl kcp bind apiexport root:provider:cowboys-stable
```bash
kubectl get logicalcluster
# NAME PHASE URL AGE
# cluster Ready https://192.168.2.166:6443/clusters/2xh2v3gzjhn4tmve
# cluster Ready https://192.168.2.166:6443/clusters/2xh2v3gzjhn4tmve
```

9. Now we gonna initiate consumer:
Expand All @@ -101,7 +103,7 @@ kubectl ws create consumer --enter
./bin/kubectl-bind http://127.0.0.1:8080/clusters/2vgrh380y0cq38du/exports --dry-run -o yaml > apiserviceexport.yaml

# Extract secret for binding process. Note that secret name is not the same as output from command above. Check secret
# name by running `kubectl get secret -n kube-bind`
# name by running `kubectl get secret -n kube-bind`
kubectl get secret kubeconfig-wvvsb -n kube-bind -o jsonpath='{.data.kubeconfig}' | base64 -d > remote.kubeconfig

./bin/kubectl-bind apiservice --remote-kubeconfig remote.kubeconfig -f apiserviceexport.yaml --skip-konnector --remote-namespace kube-bind-m5zx4
Expand Down Expand Up @@ -137,9 +139,9 @@ kubectl apply -f kcp/deploy/examples/cowboy.yaml
## Debug

```bash
cp .kcp/admin.kubeconfig .kcp/debug.kubeconfig
cp .kcp/admin.kubeconfig .kcp/debug.kubeconfig
export KUBECONFIG=.kcp/debug.kubeconfig
k ws use :root:kube-bind

k -s "$(kubectl get apiexportendpointslice kube-bind.io -o jsonpath="{.status.endpoints[0].url}")/clusters/*" api-resources
k -s "$(kubectl get apiexportendpointslice kube-bind.io -o jsonpath="{.status.endpoints[0].url}")/clusters/*" get crd
k -s "$(kubectl get apiexportendpointslice kube-bind.io -o jsonpath="{.status.endpoints[0].url}")/clusters/*" api-resources
k -s "$(kubectl get apiexportendpointslice kube-bind.io -o jsonpath="{.status.endpoints[0].url}")/clusters/*" get crd
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions kcp/go.mod → contrib/kcp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ module github.com/kube-bind/kube-bind/kcp

go 1.24.0

replace github.com/kube-bind/kube-bind => ../
replace github.com/kube-bind/kube-bind => ../../

replace github.com/kube-bind/kube-bind/sdk => ../sdk
replace github.com/kube-bind/kube-bind/sdk => ../../sdk

replace github.com/kube-bind/kube-bind/cli => ../cli
replace github.com/kube-bind/kube-bind/cli => ../../cli

require (
github.com/kcp-dev/client-go v0.0.0-20250728134101-0355faa9361b
github.com/kcp-dev/kcp v0.28.0
github.com/kcp-dev/kcp/sdk v0.28.0
github.com/kcp-dev/kcp v0.28.1
github.com/kcp-dev/kcp/sdk v0.28.1
github.com/kcp-dev/logicalcluster/v3 v3.0.5
github.com/spf13/pflag v1.0.7
k8s.io/apiextensions-apiserver v0.33.3
Expand Down Expand Up @@ -95,7 +95,7 @@ require (
golang.org/x/time v0.11.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
google.golang.org/grpc v1.69.2 // indirect
google.golang.org/grpc v1.70.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions kcp/go.sum → contrib/kcp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250728122101-adbf20db3e51 h1:l38RD
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250728122101-adbf20db3e51/go.mod h1:rF1jfvUfPjFXs+HV/LN1BtPzAz1bfjJOwVa+hAVfroQ=
github.com/kcp-dev/client-go v0.0.0-20250728134101-0355faa9361b h1:2LGrXvY9sc4l5yjKIbMZ86GEou7NyrHhA4qBPaeFfxs=
github.com/kcp-dev/client-go v0.0.0-20250728134101-0355faa9361b/go.mod h1:QdO8AaGAZPr/rIZ1iVanCM3tUOiiuX897GWv7WTByLE=
github.com/kcp-dev/kcp v0.28.0 h1:J3oaOPqc4A2Q+wZveL0iVElAuOLivFmKTCpaKVx8iXA=
github.com/kcp-dev/kcp v0.28.0/go.mod h1:q28Fx8sU/KA8kz8HGwtaqA7Iom8oR90ydoPK39jMaxo=
github.com/kcp-dev/kcp/sdk v0.28.0 h1:AOgGrgpqhrplbXMSbcvjFwCqwg4UlysTwIFZ0LvFxlk=
github.com/kcp-dev/kcp/sdk v0.28.0/go.mod h1:8oZpWxkoMu2TDpx5DgdIGDigByKHKkeqVMA4GiWneoI=
github.com/kcp-dev/kcp v0.28.1 h1:T7Ky7u9hvprkGrBnKuw0QZoP8O6TCbXqJz2Kwt6Tx+o=
github.com/kcp-dev/kcp v0.28.1/go.mod h1:q28Fx8sU/KA8kz8HGwtaqA7Iom8oR90ydoPK39jMaxo=
github.com/kcp-dev/kcp/sdk v0.28.1 h1:bTtuHVjFRjbwFEqXTPxc1J1JP2Hc3mTYqQ2xfJsi16M=
github.com/kcp-dev/kcp/sdk v0.28.1/go.mod h1:8oZpWxkoMu2TDpx5DgdIGDigByKHKkeqVMA4GiWneoI=
github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20250816165010-ffe1d7c8649b h1:CyQuxPfhWg8KdwfmY5aE6KABsh/QhkDXTH2msezxCFY=
github.com/kcp-dev/kubernetes/staging/src/k8s.io/api v0.0.0-20250816165010-ffe1d7c8649b/go.mod h1:uiagPCm7MlCfQpIm2xwPTRf8727wbCZCMgHI9uHcMpg=
github.com/kcp-dev/kubernetes/staging/src/k8s.io/apiextensions-apiserver v0.0.0-20250816165010-ffe1d7c8649b h1:5SZfhKCAqq6lu+tOOf33CDGhSty9guXc90CAfQXk3bw=
Expand Down Expand Up @@ -210,8 +210,8 @@ go.opentelemetry.io/otel/metric v1.33.0 h1:r+JOocAyeRVXD8lZpjdQjzMadVZp2M4WmQ+5W
go.opentelemetry.io/otel/metric v1.33.0/go.mod h1:L9+Fyctbp6HFTddIxClbQkjtubW6O9QS3Ann/M82u6M=
go.opentelemetry.io/otel/sdk v1.33.0 h1:iax7M131HuAm9QkZotNHEfstof92xM+N8sr3uHXc2IM=
go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM=
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU=
go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=
go.opentelemetry.io/otel/trace v1.33.0 h1:cCJuF7LRjUFso9LPnEAHJDB2pqzp+hbO8eu1qqW2d/s=
go.opentelemetry.io/otel/trace v1.33.0/go.mod h1:uIcdVUZMpTAmz0tI1z04GoVSezK37CbGV4fr1f2nBck=
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
Expand Down Expand Up @@ -273,8 +273,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 h1:
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422/go.mod h1:b6h1vNKhxaSoEI+5jc3PJUCustfli/mRab7295pY7rw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 h1:3UsHvIr4Wc2aW4brOaSCmcxh9ksica6fHEr8P1XhkYw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422/go.mod h1:3ENsm/5D1mzDyhpzeRi1NR784I0BcofWBoSc5QqqMK4=
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace
set -o xtrace

if [[ -z "${MAKELEVEL:-}" ]]; then
echo 'You must invoke this script via make'
exit 1
fi

REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)

# Generate KCP API resources from CRDs
(
${KCP_APIGEN_GEN} --input-dir "${REPO_ROOT}"/deploy/crd --output-dir "${REPO_ROOT}"/kcp/deploy/resources
)
${KCP_APIGEN_GEN} --input-dir "${REPO_ROOT}"/deploy/crd --output-dir "${REPO_ROOT}"/contrib/kcp/deploy/resources
)
23 changes: 23 additions & 0 deletions contrib/kcp/test/e2e/kcp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2025 The Kube Bind Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import "testing"

func TestSkip(t *testing.T) {
t.Skip("noop so test-e2e-contribs doesn't fail")
}
2 changes: 1 addition & 1 deletion hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ for CRD in *.yaml; do
fi
done

cd ../../kcp
cd ../../contrib/kcp
make codegen