@@ -19,6 +19,7 @@ package conformance
1919import (
2020 "context"
2121 "fmt"
22+ "strings"
2223 "testing"
2324 "time"
2425
@@ -27,6 +28,7 @@ import (
2728 corev1 "k8s.io/api/core/v1"
2829 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2930 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3032 "k8s.io/apimachinery/pkg/labels"
3133 "k8s.io/apimachinery/pkg/runtime"
3234 "k8s.io/apimachinery/pkg/runtime/schema"
@@ -45,6 +47,7 @@ import (
4547 tenancyv1alpha1 "github.com/kcp-dev/sdk/apis/tenancy/v1alpha1"
4648 kcpclientset "github.com/kcp-dev/sdk/client/clientset/versioned/cluster"
4749 kcptesting "github.com/kcp-dev/sdk/testing"
50+ kcptestinghelpers "github.com/kcp-dev/sdk/testing/helpers"
4851
4952 configcrds "github.com/kcp-dev/kcp/config/crds"
5053 "github.com/kcp-dev/kcp/pkg/informer"
@@ -196,20 +199,20 @@ func TestCRDCrossLogicalClusterListPartialObjectMetadata(t *testing.T) {
196199 t .Logf ("Install a different sheriffs CRD into workspace %q" , wsNormalCRD2 )
197200 bootstrapCRD (t , wsNormalCRD2 , crdClusterClient .ApiextensionsV1 ().CustomResourceDefinitions (), sheriffCRD2 )
198201
199- apifixtures . CreateSheriff (ctx , t , dynamicClusterClient , wsNormalCRD1a , group , wsNormalCRD1a . String () )
200- apifixtures . CreateSheriff (ctx , t , dynamicClusterClient , wsNormalCRD1b , group , wsNormalCRD1b . String () )
202+ createSheriff (ctx , t , dynamicClusterClient , wsNormalCRD1a , group )
203+ createSheriff (ctx , t , dynamicClusterClient , wsNormalCRD1b , group )
201204
202205 apifixtures .CreateSheriffsSchemaAndExport (ctx , t , wsExport1a , kcpClusterClient , group , "export1" )
203206 apifixtures .BindToExport (ctx , t , wsExport1a , group , wsConsume1a , kcpClusterClient )
204- apifixtures . CreateSheriff (ctx , t , dynamicClusterClient , wsConsume1a , group , wsConsume1a . String () )
207+ createSheriff (ctx , t , dynamicClusterClient , wsConsume1a , group )
205208
206209 apifixtures .CreateSheriffsSchemaAndExport (ctx , t , wsExport1b , kcpClusterClient , group , "export1" )
207210 apifixtures .BindToExport (ctx , t , wsExport1b , group , wsConsume1b , kcpClusterClient )
208- apifixtures . CreateSheriff (ctx , t , dynamicClusterClient , wsConsume1b , group , wsConsume1b . String () )
211+ createSheriff (ctx , t , dynamicClusterClient , wsConsume1b , group )
209212
210213 apifixtures .CreateSheriffsSchemaAndExport (ctx , t , wsExport2 , kcpClusterClient , group , "export2" )
211214 apifixtures .BindToExport (ctx , t , wsExport2 , group , wsConsume2 , kcpClusterClient )
212- apifixtures . CreateSheriff (ctx , t , dynamicClusterClient , wsConsume2 , group , wsConsume2 . String () )
215+ createSheriff (ctx , t , dynamicClusterClient , wsConsume2 , group )
213216
214217 t .Logf ("Trying to wildcard list with PartialObjectMetadata content-type and it should work" )
215218 rootShardMetadataClusterClient , err := metadataclient .NewDynamicMetadataClusterClientForConfig (rootShardConfig )
@@ -321,3 +324,32 @@ func TestBuiltInCrossLogicalClusterListPartialObjectMetadata(t *testing.T) {
321324
322325 require .Subset (t , sets.List [string ](names ), expected )
323326}
327+
328+ func createSheriff (
329+ ctx context.Context ,
330+ t * testing.T ,
331+ dynamicClusterClient kcpdynamic.ClusterInterface ,
332+ clusterName logicalcluster.Path ,
333+ group string ,
334+ ) {
335+ t .Helper ()
336+
337+ name := strings .ReplaceAll (clusterName .String (), ":" , "-" )
338+
339+ t .Logf ("Creating %s/v1 sheriffs %s|default/%s" , group , clusterName , name )
340+
341+ sheriffsGVR := schema.GroupVersionResource {Group : group , Resource : "sheriffs" , Version : "v1" }
342+
343+ sheriff := & unstructured.Unstructured {}
344+ sheriff .SetAPIVersion (group + "/v1" )
345+ sheriff .SetKind ("Sheriff" )
346+ sheriff .SetName (name )
347+
348+ // CRDs are asynchronously served because they are informer based.
349+ kcptestinghelpers .Eventually (t , func () (bool , string ) {
350+ if _ , err := dynamicClusterClient .Cluster (clusterName ).Resource (sheriffsGVR ).Namespace ("default" ).Create (ctx , sheriff , metav1.CreateOptions {}); err != nil {
351+ return false , fmt .Sprintf ("failed to create Sheriff %s|%s: %v" , clusterName , name , err .Error ())
352+ }
353+ return true , ""
354+ }, wait .ForeverTestTimeout , time .Millisecond * 100 , "error creating Sheriff %s|%s" , clusterName , name )
355+ }
0 commit comments