Skip to content

Commit 4264719

Browse files
Fix OpenShift cluster S3 backup name matching (#3500)
1 parent 53769c4 commit 4264719

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

vars/openshiftCluster.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def list(Map config = [:]) {
421421
// Transform discovered clusters to match expected format
422422
def clusters = []
423423
discoveredClusters.each { cluster ->
424-
clusters << [
424+
def clusterInfo = [
425425
name: cluster.name,
426426
version: cluster.metadata?.openshift_version ?: 'Unknown',
427427
region: cluster.metadata?.aws_region ?: params.region,
@@ -433,6 +433,11 @@ def list(Map config = [:]) {
433433
has_backup: cluster.s3State?.hasBackup ? 'Yes' : 'No',
434434
resource_count: cluster.resources?.size() ?: 0
435435
]
436+
// Include base name if present (for clusters with random suffixes)
437+
if (cluster.baseName) {
438+
clusterInfo.baseName = cluster.baseName
439+
}
440+
clusters << clusterInfo
436441
}
437442

438443
// Log discovery summary

vars/openshiftDiscovery.groovy

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,33 @@ def discoverClusters(Map params = [:]) {
107107
// Step 3: Consolidate data
108108
def consolidatedClusters = []
109109

110-
// Process all unique cluster names
111-
def allClusterNames = (s3Clusters.keySet() + awsClusters.keySet()) as Set
112-
113-
allClusterNames.each { clusterName ->
114-
def s3Cluster = s3Clusters[clusterName]
115-
def awsCluster = awsClusters[clusterName]
110+
// Track which S3 clusters have been matched to AWS clusters
111+
def matchedS3Clusters = [] as Set
112+
def matchedAWSClusters = [] as Set
113+
114+
// First pass: Try to match AWS clusters with S3 clusters
115+
// AWS cluster names often have random suffixes (e.g., test-cluster-7-qc8lc)
116+
// while S3 stores them with base names (e.g., test-cluster-7)
117+
awsClusters.each { awsClusterName, awsCluster ->
118+
def matchedS3Name = null
119+
120+
// Check if this AWS cluster name starts with any S3 cluster name
121+
s3Clusters.each { s3ClusterName, s3Cluster ->
122+
// Match if AWS cluster name starts with S3 cluster name followed by a hyphen
123+
// This handles the pattern: base-name-randomsuffix
124+
if (awsClusterName == s3ClusterName ||
125+
awsClusterName.startsWith("${s3ClusterName}-")) {
126+
matchedS3Name = s3ClusterName
127+
return true // Break out of the inner loop
128+
}
129+
}
116130

117-
if (s3Cluster && awsCluster) {
118-
// Merge data from both sources
131+
if (matchedS3Name) {
132+
// Found matching S3 backup
133+
def s3Cluster = s3Clusters[matchedS3Name]
119134
def merged = [
120-
name: clusterName,
135+
name: awsClusterName, // Use the AWS cluster name (with suffix) as the primary name
136+
baseName: matchedS3Name, // Store the base name for reference
121137
source: 'combined',
122138
status: s3Cluster.status ?: awsCluster.status,
123139
metadata: [:],
@@ -130,16 +146,26 @@ def discoverClusters(Map params = [:]) {
130146
merged.metadata.putAll(s3Cluster.metadata ?: [:])
131147

132148
consolidatedClusters << merged
133-
} else if (s3Cluster) {
134-
// S3 only - cluster might be deleted but state preserved
135-
consolidatedClusters << s3Cluster
136-
} else if (awsCluster) {
137-
// AWS only - active cluster without S3 backup
149+
matchedS3Clusters << matchedS3Name
150+
matchedAWSClusters << awsClusterName
151+
}
152+
}
153+
154+
// Second pass: Add unmatched AWS clusters (no S3 backup)
155+
awsClusters.each { awsClusterName, awsCluster ->
156+
if (!matchedAWSClusters.contains(awsClusterName)) {
138157
awsCluster.s3State = [hasBackup: false]
139158
consolidatedClusters << awsCluster
140159
}
141160
}
142161

162+
// Third pass: Add unmatched S3 clusters (deleted or no AWS resources)
163+
s3Clusters.each { s3ClusterName, s3Cluster ->
164+
if (!matchedS3Clusters.contains(s3ClusterName)) {
165+
consolidatedClusters << s3Cluster
166+
}
167+
}
168+
143169
// Sort by cluster name for consistent output
144170
consolidatedClusters.sort { it.name }
145171

vars/openshiftTools.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,10 @@ def formatClustersSummary(List clusters, String title = "OPENSHIFT CLUSTERS") {
540540
// Format each cluster
541541
clusters.each { cluster ->
542542
summary.append("Cluster: ${cluster.name}\n")
543+
// Show base name if it differs from the cluster name (for clusters with random suffixes)
544+
if (cluster.baseName && cluster.baseName != cluster.name) {
545+
summary.append(" S3 Base Name: ${cluster.baseName}\n")
546+
}
543547
summary.append(" Version: ${cluster.version}\n")
544548
summary.append(" Region: ${cluster.region}\n")
545549
summary.append(" Created: ${cluster.created_at}\n")

0 commit comments

Comments
 (0)