From 20ea92f4bc6d2fd9e428a2b4dfaf803b816f3f5f Mon Sep 17 00:00:00 2001 From: Arnab-Baishnab-Nipun <53988882+arnab-baishnab@users.noreply.github.com> Date: Fri, 24 Jan 2025 11:38:57 +0600 Subject: [PATCH] Added archiver restore field into kubedbManifest options (#143) Signed-off-by: arnab-baishnab --- apis/addons/v1alpha1/zz_generated.deepcopy.go | 1 + apis/config/v1alpha1/zz_generated.deepcopy.go | 1 + apis/core/v1alpha1/restoresession_types.go | 18 ++++ apis/core/v1alpha1/zz_generated.deepcopy.go | 21 ++++ .../storage/v1alpha1/zz_generated.deepcopy.go | 1 + apis/zz_generated.deepcopy.go | 1 + crds/core.kubestash.com_restoresessions.yaml | 96 +++++++++++++++++++ go.mod | 4 +- go.sum | 6 +- vendor/gomodules.xyz/go-sh/README.md | 43 +++++++++ vendor/gomodules.xyz/go-sh/pipe.go | 88 ++++++++++------- vendor/gomodules.xyz/go-sh/sh.go | 1 + vendor/modules.txt | 2 +- 13 files changed, 240 insertions(+), 43 deletions(-) diff --git a/apis/addons/v1alpha1/zz_generated.deepcopy.go b/apis/addons/v1alpha1/zz_generated.deepcopy.go index e1da39968..221335083 100644 --- a/apis/addons/v1alpha1/zz_generated.deepcopy.go +++ b/apis/addons/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,5 @@ //go:build !ignore_autogenerated +// +build !ignore_autogenerated /* Copyright AppsCode Inc. and Contributors diff --git a/apis/config/v1alpha1/zz_generated.deepcopy.go b/apis/config/v1alpha1/zz_generated.deepcopy.go index 56bd12184..5dac5c136 100644 --- a/apis/config/v1alpha1/zz_generated.deepcopy.go +++ b/apis/config/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,5 @@ //go:build !ignore_autogenerated +// +build !ignore_autogenerated /* Copyright AppsCode Inc. and Contributors diff --git a/apis/core/v1alpha1/restoresession_types.go b/apis/core/v1alpha1/restoresession_types.go index ab08d6987..e050cac1c 100644 --- a/apis/core/v1alpha1/restoresession_types.go +++ b/apis/core/v1alpha1/restoresession_types.go @@ -175,6 +175,15 @@ type MSSQLServerManifestOptions struct { // +optional AuthSecretName string `json:"authSecretName,omitempty"` + // Archiver specifies whether to restore the Archiver manifest or not + // +kubebuilder:default=false + // +optional + Archiver *bool `json:"archiver,omitempty"` + + // ArchiverRef specifies the new name and namespace of the Archiver yaml after restore + // +optional + ArchiverRef *kmapi.ObjectReference `json:"archiverRef,omitempty"` + // TLSIssuerRef specifies the name of the IssuerRef used for TLS configurations for both client and server. // +optional TLSIssuerRef *core.TypedLocalObjectReference `json:"tlsIssuerRef,omitempty"` @@ -241,6 +250,15 @@ type KubeDBManifestOptions struct { // +optional AuthSecretName string `json:"authSecretName,omitempty"` + // Archiver specifies whether to restore the Archiver manifest or not + // +kubebuilder:default=false + // +optional + Archiver *bool `json:"archiver,omitempty"` + + // ArchiverRef specifies the new name and namespace of the Archiver yaml after restore + // +optional + ArchiverRef *kmapi.ObjectReference `json:"archiverRef,omitempty"` + // ConfigSecret specifies whether to restore the ConfigSecret manifest or not // +kubebuilder:default=true // +optional diff --git a/apis/core/v1alpha1/zz_generated.deepcopy.go b/apis/core/v1alpha1/zz_generated.deepcopy.go index c3b15f2ac..3b12554b4 100644 --- a/apis/core/v1alpha1/zz_generated.deepcopy.go +++ b/apis/core/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,5 @@ //go:build !ignore_autogenerated +// +build !ignore_autogenerated /* Copyright AppsCode Inc. and Contributors @@ -1292,6 +1293,16 @@ func (in *KubeDBManifestOptions) DeepCopyInto(out *KubeDBManifestOptions) { *out = new(bool) **out = **in } + if in.Archiver != nil { + in, out := &in.Archiver, &out.Archiver + *out = new(bool) + **out = **in + } + if in.ArchiverRef != nil { + in, out := &in.ArchiverRef, &out.ArchiverRef + *out = new(v1.ObjectReference) + **out = **in + } if in.ConfigSecret != nil { in, out := &in.ConfigSecret, &out.ConfigSecret *out = new(bool) @@ -1332,6 +1343,16 @@ func (in *MSSQLServerManifestOptions) DeepCopyInto(out *MSSQLServerManifestOptio *out = new(bool) **out = **in } + if in.Archiver != nil { + in, out := &in.Archiver, &out.Archiver + *out = new(bool) + **out = **in + } + if in.ArchiverRef != nil { + in, out := &in.ArchiverRef, &out.ArchiverRef + *out = new(v1.ObjectReference) + **out = **in + } if in.TLSIssuerRef != nil { in, out := &in.TLSIssuerRef, &out.TLSIssuerRef *out = new(corev1.TypedLocalObjectReference) diff --git a/apis/storage/v1alpha1/zz_generated.deepcopy.go b/apis/storage/v1alpha1/zz_generated.deepcopy.go index ff661e0ad..c59854d9d 100644 --- a/apis/storage/v1alpha1/zz_generated.deepcopy.go +++ b/apis/storage/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,5 @@ //go:build !ignore_autogenerated +// +build !ignore_autogenerated /* Copyright AppsCode Inc. and Contributors diff --git a/apis/zz_generated.deepcopy.go b/apis/zz_generated.deepcopy.go index 40d4e3503..6ee74efd5 100644 --- a/apis/zz_generated.deepcopy.go +++ b/apis/zz_generated.deepcopy.go @@ -1,4 +1,5 @@ //go:build !ignore_autogenerated +// +build !ignore_autogenerated /* Copyright AppsCode Inc. and Contributors diff --git a/crds/core.kubestash.com_restoresessions.yaml b/crds/core.kubestash.com_restoresessions.yaml index 7e9e34ece..771dc339c 100644 --- a/crds/core.kubestash.com_restoresessions.yaml +++ b/crds/core.kubestash.com_restoresessions.yaml @@ -9368,6 +9368,18 @@ spec: type: object mariaDB: properties: + archiver: + default: false + type: boolean + archiverRef: + properties: + name: + type: string + namespace: + type: string + required: + - name + type: object authSecret: default: true type: boolean @@ -9404,6 +9416,18 @@ spec: type: object mongoDB: properties: + archiver: + default: false + type: boolean + archiverRef: + properties: + name: + type: string + namespace: + type: string + required: + - name + type: object authSecret: default: true type: boolean @@ -9440,6 +9464,18 @@ spec: type: object msSQLServer: properties: + archiver: + default: false + type: boolean + archiverRef: + properties: + name: + type: string + namespace: + type: string + required: + - name + type: object authSecret: default: true type: boolean @@ -9468,6 +9504,18 @@ spec: type: object mySQL: properties: + archiver: + default: false + type: boolean + archiverRef: + properties: + name: + type: string + namespace: + type: string + required: + - name + type: object authSecret: default: true type: boolean @@ -9504,6 +9552,18 @@ spec: type: object postgres: properties: + archiver: + default: false + type: boolean + archiverRef: + properties: + name: + type: string + namespace: + type: string + required: + - name + type: object authSecret: default: true type: boolean @@ -9540,6 +9600,18 @@ spec: type: object redis: properties: + archiver: + default: false + type: boolean + archiverRef: + properties: + name: + type: string + namespace: + type: string + required: + - name + type: object authSecret: default: true type: boolean @@ -9604,6 +9676,18 @@ spec: type: object singlestore: properties: + archiver: + default: false + type: boolean + archiverRef: + properties: + name: + type: string + namespace: + type: string + required: + - name + type: object authSecret: default: true type: boolean @@ -9645,6 +9729,18 @@ spec: type: object zooKeeper: properties: + archiver: + default: false + type: boolean + archiverRef: + properties: + name: + type: string + namespace: + type: string + required: + - name + type: object authSecret: default: true type: boolean diff --git a/go.mod b/go.mod index 4c4d91658..95dc8c7d9 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( go.bytebuilders.dev/license-verifier/kubernetes v0.14.4 gocloud.dev v0.40.0 gomodules.xyz/envsubst v0.2.0 - gomodules.xyz/go-sh v0.1.0 + gomodules.xyz/go-sh v0.1.1-0.20250117070215-e08594acad2a gomodules.xyz/pointer v0.1.0 gomodules.xyz/x v0.0.17 k8s.io/api v0.30.3 @@ -174,5 +174,3 @@ require ( sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect ) - -replace gomodules.xyz/go-sh v0.1.0 => github.com/anisurrahman75/go-sh v0.0.0-20241030063656-336ab30e016a diff --git a/go.sum b/go.sum index 8d6630961..7869870f7 100644 --- a/go.sum +++ b/go.sum @@ -33,10 +33,6 @@ github.com/Azure/go-autorest/autorest/to v0.4.0/go.mod h1:fE8iZBn7LQR7zH/9XU2NcP github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU= github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= -github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= -github.com/anisurrahman75/go-sh v0.0.0-20241030063656-336ab30e016a h1:vds1Kj0c/3uTud2/W66GorqmFhPcqHteeSX+6uD3+gc= -github.com/anisurrahman75/go-sh v0.0.0-20241030063656-336ab30e016a/go.mod h1:N8IrjNiYppUI/rxENYrWD6FOrSxSyEZnIekPEWM7LP0= github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/PuerkitoBio/purell v1.2.1 h1:QsZ4TjvwiMpat6gBCBxEQI0rcS9ehtkKtSpiUnd9N28= @@ -440,6 +436,8 @@ golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 h1:LLhsEBxRTBLuKlQxFBYUO golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gomodules.xyz/envsubst v0.2.0 h1:piG4OcpUa/Mu7LxSo+2Ye8JH7pXXWM2XuCD8Ic7Hdwc= gomodules.xyz/envsubst v0.2.0/go.mod h1:eB1KRKtXx6RSpl+WYxE8gFE7DhNJCoorHzSij7X3AQo= +gomodules.xyz/go-sh v0.1.1-0.20250117070215-e08594acad2a h1:Pz5BeoJLbzDpkeVu/YUmfOpaJVq/CoQuZUFl0G5WnVM= +gomodules.xyz/go-sh v0.1.1-0.20250117070215-e08594acad2a/go.mod h1:N8IrjNiYppUI/rxENYrWD6FOrSxSyEZnIekPEWM7LP0= gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= gomodules.xyz/mergo v0.3.13 h1:q6cL/MMXZH/MrR2+yjSihFFq6UifXqjwaqI48B6cMEM= diff --git a/vendor/gomodules.xyz/go-sh/README.md b/vendor/gomodules.xyz/go-sh/README.md index 64c90dcec..7346a3d8d 100644 --- a/vendor/gomodules.xyz/go-sh/README.md +++ b/vendor/gomodules.xyz/go-sh/README.md @@ -25,6 +25,7 @@ These are some of its features: * pipe command * shell build-in commands echo & test * timeout support +* run multiple concurrent leaf commands using a single pipe input Examples are important: @@ -80,6 +81,48 @@ By default, pipeline returns error only if the last command exit with a non-zero By default, pipelines's std-error is set to last command's std-error. However, you can also combine std-errors of all commands into pipeline's std-error using `session.PipeStdErrors = true`. +By default, pipeline returns error only if the last command exit with a non-zero status. However, you can also enable `pipefail` option like `bash`. In that case, pipeline returns error if any of the commands fail and for multiple failed commands, it returns the error of rightmost failed command. + + session := sh.NewSession() + session.PipeFail = true + session.Command("cat", "unknown-file").Command("echo").Run() + + +Designing a Command Chain to Run Multiple Concurrent Leaf Commands Using a Single Pipe Input. + +Features be like: +* **Input Sharing**: All leaf commands take the same input from a pipe. +* **Separate Environments**: Each leaf command runs with its own environment variables. +* **Output Aggregation**: Outputs from all commands are combined into a single result. +* **Error Handling**: Errors are collected and included in the output (e.g., shell or variable). +* **Timeouts**: Each command has same timeout and will apply simultaneously. + +Below is an example of multiple concurrent leaf commands using a single pipe input + + s := sh.NewSession() + s.ShowCMD = true + s.Command("echo", "hello world").LeafCommand("xargs").LeafCommand("xargs") + s.Run() + +Below is an example of each leaf command runs with its own environment variables + + s := sh.NewSession() + s.ShowCMD = true + var args1,args2 []interface{} + + mp := make(map[string]string) + mp["COMPANY_NAME"] = "APPSCODE" + args1 = append(args1, "COMPANY_NAME") + args1 = append(args1, mp) + s.LeafCommand("printenv", args1...) + + mp["COMPANY_NAME"] = "GOOGLE" + args2 = append(args2, "COMPANY_NAME") + args2 = append(args2, mp) + s.LeafCommand("printenv", args2...) + + s.Run() + for more information, it better to see docs. [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/gomodules.xyz/go-sh) diff --git a/vendor/gomodules.xyz/go-sh/pipe.go b/vendor/gomodules.xyz/go-sh/pipe.go index 076083914..83e31ed1d 100644 --- a/vendor/gomodules.xyz/go-sh/pipe.go +++ b/vendor/gomodules.xyz/go-sh/pipe.go @@ -56,34 +56,14 @@ func (s *Session) executeCommandChain(index int, stdin *io.PipeReader) error { if index >= len(s.cmds) { return nil } - pipeCount := s.determinePipeCount(index) - pipeReaders, pipeWriters := createPipes(pipeCount) - var writers []io.Writer - for _, writer := range pipeWriters { - writers = append(writers, writer) - s.pipeWriters = append(s.pipeWriters, writer) - } - multiWriter := io.MultiWriter(writers...) + pipeReaders, pipeWriters := createPipes(s.determinePipeCount(index)) cmd := s.cmds[index] - cmd.Stdin = stdin - if index == 0 { - cmd.Stdin = s.Stdin - } + cmd.Stdin = s.selectCmdStdin(index, stdin) + cmd.Stdout, cmd.Stderr = s.configureCmdOutput(index, pipeWriters) - if s.isLastCommand(index) && len(s.leafCmds) == 0 { - // If it's the last command and no leaf commands - cmd.Stdout = s.Stdout - cmd.Stderr = s.Stderr - } else { - // Otherwise, pipe output to the next command - cmd.Stdout = multiWriter - cmd.Stderr = os.Stderr - if s.PipeStdErrors { - cmd.Stderr = s.Stderr - } - } + s.pipeWriters = append(s.pipeWriters, pipeWriters...) if err := cmd.Start(); err != nil { return err @@ -95,17 +75,41 @@ func (s *Session) executeCommandChain(index int, stdin *io.PipeReader) error { return s.executeCommandChain(index+1, pipeReaders[0]) } +func (s *Session) selectCmdStdin(index int, stdin *io.PipeReader) io.Reader { + if index == 0 { + return s.Stdin + } + return stdin +} + +func (s *Session) configureCmdOutput(index int, pipeWriters []*io.PipeWriter) (io.Writer, io.Writer) { + if s.isLastCommand(index) && len(s.leafCmds) == 0 { + return s.Stdout, s.Stderr + } + + stdout := io.MultiWriter(pipeWritersToWriters(pipeWriters)...) + var stderr io.Writer = os.Stderr + if s.PipeStdErrors { + stderr = s.Stderr + } + + return stdout, stderr +} + +func pipeWritersToWriters(pipeWriters []*io.PipeWriter) []io.Writer { + var writers []io.Writer + for _, writer := range pipeWriters { + writers = append(writers, writer) + } + return writers +} + func (s *Session) executeLeafCommands(readers []*io.PipeReader) error { for idx, cmd := range s.leafCmds { - cmd.Stdin = s.Stdin - if readers != nil && idx < len(readers) { - cmd.Stdin = readers[idx] - } + cmd.Stdin = s.selectLeafCmdStdin(idx, readers) cmd.Stdout = s.selectLeafCmdStdout() - cmd.Stderr = s.Stderr - if s.enableErrsBuffer { - cmd.Stderr = cmd.Stdout - } + cmd.Stderr = s.selectLeafCmdStderr() + if err := cmd.Start(); err != nil { return err } @@ -113,6 +117,20 @@ func (s *Session) executeLeafCommands(readers []*io.PipeReader) error { return nil } +func (s *Session) selectLeafCmdStdin(index int, readers []*io.PipeReader) io.Reader { + if readers != nil { + return readers[index] + } + return s.Stdin +} + +func (s *Session) selectLeafCmdStderr() io.Writer { + if s.enableErrsBuffer { + return s.selectLeafCmdStdout() + } + return s.Stderr +} + func (s *Session) selectLeafCmdStdout() io.Writer { if s.enableOutputBuffer { cmdOutput := &bytes.Buffer{} @@ -154,11 +172,11 @@ func (s *Session) displayCommandChain() { } return result } - primaryCmds, backupCmds := joinCmds(s.cmds), joinCmds(s.leafCmds) + primaryCmds, leafCmds := joinCmds(s.cmds), joinCmds(s.leafCmds) totalCmd := strings.Join(primaryCmds, " | ") - if len(backupCmds) > 0 { - totalCmd += " | " + strings.Join(backupCmds, " , ") + if len(leafCmds) > 0 { + totalCmd += " | " + strings.Join(leafCmds, " , ") } s.writePrompt(totalCmd) diff --git a/vendor/gomodules.xyz/go-sh/sh.go b/vendor/gomodules.xyz/go-sh/sh.go index d8337877f..df159d7c3 100644 --- a/vendor/gomodules.xyz/go-sh/sh.go +++ b/vendor/gomodules.xyz/go-sh/sh.go @@ -195,6 +195,7 @@ func (s *Session) appendCmd(cmd string, args []string, cwd Dir, env map[string]s s.cmds = make([]*exec.Cmd, 0) s.leafCmds = make([]*exec.Cmd, 0) s.pipeWriters = make([]*io.PipeWriter, 0) + s.leafOutputBuffer = make([]*bytes.Buffer, 0) } for k, v := range s.Env { if _, ok := env[k]; !ok { diff --git a/vendor/modules.txt b/vendor/modules.txt index a8c1b42c2..7997bb05f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -765,7 +765,7 @@ golang.org/x/xerrors/internal gomodules.xyz/envsubst gomodules.xyz/envsubst/parse gomodules.xyz/envsubst/path -# gomodules.xyz/go-sh v0.1.0 => github.com/anisurrahman75/go-sh v0.0.0-20241030063656-336ab30e016a +# gomodules.xyz/go-sh v0.1.1-0.20250117070215-e08594acad2a ## explicit; go 1.15 gomodules.xyz/go-sh # gomodules.xyz/jsonpatch/v2 v2.4.0