@@ -22,12 +22,11 @@ import (
22
22
"testing"
23
23
24
24
. "github.com/onsi/gomega"
25
-
26
25
"github.com/pkg/errors"
27
-
28
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
27
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
30
28
"k8s.io/apimachinery/pkg/types"
29
+ clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
31
30
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test"
32
31
"sigs.k8s.io/controller-runtime/pkg/client"
33
32
)
@@ -64,7 +63,7 @@ func TestObjectGraph_getDiscoveryTypeMetaList(t *testing.T) {
64
63
t .Run (tt .name , func (t * testing.T ) {
65
64
g := NewWithT (t )
66
65
67
- graph := newObjectGraph (tt .fields .proxy )
66
+ graph := newObjectGraph (tt .fields .proxy , nil )
68
67
err := graph .getDiscoveryTypes ()
69
68
if tt .wantErr {
70
69
g .Expect (err ).To (HaveOccurred ())
@@ -304,7 +303,7 @@ func TestObjectGraph_addObj(t *testing.T) {
304
303
}
305
304
for _ , tt := range tests {
306
305
t .Run (tt .name , func (t * testing.T ) {
307
- graph := newObjectGraph (nil )
306
+ graph := newObjectGraph (nil , nil )
308
307
for _ , o := range tt .args .objs {
309
308
graph .addObj (o )
310
309
}
@@ -1012,44 +1011,47 @@ var objectGraphsTests = []struct {
1012
1011
},
1013
1012
},
1014
1013
{
1015
- name : "Cluster and Global + Namespaced External Objects" ,
1014
+ // NOTE: External objects are CRD types installed by clusterctl, but not directly related with the CAPI hierarchy of objects. e.g. IPAM claims.
1015
+ name : "Namespaced External Objects with force move label" ,
1016
1016
args : objectGraphTestArgs {
1017
- func () []client.Object {
1018
- objs := []client.Object {}
1019
- objs = append (objs , test .NewFakeCluster ("ns1" , "cluster1" ).Objs ()... )
1020
- objs = append (objs , test .NewFakeExternalObject ("ns1" , "externalObject1" ).Objs ()... )
1021
- objs = append (objs , test .NewFakeExternalObject ("" , "externalObject2" ).Objs ()... )
1022
-
1023
- return objs
1024
- }(),
1017
+ objs : test .NewFakeExternalObject ("ns1" , "externalObject1" ).Objs (),
1025
1018
},
1026
1019
want : wantGraph {
1027
1020
nodes : map [string ]wantGraphItem {
1028
1021
"external.cluster.x-k8s.io/v1alpha4, Kind=GenericExternalObject, ns1/externalObject1" : {},
1029
- "external.cluster.x-k8s.io/v1alpha4, Kind=GenericExternalObject, /externalObject2" : {},
1030
- "cluster.x-k8s.io/v1alpha4, Kind=Cluster, ns1/cluster1" : {},
1031
- "infrastructure.cluster.x-k8s.io/v1alpha4, Kind=GenericInfrastructureCluster, ns1/cluster1" : {
1032
- owners : []string {
1033
- "cluster.x-k8s.io/v1alpha4, Kind=Cluster, ns1/cluster1" ,
1034
- },
1035
- },
1036
- "/v1, Kind=Secret, ns1/cluster1-ca" : {
1037
- softOwners : []string {
1038
- "cluster.x-k8s.io/v1alpha4, Kind=Cluster, ns1/cluster1" , // NB. this secret is not linked to the cluster through owner ref
1039
- },
1040
- },
1041
- "/v1, Kind=Secret, ns1/cluster1-kubeconfig" : {
1042
- owners : []string {
1043
- "cluster.x-k8s.io/v1alpha4, Kind=Cluster, ns1/cluster1" ,
1044
- },
1045
- },
1022
+ },
1023
+ },
1024
+ },
1025
+ {
1026
+ // NOTE: External objects are CRD types installed by clusterctl, but not directly related with the CAPI hierarchy of objects. e.g. IPAM claims.
1027
+ name : "Global External Objects with force move label" ,
1028
+ args : objectGraphTestArgs {
1029
+ objs : test .NewFakeExternalObject ("" , "externalObject1" ).Objs (),
1030
+ },
1031
+ want : wantGraph {
1032
+ nodes : map [string ]wantGraphItem {
1033
+ "external.cluster.x-k8s.io/v1alpha4, Kind=GenericExternalObject, /externalObject1" : {},
1034
+ },
1035
+ },
1036
+ },
1037
+ {
1038
+ // NOTE: Infrastructure providers global credentials are going to be stored in Secrets in the provider's namespaces.
1039
+ name : "Secrets from provider's namespace" ,
1040
+ args : objectGraphTestArgs {
1041
+ objs : []client.Object {
1042
+ test .NewSecret ("infra1" , "credentials" ),
1043
+ },
1044
+ },
1045
+ want : wantGraph {
1046
+ nodes : map [string ]wantGraphItem {
1047
+ "/v1, Kind=Secret, infra1/credentials" : {},
1046
1048
},
1047
1049
},
1048
1050
},
1049
1051
}
1050
1052
1051
1053
func getDetachedObjectGraphWihObjs (objs []client.Object ) (* objectGraph , error ) {
1052
- graph := newObjectGraph (nil ) // detached from any cluster
1054
+ graph := newObjectGraph (nil , nil ) // detached from any cluster
1053
1055
for _ , o := range objs {
1054
1056
u := & unstructured.Unstructured {}
1055
1057
if err := test .FakeScheme .Convert (o , u , nil ); err != nil {
@@ -1084,7 +1086,10 @@ func getObjectGraphWithObjs(objs []client.Object) *objectGraph {
1084
1086
fromProxy .WithObjs (o )
1085
1087
}
1086
1088
1087
- return newObjectGraph (fromProxy )
1089
+ fromProxy .WithProviderInventory ("infra1" , clusterctlv1 .InfrastructureProviderType , "v1.2.3" , "infra1" )
1090
+ inventory := newInventoryClient (fromProxy , fakePollImmediateWaiter )
1091
+
1092
+ return newObjectGraph (fromProxy , inventory )
1088
1093
}
1089
1094
1090
1095
func getFakeProxyWithCRDs () * test.FakeProxy {
@@ -1225,6 +1230,34 @@ func TestObjectGraph_DiscoveryByNamespace(t *testing.T) {
1225
1230
},
1226
1231
},
1227
1232
},
1233
+ {
1234
+ // NOTE: External objects are CRD types installed by clusterctl, but not directly related with the CAPI hierarchy of objects. e.g. IPAM claims.
1235
+ name : "Namespaced External Objects with force move label" ,
1236
+ args : args {
1237
+ namespace : "ns1" , // read only from ns1
1238
+ objs : test .NewFakeExternalObject ("ns1" , "externalObject1" ).Objs (), // Fake external object with
1239
+ },
1240
+ want : wantGraph {
1241
+ nodes : map [string ]wantGraphItem {
1242
+ "external.cluster.x-k8s.io/v1alpha4, Kind=GenericExternalObject, ns1/externalObject1" : {},
1243
+ },
1244
+ },
1245
+ },
1246
+ {
1247
+ // NOTE: Infrastructure providers global credentials are going to be stored in Secrets in the provider's namespaces.
1248
+ name : "Secrets from provider's namespace (e.g. credentials) should always be read" ,
1249
+ args : args {
1250
+ namespace : "ns1" , // read only from ns1
1251
+ objs : []client.Object {
1252
+ test .NewSecret ("infra1" , "credentials" ), // a secret in infra1 namespace, where an infrastructure provider is installed
1253
+ },
1254
+ },
1255
+ want : wantGraph {
1256
+ nodes : map [string ]wantGraphItem {
1257
+ "/v1, Kind=Secret, infra1/credentials" : {},
1258
+ },
1259
+ },
1260
+ },
1228
1261
}
1229
1262
1230
1263
for _ , tt := range tests {
0 commit comments