Skip to content

Commit b24af6a

Browse files
committed
升级时更新 calico_backend
1 parent 1a8e784 commit b24af6a

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

server/api/cluster/change_resource_package_version.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ func ChangeResourcePackageVersion(c *gin.Context) {
4747

4848
netmanager := common.MapGetString(metadata.Inventory, "all.children.target.children.k8s_cluster.vars.kube_network_plugin")
4949

50-
if netmanager == "calico" && (common.MapGet(metadata.Inventory, "all.children.target.children.k8s_cluster.vars.calico_ipip_mode") == nil || common.MapGet(metadata.Inventory, "all.children.target.children.k8s_cluster.vars.calico_vxlan_mode") == nil) {
50+
if netmanager == "calico" && (common.MapGet(metadata.Inventory, "all.children.target.children.k8s_cluster.vars.calico_ipip_mode") == nil ||
51+
common.MapGet(metadata.Inventory, "all.children.target.children.k8s_cluster.vars.calico_vxlan_mode") == nil ||
52+
common.MapGet(metadata.Inventory, "all.children.target.children.k8s_cluster.vars.calico_backend") == nil) {
5153
shellReq1 := ansible_rpc.AnsibleCommandsRequest{
5254
Name: "calico",
5355
Command: `calicoctl.sh get ipPool default-pool -o json`,
5456
}
55-
shellResult, err := ansible_rpc.ExecuteShellCommandsAbortOnFirstSuccess("cluster", req.Cluster, "kube_control_plane[0]", []ansible_rpc.AnsibleCommandsRequest{shellReq1})
57+
shellReq2 := ansible_rpc.AnsibleCommandsRequest{
58+
Name: "calico",
59+
Command: `kubectl get cm -n kube-system calico-config -o json`,
60+
}
61+
shellResult, err := ansible_rpc.ExecuteShellCommandsAbortOnFirstSuccess("cluster", req.Cluster, "kube_control_plane[0]", []ansible_rpc.AnsibleCommandsRequest{shellReq1, shellReq2})
5662
if err != nil {
5763
common.HandleError(c, http.StatusInternalServerError, "failed to get calico status", err)
5864
return
@@ -68,6 +74,17 @@ func ChangeResourcePackageVersion(c *gin.Context) {
6874
common.HandleError(c, http.StatusInternalServerError, "failed to parse calicoIpPool", err)
6975
return
7076
}
77+
78+
stdout2 := shellResult[1].StdOut
79+
calicoBackend := map[string]interface{}{}
80+
if err := json.Unmarshal([]byte(stdout2), &calicoBackend); err == nil {
81+
calico_backend := common.MapGetString(calicoBackend, "data.calico_backend")
82+
common.MapSet(metadata.Inventory, "all.children.target.children.k8s_cluster.vars.calico_backend", calico_backend)
83+
} else {
84+
common.HandleError(c, http.StatusInternalServerError, "failed to parse calico_backend", err)
85+
return
86+
}
87+
7188
}
7289

7390
if err := cluster_common.SaveInventory(req.Cluster, metadata.Inventory); err != nil {

0 commit comments

Comments
 (0)