...

Source file src/github.com/redhat-developer/odo/pkg/libdevfile/component.go

Documentation: github.com/redhat-developer/odo/pkg/libdevfile

     1  package libdevfile
     2  
     3  import (
     4  	"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
     5  	"github.com/devfile/library/v2/pkg/devfile/parser"
     6  	"github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
     7  )
     8  
     9  type component interface {
    10  	CheckValidity() error
    11  	Apply(handler Handler, kind v1alpha2.CommandGroupKind) error
    12  }
    13  
    14  // newComponent creates a concrete component, based on its type
    15  func newComponent(devfileObj parser.DevfileObj, devfileCmp v1alpha2.Component) (component, error) {
    16  	var cmp component
    17  
    18  	componentType, err := common.GetComponentType(devfileCmp)
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  	switch componentType {
    23  
    24  	case v1alpha2.ContainerComponentType:
    25  		cmp = newContainerComponent(devfileObj, devfileCmp)
    26  
    27  	case v1alpha2.KubernetesComponentType:
    28  		cmp = newKubernetesComponent(devfileObj, devfileCmp)
    29  
    30  	case v1alpha2.OpenshiftComponentType:
    31  		cmp = newOpenshiftComponent(devfileObj, devfileCmp)
    32  
    33  	case v1alpha2.VolumeComponentType:
    34  		cmp = newVolumeComponent(devfileObj, devfileCmp)
    35  
    36  	case v1alpha2.ImageComponentType:
    37  		cmp = newImageComponent(devfileObj, devfileCmp)
    38  	}
    39  
    40  	if err := cmp.CheckValidity(); err != nil {
    41  		return nil, err
    42  	}
    43  	return cmp, nil
    44  }
    45  
    46  func IsComponentReferenced(allApplyCommands []v1alpha2.Command, cmpName string) bool {
    47  	for _, cmd := range allApplyCommands {
    48  		if cmd.Apply == nil {
    49  			continue
    50  		}
    51  		if cmd.Apply.Component == cmpName {
    52  			return true
    53  		}
    54  	}
    55  	return false
    56  }
    57  

View as plain text