Skip to content

Commit 210ca4a

Browse files
[Automated] Merged refs/heads/k8s-sync-2024-12-17-0147-6e47af7782ed52a730dff963db68ceb18d785c6b into target main
2 parents cf50448 + 8ca2be2 commit 210ca4a

32 files changed

+1220
-89
lines changed

commands/cluster_command_launcher.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ const (
6363
archiveNameKey = "archiveName"
6464
ipv6Flag = "ipv6"
6565
ipv6Key = "ipv6"
66+
enableTLSAuthFlag = "enable-tls-authentication"
6667
eonModeFlag = "eon-mode"
6768
eonModeKey = "eonMode"
6869
configParamFlag = "config-param"
6970
configParamKey = "configParam"
7071
configParamFileFlag = "config-param-file"
7172
configParamFileKey = "configParamFile"
73+
licenseFileFlag = "license-file"
74+
licenseHostFlag = "license-host"
7275
logPathFlag = "log-path"
7376
logPathKey = "logPath"
7477
keyFileFlag = "key-file"
@@ -245,6 +248,7 @@ const (
245248
createArchiveCmd = "create_archive"
246249
saveRestorePointsSubCmd = "save_restore_point"
247250
getDrainingStatusSubCmd = "get_draining_status"
251+
upgradeLicenseCmd = "upgrade_license"
248252
)
249253

250254
// cmdGlobals holds global variables shared by multiple
@@ -630,6 +634,7 @@ func constructCmds() []*cobra.Command {
630634
makeCmdPromoteSandbox(),
631635
makeCmdCreateArchive(),
632636
makeCmdSaveRestorePoint(),
637+
makeCmdUpgradeLicense(),
633638
}
634639
}
635640

commands/cmd_create_db.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ func (c *CmdCreateDB) setLocalFlags(cmd *cobra.Command) {
171171
util.GetEnvInt("NODE_STATE_POLLING_TIMEOUT", util.DefaultTimeoutSeconds),
172172
"The time, in seconds, to wait for the nodes to start after database creation (default: 300).",
173173
)
174+
cmd.Flags().BoolVar(
175+
&c.createDBOptions.EnableTLSAuth,
176+
enableTLSAuthFlag,
177+
false,
178+
"Enable TLS authentication for all users after database creation",
179+
)
174180
c.setSpreadlFlags(cmd)
175181
}
176182

commands/cmd_re_ip.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ This file should only include the IP addresses of nodes that you want to update.
5959
Examples:
6060
# Alter the IP address of database nodes with user input
6161
vcluster re_ip --db-name test_db --hosts 10.20.30.40,10.20.30.41,10.20.30.42 \
62-
--catalog-path /data --re-ip-file /data/re_ip_map.json \
62+
--catalog-path /data --re-ip-file /data/re_ip_map.json --sandbox sand \
6363
--password "PASSWORD"
6464
6565
# Alter the IP address of database nodes with config file
6666
vcluster re_ip --db-name test_db --re-ip-file /data/re_ip_map.json \
6767
--config /opt/vertica/config/vertica_cluster.yaml \
6868
--password "PASSWORD"
6969
`,
70-
[]string{dbNameFlag, hostsFlag, ipv6Flag, catalogPathFlag, configParamFlag, configFlag},
70+
[]string{dbNameFlag, hostsFlag, ipv6Flag, catalogPathFlag, configParamFlag, configFlag, sandboxFlag},
7171
)
7272

7373
// local flags
@@ -88,6 +88,12 @@ func (c *CmdReIP) setLocalFlags(cmd *cobra.Command) {
8888
"",
8989
"Path of the re-ip file",
9090
)
91+
cmd.Flags().StringVar(
92+
&c.reIPOptions.SandboxName,
93+
sandboxFlag,
94+
"",
95+
"The name of the sandbox. Required if the re-ip hosts are in a sandbox.",
96+
)
9197
}
9298

9399
func (c *CmdReIP) Parse(inputArgv []string, logger vlog.Printer) error {

commands/cmd_upgrade_license.go

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
(c) Copyright [2023-2024] Open Text.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
You may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package commands
17+
18+
import (
19+
"github.com/spf13/cobra"
20+
"github.com/vertica/vcluster/vclusterops"
21+
"github.com/vertica/vcluster/vclusterops/vlog"
22+
)
23+
24+
/* CmdUpgradeLicense
25+
*
26+
* Parses arguments to upgrade-license and calls
27+
* the high-level function for upgrade-license.
28+
*
29+
* Implements ClusterCommand interface
30+
*/
31+
32+
type CmdUpgradeLicense struct {
33+
CmdBase
34+
upgradeLicenseOptions *vclusterops.VUpgradeLicenseOptions
35+
}
36+
37+
func makeCmdUpgradeLicense() *cobra.Command {
38+
newCmd := &CmdUpgradeLicense{}
39+
opt := vclusterops.VUpgradeLicenseFactory()
40+
newCmd.upgradeLicenseOptions = &opt
41+
42+
cmd := makeBasicCobraCmd(
43+
newCmd,
44+
upgradeLicenseCmd,
45+
"Upgrade license.",
46+
`Upgrade license.
47+
48+
Examples:
49+
# Upgrade license
50+
vcluster upgrade_license --license-file LICENSE_FILE --license-host HOST_OF_LICENSE_FILE
51+
52+
# Upgrade license with connecting using database password
53+
vcluster upgrade_license --license-file LICENSE_FILE --license-host HOST_OF_LICENSE_FILE --password "PASSWORD"
54+
`,
55+
[]string{dbNameFlag, configFlag, passwordFlag,
56+
hostsFlag, ipv6Flag},
57+
)
58+
59+
// local flags
60+
newCmd.setLocalFlags(cmd)
61+
62+
// require license file path
63+
markFlagsRequired(cmd, licenseFileFlag)
64+
markFlagsRequired(cmd, licenseHostFlag)
65+
66+
return cmd
67+
}
68+
69+
// setLocalFlags will set the local flags the command has
70+
func (c *CmdUpgradeLicense) setLocalFlags(cmd *cobra.Command) {
71+
cmd.Flags().StringVar(
72+
&c.upgradeLicenseOptions.LicenseFilePath,
73+
licenseFileFlag,
74+
"",
75+
"Absolute path of the license file.",
76+
)
77+
cmd.Flags().StringVar(
78+
&c.upgradeLicenseOptions.LicenseHost,
79+
licenseHostFlag,
80+
"",
81+
"The host the license file located on.",
82+
)
83+
}
84+
85+
func (c *CmdUpgradeLicense) Parse(inputArgv []string, logger vlog.Printer) error {
86+
c.argv = inputArgv
87+
logger.LogArgParse(&c.argv)
88+
89+
// for some options, we do not want to use their default values,
90+
// if they are not provided in cli,
91+
// reset the value of those options to nil
92+
c.ResetUserInputOptions(&c.upgradeLicenseOptions.DatabaseOptions)
93+
94+
return c.validateParse(logger)
95+
}
96+
97+
func (c *CmdUpgradeLicense) validateParse(logger vlog.Printer) error {
98+
logger.Info("Called validateParse()")
99+
100+
err := c.ValidateParseBaseOptions(&c.upgradeLicenseOptions.DatabaseOptions)
101+
if err != nil {
102+
return err
103+
}
104+
105+
if !c.usePassword() {
106+
err = c.getCertFilesFromCertPaths(&c.upgradeLicenseOptions.DatabaseOptions)
107+
if err != nil {
108+
return err
109+
}
110+
}
111+
err = c.setDBPassword(&c.upgradeLicenseOptions.DatabaseOptions)
112+
if err != nil {
113+
return err
114+
}
115+
116+
return nil
117+
}
118+
119+
func (c *CmdUpgradeLicense) Analyze(logger vlog.Printer) error {
120+
logger.Info("Called method Analyze()")
121+
return nil
122+
}
123+
124+
func (c *CmdUpgradeLicense) Run(vcc vclusterops.ClusterCommands) error {
125+
vcc.LogInfo("Called method Run()")
126+
127+
options := c.upgradeLicenseOptions
128+
129+
err := vcc.VUpgradeLicense(options)
130+
if err != nil {
131+
vcc.LogError(err, "failed to upgrade license", "license file", options.LicenseFilePath)
132+
return err
133+
}
134+
135+
vcc.DisplayInfo("Successfully upgraded license: %s", options.LicenseFilePath)
136+
return nil
137+
}
138+
139+
// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdUpgradeLicense
140+
func (c *CmdUpgradeLicense) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) {
141+
c.upgradeLicenseOptions.DatabaseOptions = *opt
142+
}

commands/user_input_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"testing"
2525

2626
"github.com/stretchr/testify/assert"
27+
"github.com/vertica/vcluster/vclusterops"
2728
"gopkg.in/yaml.v3"
2829
)
2930

@@ -90,6 +91,21 @@ func TestManageReplication(t *testing.T) {
9091
assert.ErrorContains(t, err, `unknown command "test" for "vcluster replication start"`)
9192
}
9293

94+
func TestAsyncReplicationErrorMessage(t *testing.T) {
95+
vcommand := vclusterops.VClusterCommands{}
96+
replicationDatabaseOptions := vclusterops.VReplicationDatabaseFactory()
97+
replicationDatabaseOptions.DBName = "db"
98+
replicationDatabaseOptions.Hosts = []string{"12.34.56.78"}
99+
replicationDatabaseOptions.IsEon = true
100+
password := "password"
101+
replicationDatabaseOptions.Password = &password
102+
replicationDatabaseOptions.TargetDB.Hosts = []string{"23.45.67.89"}
103+
replicationDatabaseOptions.TargetDB.DBName = "targetDb"
104+
replicationDatabaseOptions.TableOrSchemaName = ".ns1.s1.*"
105+
_, err := vcommand.VReplicateDatabase(&replicationDatabaseOptions)
106+
assert.ErrorContains(t, err, "not allowed in --table-or-schema-name. HINT:")
107+
}
108+
93109
func TestCreateConnectionFileWrongFileType(t *testing.T) {
94110
// vertica_connection.txt will not be created and a unique name is not required
95111
var tempConnFilePath = filepath.Join(os.TempDir(), "vertica_connection.txt")

vclusterops/cluster_op.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ func (hostResult *hostHTTPResult) isEOF() bool {
168168
return hostResult.status == EOFEXCEPTION
169169
}
170170

171+
// process a single result, return the error in the result
172+
func (hostResult *hostHTTPResult) getError(host, opName string) error {
173+
if hostResult.isUnauthorizedRequest() {
174+
return fmt.Errorf("[%s] wrong password/certificates for https service on host %s", opName, host)
175+
}
176+
if !hostResult.isPassing() {
177+
return hostResult.err
178+
}
179+
return nil
180+
}
181+
171182
// getStatusString converts ResultStatus to string
172183
func (status resultStatus) getStatusString() string {
173184
if status == FAILURE {
@@ -601,6 +612,7 @@ type ClusterCommands interface {
601612
VStopNode(options *VStopNodeOptions) error
602613
VStopSubcluster(options *VStopSubclusterOptions) error
603614
VUnsandbox(options *VUnsandboxOptions) error
615+
VUpgradeLicense(options *VUpgradeLicenseOptions) error
604616
}
605617

606618
type VClusterCommandsLogger struct {

vclusterops/cluster_op_engine_context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type opEngineExecContext struct {
2222
networkProfiles map[string]networkProfile
2323
nmaVDatabase nmaVDatabase
2424
upHosts []string // a sorted host list that contains all up nodes
25+
computeHosts []string // a sorted host list that contains all up (COMPUTE) compute nodes
2526
nodesInfo []NodeInfo
2627
scNodesInfo []NodeInfo // a node list contains all nodes in a subcluster
2728

vclusterops/cmd_type.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
RemoveNodeSyncCat
4444
CreateArchiveCmd
4545
PollSubclusterStateCmd
46+
UpgradeLicenseCmd
4647
)
4748

4849
var cmdStringMap = map[CmdType]string{
@@ -84,6 +85,7 @@ var cmdStringMap = map[CmdType]string{
8485
RemoveNodeSyncCat: "remove_node_sync_cat",
8586
CreateArchiveCmd: "create_archive",
8687
PollSubclusterStateCmd: "poll_subcluster_state",
88+
UpgradeLicenseCmd: "upgrade_license",
8789
}
8890

8991
func (cmd CmdType) CmdString() string {

0 commit comments

Comments
 (0)