func (discovery *DeviceDiscovery) ensureDiscoveryResultCR() error {
	nodeName := os.Getenv("MY_NODE_NAME")
	namespace := os.Getenv("WATCH_NAMESPACE")
	parentObjUID := os.Getenv("UID")
	parentObjName := os.Getenv("POD_NAME")
	if nodeName == "" || namespace == "" || parentObjUID == "" || parentObjName == "" {
		return errors.New("failed to create LocalVolumeDiscoveryResult resource. missing required env variables")
	}
	newCR := newDiscoveryResultInstance(nodeName, namespace, parentObjName, parentObjUID)
	existingCR, err := discovery.apiClient.GetDiscoveryResult(newCR.Name, newCR.Namespace)
	switch {
	case err == nil:
		existingCR.ObjectMeta.OwnerReferences = newCR.ObjectMeta.OwnerReferences
		newCR.ObjectMeta = existingCR.ObjectMeta
		err = discovery.apiClient.UpdateDiscoveryResult(newCR)
		if err != nil {
			return errors.Wrapf(err, "failed to update LocalVolumeDiscoveryResult resource")
		}
		klog.Info("successfully updated LocalVolumeDiscoveryResult resource")
		return nil
	case kerrors.IsNotFound(err):
		err = discovery.apiClient.CreateDiscoveryResult(newCR)
		if err != nil {
			return errors.Wrapf(err, "failed to create LocalVolumeDiscoveryResult resource")
		}
		message := "successfully created LocalVolumeDiscoveryResult resource"
		e := diskmaker.NewSuccessEvent(diskmaker.CreatedDiscoveryResultObject, message, "")
		discovery.eventSync.Report(e, discovery.localVolumeDiscovery)
		klog.Info(message)
		return nil
	}

	return err
}
// ensureDiscoveryResultCR creates a new LocalVolumeDiscoveryResult custome resource on the node, if not present
ensureDiscoveryResultCR creates a new LocalVolumeDiscoveryResult custome resource on the node, if not present
// ensureDiscoveryResultCR creates a new LocalVolumeDiscoveryResult custome resource on the node if not present
func (discovery *DeviceDiscovery) ensureDiscoveryResultCR() error {
	nodeName := os.Getenv("MY_NODE_NAME")
	namespace := os.Getenv("WATCH_NAMESPACE")
	parentObjUID := os.Getenv("UID")
	parentObjName := os.Getenv("POD_NAME")
	if nodeName == "" || namespace == "" || parentObjUID == "" || parentObjName == "" {
		return errors.New("failed to create LocalVolumeDiscoveryResult resource. missing required env variables")
	}
	newCR := newDiscoveryResultInstance(nodeName, namespace, parentObjName, parentObjUID)
	existingCR, err := discovery.apiClient.GetDiscoveryResult(newCR.Name, newCR.Namespace)
	switch {
	case err == nil:
		existingCR.ObjectMeta.OwnerReferences = newCR.ObjectMeta.OwnerReferences
		newCR.ObjectMeta = existingCR.ObjectMeta
		err = discovery.apiClient.UpdateDiscoveryResult(newCR)
		if err != nil {
			return errors.Wrapf(err, "failed to update LocalVolumeDiscoveryResult resource")
		}
		klog.Info("successfully updated LocalVolumeDiscoveryResult resource")
		return nil
	case kerrors.IsNotFound(err):
		err = discovery.apiClient.CreateDiscoveryResult(newCR)
		if err != nil {
			return errors.Wrapf(err, "failed to create LocalVolumeDiscoveryResult resource")
		}
		message := "successfully created LocalVolumeDiscoveryResult resource"
		e := diskmaker.NewSuccessEvent(diskmaker.CreatedDiscoveryResultObject, message, "")
		discovery.eventSync.Report(e, discovery.localVolumeDiscovery)
		klog.Info(message)
		return nil
	}
	return err
}
func ( discovery * DeviceDiscovery ) ensureDiscoveryResultCR ( ) error { nodeName := os . Getenv ( " " ) namespace := os . Getenv ( " " ) parentObjUID := os . Getenv ( " " ) parentObjName := os . Getenv ( " " ) if nodeName == " " || namespace == " " || parentObjUID == " " || parentObjName == " " { return errors . New ( " " ) } newCR := newDiscoveryResultInstance ( nodeName , namespace , parentObjName , parentObjUID ) existingCR , err := discovery . apiClient . GetDiscoveryResult ( newCR . Name , newCR . Namespace ) switch { case err == nil : existingCR . ObjectMeta . OwnerReferences = newCR . ObjectMeta . OwnerReferences newCR . ObjectMeta = existingCR . ObjectMeta err = discovery . apiClient . UpdateDiscoveryResult ( newCR ) if err != nil { return errors . Wrapf ( err , " " ) } klog . Info ( " " ) return nil case kerrors . IsNotFound ( err ) : err = discovery . apiClient . CreateDiscoveryResult ( newCR ) if err != nil { return errors . Wrapf ( err , " " ) } message := " " e := diskmaker . NewSuccessEvent ( diskmaker . CreatedDiscoveryResultObject , message , " " ) discovery . eventSync . Report ( e , discovery . localVolumeDiscovery ) klog . Info ( message ) return nil } return err }
ensureDiscoveryResultCR creates a new LocalVolumeDiscoveryResult custome resource on the node, if not present
ensureDiscoveryResultCR creates a new LocalVolumeDiscoveryResult custome resource on the node if not present