@@ -1134,7 +1134,14 @@ func (gm *GroupModel) GetImports() map[string]*ResourceModel {
1134
1134
for _ , grName := range gm .XImportResources {
1135
1135
parts := strings .Split (grName , "/" )
1136
1136
r := gm .Model .FindResourceModel (parts [1 ], parts [2 ])
1137
- PanicIf (r == nil , "Can't find %q" , grName )
1137
+ if r == nil {
1138
+ // While this should technically be an error, assume that
1139
+ // we'll flag it during the verify() work and not here since
1140
+ // some calls to this are just looking to see if something
1141
+ // exists in the list and we don't really care about bad
1142
+ // refs right then.
1143
+ continue
1144
+ }
1138
1145
gm .imports [parts [2 ]] = r
1139
1146
}
1140
1147
}
@@ -1840,55 +1847,112 @@ func (gm *GroupModel) Verify(gmName string) error {
1840
1847
1841
1848
// TODO: verify the Groups data are model compliant
1842
1849
1850
+ // Save the plurals/singulars are we go so we can quickly see when
1851
+ // dups are specified. We don't use the values, yet... maybe one day
1852
+ plurals := map [string ]string {} // plural->singular
1853
+ singulars := map [string ]string {} // singular->plural
1854
+
1843
1855
// Verify the "ximportresources" list, same names for later checking
1844
- resList := map [string ]bool {}
1845
1856
for _ , grName := range gm .XImportResources {
1857
+ // In this func be careful using the *.Plural value because some
1858
+ // may not be filled in yet - like r.Plural. gm.Plural as done above
1859
+
1846
1860
parts := strings .Split (grName , "/" )
1847
1861
if len (parts ) != 3 {
1848
- return fmt .Errorf ("Group %q has an invalid ximportresources value " +
1849
- "(%s), must be of the form \" /GroupType/ResourceType \" " ,
1862
+ return fmt .Errorf ("Group %q has an invalid \" ximportresources\" " +
1863
+ "value (%s), must be of the form \" /Group/Resource \" " ,
1850
1864
gm .Plural , grName )
1851
1865
}
1852
1866
if parts [0 ] != "" {
1853
- return fmt .Errorf ("Group %q has an invalid ximportresources value " +
1854
- "(%s), must start with \" /\" and be of the form " +
1855
- "\" /GroupType/ResourceType \" " , gm .Plural , grName )
1867
+ return fmt .Errorf ("Group %q has an invalid \" ximportresources\" " +
1868
+ "value (%s), must start with \" /\" and be of the form " +
1869
+ "\" /Group/Resource \" " , gm .Plural , grName )
1856
1870
}
1857
1871
if parts [1 ] == gm .Plural {
1858
- return fmt .Errorf ("Group %q has a bad ximportresources value " +
1872
+ return fmt .Errorf ("Group %q has a bad \" ximportresources\" value " +
1859
1873
"(%s), it can't reference itself" , gm .Plural , grName )
1860
1874
}
1861
1875
1862
1876
g := gm .Model .FindGroupModel (parts [1 ])
1863
1877
if g == nil {
1864
- return fmt .Errorf ("Group %q references a non-existing Group in: " +
1865
- "%s " , gm .Plural , grName )
1878
+ return fmt .Errorf ("Group %q references a non-existing " +
1879
+ "Group %q " , gm .Plural , parts [ 1 ] )
1866
1880
}
1867
1881
1868
- r := g .FindResourceModel (parts [2 ])
1882
+ // r := g.FindResourceModel(parts[2]) - don't use, don't want ximps
1883
+ r := g .Resources [parts [2 ]]
1869
1884
if r == nil {
1870
- return fmt .Errorf ("Group %q references a non-existing Resource " +
1871
- "in: " + "%s" , gm .Plural , grName )
1885
+ for _ , imp := range g .XImportResources {
1886
+ if strings .HasSuffix (imp , "/" + parts [2 ]) {
1887
+ return fmt .Errorf ("Group %q references an imported " +
1888
+ "Resource %q, try using %q instead" ,
1889
+ gm .Plural , grName , imp )
1890
+ }
1891
+ }
1892
+ return fmt .Errorf ("Group %q references a non-existing " +
1893
+ "Resource %q" , gm .Plural , grName )
1894
+ }
1895
+
1896
+ if _ , ok := plurals [parts [2 ]]; ok {
1897
+ return fmt .Errorf ("Group %q has a duplicate Resource \" plural\" " +
1898
+ "name %q" , gm .Plural , parts [2 ])
1899
+ }
1900
+
1901
+ if _ , ok := plurals [r .Singular ]; ok {
1902
+ return fmt .Errorf ("Group %q has a \" singular\" Resource name " +
1903
+ "%q that conflicts with a \" plural\" Resource name" ,
1904
+ gm .Plural , parts [2 ])
1872
1905
}
1873
- resList [r .Plural ] = true
1906
+
1907
+ if _ , ok := singulars [r .Singular ]; ok {
1908
+ return fmt .Errorf ("Group %q has a duplicate \" singular\" " +
1909
+ "Resource name %q" , gm .Plural , r .Singular )
1910
+ }
1911
+
1912
+ plurals [parts [2 ]] = r .Singular
1913
+ singulars [r .Singular ] = parts [2 ]
1874
1914
}
1875
1915
1876
1916
// Verify the Resources to catch invalid Resource names early
1877
- for rmName , rm := range gm .Resources {
1917
+ // Just so we always do them in order for consistent testing
1918
+ rList := SortedKeys (gm .Resources )
1919
+ for _ , rmName := range rList {
1920
+ rm := gm .Resources [rmName ]
1878
1921
if rm == nil {
1879
- return fmt .Errorf ("Resource %q can't be empty" , rmName )
1922
+ return fmt .Errorf ("Group %q has an empty Resource %q" ,
1923
+ gm .Plural , rmName )
1924
+ }
1925
+
1926
+ if _ , ok := plurals [rmName ]; ok {
1927
+ return fmt .Errorf ("Group %q has a Resource %q that has a " +
1928
+ "duplicate \" plural\" name" , gm .Plural , rmName )
1880
1929
}
1881
1930
1882
- if resList [rmName ] == true {
1883
- return fmt .Errorf ("Resource %q is a duplicate name from the " +
1884
- "\" ximportresources \" list" , rmName )
1931
+ if _ , ok := singulars [rmName ]; ok {
1932
+ return fmt .Errorf ("Group %q has a Resource %q that has a " +
1933
+ "duplicate \" singular \" name" , gm . Plural , rmName )
1885
1934
}
1886
1935
1887
1936
rm .GroupModel = gm
1888
1937
1889
1938
if err := rm .Verify (rmName ); err != nil {
1890
1939
return err
1891
1940
}
1941
+
1942
+ if _ , ok := plurals [rm .Singular ]; ok {
1943
+ return fmt .Errorf ("Group %q has a Resource %q that has a " +
1944
+ "\" singular\" name that conflicts with an existing " +
1945
+ "\" plural\" name" , gm .Plural , rmName )
1946
+ }
1947
+
1948
+ if _ , ok := singulars [rm .Singular ]; ok {
1949
+ return fmt .Errorf ("Group %q has a Resource %q that has a " +
1950
+ "duplicate \" singular\" name %q" ,
1951
+ gm .Plural , rmName , rm .Singular )
1952
+ }
1953
+
1954
+ plurals [rmName ] = rm .Singular
1955
+ singulars [rm .Singular ] = rmName
1892
1956
}
1893
1957
1894
1958
// Make sure we have the xRegistry core/spec defined attributes
0 commit comments