// NewComponentFullDescriptionFromClientAndLocalConfig gets the complete description of the component from both localconfig and cluster
NewComponentFullDescriptionFromClientAndLocalConfig gets the complete description of the component from both localconfig and cluster
// NewComponentFullDescriptionFromClientAndLocalConfig gets the complete description of the component from both localconfig and cluster
func NewComponentFullDescriptionFromClientAndLocalConfig(client *occlient.Client, localConfigInfo *config.LocalConfigInfo, envInfo *envinfo.EnvSpecificInfo, componentName string, applicationName string, projectName string) (*ComponentFullDescription, error) {
	cfd := &ComponentFullDescription{}
	var state State
	if client == nil {
		state = StateTypeUnknown
	} else {
		state = GetComponentState(client, componentName, applicationName)
	}
	var componentDesc Component
	var devfile devfileParser.DevfileObj
	var err error
	var configLinks []string
	if envInfo != nil {
		componentDesc, devfile, err = GetComponentFromDevfile(envInfo)
		if err != nil {
			return cfd, err
		}
		configLinks, err = service.ListDevfileLinks(devfile)
	} else {
		componentDesc, err = GetComponentFromConfig(localConfigInfo)
	}
	if err != nil {
		return cfd, err
	}
	err = cfd.copyFromComponentDesc(&componentDesc)
	if err != nil {
		return cfd, err
	}
	cfd.Status.State = state
	if state == StateTypePushed {
		componentDescFromCluster, err := getRemoteComponentMetadata(client, componentName, applicationName, false, false)
		if err != nil {
			return cfd, err
		}
		cfd.Spec.Env = componentDescFromCluster.Spec.Env
		cfd.Spec.Type = componentDescFromCluster.Spec.Type
		cfd.Spec.SourceType = componentDescFromCluster.Spec.SourceType
		cfd.Status.LinkedServices = componentDescFromCluster.Status.LinkedServices
	}
	for _, link := range configLinks {
		found := false
		for _, linked := range cfd.Status.LinkedServices {
			if linked.ServiceName == link {
				found = true
				break
			}
		}
		if !found {
			cfd.Status.LinkedServices = append(cfd.Status.LinkedServices, SecretMount{
				ServiceName: link,
			})
		}
	}
	cfd.fillEmptyFields(componentDesc, componentName, applicationName, projectName)
	var urls urlpkg.URLList
	var routeSupported bool
	var e error
	if client == nil {
		routeSupported = false
	} else {
		routeSupported, e = client.IsRouteSupported()
		if e != nil {
			routeSupported = false
		}
	}
	var configProvider localConfigProvider.LocalConfigProvider
	if envInfo != nil {
		envInfo.SetDevfileObj(devfile)
		configProvider = envInfo
	} else {
		configProvider = localConfigInfo
	}
	var derefClient occlient.Client
	if client != nil {
		derefClient = *client
	}
	urlClient := urlpkg.NewClient(urlpkg.ClientOptions{
		LocalConfigProvider: configProvider,
		OCClient:            derefClient,
		IsRouteSupported:    routeSupported,
	})
	urls, err = urlClient.List()
	if err != nil {
		log.Warningf("URLs couldn't not be retrieved: %v", err)
	}
	cfd.Spec.URL = urls
	err = cfd.loadStoragesFromClientAndLocalConfig(client, configProvider, componentName, applicationName, &componentDesc)
	if err != nil {
		return cfd, err
	}
	return cfd, nil
}
func NewComponentFullDescriptionFromClientAndLocalConfig ( client * occlient . Client , localConfigInfo * config . LocalConfigInfo , envInfo * envinfo . EnvSpecificInfo , componentName string , applicationName string , projectName string ) ( * ComponentFullDescription , error ) { cfd := & ComponentFullDescription { } var state State if client == nil { state = StateTypeUnknown } else { state = GetComponentState ( client , componentName , applicationName ) } var componentDesc Component var devfile devfileParser . DevfileObj var err error var configLinks [ ] string if envInfo != nil { componentDesc , devfile , err = GetComponentFromDevfile ( envInfo ) if err != nil { return cfd , err } configLinks , err = service . ListDevfileLinks ( devfile ) } else { componentDesc , err = GetComponentFromConfig ( localConfigInfo ) } if err != nil { return cfd , err } err = cfd . copyFromComponentDesc ( & componentDesc ) if err != nil { return cfd , err } cfd . Status . State = state if state == StateTypePushed { componentDescFromCluster , err := getRemoteComponentMetadata ( client , componentName , applicationName , false , false ) if err != nil { return cfd , err } cfd . Spec . Env = componentDescFromCluster . Spec . Env cfd . Spec . Type = componentDescFromCluster . Spec . Type cfd . Spec . SourceType = componentDescFromCluster . Spec . SourceType cfd . Status . LinkedServices = componentDescFromCluster . Status . LinkedServices } for _ , link := range configLinks { found := false for _ , linked := range cfd . Status . LinkedServices { if linked . ServiceName == link { found = true break } } if ! found { cfd . Status . LinkedServices = append ( cfd . Status . LinkedServices , SecretMount { ServiceName : link , } ) } } cfd . fillEmptyFields ( componentDesc , componentName , applicationName , projectName ) var urls urlpkg . URLList var routeSupported bool var e error if client == nil { routeSupported = false } else { routeSupported , e = client . IsRouteSupported ( ) if e != nil { routeSupported = false } } var configProvider localConfigProvider . LocalConfigProvider if envInfo != nil { envInfo . SetDevfileObj ( devfile ) configProvider = envInfo } else { configProvider = localConfigInfo } var derefClient occlient . Client if client != nil { derefClient = * client } urlClient := urlpkg . NewClient ( urlpkg . ClientOptions { LocalConfigProvider : configProvider , OCClient : derefClient , IsRouteSupported : routeSupported , } ) urls , err = urlClient . List ( ) if err != nil { log . Warningf ( " " , err ) } cfd . Spec . URL = urls err = cfd . loadStoragesFromClientAndLocalConfig ( client , configProvider , componentName , applicationName , & componentDesc ) if err != nil { return cfd , err } return cfd , nil }
NewComponentFullDescriptionFromClientAndLocalConfig gets the complete description of the component from both localconfig and cluster
NewComponentFullDescriptionFromClientAndLocalConfig gets the complete description of the component from both localconfig and cluster
// we assume if there was an error then the cluster is not connected