@@ -19,6 +19,7 @@ limitations under the License.
1919package clusterinit
2020
2121import (
22+ "fmt"
2223 "strings"
2324 "testing"
2425
@@ -31,6 +32,7 @@ import (
3132 kcptenancyv1alpha1 "github.com/kcp-dev/sdk/apis/tenancy/v1alpha1"
3233
3334 rbacv1 "k8s.io/api/rbac/v1"
35+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
3436 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3537 "k8s.io/apimachinery/pkg/types"
3638 ctrlruntime "sigs.k8s.io/controller-runtime"
@@ -193,51 +195,23 @@ spec:
193195 // Verify the CRD exists in the target workspace and is Established
194196 targetClient := kcpClusterClient .Cluster (rootCluster .Join (targetWorkspace ))
195197
196- crd := utils .YAMLToUnstructured (t , `
197- apiVersion: apiextensions.k8s.io/v1
198- kind: CustomResourceDefinition
199- metadata:
200- name: widgets.example.com
201- ` )
202-
203- if err := targetClient .Get (ctx , types.NamespacedName {Name : crd .GetName ()}, crd ); err != nil {
198+ crd := & apiextensionsv1.CustomResourceDefinition {}
199+ if err := targetClient .Get (ctx , types.NamespacedName {Name : "widgets.example.com" }, crd ); err != nil {
204200 t .Fatalf ("Failed to find CRD in target workspace: %v" , err )
205201 }
206202
207- // Verify the CRD has the Established condition set to True
208- conditions , found , err := getConditions (crd .Object )
209- if err != nil || ! found {
210- t .Fatal ("CRD does not have conditions in status" )
211- }
203+ fmt .Printf ("crd status: %+v\n " , crd .Status )
212204
205+ // Verify the CRD has the Established condition set to True
213206 established := false
214- for _ , c := range conditions {
215- condition , ok := c .(map [string ]any )
216- if ! ok {
217- continue
218- }
219-
220- cType := condition ["type" ].(string )
221- cStatus := condition ["status" ].(string )
222- if cType == "Established" && cStatus == "True" {
207+ for _ , condition := range crd .Status .Conditions {
208+ if condition .Type == apiextensionsv1 .Established && condition .Status == apiextensionsv1 .ConditionTrue {
223209 established = true
224210 break
225211 }
226212 }
227213
228214 if ! established {
229- t .Fatal ("Expected CRD to have Established=True condition, but it was not found or not True" )
230- }
231- }
232-
233- func getConditions (obj map [string ]any ) ([]any , bool , error ) {
234- status , ok := obj ["status" ].(map [string ]any )
235- if ! ok {
236- return nil , false , nil
237- }
238- conditions , ok := status ["conditions" ].([]any )
239- if ! ok {
240- return nil , false , nil
215+ t .Fatal ("Expected CRD to have Established=True condition, but has not." )
241216 }
242- return conditions , true , nil
243217}
0 commit comments