What is the database schema?
The timoni
database schema is represented by the InstanceSchema
constant in the internal/engine/module_builder.go
file:
// InstanceSchema is the CUE schema for the instance.
// The schema is used to validate the instance configuration
// and to generate the Kubernetes resources.
const InstanceSchema = `
// The module name.
module: string
// The module version.
version: string
// The module source.
source: string
// The instance name.
name: string
// The instance namespace.
namespace: string
// The instance resources.
resources: {
// The Kubernetes resources.
[*]: {
// The kind of the Kubernetes resource.
kind: string
// The metadata of the Kubernetes resource.
metadata: {
// The name of the Kubernetes resource.
name: string
// The namespace of the Kubernetes resource.
namespace: string
// The labels of the Kubernetes resource.
labels: {
[string]: string
}
// The annotations of the Kubernetes resource.
annotations: {
[string]: string
}
}
// The spec of the Kubernetes resource.
spec: *
}
}
// The instance configuration.
config: {
// The configuration values.
[string]: *
}
`
Source: internal/engine/module_builder.go
This constant defines the structure of the instance configuration file in CUE format. timoni
uses CUE to define and validate the schema of the instance configuration. The instance schema is a CUE value that defines the structure of the instance configuration. The InstanceSchema
constant is used by the timoni
module builder to generate the instance schema file. The instance schema file is used by the timoni
CLI to validate the instance configuration and to generate the Kubernetes resources.
How do I query the database?
The timoni
CLI tool offers several commands for interacting with the inventory database.
Querying the database with timoni list
The timoni list
command queries the database and displays a list of all entries. You can use various flags to filter the results.
Example
timoni list --namespace default
This command lists all entries in the default
namespace.
Reference:
Querying the database with timoni inspect values
The timoni inspect values
command retrieves and displays all values for a specific resource.
Example
timoni inspect values --namespace default --name redis --resource redis.io/v1
This command displays all values for a resource named redis
with the Kubernetes resource type redis.io/v1
in the default
namespace.
Reference:
Querying the database with timoni mod show config
The timoni mod show config
command displays the configuration of a specific module. This command retrieves the configuration data from the inventory database.
Example
timoni mod show config --namespace default --name my-module
This command displays the configuration for the module my-module
in the default
namespace.
Reference:
Querying the database through the InstanceManager
API
The InstanceManager
API provides programmatic access to the inventory database. You can use the ListMeta()
method to retrieve a list of all inventory entries as object.ObjMetadata
objects.
Example
package main
import (
"github.com/stefanprodan/timoni/internal/runtime"
"github.com/stefanprodan/timoni/pkg/object"
)
func main() {
// Create an InstanceManager
instanceManager := runtime.NewInstanceManager(...)
// Retrieve a list of inventory entries
metas, err := instanceManager.ListMeta()
if err != nil {
// Handle error
}
// Iterate over the metadata objects
for _, meta := range metas {
// Access metadata fields
// ...
}
}
Reference: