Skip to main content
Work in Progress

You are viewing development documentation built from the latest commit on main (last tag v0.2.0-rc.2, source commit 25e1a892). APIs and features are subject to change.

MariaDB Builders

Go Reference Go Reference

The mariadb package provides the generated constructors for the MariaDB operator (k8s.mariadb.com/v1alpha1) kinds. It is the canonical entry point for building MariaDB, its backups, restores, SQL jobs and SQL objects in kure. The Go types come from github.com/mariadb-operator/mariadb-operator/v26/api/v1alpha1, at the version kure’s go.mod pins.

Overview

Every kind this package covers is namespaced and takes (name, namespace):

ResourcePurpose
MariaDBA MariaDB server: single instance, replication or Galera.
BackupA logical backup, once or on a schedule.
PhysicalBackupA physical backup or volume snapshot, once or on a schedule.
RestoreA restore from a Backup or from object storage.
PointInTimeRecoveryThe binary-log archive a point-in-time restore reads.
SqlJobA SQL script run against a MariaDB, once or on a schedule.
Database, User, GrantSQL objects the operator keeps in a MariaDB.
ConnectionA Secret with connection details for an application.
ExternalMariaDBA MariaDB server outside the cluster, for the other kinds to point at.

MaxScale is not covered. It is the one other kind of the group: kure does not register it in its scheme and generates no constructor for it. A caller that needs one builds the upstream mariadbv1alpha1.MaxScale type directly.

Each block on this page is the body of an Example function in example_test.go, which go test runs: it imports this package as mariadb, the upstream API as mariadbv1alpha1 "github.com/mariadb-operator/mariadb-operator/v26/api/v1alpha1", k8s.io/apimachinery/pkg/api/resource, k8s.io/utils/ptr, github.com/go-kure/kure/pkg/kubernetes, and fmt for the line that prints what the example built.

Constructors

Every kind this package registers has a generated Create<Kind> wrapper in zz_generated_create.go, produced from the scheme by pkg/kubernetes/internal/gen (make gen-builders, checked by make check-builders in CI). A wrapper delegates to kubernetes.Create[T] and emits TypeMeta and identity only: no default, no label, no spec value. The spec is the caller’s own field assignment:

db := mariadb.CreateMariaDB("mariadb", "databases")
db.Spec.Replicas = 3
db.Spec.Storage = mariadbv1alpha1.Storage{Size: ptr.To(resource.MustParse("10Gi"))}
db.Spec.Galera = &mariadbv1alpha1.Galera{Enabled: true}

kubernetes.AddLabel(db, "app", "shop")
fmt.Println(db.APIVersion, db.Kind, db.Namespace+"/"+db.Name, db.Spec.Replicas, db.Spec.Storage.Size)

The package has no Set* or Add* helpers: no field of these kinds needs one that the builder contract admits. Labels and annotations use the generic kubernetes.AddLabel and kubernetes.AddAnnotation.

The upstream structs embed several sub-structs by value, so a zero sub-struct is still written out: a MariaDB with Galera: &Galera{Enabled: true} serializes galera.agent: {} and galera.initContainer.image: "". The operator’s CRD admits these, and testdata/mariadb.yaml shows the exact output.

The kinds this package registers, their scope, and what stated that scope are rows in the generated Supported kinds and field maturity tables.

SQL objects

A Database, a User and a Grant each point at their MariaDB through MariaDBRef:

ref := mariadbv1alpha1.MariaDBRef{ObjectReference: mariadbv1alpha1.ObjectReference{Name: "mariadb"}}

database := mariadb.CreateDatabase("shop", "databases")
database.Spec.MariaDBRef = ref

user := mariadb.CreateUser("shop", "databases")
user.Spec.MariaDBRef = ref
user.Spec.PasswordSecretKeyRef = &mariadbv1alpha1.SecretKeySelector{
    LocalObjectReference: mariadbv1alpha1.LocalObjectReference{Name: "shop-db"},
    Key:                  "password",
}

grant := mariadb.CreateGrant("shop", "databases")
grant.Spec.MariaDBRef = ref
grant.Spec.Privileges = []string{"ALL PRIVILEGES"}
grant.Spec.Database = "shop"
grant.Spec.Username = "shop"

fmt.Println(database.Kind, user.Kind, grant.Kind, grant.Spec.Privileges[0])

Validation

The golden tests (golden_test.go) build a MariaDB, a Backup, a PhysicalBackup, a Restore and a SqlJob, and hold each one to the CustomResourceDefinition the pinned operator release ships before comparing it with its fixture under testdata/.