9da206dc7c
PVCs and CloudNativePG Clusters need S3 buckets and backup schedules
provisioned consistently. This operator watches the
backups.unkin.net/{schedule,destination} annotations on those objects and
provisions everything needed to back them up, with no new CRDs.
- Add a PVC controller that provisions cephrgw ObjectStoreUser/Bucket/BucketAccess,
auto-generates a restic repo-password Secret and creates a k8up Schedule scoped
to the PVC via spec.backup.volumes[].persistentVolumeClaim.claimName.
- Add a CNPG Cluster controller that provisions the same bucket stack, idempotently
patches spec.backup.barmanObjectStore (leaving a user-set destinationPath alone
with a Warning event) and creates a ScheduledBackup.
- Resolve destinations through a ConfigMap lookup table; requeue until the
BucketAccess is Ready before creating schedule resources; own-reference created
resources and retain bucket data by default.
- Add schedule-mapping helpers (k8up 5-field/shortcut pass-through, CNPG 6-field
seconds-first) and deterministic, length-bounded name derivation.
- Add unit tests (schedule mapping, name derivation, destination resolution) and
envtest controller tests for both paths, wiring the external CRDs into envtest.
- Add kubebuilder-generated RBAC, a Dockerfile (distroless/nonroot), Woodpecker
lint/test/build pipelines and a tag-triggered image push to the artifactapi
docker-internal registry, plus a version-bump Makefile and deploy manifests.
124 lines
2.0 KiB
Go
124 lines
2.0 KiB
Go
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package mangling
|
|
|
|
import (
|
|
"bytes"
|
|
"sync"
|
|
)
|
|
|
|
const maxAllocMatches = 8
|
|
|
|
type (
|
|
// memory pools of temporary objects.
|
|
//
|
|
// These are used to recycle temporarily allocated objects
|
|
// and relieve the GC from undue pressure.
|
|
|
|
matchesPool struct {
|
|
*sync.Pool
|
|
}
|
|
|
|
buffersPool struct {
|
|
*sync.Pool
|
|
}
|
|
|
|
lexemsPool struct {
|
|
*sync.Pool
|
|
}
|
|
|
|
stringsPool struct {
|
|
*sync.Pool
|
|
}
|
|
)
|
|
|
|
var (
|
|
// poolOfMatches holds temporary slices for recycling during the initialism match process
|
|
poolOfMatches = matchesPool{
|
|
Pool: &sync.Pool{
|
|
New: func() any {
|
|
s := make(initialismMatches, 0, maxAllocMatches)
|
|
|
|
return &s
|
|
},
|
|
},
|
|
}
|
|
|
|
poolOfBuffers = buffersPool{
|
|
Pool: &sync.Pool{
|
|
New: func() any {
|
|
return new(bytes.Buffer)
|
|
},
|
|
},
|
|
}
|
|
|
|
poolOfLexems = lexemsPool{
|
|
Pool: &sync.Pool{
|
|
New: func() any {
|
|
s := make([]nameLexem, 0, maxAllocMatches)
|
|
|
|
return &s
|
|
},
|
|
},
|
|
}
|
|
|
|
poolOfStrings = stringsPool{
|
|
Pool: &sync.Pool{
|
|
New: func() any {
|
|
s := make([]string, 0, maxAllocMatches)
|
|
|
|
return &s
|
|
},
|
|
},
|
|
}
|
|
)
|
|
|
|
func (p matchesPool) BorrowMatches() *initialismMatches {
|
|
s := p.Get().(*initialismMatches)
|
|
*s = (*s)[:0] // reset slice, keep allocated capacity
|
|
|
|
return s
|
|
}
|
|
|
|
func (p buffersPool) BorrowBuffer(size int) *bytes.Buffer {
|
|
s := p.Get().(*bytes.Buffer)
|
|
s.Reset()
|
|
|
|
if s.Cap() < size {
|
|
s.Grow(size)
|
|
}
|
|
|
|
return s
|
|
}
|
|
|
|
func (p lexemsPool) BorrowLexems() *[]nameLexem {
|
|
s := p.Get().(*[]nameLexem)
|
|
*s = (*s)[:0] // reset slice, keep allocated capacity
|
|
|
|
return s
|
|
}
|
|
|
|
func (p stringsPool) BorrowStrings() *[]string {
|
|
s := p.Get().(*[]string)
|
|
*s = (*s)[:0] // reset slice, keep allocated capacity
|
|
|
|
return s
|
|
}
|
|
|
|
func (p matchesPool) RedeemMatches(s *initialismMatches) {
|
|
p.Put(s)
|
|
}
|
|
|
|
func (p buffersPool) RedeemBuffer(s *bytes.Buffer) {
|
|
p.Put(s)
|
|
}
|
|
|
|
func (p lexemsPool) RedeemLexems(s *[]nameLexem) {
|
|
p.Put(s)
|
|
}
|
|
|
|
func (p stringsPool) RedeemStrings(s *[]string) {
|
|
p.Put(s)
|
|
}
|