From 94a9fcfc4eaa26308031b202f65656806a0c92ee Mon Sep 17 00:00:00 2001 From: Petr Muller Date: Sun, 19 May 2024 00:04:28 +0200 Subject: [PATCH] OCPBUGS-33762: Hardcode resource groups/kinds for now 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 (https://github.com/kubernetes/client-go/issues/1328, https://github.com/kubernetes/client-go/issues/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. --- pkg/cli/admin/upgrade/status/controlplane.go | 8 +++++--- pkg/cli/admin/upgrade/status/workerpool.go | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/cli/admin/upgrade/status/controlplane.go b/pkg/cli/admin/upgrade/status/controlplane.go index 64eb41915c..304dba8bb9 100644 --- a/pkg/cli/admin/upgrade/status/controlplane.go +++ b/pkg/cli/admin/upgrade/status/controlplane.go @@ -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 { @@ -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{ @@ -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 { diff --git a/pkg/cli/admin/upgrade/status/workerpool.go b/pkg/cli/admin/upgrade/status/workerpool.go index 68915c9cb6..6310546c22 100644 --- a/pkg/cli/admin/upgrade/status/workerpool.go +++ b/pkg/cli/admin/upgrade/status/workerpool.go @@ -59,6 +59,9 @@ const ( nodeAssessmentExcluded nodeAssessmentOutdated nodeAssessmentCompleted + + nodeKind string = "Node" + mcpKind string = "MachineConfigPool" ) func (assessment nodeAssessment) String() string { @@ -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{}, @@ -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,