Skip to content

Commit

Permalink
flexbot v1.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-feoktistov committed Nov 5, 2024
1 parent da018b7 commit 557d2f3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 45 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.11.1 (November 5, 2024)

ENHANCEMENTS:
* Enhancements to improve resiliency in rke2 API provider calls


## 1.11.0 (October 10, 2024)

ENHANCEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DISTFILE=terraform-provider-flexbot
VERSION=1.11.0
VERSION=1.11.1
OSFLAG=$(shell go env GOHOSTOS)

default: build
Expand Down
6 changes: 6 additions & 0 deletions pkg/rancher/rk-api-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ func (client *RkApiClient) IsTransientError(err error) (bool) {
if strings.Contains(err.Error(), "i/o timeout") {
return true
}
if strings.Contains(err.Error(), "handshake timeout") {
return true
}
if strings.Contains(err.Error(), "connection reset by peer") {
return true
}
if strings.Contains(err.Error(), "context deadline exceeded") {
return true
}
Expand Down
83 changes: 41 additions & 42 deletions pkg/rancher/rke2-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func (client *Rke2Client) IsTransientError(err error) (bool) {
if strings.Contains(err.Error(), "i/o timeout") {
return true
}
if strings.Contains(err.Error(), "handshake timeout") {
return true
}
if strings.Contains(err.Error(), "connection reset by peer") {
return true
}
if strings.Contains(err.Error(), "context deadline exceeded") {
return true
}
Expand All @@ -57,23 +63,23 @@ func (client *Rke2Client) IsNotFoundError(err error) (bool) {
return false
}

// GetNode gets RKE2 node by node IP address
func (client *Rke2Client) GetNode(nodeIpAddr string) (nodeName string, err error) {
// GetNode gets RKE2 node name by node IP address
func (client *Rke2Client) GetNodeName(nodeIpAddr string) (nodeName string, err error) {
var nodes *v1.NodeList
for retry := 0; retry < client.RancherConfig.Retries; retry++ {
if nodes, err = client.Management.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}); err == nil {
for _, item := range nodes.Items {
var hostIpAddr net.IP
if hostIpAddr, err = node.GetNodeHostIP(&item); err != nil {
err = fmt.Errorf("rke2-client.GetNode().node.GetNodeHostIP() error: %s", err)
err = fmt.Errorf("rke2-client.GetNodeName().node.GetNodeHostIP() error: %s", err)
return
}
if hostIpAddr.String() == nodeIpAddr {
nodeName = item.Name
return
}
}
err = fmt.Errorf("rke2-client.GetNode().node.GetNodeHostIP() error: node with IP address %s not found", nodeIpAddr)
err = fmt.Errorf("rke2-client.GetNodeName().node.GetNodeHostIP() error: node with IP address %s not found", nodeIpAddr)
return
}
if !client.IsTransientError(err) {
Expand All @@ -82,25 +88,15 @@ func (client *Rke2Client) GetNode(nodeIpAddr string) (nodeName string, err error
time.Sleep(rke2RetriesWait * time.Second)
}
if err != nil {
err = fmt.Errorf("rke2-client.GetNode() error: %s", err)
err = fmt.Errorf("rke2-client.GetNodeName() error: %s", err)
}
return
}

// GetNodeRole gets RKE2 node role
func (client *Rke2Client) GetNodeRole(nodeName string) (controlplane bool, etcd bool, worker bool, err error) {
var node *v1.Node
// GetNodeByName gets RKE2 node by node name
func (client *Rke2Client) GetNodeByName(nodeName string) (node *v1.Node, err error) {
for retry := 0; retry < client.RancherConfig.Retries; retry++ {
if node, err = client.Management.CoreV1().Nodes().Get(context.TODO(), nodeName, metav1.GetOptions{}); err == nil {
if strings.ToLower(node.Labels[Rke2NodeRoleLabelWorker]) == "true" {
worker = true
}
if strings.ToLower(node.Labels[Rke2NodeRoleLabelControlplane]) == "true" {
controlplane = true
}
if strings.ToLower(node.Labels[Rke2NodeRoleLabelEtcd]) == "true" {
etcd = true
}
return
}
if !client.IsTransientError(err) {
Expand All @@ -109,6 +105,25 @@ func (client *Rke2Client) GetNodeRole(nodeName string) (controlplane bool, etcd
time.Sleep(rke2RetriesWait * time.Second)
}
if err != nil {
err = fmt.Errorf("rke2-client.GetNodeByName(%s) error: %s", nodeName, err)
}
return
}

// GetNodeRole gets RKE2 node role
func (client *Rke2Client) GetNodeRole(nodeName string) (controlplane bool, etcd bool, worker bool, err error) {
var node *v1.Node
if node, err = client.GetNodeByName(nodeName); err == nil {
if strings.ToLower(node.Labels[Rke2NodeRoleLabelWorker]) == "true" {
worker = true
}
if strings.ToLower(node.Labels[Rke2NodeRoleLabelControlplane]) == "true" {
controlplane = true
}
if strings.ToLower(node.Labels[Rke2NodeRoleLabelEtcd]) == "true" {
etcd = true
}
} else {
err = fmt.Errorf("rke2-client.GetNodeRole(%s) error: %s", nodeName, err)
}
return
Expand All @@ -117,17 +132,9 @@ func (client *Rke2Client) GetNodeRole(nodeName string) (controlplane bool, etcd
// IsNodeReady returns true if node ready
func (client *Rke2Client) IsNodeReady(nodeName string) (ready bool, err error) {
var nodeObj *v1.Node
for retry := 0; retry < client.RancherConfig.Retries; retry++ {
if nodeObj, err = client.Management.CoreV1().Nodes().Get(context.TODO(), nodeName, metav1.GetOptions{}); err == nil {
ready = node.IsNodeReady(nodeObj)
return
}
if !client.IsTransientError(err) {
break
}
time.Sleep(rke2RetriesWait * time.Second)
}
if err != nil {
if nodeObj, err = client.GetNodeByName(nodeName); err == nil {
ready = node.IsNodeReady(nodeObj)
} else {
err = fmt.Errorf("rke2-client.IsNodeReady(%s) error: %s", nodeName, err)
}
return
Expand Down Expand Up @@ -277,10 +284,10 @@ func (client *Rke2Client) NodeSetAnnotationsLabelsTaints(nodeName string, annota
// NodeGetLabels get RKE2 node labels
func (client *Rke2Client) NodeGetLabels(nodeName string) (nodeLabels map[string]string, err error) {
var node *v1.Node
if node, err = client.Management.CoreV1().Nodes().Get(context.TODO(), nodeName, metav1.GetOptions{}); err != nil {
err = fmt.Errorf("rke2-client.NodeGetLabels() error: %s", err)
} else {
if node, err = client.GetNodeByName(nodeName); err == nil {
nodeLabels = node.Labels
} else {
err = fmt.Errorf("rke2-client.NodeGetLabels() error: %s", err)
}
return
}
Expand Down Expand Up @@ -319,17 +326,9 @@ func (client *Rke2Client) NodeUpdateLabels(nodeName string, oldLabels map[string
// NodeGetTaints get RKE2 node taints
func (client *Rke2Client) NodeGetTaints(nodeName string) (nodeTaints []v1.Taint, err error) {
var node *v1.Node
for retry := 0; retry < client.RancherConfig.Retries; retry++ {
if node, err = client.Management.CoreV1().Nodes().Get(context.TODO(), nodeName, metav1.GetOptions{}); err == nil {
nodeTaints = node.Spec.Taints
return
}
if !client.IsTransientError(err) {
break
}
time.Sleep(rke2RetriesWait * time.Second)
}
if err != nil {
if node, err = client.GetNodeByName(nodeName); err == nil {
nodeTaints = node.Spec.Taints
} else {
err = fmt.Errorf("rke2-client.NodeGetTaints() error: %s", err)
}
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/rancher/rke2.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Rke2APIInitialize(d *schema.ResourceData, meta interface{}, nodeConfig *con
return
}
node.RancherClient = rke2Client
if node.NodeID, err = node.RancherClient.GetNode(network["node"].([]interface{})[0].(map[string]interface{})["ip"].(string)); err == nil {
if node.NodeID, err = node.RancherClient.GetNodeName(network["node"].([]interface{})[0].(map[string]interface{})["ip"].(string)); err == nil {
if len(node.NodeID) > 0 {
node.NodeControlPlane, node.NodeEtcd, node.NodeWorker, err = node.RancherClient.GetNodeRole(node.NodeID)
}
Expand All @@ -80,7 +80,7 @@ func (node *Rke2Node) RancherAPINodeGetID(d *schema.ResourceData, meta interface
meta.(*config.FlexbotConfig).Sync.Lock()
network := d.Get("network").([]interface{})[0].(map[string]interface{})
meta.(*config.FlexbotConfig).Sync.Unlock()
if node.NodeID, err = node.RancherClient.GetNode(network["node"].([]interface{})[0].(map[string]interface{})["ip"].(string)); err != nil {
if node.NodeID, err = node.RancherClient.GetNodeName(network["node"].([]interface{})[0].(map[string]interface{})["ip"].(string)); err != nil {
err = fmt.Errorf("rancherAPINodeGetID(): node %s not found", node.NodeConfig.Compute.HostName)
}
}
Expand Down

0 comments on commit 557d2f3

Please sign in to comment.