// RegisterCRDs registers the CRD so that unit tests can use the CRD to perform bucket API testing
RegisterCRDs registers the CRD so that unit tests can use the CRD to perform bucket API testing
// RegisterCRDs registers the CRD so that unit tests can use the CRD to perform bucket API testing
func RegisterCRDs(ctx context.Context, client apiextensions.CustomResourceDefinitionInterface) error {
	var err error
	if client == nil {
		client, err = getCRDClient()
	}
	if err != nil {
		return err
	}
	roots, err := loader.LoadRoots("github.com/kubernetes-sigs/container-object-storage-interface-api/apis/objectstorage.k8s.io/v1alpha1")
	if err != nil {
		return err
	}
	defn := markers.Must(markers.MakeDefinition("crd", markers.DescribesPackage, crd.Generator{}))
	optionsRegistry := &markers.Registry{}
	if err := optionsRegistry.Register(defn); err != nil {
		return err
	}
	if err := genall.RegisterOptionsMarkers(optionsRegistry); err != nil {
		return err
	}
	if err := crdmarkers.Register(optionsRegistry); err != nil {
		return err
	}
	parser := &crd.Parser{
		Collector: &markers.Collector{
			Registry: optionsRegistry,
		},
		Checker: &loader.TypeChecker{},
	}
	crd.AddKnownTypes(parser)
	for _, root := range roots {
		parser.NeedPackage(root)
	}
	metav1Pkg := crd.FindMetav1(roots)
	if metav1Pkg == nil {
		return fmt.Errorf("no objects found in all roots")
	}
	kubeKinds := crd.FindKubeKinds(parser, metav1Pkg)
	if len(kubeKinds) == 0 {
		return fmt.Errorf("no kube kind-objects found in all roots")
	}
	crdClient := client
	for groupKind := range kubeKinds {
		parser.NeedCRDFor(groupKind, func() *int {
			i := 256
			return &i
		}())
		crdRaw := parser.CustomResourceDefinitions[groupKind]
		glog.Infof("creating CRD: %v", groupKind)
		if crdRaw.ObjectMeta.Annotations == nil {
			crdRaw.ObjectMeta.Annotations = map[string]string{}
		}
		if _, ok := crdRaw.ObjectMeta.Annotations[apiextensionsv1.KubeAPIApprovedAnnotation]; !ok {
			crdRaw.ObjectMeta.Annotations[apiextensionsv1.KubeAPIApprovedAnnotation] = "https://github.com/kubernetes/kubernetes/pull/78458"
		}
		if _, err := crdClient.Create(ctx, &crdRaw, metav1.CreateOptions{}); err != nil {
			if !apierrors.IsAlreadyExists(err) {
				return err
			}
		}
	}
	return nil
}
func RegisterCRDs ( ctx context . Context , client apiextensions . CustomResourceDefinitionInterface ) error { var err error if client == nil { client , err = getCRDClient ( ) } if err != nil { return err } roots , err := loader . LoadRoots ( " " ) if err != nil { return err } defn := markers . Must ( markers . MakeDefinition ( " " , markers . DescribesPackage , crd . Generator { } ) ) optionsRegistry := & markers . Registry { } if err := optionsRegistry . Register ( defn ) ; err != nil { return err } if err := genall . RegisterOptionsMarkers ( optionsRegistry ) ; err != nil { return err } if err := crdmarkers . Register ( optionsRegistry ) ; err != nil { return err } parser := & crd . Parser { Collector : & markers . Collector { Registry : optionsRegistry , } , Checker : & loader . TypeChecker { } , } crd . AddKnownTypes ( parser ) for _ , root := range roots { parser . NeedPackage ( root ) } metav1Pkg := crd . FindMetav1 ( roots ) if metav1Pkg == nil { return fmt . Errorf ( " " ) } kubeKinds := crd . FindKubeKinds ( parser , metav1Pkg ) if len ( kubeKinds ) == 0 { return fmt . Errorf ( " " ) } crdClient := client for groupKind := range kubeKinds { parser . NeedCRDFor ( groupKind , func ( ) * int { i := 256 return & i } ( ) ) crdRaw := parser . CustomResourceDefinitions [ groupKind ] glog . Infof ( " " , groupKind ) if crdRaw . ObjectMeta . Annotations == nil { crdRaw . ObjectMeta . Annotations = map [ string ] string { } } if _ , ok := crdRaw . ObjectMeta . Annotations [ apiextensionsv1 . KubeAPIApprovedAnnotation ] ; ! ok { crdRaw . ObjectMeta . Annotations [ apiextensionsv1 . KubeAPIApprovedAnnotation ] = " " } if _ , err := crdClient . Create ( ctx , & crdRaw , metav1 . CreateOptions { } ) ; err != nil { if ! apierrors . IsAlreadyExists ( err ) { return err } } } return nil }
RegisterCRDs registers the CRD so that unit tests can use the CRD to perform bucket API testing
RegisterCRDs registers the CRD so that unit tests can use the CRD to perform bucket API testing
// no objects in the roots, since nothing imported metav1 // TODO: allow selecting a specific object // no objects in the roots //crdClient := utils.GetCRDClient()