Skip to content

Commit

Permalink
OCPBUGS-33762: Hardcode resource groups/kinds for now
Browse files Browse the repository at this point in the history
Previous code used `GroupVersionKind` method on actual resources to determine group/kind strings for them, but client-go unfortunately drops `TypeMeta` on resources processed by typed client (kubernetes/client-go#1328, kubernetes/client-go#541). Fortunately we know what types we build insights for, so we can use appropriate strings from client code for groups and hardcode kinds ourselves.
  • Loading branch information
petr-muller committed May 18, 2024
1 parent 27e9057 commit fad39d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions pkg/cli/admin/upgrade/status/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const (
// clusterStatusFailing is set on the ClusterVersion status when a cluster
// cannot reach the desired state.
clusterStatusFailing = v1.ClusterStatusConditionType("Failing")

clusterVersionKind string = "ClusterVersion"
clusterOperatorKind string = "ClusterOperator"
)

type operators struct {
Expand Down Expand Up @@ -75,7 +78,7 @@ const (
)

func coInsights(name string, available *v1.ClusterOperatorStatusCondition, degraded *v1.ClusterOperatorStatusCondition, evaluated time.Time) []updateInsight {
coGroupKind := scopeGroupKind{group: v1.GroupName, kind: "ClusterOperator"}
coGroupKind := scopeGroupKind{group: v1.GroupName, kind: clusterOperatorKind}
var insights []updateInsight
if available != nil && available.Status == v1.ConditionFalse && evaluated.After(available.LastTransitionTime.Time.Add(unavailableWarningThreshold)) {
insight := updateInsight{
Expand Down Expand Up @@ -128,8 +131,7 @@ func assessControlPlaneStatus(cv *v1.ClusterVersion, operators []v1.ClusterOpera
var insights []updateInsight

targetVersion := cv.Status.Desired.Version
cvGvk := cv.GroupVersionKind()
cvGroupKind := scopeGroupKind{group: cvGvk.Group, kind: cvGvk.Kind}
cvGroupKind := scopeGroupKind{group: v1.GroupName, kind: clusterVersionKind}
cvScope := scopeResource{kind: cvGroupKind, name: cv.Name}

if c := findClusterOperatorStatusCondition(cv.Status.Conditions, clusterStatusFailing); c == nil {
Expand Down
10 changes: 6 additions & 4 deletions pkg/cli/admin/upgrade/status/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const (
nodeAssessmentExcluded
nodeAssessmentOutdated
nodeAssessmentCompleted

nodeKind string = "Node"
mcpKind string = "MachineConfigPool"
)

func (assessment nodeAssessment) String() string {
Expand Down Expand Up @@ -337,8 +340,7 @@ func nodeInsights(pool mcfgv1.MachineConfigPool, node corev1.Node, reason string
if pool.Name == "master" {
scope = scopeTypeControlPlane
}
nodeGvk := node.GroupVersionKind()
nodeGroupKind := scopeGroupKind{group: nodeGvk.Group, kind: nodeGvk.Kind}
nodeGroupKind := scopeGroupKind{kind: nodeKind}
if isUnavailable && !isUpdating {
insights = append(insights, updateInsight{
startedAt: time.Time{},
Expand Down Expand Up @@ -449,12 +451,12 @@ func machineConfigPoolInsights(poolDisplay poolDisplayData, pool mcfgv1.MachineC
// TODO: Only generate this insight if the pool has some work remaining that will not finish
// Depends on how MCO actually works: will it stop updating a node that already started e.g. draining?)
if poolDisplay.NodesOverview.Excluded > 0 && pool.Spec.Paused {
poolGvk := pool.GroupVersionKind()

insights = append(insights, updateInsight{
startedAt: time.Time{},
scope: updateInsightScope{
scopeType: scopeTypeWorkerPool,
resources: []scopeResource{{kind: scopeGroupKind{group: poolGvk.Group, kind: poolGvk.Kind}, name: pool.Name}},
resources: []scopeResource{{kind: scopeGroupKind{group: mcfgv1.GroupName, kind: mcpKind}, name: pool.Name}},
},
impact: updateInsightImpact{
level: warningImpactLevel,
Expand Down

0 comments on commit fad39d2

Please sign in to comment.