This repository generates Go client SDKs for Datum Cloud APIs using Kubernetes client-gen.
The SDK generator creates typed Kubernetes-style clients (clientsets, informers, listers) for Datum Cloud API resources. Each project gets its own directory with generated clients that can be imported independently.
| Project | Import Path | Upstream Module | API Groups |
|---|---|---|---|
| Activity | github.com/datum-cloud/go-sdk-generator/activity/client/clientset/versioned |
go.miloapis.com/activity |
activity |
| Milo | github.com/datum-cloud/go-sdk-generator/milo/client/clientset/versioned |
go.miloapis.com/milo |
iam, identity, infrastructure, notes, notification, quota, resourcemanager |
# Activity SDK
go get github.com/datum-cloud/go-sdk-generator/activity/client/clientset/versioned
# Milo SDK
go get github.com/datum-cloud/go-sdk-generator/milo/client/clientset/versionedpackage main
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
activityclient "github.com/datum-cloud/go-sdk-generator/activity/client/clientset/versioned"
)
func main() {
config, _ := clientcmd.BuildConfigFromFlags("", clientcmd.RecommendedHomeFile)
client, _ := activityclient.NewForConfig(config)
ctx := context.Background()
activities, _ := client.ActivityV1alpha1().Activities("default").List(ctx, metav1.ListOptions{})
for _, activity := range activities.Items {
fmt.Printf("Activity: %s\n", activity.Name)
}
}package main
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
miloclient "github.com/datum-cloud/go-sdk-generator/milo/client/clientset/versioned"
)
func main() {
config, _ := clientcmd.BuildConfigFromFlags("", clientcmd.RecommendedHomeFile)
client, _ := miloclient.NewForConfig(config)
ctx := context.Background()
// List organizations (cluster-scoped)
orgs, _ := client.ResourcemanagerV1alpha1().Organizations().List(ctx, metav1.ListOptions{})
for _, org := range orgs.Items {
fmt.Printf("Organization: %s\n", org.Name)
}
// List users (cluster-scoped)
users, _ := client.IamV1alpha1().Users().List(ctx, metav1.ListOptions{})
for _, user := range users.Items {
fmt.Printf("User: %s\n", user.Name)
}
// List projects (cluster-scoped)
projects, _ := client.ResourcemanagerV1alpha1().Projects().List(ctx, metav1.ListOptions{})
for _, project := range projects.Items {
fmt.Printf("Project: %s\n", project.Name)
}
}- Go 1.21+
- Task (optional, for running tasks)
Enter the development shell (if using Nix):
nix developOr install dependencies manually:
go mod download# Show all available tasks
task
# Sync API types from upstream modules
task sync-apis
# Generate all client code
task generate
# Generate only activity client
task generate:activity
# Generate only milo client
task generate:milo
# Clean generated files
task clean
# Run go mod tidy
task tidy
# Install code-generator tools
task install-tools-
Add the upstream module to
go.mod:go get example.com/new-project@v1.0.0
-
Add a sync function in
hack/sync-apis.sh:sync_newproject() { local version version=$(go list -m -f '{{.Version}}' example.com/new-project) local src="${GOMODCACHE}/example.com/new-project@${version}/pkg/apis/newproject" local dst="${SCRIPT_ROOT}/newproject/apis/newproject" echo "Syncing newproject APIs from ${src}..." rm -rf "${dst}" mkdir -p "${dst}" cp -r "${src}"/* "${dst}/" chmod -R u+w "${dst}" echo "Newproject APIs synced successfully" } sync_newproject
-
Add generation in
hack/update-codegen.sh:echo "Generating client for newproject..." kube::codegen::gen_client \ --output-dir "${SCRIPT_ROOT}/newproject/client" \ --output-pkg "${THIS_PKG}/newproject/client" \ --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ --with-watch \ "${SCRIPT_ROOT}/newproject/apis"
-
Run generation:
task generate
go-sdk-generator/
├── activity/
│ ├── apis/ # Synced API types
│ │ └── activity/
│ │ └── v1alpha1/
│ └── client/ # Generated clients
│ ├── clientset/versioned/ # Typed clientset
│ ├── informers/ # Shared informers
│ └── listers/ # Listers for caching
├── milo/
│ ├── apis/ # Synced API types
│ │ ├── iam/v1alpha1/
│ │ ├── identity/v1alpha1/
│ │ ├── infrastructure/v1alpha1/
│ │ ├── notes/v1alpha1/
│ │ ├── notification/v1alpha1/
│ │ ├── quota/v1alpha1/
│ │ └── resourcemanager/v1alpha1/
│ └── client/ # Generated clients
│ ├── clientset/versioned/
│ ├── informers/
│ └── listers/
├── hack/
│ ├── boilerplate.go.txt # License header
│ ├── sync-apis.sh # API sync script
│ └── update-codegen.sh # Code generation script
├── Taskfile.yaml
├── flake.nix
├── go.mod
└── go.sum
The Milo SDK provides clients for the following API groups:
| Group | Description | Example Resources |
|---|---|---|
iam.miloapis.com |
Identity and Access Management | User, Group, Role, PolicyBinding, MachineAccount |
identity.miloapis.com |
Identity providers | UserIdentity, Session |
infrastructure.miloapis.com |
Infrastructure management | ProjectControlPlane |
notes.miloapis.com |
Notes and annotations | Note, ClusterNote |
notification.miloapis.com |
Notification system | Contact, ContactGroup, Email, EmailTemplate |
quota.miloapis.com |
Resource quota management | ResourceGrant, ResourceClaim, AllowanceBucket |
resourcemanager.miloapis.com |
Resource hierarchy | Organization, Project, OrganizationMembership |
Some upstream projects like milo are built with kubebuilder and use controller-runtime clients instead of client-gen. These projects require additional processing during sync:
-
Missing
+genclientmarkers - Kubebuilder doesn't add these by default. The sync script automatically injects+genclient(and+genclient:nonNamespacedfor cluster-scoped resources) before type definitions. -
GroupVersionvsSchemeGroupVersion- Some kubebuilder projects useGroupVersionas the variable name, but client-gen expectsSchemeGroupVersion. The sync script renames these. -
Missing
Resource()function - Client-gen generated listers require aResource()function in register.go. The sync script adds this if missing.
Projects like activity that are already designed for client-gen don't need these fixes - they just copy and generate.
Apache License 2.0