diff --git a/pkg/pmk/checkNode.go b/pkg/pmk/checkNode.go index 5a68a30..efccc27 100644 --- a/pkg/pmk/checkNode.go +++ b/pkg/pmk/checkNode.go @@ -98,7 +98,7 @@ func CheckNode(ctx objects.Config, allClients client.Client, auth keystone.Keyst //If hostID is empty then host could be connected to other DU var connected bool if len(id) != 0 { - connected = allClients.Resmgr.HostSatus(auth.Token, id[0]) + connected = allClients.Resmgr.HostStatus(auth.Token, id[0]) } else { zap.S().Fatalf("Hostagent is installed on this host, but this host is not part of the DU %s specified in the config", ctx.Fqdn) } diff --git a/pkg/pmk/cluster.go b/pkg/pmk/cluster.go index fda668d..bee923e 100644 --- a/pkg/pmk/cluster.go +++ b/pkg/pmk/cluster.go @@ -71,7 +71,7 @@ func Bootstrap(ctx objects.Config, c client.Client, req qbert.ClusterCreateReque LoopVariable := 1 for LoopVariable <= util.MaxLoopValue { - hostStatus := c.Resmgr.HostSatus(token, nodeID) + hostStatus := c.Resmgr.HostStatus(token, nodeID) if !hostStatus { zap.S().Debugf("Host is Down...Trying again") } else { @@ -150,7 +150,7 @@ func Bootstrap(ctx objects.Config, c client.Client, req qbert.ClusterCreateReque return nil } -//Checks Prerequisites for Bootstrap Command +// Checks Prerequisites for Bootstrap Command func PreReqBootstrap(executor cmdexec.Executor) (bool, bool, error) { os, err := ValidatePlatform(executor) @@ -183,7 +183,7 @@ func PreReqBootstrap(executor cmdexec.Executor) (bool, bool, error) { return val, val1, nil } -//Deleting the cluster if the node is not attached to the cluster +// Deleting the cluster if the node is not attached to the cluster func DeleteClusterBootstrap(clusterID string, c client.Client, keystoneAuth keystone.KeystoneAuth, token string) { err := c.Qbert.DeleteCluster(clusterID, keystoneAuth.ProjectID, token) diff --git a/pkg/pmk/decomissionNode.go b/pkg/pmk/decomissionNode.go index dd88b2c..ef2a211 100644 --- a/pkg/pmk/decomissionNode.go +++ b/pkg/pmk/decomissionNode.go @@ -134,6 +134,12 @@ func DecommissionNode(cfg *objects.Config, nc objects.NodeConfig, removePf9 bool fmt.Printf("Node is connected to %s cluster\n", nodeInfo.ClusterName) fmt.Println("Detaching node from cluster...") err = c.Qbert.DetachNode(nodeInfo.ClusterUuid, auth.ProjectID, auth.Token, hostID[0]) + for { + nodeInfo := c.Resmgr.GetHostInfo(auth.Token, hostID[0]) + if nodeInfo.Extensions.Pf9KubeStatus.Data.Pf9ClusterID == "" { + break + } + } if err != nil { zap.S().Fatalf("Failed to detach host from cluster") } else { diff --git a/pkg/qbert/qbert.go b/pkg/qbert/qbert.go index 1809b2a..288fe14 100644 --- a/pkg/qbert/qbert.go +++ b/pkg/qbert/qbert.go @@ -492,7 +492,7 @@ func (c QbertImpl) CheckClusterExistsWithUuid(uuid, projectID, token string) (st return "", fmt.Errorf("error finding cluster with uuid %s", uuid) } -//Function to Check status of attach-node API +// Function to Check status of attach-node API func Attach_Status(attachEndpoint string, token string, byt []byte) (*http.Response, error) { client := http.Client{} req, err := http.NewRequest("POST", attachEndpoint, strings.NewReader(string(byt))) @@ -513,7 +513,7 @@ func Attach_Status(attachEndpoint string, token string, byt []byte) (*http.Respo return resp, nil } -//There are two different payload structures based on pmk version +// There are two different payload structures based on pmk version func updatePayload(p string) string { var monitoringDetails string var tagDetails string diff --git a/pkg/resmgr/resmgr.go b/pkg/resmgr/resmgr.go index 2e5c7a5..f775258 100644 --- a/pkg/resmgr/resmgr.go +++ b/pkg/resmgr/resmgr.go @@ -18,7 +18,8 @@ import ( type Resmgr interface { AuthorizeHost(hostID, token string) error GetHostId(token string, hostIP []string) []string - HostSatus(token string, hostID string) bool + HostStatus(token string, hostID string) bool + GetHostInfo(token string, hostID string) Info } type ResmgrImpl struct { @@ -38,6 +39,30 @@ type hostInfo []struct { ID string `json:"id,omitempty"` } +type Info struct { + Extensions struct { + Pf9KubeStatus struct { + //Status string `json:"status"` + Data struct { + /*Pf9KubeServiceState string `json:"pf9_kube_service_state"` + Pf9KubeNodeState string `json:"pf9_kube_node_state"` + Pf9KubeStartAttempt int `json:"pf9_kube_start_attempt"`*/ + Pf9ClusterID string `json:"pf9_cluster_id,omitempty"` + /*Pf9ClusterRole string `json:"pf9_cluster_role"` + AllStatusChecks []string `json:"all_status_checks"` + AllTasks []string `json:"all_tasks"` + CompletedTasks []string `json:"completed_tasks"` + CurrentStatusCheck string `json:"current_status_check"` + CurrentTask string `json:"current_task"` + LastFailedStatusCheck string `json:"last_failed_status_check"` + LastFailedStatusTime int `json:"last_failed_status_time"` + LastFailedTask string `json:"last_failed_task"` + StatusCheckTimestamp int `json:"status_check_timestamp"`*/ + } `json:"data,omitempty"` + } `json:"pf9_kube_status,omitempty"` + } `json:"extensions,omitempty"` +} + func NewResmgr(fqdn string, maxHttpRetry int, minWait, maxWait time.Duration, allowInsecure bool) Resmgr { return &ResmgrImpl{fqdn, minWait, maxWait, maxHttpRetry, allowInsecure} @@ -121,7 +146,7 @@ func (c *ResmgrImpl) GetHostId(token string, hostIPs []string) []string { return hostUUIDs } -func (c *ResmgrImpl) HostSatus(token string, hostID string) bool { +func (c *ResmgrImpl) HostStatus(token string, hostID string) bool { url := fmt.Sprintf("%s/resmgr/v1/hosts/%s", c.fqdn, hostID) req, err := http.NewRequest("GET", url, nil) if err != nil { @@ -151,3 +176,30 @@ func (c *ResmgrImpl) HostSatus(token string, hostID string) bool { } return host.Info.Responding } + +func (c *ResmgrImpl) GetHostInfo(token string, hostID string) Info { + url := fmt.Sprintf("%s/resmgr/v1/hosts/%s", c.fqdn, hostID) + req, err := http.NewRequest("GET", url, nil) + if err != nil { + zap.S().Infof("Unable to create a new request: %w", err) + } + req.Header.Set("X-Auth-Token", token) + client := http.Client{} + resp, err := client.Do(req) + if err != nil { + zap.S().Infof("Client is unable to send the request: %w", err) + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + zap.S().Infof("Unable to read resp body: %w", err) + } + + nodeInfo := Info{} + err = json.Unmarshal(body, &nodeInfo) + if err != nil { + zap.S().Debugf("Unable to unmarshal resp body to struct: %w", err) + } + + return nodeInfo +}