@@ -37,18 +37,18 @@ const (
3737ORC's API design philosophy states that spec fields should only reference
3838ORC Kubernetes objects, not OpenStack resources directly by UUID.
3939
40- Fields ending with 'ID' (like ProjectID, NetworkID ) in spec structs should
41- instead use KubernetesNameRef type with a 'Ref' suffix (like ProjectRef, NetworkRef ).
40+ Fields ending with 'ID' or 'IDs' (like ProjectID, NetworkIDs ) in spec structs should
41+ instead use KubernetesNameRef type with a 'Ref' or 'Refs' suffix (like ProjectRef, NetworkRefs ).
4242
4343See: https://k-orc.cloud/development/api-design/`
4444)
4545
46- // openstackIDPattern matches field names that end with "ID" and are likely
46+ // openstackIDPattern matches field names that end with "ID" or "IDs" and are likely
4747// references to OpenStack resources by UUID. These should instead use
48- // KubernetesNameRef with a "Ref" suffix to reference ORC objects.
49- var openstackIDPattern = regexp .MustCompile (`ID $` )
48+ // KubernetesNameRef with a "Ref" or "Refs" suffix to reference ORC objects.
49+ var openstackIDPattern = regexp .MustCompile (`IDs? $` )
5050
51- // excludedIDPatterns contains field name patterns that end in "ID" but are
51+ // excludedIDPatterns contains field name patterns that end in "ID" or "IDs" but are
5252// not OpenStack resource references.
5353var excludedIDPatterns = []string {
5454 "SegmentationID" , // VLAN segmentation ID, not an OpenStack resource
@@ -120,7 +120,14 @@ func checkField(pass *analysis.Pass, field *ast.Field, qualifiedFieldName string
120120 return
121121 }
122122
123- suggestedRef := strings .TrimSuffix (fieldName , "ID" ) + "Ref"
123+ // Generate the suggested Ref/Refs name based on singular/plural
124+ var suggestedRef string
125+ if strings .HasSuffix (fieldName , "IDs" ) {
126+ suggestedRef = strings .TrimSuffix (fieldName , "IDs" ) + "Refs"
127+ } else {
128+ suggestedRef = strings .TrimSuffix (fieldName , "ID" ) + "Ref"
129+ }
130+
124131 pass .Reportf (field .Pos (),
125132 "field %s references OpenStack resource by ID in spec; " +
126133 "use *KubernetesNameRef with %s instead; " +
0 commit comments