Skip to content

Commit ddfd0f7

Browse files
authored
Merge pull request #60 from kcp-dev/sdk-module
Introduce standalone SDK
2 parents 3c8f5f0 + c462a86 commit ddfd0f7

File tree

59 files changed

+611
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+611
-115
lines changed

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,18 @@ $(GIMPS):
6262
gimps \
6363
${GIMPS_VERSION}
6464

65+
# wwhrd is installed as a Go module rather than from the provided
66+
# binaries because there is no arm64 binary available from the author.
67+
6568
WWHRD = _tools/wwhrd
66-
WWHRD_VERSION = 0.4.0
69+
WWHRD_VERSION = 06b99400ca6db678386ba5dc39bbbdcdadb664ff
6770

6871
.PHONY: $(WWHRD)
6972
$(WWHRD):
70-
@hack/download-tool.sh \
71-
https://github.com/frapposelli/wwhrd/releases/download/v${WWHRD_VERSION}/wwhrd_${WWHRD_VERSION}_${GOOS}_${GOARCH}.tar.gz \
73+
@GO_MODULE=true hack/download-tool.sh \
74+
github.com/frapposelli/wwhrd \
7275
wwhrd \
73-
${WWHRD_VERSION} \
74-
wwhrd
76+
${WWHRD_VERSION}
7577

7678
BOILERPLATE = _tools/boilerplate
7779
BOILERPLATE_VERSION = 0.3.0

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/kcp-dev/api-syncagent?sort=semver)](https://img.shields.io/github/v/release/kcp-dev/api-syncagent?sort=semver)
66
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkcp-dev%2Fapi-syncagent.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkcp-dev%2Fapi-syncagent?ref=badge_shield)
77

8+
The kcp API Sync Agent is a Kubernetes controller capable of synchronizing objects from many kcp
9+
workspaces onto a single Kubernetes cluster (with kcp being the source of truth). In doing so it will
10+
move the desired state (usually the spec) of an object from kcp to the local cluster where the agent
11+
is running, and move the current object status back up into kcp. The agent can also sync so-called
12+
related objects, like a Secret belonging to a Certificate, in both directions.
13+
14+
The agent can be used to provide an API in kcp and then serving it from a remote Kubernetes cluster
15+
where the actual workload is then processed, usually by a 3rd-party operator. In many situations the
16+
synchronized objects are further processed using tools like Crossplane.
17+
18+
## Documentation
19+
20+
Please visit [https://docs.kcp.io/api-syncagent](https://docs.kcp.io/api-syncagent) for the latest
21+
documentation.
22+
823
## Troubleshooting
924

1025
If you encounter problems, please [file an issue][1].

docs/content/releasing.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Release Process
2+
3+
The guide describes how to release a new version of the api-syncagent.
4+
5+
## Prerequisites
6+
7+
1. Have all desired changes merged and/or cherrypicked into the appropriate
8+
release branch.
9+
10+
## Minor Release
11+
12+
Minor releases (0.x) are tagged directly on the `main` branch and the `v0.X.0`
13+
tag represents where the corresponding `release/v0.X` branch branches off.
14+
15+
1. Checkout the desired `main` branch commit.
16+
1. Tag the main module: `git tag -m "version 0.X" v0.X.0`
17+
1. Tag the SDK module: `git tag -m "SDK version 0.X" sdk/v0.X.0`
18+
1. Push the tags: `git push upstream v0.X.0 sdk/v0.X.0`
19+
1. Create the release branch: `git checkout -B release/v0.X`
20+
1. Push the release branch: `git push -u upstream release/v0.X`
21+
22+
## Patch Releases
23+
24+
Patch releases (v0.x.y) are tagged with in a release branch.
25+
26+
1. Checkout the desired `release/v0.X` branch commit.
27+
1. Tag the main module: `git tag -m "version 0.X.Y" v0.X.Y`
28+
1. Tag the SDK module: `git tag -m "SDK version 0.X.Y" sdk/v0.X.Y`
29+
1. Push the tags: `git push upstream v0.X.Y sdk/v0.X.Y`

docs/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ nav:
2525
- Publishing Resources: publish-resources.md
2626
- Consuming Services: consuming-services.md
2727
- FAQ: faq.md
28+
- Release Process: releasing.md
2829

2930
# Site content
3031
docs_dir: 'content'

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/kcp-dev/api-syncagent
22

33
go 1.23.0
44

5-
toolchain go1.24.0
5+
replace github.com/kcp-dev/api-syncagent/sdk => ./sdk
66

77
replace (
88
k8s.io/apiextensions-apiserver => github.com/kcp-dev/kubernetes/staging/src/k8s.io/apiextensions-apiserver v0.0.0-20250313100806-0011b8c72acd
@@ -17,8 +17,7 @@ require (
1717
github.com/go-logr/logr v1.4.2
1818
github.com/go-logr/zapr v1.3.0
1919
github.com/google/go-cmp v0.7.0
20-
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250223115924-431177b024f3
21-
github.com/kcp-dev/client-go v0.0.0-20250223133118-3dea338dc267
20+
github.com/kcp-dev/api-syncagent/sdk v0.0.0-00010101000000-000000000000
2221
github.com/kcp-dev/code-generator/v2 v2.3.1
2322
github.com/kcp-dev/kcp v0.27.1
2423
github.com/kcp-dev/kcp/sdk v0.27.1
@@ -40,7 +39,6 @@ require (
4039
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
4140
sigs.k8s.io/controller-runtime v0.18.3
4241
sigs.k8s.io/controller-tools v0.16.5
43-
sigs.k8s.io/structured-merge-diff/v4 v4.6.0
4442
sigs.k8s.io/yaml v1.4.0
4543
)
4644

@@ -61,7 +59,6 @@ require (
6159
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
6260
github.com/distribution/reference v0.6.0 // indirect
6361
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
64-
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
6562
github.com/fatih/color v1.18.0 // indirect
6663
github.com/felixge/httpsnoop v1.0.4 // indirect
6764
github.com/fsnotify/fsnotify v1.8.0 // indirect
@@ -87,6 +84,8 @@ require (
8784
github.com/inconshreveable/mousetrap v1.1.0 // indirect
8885
github.com/josharian/intern v1.0.0 // indirect
8986
github.com/json-iterator/go v1.1.12 // indirect
87+
github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250223115924-431177b024f3 // indirect
88+
github.com/kcp-dev/client-go v0.0.0-20250223133118-3dea338dc267 // indirect
9089
github.com/klauspost/compress v1.17.11 // indirect
9190
github.com/kylelemons/godebug v1.1.0 // indirect
9291
github.com/mailru/easyjson v0.9.0 // indirect
@@ -158,4 +157,5 @@ require (
158157
k8s.io/kubernetes v1.31.6 // indirect
159158
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
160159
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
160+
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
161161
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Copyright The KCP Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/

hack/reconciling.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# https://github.com/kubermatic/reconciler
1717

1818
package: reconciling
19-
boilerplate: hack/boilerplate/boilerplate.go.txt
19+
boilerplate: hack/boilerplate/generated/boilerplate.go.txt
2020
resourceTypes:
2121
# kcp-dev/v1alpha1
2222
- { package: github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1, importAlias: kcpdevv1alpha1, resourceName: APIExport }

hack/update-codegen-crds.sh

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@ set -euo pipefail
1919
cd $(dirname $0)/..
2020
source hack/lib.sh
2121

22-
sed="sed"
23-
[ "$(command -v gsed)" ] && sed="gsed"
22+
mkdir -p _tools
23+
export GOBIN=$(realpath _tools)
24+
25+
go install k8c.io/reconciler/cmd/reconciler-gen
26+
go install sigs.k8s.io/controller-tools/cmd/controller-gen
2427

2528
echodate "Generating reconciling helpers…"
2629

2730
reconcileHelpers=internal/resources/reconciling/zz_generated_reconcile.go
28-
go run k8c.io/reconciler/cmd/reconciler-gen --config hack/reconciling.yaml > $reconcileHelpers
29-
30-
currentYear=$(date +%Y)
31-
$sed -i "s/Copyright YEAR/Copyright $currentYear/g" $reconcileHelpers
32-
$sed -i "s/Copyright © YEAR/Copyright © $currentYear/g" $reconcileHelpers
31+
$GOBIN/reconciler-gen --config hack/reconciling.yaml > $reconcileHelpers
3332

3433
CRD_DIR=deploy/crd
3534
KCP_CRD_DIR="$CRD_DIR/kcp.io"
@@ -38,17 +37,14 @@ mkdir -p "$KCP_CRD_DIR"
3837

3938
echodate "Generating openAPI v3 CRDs…"
4039

41-
# this also generates the deepcopy funcs
42-
go run sigs.k8s.io/controller-tools/cmd/controller-gen \
40+
$GOBIN/controller-gen \
4341
crd \
44-
object:headerFile=./hack/boilerplate/boilerplate.go.txt \
4542
paths=./sdk/apis/... \
4643
output:crd:dir=./$KCP_CRD_DIR
4744

4845
# these are types only used for testing the syncer
49-
go run sigs.k8s.io/controller-tools/cmd/controller-gen \
46+
$GOBIN/controller-gen \
5047
crd \
51-
object:headerFile=./hack/boilerplate/boilerplate.go.txt \
5248
paths=./internal/sync/apis/... \
5349
output:crd:dir=./internal/sync/crd/
5450

hack/update-codegen-sdk.sh

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,55 @@ set -euo pipefail
1919
cd $(dirname $0)/..
2020
source hack/lib.sh
2121

22-
BOILERPLATE_HEADER="$(realpath hack/boilerplate/boilerplate.go.txt)"
22+
BOILERPLATE_HEADER="$(realpath hack/boilerplate/generated/boilerplate.go.txt)"
23+
SDK_MODULE="github.com/kcp-dev/api-syncagent/sdk"
24+
APIS_PKG="$SDK_MODULE/apis"
2325

24-
BASE=github.com/kcp-dev/api-syncagent
25-
MODULE="$BASE/sdk"
26-
SDK_DIR=sdk
27-
SDK_PKG="$MODULE"
28-
APIS_PKG="$MODULE/apis"
26+
mkdir -p _tools
27+
export GOBIN=$(realpath _tools)
2928

3029
set -x
31-
rm -rf -- $SDK_DIR/{applyconfiguration,clientset,informers,listers}
3230

33-
go run k8s.io/code-generator/cmd/applyconfiguration-gen \
31+
go install k8s.io/code-generator/cmd/applyconfiguration-gen
32+
go install k8s.io/code-generator/cmd/client-gen
33+
go install github.com/kcp-dev/code-generator/v2
34+
go install github.com/openshift-eng/openshift-goimports
35+
go install sigs.k8s.io/controller-tools/cmd/controller-gen
36+
37+
# these are types only used for testing the syncer
38+
$GOBIN/controller-gen \
39+
"object:headerFile=$BOILERPLATE_HEADER" \
40+
paths=./internal/sync/apis/...
41+
42+
cd sdk
43+
rm -rf -- applyconfiguration clientset informers listers
44+
45+
$GOBIN/controller-gen \
46+
"object:headerFile=$BOILERPLATE_HEADER" \
47+
paths=./apis/...
48+
49+
$GOBIN/applyconfiguration-gen \
3450
--go-header-file "$BOILERPLATE_HEADER" \
35-
--output-dir $SDK_DIR/applyconfiguration \
36-
--output-pkg $SDK_PKG/applyconfiguration \
37-
$APIS_PKG/syncagent/v1alpha1
51+
--output-dir applyconfiguration \
52+
--output-pkg $SDK_MODULE/applyconfiguration \
53+
./apis/...
3854

39-
go run k8s.io/code-generator/cmd/client-gen \
40-
--input-base "" \
41-
--input $APIS_PKG/syncagent/v1alpha1 \
42-
--clientset-name versioned \
55+
$GOBIN/client-gen \
4356
--go-header-file "$BOILERPLATE_HEADER" \
44-
--output-dir $SDK_DIR/clientset \
45-
--output-pkg $SDK_PKG/clientset
57+
--output-dir clientset \
58+
--output-pkg $SDK_MODULE/clientset \
59+
--clientset-name versioned \
60+
--input-base $APIS_PKG \
61+
--input syncagent/v1alpha1
4662

47-
go run github.com/kcp-dev/code-generator/v2 \
48-
"client:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG,outputPackagePath=$SDK_PKG,singleClusterClientPackagePath=$SDK_PKG/clientset/versioned,singleClusterApplyConfigurationsPackagePath=$SDK_PKG/applyconfiguration" \
49-
"informer:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG,outputPackagePath=$SDK_PKG,singleClusterClientPackagePath=$SDK_PKG/clientset/versioned" \
63+
$GOBIN/code-generator \
64+
"client:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG,outputPackagePath=$SDK_MODULE,singleClusterClientPackagePath=$SDK_MODULE/clientset/versioned,singleClusterApplyConfigurationsPackagePath=applyconfiguration" \
65+
"informer:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG,outputPackagePath=$SDK_MODULE,singleClusterClientPackagePath=$SDK_MODULE/clientset/versioned" \
5066
"lister:headerFile=$BOILERPLATE_HEADER,apiPackagePath=$APIS_PKG" \
51-
"paths=./sdk/apis/..." \
52-
"output:dir=$SDK_DIR"
67+
"paths=./apis/..." \
68+
"output:dir=."
5369

5470
# Use openshift's import fixer because gimps fails to parse some of the files;
5571
# its output is identical to how gimps would sort the imports, but it also fixes
5672
# the misplaced go:build directives.
57-
for submodule in "applyconfiguration" "clientset" "informers" "listers"; do
58-
go run github.com/openshift-eng/openshift-goimports \
59-
--module "$MODULE/$submodule" \
60-
--path "$SDK_DIR/$submodule"
61-
done
73+
$GOBIN/openshift-goimports .

hack/verify-boilerplate.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,22 @@ source hack/lib.sh
2222
make --no-print-directory _tools/boilerplate
2323

2424
echo "Checking file boilerplates…"
25+
26+
set -x
27+
2528
_tools/boilerplate \
2629
-boilerplates hack/boilerplate \
2730
-exclude .github \
2831
-exclude internal/certificates/triple \
32+
-exclude sdk/applyconfiguration \
2933
-exclude sdk/clientset \
3034
-exclude sdk/informers \
3135
-exclude sdk/listers \
3236
-exclude test/crds
37+
38+
_tools/boilerplate \
39+
-boilerplates hack/boilerplate/generated \
40+
sdk/applyconfiguration \
41+
sdk/clientset \
42+
sdk/informers \
43+
sdk/listers

0 commit comments

Comments
 (0)