[pve-devel] applied: [PATCH cluster] join API version: factor out checks and add info to outputs

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Mar 25 17:40:24 CET 2020


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 data/PVE/API2/ClusterConfig.pm |  7 +------
 data/PVE/CLI/pvecm.pm          |  7 +------
 data/PVE/Cluster/Setup.pm      | 30 ++++++++++++++++++++++--------
 3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/data/PVE/API2/ClusterConfig.pm b/data/PVE/API2/ClusterConfig.pm
index 205252f..7a4bce0 100644
--- a/data/PVE/API2/ClusterConfig.pm
+++ b/data/PVE/API2/ClusterConfig.pm
@@ -263,12 +263,7 @@ __PACKAGE__->register_method ({
 	my ($param) = @_;
 
 	$param->{apiversion} //= 0;
-	if ($param->{apiversion} < (PVE::Cluster::Setup::JOIN_API_VERSION -
-	    PVE::Cluster::Setup::JOIN_API_AGE_AS_CLUSTER)) {
-	    die "unsupported old API version on joining node ($param->{apiversion},"
-		. " cluster node has " . PVE::Cluster::Setup::JOIN_API_VERSION
-		. "), please upgrade before joining\n";
-	}
+	PVE::Cluster::Setup::assert_node_can_join_our_version($param->{apiversion});
 
 	PVE::Cluster::check_cfs_quorum();
 
diff --git a/data/PVE/CLI/pvecm.pm b/data/PVE/CLI/pvecm.pm
index f205b8d..4b52dee 100755
--- a/data/PVE/CLI/pvecm.pm
+++ b/data/PVE/CLI/pvecm.pm
@@ -397,12 +397,7 @@ __PACKAGE__->register_method ({
 		chomp $remote_apiver;
 	    }, 'noerr' => 1);
 
-	    if ($remote_apiver < (PVE::Cluster::Setup::JOIN_API_VERSION -
-		PVE::Cluster::Setup::JOIN_API_AGE_AS_JOINEE)) {
-		die "error: incompatible join API version on cluster ($remote_apiver,"
-		    . " local has " . PVE::Cluster::Setup::JOIN_API_VERSION . "). Make"
-		    . " sure all nodes are up-to-date.\n";
-	    }
+	    PVE::Cluster::Setup::assert_we_can_join_cluster_version($remote_apiver);
 
 	    $cmd = ['ssh', $host, '-o', 'BatchMode=yes',
 		    'pvecm', 'addnode', $nodename, '--force', 1];
diff --git a/data/PVE/Cluster/Setup.pm b/data/PVE/Cluster/Setup.pm
index 72289c0..1f06477 100644
--- a/data/PVE/Cluster/Setup.pm
+++ b/data/PVE/Cluster/Setup.pm
@@ -20,13 +20,31 @@ use PVE::Network;
 use PVE::Tools;
 use PVE::Certificate;
 
-# Only relevant for pre-join checks, after join happened versions can differ
+# relevant for joining or getting joined checks, after that versions in cluster can differ
 use constant JOIN_API_VERSION => 1;
-# (APIVER-this) is oldest version a new node in addnode can have to be accepted
+# (APIVER-this) is oldest version a new node in addnode can have and still be accepted
 use constant JOIN_API_AGE_AS_CLUSTER => 1;
 # (APIVER-this) is oldest version a cluster node can have to still try joining
 use constant JOIN_API_AGE_AS_JOINEE => 1;
 
+sub assert_we_can_join_cluster_version {
+    my ($version) = @_;
+    my $min_version = JOIN_API_VERSION - JOIN_API_AGE_AS_JOINEE;
+    return if $version >= $min_version;
+    die "error: incompatible join API version on cluster ($version), local node"
+	." has ". JOIN_API_VERSION ." and supports >= $min_version. Make sure"
+	."all cluster nodes are up-to-date.\n";
+}
+
+sub assert_node_can_join_our_version {
+    my ($version) = @_;
+    my $min_version = JOIN_API_VERSION - JOIN_API_AGE_AS_CLUSTER;
+    return if $version >= $min_version;
+    die "error: unsupported old API version on joining node ($version), cluster"
+	." node has ". JOIN_API_VERSION ." and supports >= $min_version. Please"
+	." upgrade node before joining\n";
+}
+
 my $pmxcfs_base_dir = PVE::Cluster::base_dir();
 my $pmxcfs_auth_dir = PVE::Cluster::auth_dir();
 
@@ -684,13 +702,9 @@ sub join {
     # login raises an exception on failure, so if we get here we're good
     print "Login succeeded.\n";
 
-    # check cluster join API version
+    print "check cluster join API version\n";
     my $apiver = eval { $conn->get("/cluster/config/apiversion") } // 0;
-
-    if ($apiver < (JOIN_API_VERSION - JOIN_API_AGE_AS_JOINEE)) {
-	die "error: incompatible join API version on cluster ($apiver, local has "
-	    . JOIN_API_VERSION . "). Make sure all nodes are up-to-date.\n";
-    }
+    assert_we_can_join_cluster_version($apiver);
 
     my $args = {};
     $args->{force} = $param->{force} if defined($param->{force});
-- 
2.20.1





More information about the pve-devel mailing list