probe: move cordon buttons to kubernetes probe

This commit is contained in:
Deepak
2021-01-18 23:46:21 +05:30
parent ce2180f24e
commit 71b4409958
7 changed files with 27 additions and 7 deletions

View File

@@ -22,6 +22,10 @@ rules:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups:
- ""
resources:

View File

@@ -65,7 +65,8 @@ type Client interface {
DeleteVolumeSnapshot(namespaceID, volumeSnapshotID string) error
ScaleUp(namespaceID, id string) error
ScaleDown(namespaceID, id string) error
CordonNode(name string) error
// Cordon or Uncordon a node based on whether `desired` is true or false respectively.
CordonNode(name string, desired bool) error
}
// ResourceMap is the mapping of resource and their GroupKind
@@ -626,14 +627,14 @@ func (c *client) Stop() {
close(c.quit)
}
func (c *client) CordonNode(name string) error {
func (c *client) CordonNode(name string, desired bool) error {
node, err := c.client.CoreV1().Nodes().Get(name, metav1.GetOptions{})
if err != nil {
return err
}
helper := newCordonHelper(node)
if updateRequired := helper.updateIfRequired(true); !updateRequired {
if updateRequired := helper.updateIfRequired(desired); !updateRequired {
return nil
}

View File

@@ -499,7 +499,12 @@ func (r *Reporter) ScaleDown(req xfer.Request, namespace, id string) xfer.Respon
// CordonNode is the control to cordon a node.
func (r *Reporter) CordonNode(req xfer.Request, name string) xfer.Response {
return xfer.ResponseError(r.client.CordonNode(name))
return xfer.ResponseError(r.client.CordonNode(name, true))
}
// UncordonNode is the control to un-cordon a node.
func (r *Reporter) UncordonNode(req xfer.Request, name string) xfer.Response {
return xfer.ResponseError(r.client.CordonNode(name, false))
}
func (r *Reporter) registerControls() {
@@ -513,7 +518,7 @@ func (r *Reporter) registerControls() {
ScaleUp: r.CaptureDeployment(r.ScaleUp),
ScaleDown: r.CaptureDeployment(r.ScaleDown),
CordonNode: r.CaptureNode(r.CordonNode),
UncordonNode: r.CaptureNode(r.CordonNode),
UncordonNode: r.CaptureNode(r.UncordonNode),
}
r.handlerRegistry.Batch(nil, controls)
}

View File

@@ -306,7 +306,6 @@ func (r *Tagger) Tag(rpt report.Report) (report.Report, error) {
controls := append(n.ActiveControls(), CordonNode, UncordonNode)
rpt.Host.Nodes[id] = n.WithLatestActiveControls(controls...)
}
rpt.Host.Controls.AddControls(CordonControl)
return rpt, nil
}
@@ -379,6 +378,13 @@ func (r *Reporter) Report() (report.Report, error) {
result.VolumeSnapshot = result.VolumeSnapshot.Merge(volumeSnapshotTopology)
result.VolumeSnapshotData = result.VolumeSnapshotData.Merge(volumeSnapshotDataTopology)
result.Job = result.Job.Merge(jobTopology)
// Add buttons for Host view, with the ID of the Kubernetes probe
for _, control := range CordonControl {
control.ProbeID = r.probeID
result.Host.Controls.AddControl(control)
}
return result, nil
}

View File

@@ -205,7 +205,7 @@ func (c *mockClient) Describe(namespaceID, resourceID string, groupKind schema.G
return nil, nil
}
func (c *mockClient) CordonNode(name string) error {
func (c *mockClient) CordonNode(name string, desired bool) error {
return nil
}

View File

@@ -113,6 +113,9 @@ func controlsFor(topology report.Topology, nodeID string) []ControlInstance {
}
for _, controlID := range node.ActiveControls() {
if control, ok := topology.Controls[controlID]; ok {
if control.ProbeID != "" { // does this Control have an override for the node probe?
probeID = control.ProbeID
}
result = append(result, ControlInstance{
ProbeID: probeID,
NodeID: nodeID,

View File

@@ -10,6 +10,7 @@ type Control struct {
Icon string `json:"icon"` // from https://fortawesome.github.io/Font-Awesome/cheatsheet/ please
Confirmation string `json:"confirmation,omitempty"`
Rank int `json:"rank"`
ProbeID string `json:"probeId,omitempty"`
}
// Merge merges other with cs, returning a fresh Controls.