@@ -1120,6 +1120,8 @@ var objectGraphsTests = []struct {
1120
1120
"addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSetBinding, ns1/cluster1" : {
1121
1121
owners : []string {
1122
1122
"addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSet, ns1/crs1" ,
1123
+ },
1124
+ softOwners : []string {
1123
1125
"cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" ,
1124
1126
},
1125
1127
},
@@ -1201,12 +1203,16 @@ var objectGraphsTests = []struct {
1201
1203
"addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSetBinding, ns1/cluster1" : {
1202
1204
owners : []string {
1203
1205
"addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSet, ns1/crs1" ,
1206
+ },
1207
+ softOwners : []string {
1204
1208
"cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" ,
1205
1209
},
1206
1210
},
1207
1211
"addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSetBinding, ns1/cluster2" : {
1208
1212
owners : []string {
1209
1213
"addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSet, ns1/crs1" ,
1214
+ },
1215
+ softOwners : []string {
1210
1216
"cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster2" ,
1211
1217
},
1212
1218
},
@@ -1887,32 +1893,148 @@ func Test_objectGraph_setSoftOwnership(t *testing.T) {
1887
1893
objs []client.Object
1888
1894
}
1889
1895
tests := []struct {
1890
- name string
1891
- fields fields
1892
- wantSecrets map [ string ][] string
1896
+ name string
1897
+ fields fields
1898
+ want wantGraph
1893
1899
}{
1894
1900
{
1895
1901
name : "A cluster with a soft owned secret" ,
1896
1902
fields : fields {
1897
- objs : test .NewFakeCluster ("ns1" , "foo " ).Objs (),
1903
+ objs : test .NewFakeCluster ("ns1" , "cluster1 " ).Objs (),
1898
1904
},
1899
- wantSecrets : map [string ][]string { // wantSecrets is a map[node UID] --> list of soft owner UIDs
1900
- "/v1, Kind=Secret, ns1/foo-ca" : { // the ca secret has no explicit OwnerRef to the cluster, so it should be identified as a soft ownership
1901
- "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/foo" ,
1905
+ want : wantGraph {
1906
+ nodes : map [string ]wantGraphItem {
1907
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" : {
1908
+ forceMove : true ,
1909
+ forceMoveHierarchy : true ,
1910
+ },
1911
+ "infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericInfrastructureCluster, ns1/cluster1" : {
1912
+ owners : []string {
1913
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" ,
1914
+ },
1915
+ },
1916
+ "/v1, Kind=Secret, ns1/cluster1-ca" : { // the ca secret has no explicit OwnerRef to the cluster, so it should be identified as a soft ownership
1917
+ softOwners : []string {
1918
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" ,
1919
+ },
1920
+ },
1921
+ "/v1, Kind=Secret, ns1/cluster1-kubeconfig" : { // the kubeconfig secret has explicit OwnerRef to the cluster, so it should NOT be identified as a soft ownership
1922
+ owners : []string {
1923
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" ,
1924
+ },
1925
+ },
1902
1926
},
1903
- "/v1, Kind=Secret, ns1/foo-kubeconfig" : {}, // the kubeconfig secret has explicit OwnerRef to the cluster, so it should NOT be identified as a soft ownership
1904
1927
},
1905
1928
},
1906
1929
{
1907
- name : "A cluster with a soft owned secret (cluster name with - in the middle) " ,
1930
+ name : "A ClusterClass with a soft owned Cluster " ,
1908
1931
fields : fields {
1909
- objs : test .NewFakeCluster ("ns1" , "foo-bar" ).Objs (),
1932
+ objs : func () []client.Object {
1933
+ objs := test .NewFakeClusterClass ("ns1" , "class1" ).Objs ()
1934
+ objs = append (objs , test .NewFakeCluster ("ns1" , "cluster1" ).WithTopologyClass ("class1" ).Objs ()... )
1935
+
1936
+ return objs
1937
+ }(),
1910
1938
},
1911
- wantSecrets : map [string ][]string { // wantSecrets is a map[node UID] --> list of soft owner UIDs
1912
- "/v1, Kind=Secret, ns1/foo-bar-ca" : { // the ca secret has no explicit OwnerRef to the cluster, so it should be identified as a soft ownership
1913
- "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/foo-bar" ,
1939
+ want : wantGraph {
1940
+ nodes : map [string ]wantGraphItem {
1941
+ "cluster.x-k8s.io/v1beta1, Kind=ClusterClass, ns1/class1" : {
1942
+ forceMove : true ,
1943
+ forceMoveHierarchy : true ,
1944
+ },
1945
+ "infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericInfrastructureClusterTemplate, ns1/class1" : {
1946
+ owners : []string {
1947
+ "cluster.x-k8s.io/v1beta1, Kind=ClusterClass, ns1/class1" ,
1948
+ },
1949
+ },
1950
+ "controlplane.cluster.x-k8s.io/v1beta1, Kind=GenericControlPlaneTemplate, ns1/class1" : {
1951
+ owners : []string {
1952
+ "cluster.x-k8s.io/v1beta1, Kind=ClusterClass, ns1/class1" ,
1953
+ },
1954
+ },
1955
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" : {
1956
+ forceMove : true ,
1957
+ forceMoveHierarchy : true ,
1958
+ softOwners : []string {
1959
+ "cluster.x-k8s.io/v1beta1, Kind=ClusterClass, ns1/class1" , // NB. this cluster is not linked to the clusterclass through owner ref, but it is detected as soft ownership
1960
+ },
1961
+ },
1962
+ "infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericInfrastructureCluster, ns1/cluster1" : {
1963
+ owners : []string {
1964
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" ,
1965
+ },
1966
+ },
1967
+ "/v1, Kind=Secret, ns1/cluster1-ca" : {
1968
+ softOwners : []string {
1969
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" , // NB. this secret is not linked to the cluster through owner ref, but it is detected as soft ownership
1970
+ },
1971
+ },
1972
+ "/v1, Kind=Secret, ns1/cluster1-kubeconfig" : {
1973
+ owners : []string {
1974
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" ,
1975
+ },
1976
+ },
1977
+ },
1978
+ },
1979
+ },
1980
+ {
1981
+ name : "A Cluster with a soft owned ClusterResourceSetBinding" ,
1982
+ fields : fields {
1983
+ objs : func () []client.Object {
1984
+ objs := test .NewFakeCluster ("ns1" , "cluster1" ).Objs ()
1985
+ objs = append (objs , test .NewFakeClusterResourceSet ("ns1" , "crs1" ).
1986
+ WithSecret ("resource-s1" ).
1987
+ WithConfigMap ("resource-c1" ).
1988
+ ApplyToCluster (test .SelectClusterObj (objs , "ns1" , "cluster1" )).
1989
+ Objs ()... )
1990
+
1991
+ return objs
1992
+ }(),
1993
+ },
1994
+ want : wantGraph {
1995
+ nodes : map [string ]wantGraphItem {
1996
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" : {
1997
+ forceMove : true ,
1998
+ forceMoveHierarchy : true ,
1999
+ },
2000
+ "infrastructure.cluster.x-k8s.io/v1beta1, Kind=GenericInfrastructureCluster, ns1/cluster1" : {
2001
+ owners : []string {
2002
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" ,
2003
+ },
2004
+ },
2005
+ "/v1, Kind=Secret, ns1/cluster1-ca" : {
2006
+ softOwners : []string {
2007
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" , // NB. this secret is not linked to the cluster through owner ref, but it is detected as soft ownership
2008
+ },
2009
+ },
2010
+ "/v1, Kind=Secret, ns1/cluster1-kubeconfig" : {
2011
+ owners : []string {
2012
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" ,
2013
+ },
2014
+ },
2015
+ "addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSet, ns1/crs1" : {
2016
+ forceMove : true ,
2017
+ forceMoveHierarchy : true ,
2018
+ },
2019
+ "addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSetBinding, ns1/cluster1" : {
2020
+ owners : []string {
2021
+ "addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSet, ns1/crs1" ,
2022
+ },
2023
+ softOwners : []string {
2024
+ "cluster.x-k8s.io/v1beta1, Kind=Cluster, ns1/cluster1" , // NB. this ClusterResourceSetBinding is not linked to the cluster through owner ref, but it is detected as soft ownership
2025
+ },
2026
+ },
2027
+ "/v1, Kind=Secret, ns1/resource-s1" : {
2028
+ owners : []string {
2029
+ "addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSet, ns1/crs1" ,
2030
+ },
2031
+ },
2032
+ "/v1, Kind=ConfigMap, ns1/resource-c1" : {
2033
+ owners : []string {
2034
+ "addons.cluster.x-k8s.io/v1beta1, Kind=ClusterResourceSet, ns1/crs1" ,
2035
+ },
2036
+ },
1914
2037
},
1915
- "/v1, Kind=Secret, ns1/foo-bar-kubeconfig" : {}, // the kubeconfig secret has explicit OwnerRef to the cluster, so it should NOT be identified as a soft ownership
1916
2038
},
1917
2039
},
1918
2040
}
@@ -1925,20 +2047,7 @@ func Test_objectGraph_setSoftOwnership(t *testing.T) {
1925
2047
1926
2048
graph .setSoftOwnership ()
1927
2049
1928
- gotSecrets := graph .getSecrets ()
1929
- g .Expect (gotSecrets ).To (HaveLen (len (tt .wantSecrets )))
1930
-
1931
- for _ , secret := range gotSecrets {
1932
- wantObjects , ok := tt .wantSecrets [string (secret .identity .UID )]
1933
- g .Expect (ok ).To (BeTrue ())
1934
-
1935
- gotObjects := []string {}
1936
- for softOwners := range secret .softOwners {
1937
- gotObjects = append (gotObjects , string (softOwners .identity .UID ))
1938
- }
1939
-
1940
- g .Expect (gotObjects ).To (ConsistOf (wantObjects ))
1941
- }
2050
+ assertGraph (t , graph , tt .want )
1942
2051
})
1943
2052
}
1944
2053
}
0 commit comments