New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
staticpod: improve operator messages #913
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,15 +422,77 @@ func setNodeStatusFn(status *operatorv1.NodeStatus) v1helpers.UpdateStaticPodSta | |
} | ||
} | ||
|
||
type revisionDescriptionPrinter struct { | ||
nodes []operatorv1.NodeStatus | ||
latestRevision int32 | ||
progressing bool | ||
} | ||
|
||
func newRevisionDescriptionPrinter(nodes []operatorv1.NodeStatus, latestRevision int32, progressing bool) *revisionDescriptionPrinter { | ||
return &revisionDescriptionPrinter{nodes: nodes, latestRevision: latestRevision, progressing: progressing} | ||
} | ||
|
||
func pluralizedNode(i int) string { | ||
if i < 2 { | ||
return "node" | ||
} | ||
return "nodes" | ||
} | ||
|
||
func (r revisionDescriptionPrinter) String() string { | ||
currentRevisions := sets.NewInt32() | ||
latestCount := 0 | ||
availableCount := 0 | ||
for i := range r.nodes { | ||
c := r.nodes[i].CurrentRevision | ||
currentRevisions.Insert(c) | ||
if c == r.latestRevision { | ||
latestCount++ | ||
} | ||
if c != 0 { | ||
availableCount++ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does this mean anything about availability? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the existing code "numAvailable" is determined by CurrentRevision!=0 ... So i guess CurrentRevision==0 means the node is not available or not actively making progress? i'm a bit confused here as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this has nothing to do with availability. It only says that this revision was the last that got ready eventually. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's a count. |
||
} | ||
} | ||
|
||
notAvailable := fmt.Sprintf("%d %s are not available and ", availableCount, pluralizedNode(availableCount)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cannot follow. This must be And better turn the wording into: |
||
if availableCount == len(r.nodes) { | ||
notAvailable = "" | ||
} | ||
if availableCount == 0 { | ||
return "none of the nodes are available" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. none of the nodes was ever available. |
||
} | ||
|
||
if !currentRevisions.Has(r.latestRevision) { | ||
if r.progressing { | ||
return fmt.Sprintf("%snodes progressing towards revision %d", notAvailable, r.latestRevision) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. am confused about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i tried to incorporate that into message, so we don't lose it but also get rid of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh. you mean "all nodes progressing ..." |
||
} | ||
return fmt.Sprintf("%snone of the nodes reached latest available revision %d", notAvailable, r.latestRevision) | ||
} | ||
if currentRevisions.Equal(sets.NewInt32(r.latestRevision)) { | ||
return fmt.Sprintf("%sall nodes reached revision %d", notAvailable, r.latestRevision) | ||
} | ||
if currentRevisions.Has(r.latestRevision) { | ||
oldRevisionStringList := []string{} | ||
for _, i := range currentRevisions.Difference(sets.NewInt32(r.latestRevision)).List() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. loop over currentRevisions and exclude |
||
oldRevisionStringList = append(oldRevisionStringList, fmt.Sprintf("%d", i)) | ||
} | ||
return fmt.Sprintf("%ssome nodes are on old revisions (%s), %d %s reached latest available revision %d", notAvailable, strings.Join(oldRevisionStringList, ","), latestCount, pluralizedNode(latestCount), r.latestRevision) | ||
} | ||
return "" | ||
} | ||
|
||
// setAvailableProgressingConditions sets the Available and Progressing conditions | ||
func setAvailableProgressingNodeInstallerFailingConditions(newStatus *operatorv1.StaticPodOperatorStatus) error { | ||
// Available means that we have at least one pod at the latest level | ||
numAvailable := 0 | ||
numAtLatestRevision := 0 | ||
numProgressing := 0 | ||
numNodes := len(newStatus.NodeStatuses) | ||
counts := map[int32]int{} | ||
failingCount := map[int32]int{} | ||
failing := map[int32][]string{} | ||
var latestRevision int32 | ||
|
||
for _, currNodeStatus := range newStatus.NodeStatuses { | ||
counts[currNodeStatus.CurrentRevision] = counts[currNodeStatus.CurrentRevision] + 1 | ||
if currNodeStatus.CurrentRevision != 0 { | ||
|
@@ -448,31 +510,26 @@ func setAvailableProgressingNodeInstallerFailingConditions(newStatus *operatorv1 | |
} else { | ||
numProgressing += 1 | ||
} | ||
} | ||
|
||
revisionStrings := []string{} | ||
for _, currentRevision := range Int32KeySet(counts).List() { | ||
count := counts[currentRevision] | ||
revisionStrings = append(revisionStrings, fmt.Sprintf("%d nodes are at revision %d", count, currentRevision)) | ||
} | ||
// if we are progressing and no nodes have achieved that level, we should indicate | ||
if numProgressing > 0 && counts[newStatus.LatestAvailableRevision] == 0 { | ||
revisionStrings = append(revisionStrings, fmt.Sprintf("%d nodes have achieved new revision %d", 0, newStatus.LatestAvailableRevision)) | ||
if newStatus.LatestAvailableRevision > latestRevision { | ||
latestRevision = newStatus.LatestAvailableRevision | ||
} | ||
} | ||
revisionDescription := strings.Join(revisionStrings, "; ") | ||
|
||
revisionDescription := newRevisionDescriptionPrinter(newStatus.NodeStatuses, latestRevision, numProgressing > 0).String() | ||
|
||
if numAvailable > 0 { | ||
v1helpers.SetOperatorCondition(&newStatus.Conditions, operatorv1.OperatorCondition{ | ||
Type: condition.StaticPodsAvailableConditionType, | ||
Status: operatorv1.ConditionTrue, | ||
Message: fmt.Sprintf("%d nodes are active; %s", numAvailable, revisionDescription), | ||
Message: revisionDescription, | ||
}) | ||
} else { | ||
v1helpers.SetOperatorCondition(&newStatus.Conditions, operatorv1.OperatorCondition{ | ||
Type: condition.StaticPodsAvailableConditionType, | ||
Status: operatorv1.ConditionFalse, | ||
Reason: "ZeroNodesActive", | ||
Message: fmt.Sprintf("%d nodes are active; %s", numAvailable, revisionDescription), | ||
Message: revisionDescription, | ||
}) | ||
} | ||
|
||
|
@@ -481,22 +538,26 @@ func setAvailableProgressingNodeInstallerFailingConditions(newStatus *operatorv1 | |
v1helpers.SetOperatorCondition(&newStatus.Conditions, operatorv1.OperatorCondition{ | ||
Type: condition.NodeInstallerProgressingConditionType, | ||
Status: operatorv1.ConditionTrue, | ||
Message: fmt.Sprintf("%s", revisionDescription), | ||
Message: revisionDescription, | ||
}) | ||
} else { | ||
v1helpers.SetOperatorCondition(&newStatus.Conditions, operatorv1.OperatorCondition{ | ||
Type: condition.NodeInstallerProgressingConditionType, | ||
Status: operatorv1.ConditionFalse, | ||
Reason: "AllNodesAtLatestRevision", | ||
Message: fmt.Sprintf("%s", revisionDescription), | ||
Message: revisionDescription, | ||
}) | ||
} | ||
|
||
if len(failing) > 0 { | ||
failingStrings := []string{} | ||
for _, failingRevision := range Int32KeySet(failing).List() { | ||
errorStrings := failing[failingRevision] | ||
failingStrings = append(failingStrings, fmt.Sprintf("%d nodes are failing on revision %d:\n%v", failingCount[failingRevision], failingRevision, strings.Join(errorStrings, "\n"))) | ||
if count := failingCount[failingRevision]; count == 1 { | ||
failingStrings = append(failingStrings, fmt.Sprintf("%d/%d node is failing to achieve revision %d:\n%v", failingCount[failingRevision], numNodes, failingRevision, strings.Join(errorStrings, "\n"))) | ||
} else { | ||
failingStrings = append(failingStrings, fmt.Sprintf("%d/%d nodes are failing to achieve revision %d:\n%v", failingCount[failingRevision], numNodes, failingRevision, strings.Join(errorStrings, "\n"))) | ||
} | ||
} | ||
failingDescription := strings.Join(failingStrings, "; ") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an object in the first place and not just a simple func?