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.
126 lines
4.3 KiB
Go
126 lines
4.3 KiB
Go
package pflag
|
|
|
|
// -- stringArray Value
|
|
type stringArrayValue struct {
|
|
value *[]string
|
|
changed bool
|
|
}
|
|
|
|
func newStringArrayValue(val []string, p *[]string) *stringArrayValue {
|
|
ssv := new(stringArrayValue)
|
|
ssv.value = p
|
|
*ssv.value = val
|
|
return ssv
|
|
}
|
|
|
|
func (s *stringArrayValue) Set(val string) error {
|
|
if !s.changed {
|
|
*s.value = []string{val}
|
|
s.changed = true
|
|
} else {
|
|
*s.value = append(*s.value, val)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *stringArrayValue) Append(val string) error {
|
|
*s.value = append(*s.value, val)
|
|
return nil
|
|
}
|
|
|
|
func (s *stringArrayValue) Replace(val []string) error {
|
|
out := make([]string, len(val))
|
|
for i, d := range val {
|
|
out[i] = d
|
|
}
|
|
*s.value = out
|
|
return nil
|
|
}
|
|
|
|
func (s *stringArrayValue) GetSlice() []string {
|
|
out := make([]string, len(*s.value))
|
|
for i, d := range *s.value {
|
|
out[i] = d
|
|
}
|
|
return out
|
|
}
|
|
|
|
func (s *stringArrayValue) Type() string {
|
|
return "stringArray"
|
|
}
|
|
|
|
func (s *stringArrayValue) String() string {
|
|
str, _ := writeAsCSV(*s.value)
|
|
return "[" + str + "]"
|
|
}
|
|
|
|
func stringArrayConv(sval string) (interface{}, error) {
|
|
sval = sval[1 : len(sval)-1]
|
|
// An empty string would cause a array with one (empty) string
|
|
if len(sval) == 0 {
|
|
return []string{}, nil
|
|
}
|
|
return readAsCSV(sval)
|
|
}
|
|
|
|
// GetStringArray return the []string value of a flag with the given name
|
|
func (f *FlagSet) GetStringArray(name string) ([]string, error) {
|
|
val, err := f.getFlagType(name, "stringArray", stringArrayConv)
|
|
if err != nil {
|
|
return []string{}, err
|
|
}
|
|
return val.([]string), nil
|
|
}
|
|
|
|
// StringArrayVar defines a string flag with specified name, default value, and usage string.
|
|
// The argument p points to a []string variable in which to store the values of the multiple flags.
|
|
// The value of each argument will not try to be separated by comma. Use a StringSlice for that.
|
|
func (f *FlagSet) StringArrayVar(p *[]string, name string, value []string, usage string) {
|
|
f.VarP(newStringArrayValue(value, p), name, "", usage)
|
|
}
|
|
|
|
// StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
|
|
func (f *FlagSet) StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) {
|
|
f.VarP(newStringArrayValue(value, p), name, shorthand, usage)
|
|
}
|
|
|
|
// StringArrayVar defines a string flag with specified name, default value, and usage string.
|
|
// The argument p points to a []string variable in which to store the value of the flag.
|
|
// The value of each argument will not try to be separated by comma. Use a StringSlice for that.
|
|
func StringArrayVar(p *[]string, name string, value []string, usage string) {
|
|
CommandLine.VarP(newStringArrayValue(value, p), name, "", usage)
|
|
}
|
|
|
|
// StringArrayVarP is like StringArrayVar, but accepts a shorthand letter that can be used after a single dash.
|
|
func StringArrayVarP(p *[]string, name, shorthand string, value []string, usage string) {
|
|
CommandLine.VarP(newStringArrayValue(value, p), name, shorthand, usage)
|
|
}
|
|
|
|
// StringArray defines a string flag with specified name, default value, and usage string.
|
|
// The return value is the address of a []string variable that stores the value of the flag.
|
|
// The value of each argument will not try to be separated by comma. Use a StringSlice for that.
|
|
func (f *FlagSet) StringArray(name string, value []string, usage string) *[]string {
|
|
p := []string{}
|
|
f.StringArrayVarP(&p, name, "", value, usage)
|
|
return &p
|
|
}
|
|
|
|
// StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
|
|
func (f *FlagSet) StringArrayP(name, shorthand string, value []string, usage string) *[]string {
|
|
p := []string{}
|
|
f.StringArrayVarP(&p, name, shorthand, value, usage)
|
|
return &p
|
|
}
|
|
|
|
// StringArray defines a string flag with specified name, default value, and usage string.
|
|
// The return value is the address of a []string variable that stores the value of the flag.
|
|
// The value of each argument will not try to be separated by comma. Use a StringSlice for that.
|
|
func StringArray(name string, value []string, usage string) *[]string {
|
|
return CommandLine.StringArrayP(name, "", value, usage)
|
|
}
|
|
|
|
// StringArrayP is like StringArray, but accepts a shorthand letter that can be used after a single dash.
|
|
func StringArrayP(name, shorthand string, value []string, usage string) *[]string {
|
|
return CommandLine.StringArrayP(name, shorthand, value, usage)
|
|
}
|