From 4bbbe18ddbcffd480c7443042091b475fc30303a Mon Sep 17 00:00:00 2001 From: dislbenn Date: Wed, 29 Apr 2026 13:43:44 -0400 Subject: [PATCH] [ACM-30429] Fix nil pointer dereference in Equal() method Fixed nil pointer panic in DiscoveredCluster.Equal() by adding nil checks for ActivityTimestamp and CreationTimestamp pointers before calling Truncate(). Changes: - Added timestampsEqual() helper function to safely compare *metav1.Time pointers - Updated Equal() method in api/v1 to use the helper - Updated component version from 2.17 to 5.0 in COMPONENT_VERSION and Dockerfile Fixes: ACM-30429 Signed-off-by: dislbenn --- COMPONENT_VERSION | 2 +- api/v1/discoveredcluster_types.go | 15 +++++++++++++-- build/Dockerfile.rhtap | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/COMPONENT_VERSION b/COMPONENT_VERSION index 6618ab545..28cbf7c0a 100644 --- a/COMPONENT_VERSION +++ b/COMPONENT_VERSION @@ -1 +1 @@ -2.17.0 \ No newline at end of file +5.0.0 \ No newline at end of file diff --git a/api/v1/discoveredcluster_types.go b/api/v1/discoveredcluster_types.go index 21bfea88b..39b4409a8 100644 --- a/api/v1/discoveredcluster_types.go +++ b/api/v1/discoveredcluster_types.go @@ -160,13 +160,24 @@ func init() { SchemeBuilder.Register(&DiscoveredCluster{}, &DiscoveredClusterList{}) } +// timestampsEqual checks if two timestamp pointers are equal (handling nil cases). +func timestampsEqual(a, b *metav1.Time) bool { + if a == nil && b == nil { + return true + } + if a == nil || b == nil { + return false + } + return a.Truncate(time.Second).Equal(b.Truncate(time.Second)) +} + // Equal reports whether the spec of a is equal to b. func (a DiscoveredCluster) Equal(b DiscoveredCluster) bool { if a.Spec.APIURL != b.Spec.APIURL || - a.Spec.ActivityTimestamp.Truncate(time.Second) != b.Spec.ActivityTimestamp.Truncate(time.Second) || + !timestampsEqual(a.Spec.ActivityTimestamp, b.Spec.ActivityTimestamp) || a.Spec.CloudProvider != b.Spec.CloudProvider || a.Spec.Console != b.Spec.Console || - a.Spec.CreationTimestamp.Truncate(time.Second) != b.Spec.CreationTimestamp.Truncate(time.Second) || + !timestampsEqual(a.Spec.CreationTimestamp, b.Spec.CreationTimestamp) || a.Spec.Credential != b.Spec.Credential || a.Spec.DisplayName != b.Spec.DisplayName || a.Spec.ImportAsManagedCluster != b.Spec.ImportAsManagedCluster || diff --git a/build/Dockerfile.rhtap b/build/Dockerfile.rhtap index b45dc6192..c8d05c008 100644 --- a/build/Dockerfile.rhtap +++ b/build/Dockerfile.rhtap @@ -30,7 +30,7 @@ LABEL org.label-schema.vendor="Red Hat" \ io.k8s.description="Operator for managing discovered clusters from OpenShift Cluster Manager" \ com.redhat.component="multicluster-engine-discovery-operator-container" \ io.openshift.tags="data,images" \ - cpe="cpe:/a:redhat:multicluster_engine:2.17::el9" + cpe="cpe:/a:redhat:multicluster_engine:5.0::el9" WORKDIR / COPY --from=plugin-builder /workspace/manager .