forked from vertica/vertica-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move restart_node and start_db behind dispatcher abstraction (vertica…
…#428) This is a continuation of building out the dispatcher interface. The dispatcher interface will be used to switch between admintools and vcluster library. This adds the final two calls: RestartNode and StartDB.
- Loading branch information
spilchen
committed
Jun 26, 2023
1 parent
edb0481
commit 6a524b6
Showing
14 changed files
with
432 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
(c) Copyright [2021-2023] Open Text. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package restartnode | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
// Parms holds all of the option for a revive DB invocation. | ||
type Parms struct { | ||
InitiatorName types.NamespacedName | ||
InitiatorIP string | ||
HostVNodes []string | ||
HostIPs []string | ||
} | ||
|
||
type Option func(*Parms) | ||
|
||
// Make will fill in the Parms based on the options chosen | ||
func (s *Parms) Make(opts ...Option) { | ||
for _, opt := range opts { | ||
opt(s) | ||
} | ||
} | ||
|
||
func WithInitiator(nm types.NamespacedName, ip string) Option { | ||
return func(s *Parms) { | ||
s.InitiatorName = nm | ||
s.InitiatorIP = ip | ||
} | ||
} | ||
|
||
func WithHost(vnode, ip string) Option { | ||
return func(s *Parms) { | ||
if s.HostVNodes == nil { | ||
s.HostVNodes = make([]string, 0) | ||
} | ||
if s.HostIPs == nil { | ||
s.HostIPs = make([]string, 0) | ||
} | ||
s.HostVNodes = append(s.HostVNodes, vnode) | ||
s.HostIPs = append(s.HostIPs, ip) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
(c) Copyright [2021-2023] Open Text. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package startdb | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
// Parms holds all of the option for a revive DB invocation. | ||
type Parms struct { | ||
InitiatorName types.NamespacedName | ||
InitiatorIP string | ||
Hosts []string | ||
} | ||
|
||
type Option func(*Parms) | ||
|
||
// Make will fill in the Parms based on the options chosen | ||
func (s *Parms) Make(opts ...Option) { | ||
for _, opt := range opts { | ||
opt(s) | ||
} | ||
} | ||
|
||
func WithInitiator(nm types.NamespacedName, ip string) Option { | ||
return func(s *Parms) { | ||
s.InitiatorName = nm | ||
s.InitiatorIP = ip | ||
} | ||
} | ||
|
||
func WithHost(hostName string) Option { | ||
return func(s *Parms) { | ||
if s.Hosts == nil { | ||
s.Hosts = make([]string, 0) | ||
} | ||
s.Hosts = append(s.Hosts, hostName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
(c) Copyright [2021-2023] Open Text. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package vadmin | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/vertica/vertica-kubernetes/pkg/events" | ||
"github.com/vertica/vertica-kubernetes/pkg/vadmin/opts/restartnode" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
// RestartNode will restart a subset of nodes. Use this when vertica has not | ||
// lost cluster quorum. The IP given for each vnode may not match the current IP | ||
// in the vertica catalogs. | ||
func (a Admintools) RestartNode(ctx context.Context, opts ...restartnode.Option) (ctrl.Result, error) { | ||
s := restartnode.Parms{} | ||
s.Make(opts...) | ||
cmd := a.genRestartNodeCmd(&s) | ||
stdout, err := a.execAdmintools(ctx, s.InitiatorName, cmd...) | ||
if err != nil { | ||
return a.logFailure("restart_node", events.MgmtFailed, stdout, err) | ||
} | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
// genRestartNodeCmd returns the command to run to restart a pod | ||
func (a Admintools) genRestartNodeCmd(s *restartnode.Parms) []string { | ||
cmd := []string{ | ||
"-t", "restart_node", | ||
"--database=" + a.VDB.Spec.DBName, | ||
"--hosts=" + strings.Join(s.HostVNodes, ","), | ||
"--new-host-ips=" + strings.Join(s.HostIPs, ","), | ||
"--noprompt", | ||
} | ||
if a.VDB.Spec.RestartTimeout != 0 { | ||
cmd = append(cmd, fmt.Sprintf("--timeout=%d", a.VDB.Spec.RestartTimeout)) | ||
} | ||
return cmd | ||
} |
Oops, something went wrong.