Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import json
import sys
import agent

agent.set_weight("00validate_cluster", 0)
agent.set_weight("10validate_network", 0)
agent.set_weight("40update_cluster", 3)

request = json.load(sys.stdin)

rdb = agent.redis_connect()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3

#
# Copyright (C) 2026 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import sys
import agent
import os

update_core_response = agent.tasks.run(
agent_id='cluster',
action='update-core',
data={'nodes': [1]}, # always 1 in a new cluster
endpoint="redis://cluster-leader",
)
if update_core_response['exit_code'] != 0:
print(agent.SD_ERR + "update-core failed", file=sys.stderr)
sys.exit(1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to not abort the create-cluster if the update fails.
Also make sure that is safe enough to call the update-core even if the cluster is not still completely configured.

Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ agent.assert_exp(add1_module_failures == 0)
# Update completed successfully, enable the phonehome.timer
agent.run_helper(*'systemctl enable --now phonehome.timer'.split(' ')).check_returncode()

agent.unset_env("FIRST_CONFIGURATION")

json.dump({
"ip_address": ip_address,
}, fp=sys.stdout)
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ leader_id = int(rdb.hget("cluster/environment", "NODE_ID"))
leader_endpoint = rdb.hget(f"node/{leader_id}/vpn", "endpoint") or "leader.invalid:55820"
local_id = int(os.environ['NODE_ID'])
local_public_key = rdb.hget(f"node/{local_id}/vpn", "public_key")
initialized = os.getenv("FIRST_CONFIGURATION") != "1"

ret = { 'initialized': False, 'leader': False, 'nodes': [], 'leader_url': '', 'default_password': False, 'ui_name': cluster_ui_name, }
ret = { 'initialized': initialized, 'leader': False, 'nodes': [], 'leader_url': '', 'default_password': False, 'ui_name': cluster_ui_name, }
vpn = {}

default_password = hashlib.sha256(b'Nethesis,1234').hexdigest()
Expand All @@ -82,7 +83,6 @@ for p in admin['passwords']:

network = rdb.get('cluster/network')
if network is not None:
ret["initialized"] = True
# The leader must have a public endpoint:
leader_hostname, _ = leader_endpoint.rsplit(":", 1)
ret['leader_url'] = f'https://{leader_hostname}/cluster-admin/'
Expand Down
1 change: 1 addition & 0 deletions core/imageroot/var/lib/nethserver/node/install-finalize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ echo "Grant initial permissions:"
runagent python3 <<'EOF'
import agent
import cluster.grants
agent.set_env("FIRST_CONFIGURATION", "1")
rdb = agent.redis_connect(privileged=True)
cluster.grants.grant(rdb, action_clause="*", to_clause="owner", on_clause='cluster')
cluster.grants.grant(rdb, action_clause="list-*", to_clause="reader", on_clause='cluster')
Expand Down
29 changes: 26 additions & 3 deletions core/ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import ShellHeader from "@/components/shell/ShellHeader";
import SideMenu from "@/components/shell/SideMenu";
import MobileSideMenu from "@/components/shell/MobileSideMenu";
import axios from "axios";
import WebSocketService from "@/mixins/websocket";
import { mapState, mapActions } from "vuex";
import to from "await-to-js";
Expand Down Expand Up @@ -187,15 +186,39 @@ export default {
}
});
},
isRetryableAgentRequest(error) {
return (
// The cluster agent may be temporarily unavailable while restarting.
error.config?.method?.toLowerCase() === "post" &&
error.response?.status == 404 &&
error.response?.data?.message === "client idle check failed" &&
error.config?.url?.endsWith("/cluster/tasks")
);
},
configureAxiosInterceptors() {
const context = this;
const maxAgentRestartRetries = 5;

// response interceptor
axios.interceptors.response.use(
this.axios.interceptors.response.use(
function (response) {
return response;
},
function (error) {
async function (error) {
if (context.isRetryableAgentRequest(error)) {
const retryConfig = error.config;
retryConfig.__agentRestartRetryCount =
(retryConfig.__agentRestartRetryCount || 0) + 1;

if (
retryConfig.__agentRestartRetryCount <=
maxAgentRestartRetries
) {
await new Promise((resolve) => setTimeout(resolve, 2000));
return context.axios.request(retryConfig);
}
}

console.error(error);

// print specific error message, if available
Expand Down
Loading