@@ -1110,6 +1110,7 @@ func (sc *syncContext) shouldUseServerSideApply(targetObj *unstructured.Unstruct
1110
1110
return sc .serverSideApply || resourceutil .HasAnnotationOption (targetObj , common .AnnotationSyncOptions , common .SyncOptionServerSideApply )
1111
1111
}
1112
1112
1113
+ << << << < HEAD
1113
1114
// needsClientSideApplyMigration checks if a resource has fields managed by the specified manager
1114
1115
// that need to be migrated to the server-side apply manager
1115
1116
func (sc * syncContext ) needsClientSideApplyMigration (liveObj * unstructured.Unstructured , fieldManager string ) bool {
@@ -1156,56 +1157,103 @@ func (sc *syncContext) performClientSideApplyMigration(targetObj *unstructured.U
1156
1157
return nil
1157
1158
}
1158
1159
1160
+ == == == =
1161
+ // formatValue converts any value to its string representation with special handling for
1162
+ // templates, maps, and strings. Returns "<nil>" for nil values.
1163
+ >> >> >> > 3 df63b1 (refactor formatValue method to reduce complexity )
1159
1164
func formatValue (v any ) string {
1160
1165
if v == nil {
1161
1166
return "<nil>"
1162
1167
}
1163
1168
1164
- // Special case for volumeClaimTemplates
1165
- if templates , ok := v .([]any ); ok {
1166
- // For a single volumeClaimTemplate field change
1167
- if len (templates ) == 1 {
1168
- if template , ok := templates [0 ].(map [string ]any ); ok {
1169
- if storage := getTemplateStorage (template ); storage != "" {
1170
- return fmt .Sprintf ("%q" , storage )
1171
- }
1172
- }
1173
- }
1174
- // For multiple templates or other array types format
1175
- var names []string
1176
- for _ , t := range templates {
1177
- if template , ok := t .(map [string ]any ); ok {
1178
- if metadata , ok := template ["metadata" ].(map [string ]any ); ok {
1179
- if name , ok := metadata ["name" ].(string ); ok {
1180
- if storage := getTemplateStorage (template ); storage != "" {
1181
- names = append (names , fmt .Sprintf ("%s(%s)" , name , storage ))
1182
- continue
1183
- }
1184
- names = append (names , name )
1185
- }
1186
- }
1187
- }
1169
+ switch val := v .(type ) {
1170
+ case []any :
1171
+ return formatTemplates (val )
1172
+ case map [string ]any :
1173
+ return formatMap (val )
1174
+ case string :
1175
+ return fmt .Sprintf ("%q" , val )
1176
+ default :
1177
+ return fmt .Sprintf ("%v" , val )
1178
+ }
1179
+ }
1180
+
1181
+ // formatTemplates handles the formatting of volumeClaimTemplates arrays.
1182
+ // For single templates with storage, returns the storage value.
1183
+ // For multiple templates, returns a formatted list of template names with storage.
1184
+ func formatTemplates (templates []any ) string {
1185
+ if len (templates ) == 1 {
1186
+ if storage := getSingleTemplateStorage (templates [0 ]); storage != "" {
1187
+ return fmt .Sprintf ("%q" , storage )
1188
1188
}
1189
- return fmt .Sprintf ("[%s]" , strings .Join (names , ", " ))
1190
1189
}
1190
+ return formatMultipleTemplates (templates )
1191
+ }
1191
1192
1192
- // Special case for selector matchLabels
1193
- if m , ok := v .(map [string ]any ); ok {
1194
- if matchLabels , exists := m ["matchLabels" ].(map [string ]any ); exists {
1195
- var labels []string
1196
- for k , v := range matchLabels {
1197
- labels = append (labels , fmt .Sprintf ("%s:%s" , k , v ))
1198
- }
1199
- sort .Strings (labels )
1200
- return fmt .Sprintf ("{%s}" , strings .Join (labels , ", " ))
1193
+ // getSingleTemplateStorage extracts storage value from a single template.
1194
+ // Returns empty string if template is invalid or has no storage.
1195
+ func getSingleTemplateStorage (t any ) string {
1196
+ template , ok := t .(map [string ]any )
1197
+ if ! ok {
1198
+ return ""
1199
+ }
1200
+ return getTemplateStorage (template )
1201
+ }
1202
+
1203
+ // formatMultipleTemplates formats an array of templates into a string list
1204
+ // of template names, optionally including storage information.
1205
+ func formatMultipleTemplates (templates []any ) string {
1206
+ var names []string
1207
+ for _ , t := range templates {
1208
+ if name := getTemplateName (t ); name != "" {
1209
+ names = append (names , name )
1201
1210
}
1202
1211
}
1203
- // Add quotes for string values
1204
- if str , ok := v .(string ); ok {
1205
- return fmt .Sprintf ("%q" , str )
1212
+ return fmt .Sprintf ("[%s]" , strings .Join (names , ", " ))
1213
+ }
1214
+
1215
+ // getTemplateName extracts and formats the name from a template.
1216
+ // If template has storage, appends it to the name in parentheses.
1217
+ func getTemplateName (t any ) string {
1218
+ template , ok := t .(map [string ]any )
1219
+ if ! ok {
1220
+ return ""
1221
+ }
1222
+
1223
+ metadata , ok := template ["metadata" ].(map [string ]any )
1224
+ if ! ok {
1225
+ return ""
1226
+ }
1227
+
1228
+ name , ok := metadata ["name" ].(string )
1229
+ if ! ok {
1230
+ return ""
1231
+ }
1232
+
1233
+ if storage := getTemplateStorage (template ); storage != "" {
1234
+ return fmt .Sprintf ("%s(%s)" , name , storage )
1235
+ }
1236
+ return name
1237
+ }
1238
+
1239
+ // formatMap handles special case formatting for maps, particularly for matchLabels.
1240
+ // Returns standard string representation for non-matchLabel maps.
1241
+ func formatMap (m map [string ]any ) string {
1242
+ if matchLabels , exists := m ["matchLabels" ].(map [string ]any ); exists {
1243
+ return formatMatchLabels (matchLabels )
1244
+ }
1245
+ return fmt .Sprintf ("%v" , m )
1246
+ }
1247
+
1248
+ // formatMatchLabels converts a matchLabels map into a sorted string list
1249
+ // of key:value pairs enclosed in curly braces.
1250
+ func formatMatchLabels (matchLabels map [string ]any ) string {
1251
+ var labels []string
1252
+ for k , v := range matchLabels {
1253
+ labels = append (labels , fmt .Sprintf ("%s:%s" , k , v ))
1206
1254
}
1207
- // For other types, use standard formatting
1208
- return fmt .Sprintf ("%v " , v )
1255
+ sort . Strings ( labels )
1256
+ return fmt .Sprintf ("{%s} " , strings . Join ( labels , ", " ) )
1209
1257
}
1210
1258
1211
1259
// Get storage size from template
0 commit comments