Documentation
¶
Overview ¶
Package volsync exposes the generated constructors and the admissible sugar for VolSync (volsync.backube/v1alpha1) resources: ReplicationSource and ReplicationDestination. Each constructor returns a controller-runtime object carrying identity only; the upstream volsyncv1alpha1 struct is the construction API.
A replication's mover is the upstream one-of: a pointer per arm on the spec (Restic, Rsync, RsyncTLS, Rclone, Syncthing on a source, External). Set the one you mean and leave the others nil.
rs := volsync.CreateReplicationSource("db-backup", "data")
rs.Spec = volsyncv1alpha1.ReplicationSourceSpec{
SourcePVC: "postgres-data",
Trigger: &volsyncv1alpha1.ReplicationSourceTriggerSpec{Schedule: ptr.To("@hourly")},
Restic: &volsyncv1alpha1.ReplicationSourceResticSpec{
Repository: "restic-creds",
ReplicationSourceVolumeOptions: volsyncv1alpha1.ReplicationSourceVolumeOptions{
CopyMethod: volsync.CopyMethodSnapshot,
},
},
}
AddSyncthingPeer appends to a Syncthing mover's peer list; CopyMethod and its constants re-export the upstream copy-method type.
The config-struct layer this package used to carry — ReplicationSource and ReplicationDestination taking a *Config whose Mover was a sealed SourceMover / DestinationMover sum — was retired by release 2 of the builder contract; see docs/builder-contract-release-2.md for the field-by-field mapping.
Index ¶
- Constants
- func AddSyncthingPeer(spec *volsyncv1alpha1.ReplicationSourceSyncthingSpec, address, id string, ...)
- func CreateReplicationDestination(name, namespace string) *volsyncv1alpha1.ReplicationDestination
- func CreateReplicationSource(name, namespace string) *volsyncv1alpha1.ReplicationSource
- type CopyMethod
Examples ¶
Constants ¶
const ( CopyMethodDirect = volsyncv1alpha1.CopyMethodDirect CopyMethodNone = volsyncv1alpha1.CopyMethodNone CopyMethodClone = volsyncv1alpha1.CopyMethodClone CopyMethodSnapshot = volsyncv1alpha1.CopyMethodSnapshot )
Variables ¶
This section is empty.
Functions ¶
func AddSyncthingPeer ¶
func AddSyncthingPeer(spec *volsyncv1alpha1.ReplicationSourceSyncthingSpec, address, id string, introducer bool)
AddSyncthingPeer appends a peer to a ReplicationSource's Syncthing mover spec, the value assigned to rs.Spec.Syncthing.
Example ¶
package main
import (
"fmt"
volsyncv1alpha1 "github.com/backube/volsync/api/v1alpha1"
"github.com/go-kure/kure/pkg/kubernetes/volsync"
)
func main() {
rs := volsync.CreateReplicationSource("db-backup", "data")
rs.Spec.Syncthing = &volsyncv1alpha1.ReplicationSourceSyncthingSpec{}
volsync.AddSyncthingPeer(rs.Spec.Syncthing, "tcp://peer:22000", "PEER-ID", false)
fmt.Println(rs.Spec.Syncthing.Peers[0].ID, rs.Spec.Syncthing.Peers[0].Address)
}
Output: PEER-ID tcp://peer:22000
func CreateReplicationDestination ¶
func CreateReplicationDestination(name, namespace string) *volsyncv1alpha1.ReplicationDestination
CreateReplicationDestination returns a volsync.backube/v1alpha1 ReplicationDestination carrying TypeMeta and identity only.
Example ¶
package main
import (
"fmt"
volsyncv1alpha1 "github.com/backube/volsync/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"github.com/go-kure/kure/pkg/kubernetes/volsync"
)
func main() {
capacity := resource.MustParse("10Gi")
rd := volsync.CreateReplicationDestination("db-restore", "dr")
rd.Spec = volsyncv1alpha1.ReplicationDestinationSpec{
Trigger: &volsyncv1alpha1.ReplicationDestinationTriggerSpec{Manual: "restore-1"},
Restic: &volsyncv1alpha1.ReplicationDestinationResticSpec{
Repository: "restic-creds",
ReplicationDestinationVolumeOptions: volsyncv1alpha1.ReplicationDestinationVolumeOptions{
CopyMethod: volsync.CopyMethodSnapshot,
Capacity: &capacity,
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
},
},
}
fmt.Println(rd.Spec.Trigger.Manual, rd.Spec.Restic.Capacity.String())
}
Output: restore-1 10Gi
func CreateReplicationSource ¶
func CreateReplicationSource(name, namespace string) *volsyncv1alpha1.ReplicationSource
CreateReplicationSource returns a volsync.backube/v1alpha1 ReplicationSource carrying TypeMeta and identity only.
Example ¶
package main
import (
"fmt"
"github.com/go-kure/kure/pkg/kubernetes/volsync"
)
func main() {
obj := volsync.CreateReplicationSource("db-backup", "data")
fmt.Println(obj.Kind, obj.Namespace+"/"+obj.Name)
}
Output: ReplicationSource data/db-backup
Example (Modify) ¶
package main
import (
"fmt"
volsyncv1alpha1 "github.com/backube/volsync/api/v1alpha1"
"github.com/go-kure/kure/pkg/kubernetes/volsync"
)
func main() {
rs := volsync.CreateReplicationSource("db-backup", "data")
rs.Spec.Paused = false
rs.Spec.Trigger = &volsyncv1alpha1.ReplicationSourceTriggerSpec{Manual: "go"}
fmt.Println(rs.Spec.Trigger.Manual)
}
Output: go
Example (Restic) ¶
package main
import (
"fmt"
volsyncv1alpha1 "github.com/backube/volsync/api/v1alpha1"
"k8s.io/utils/ptr"
"github.com/go-kure/kure/pkg/kubernetes/volsync"
)
func main() {
rs := volsync.CreateReplicationSource("db-backup", "data")
rs.Spec = volsyncv1alpha1.ReplicationSourceSpec{
SourcePVC: "postgres-data",
Trigger: &volsyncv1alpha1.ReplicationSourceTriggerSpec{Schedule: ptr.To("@hourly")},
Restic: &volsyncv1alpha1.ReplicationSourceResticSpec{
Repository: "restic-creds",
ReplicationSourceVolumeOptions: volsyncv1alpha1.ReplicationSourceVolumeOptions{
CopyMethod: volsync.CopyMethodSnapshot,
},
Retain: &volsyncv1alpha1.ResticRetainPolicy{
Daily: ptr.To[int32](7),
Weekly: ptr.To[int32](4),
Monthly: ptr.To[int32](12),
},
},
}
fmt.Println(rs.Spec.SourcePVC, *rs.Spec.Trigger.Schedule, rs.Spec.Restic.CopyMethod)
}
Output: postgres-data @hourly Snapshot
Types ¶
type CopyMethod ¶
type CopyMethod = volsyncv1alpha1.CopyMethodType
CopyMethod re-exports the upstream CopyMethodType for caller convenience.