Want to contribute to the Kubernetes extension? We recommend opening an issue first to discuss your proposed changes. Once aligned, refer to the guide below for development workflow.
cmd/main.go # Entry point
pkg/extension/
extension.go # Extension struct, New(), Run()
client.go # ResourceClient interface and adapter
resource.go # Resource reference parsing helpers
operations.go # Operation registration
create.go # Create handler
wait.go # Wait handler
delete.go # Delete handler
*_test.go # Unit tests
- Create
pkg/extension/<operation>.gowith your handler:
func (e *Extension) handleMyOp(ctx context.Context, req *sdk.OperationRequest) (*sdk.OperationResult, error) {
if e.client == nil {
return sdk.Failure(fmt.Errorf("kubernetes client not initialized")), nil
}
args, ok := req.Args.(map[string]any)
if !ok {
return sdk.Failure(fmt.Errorf("args must be an object")), nil
}
// Your logic here
e.LogInfo(ctx, "Operation completed", map[string]any{"key": "value"})
return sdk.Success("Done"), nil
}- Register the operation in
operations.go:
e.AddOperation(
sdk.NewOperation("myop",
sdk.WithDescription("Description of your operation"),
sdk.WithParams(jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"field": {Type: "string", Description: "Field description"},
},
Required: []string{"field"},
}),
),
e.handleMyOp,
)- Add tests in
pkg/extension/<operation>_test.gousing table-driven tests.
Run all tests:
go test ./...Run with verbose output:
go test ./... -v- Use
e.LogInfo()ande.LogError()for logging - Return
sdk.Failure(err)for errors, not Go errors - Use
parseResourceRef()for standard resource arguments - Keep handlers focused on a single responsibility