...
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 parsercommon "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
7 )
8
9
10 type kubernetesComponent struct {
11 component v1alpha2.Component
12 devfileObj parser.DevfileObj
13 }
14
15 var _ component = (*kubernetesComponent)(nil)
16
17 func newKubernetesComponent(devfileObj parser.DevfileObj, component v1alpha2.Component) *kubernetesComponent {
18 return &kubernetesComponent{
19 component: component,
20 devfileObj: devfileObj,
21 }
22 }
23
24 func (e *kubernetesComponent) CheckValidity() error {
25 return nil
26 }
27
28 func (e *kubernetesComponent) Apply(handler Handler, kind v1alpha2.CommandGroupKind) error {
29 return handler.ApplyKubernetes(e.component, kind)
30 }
31
32
33
34
35
36 func GetK8sAndOcComponentsToPush(devfileObj parser.DevfileObj, allowApply bool) ([]v1alpha2.Component, error) {
37 var allK8sAndOcComponents []v1alpha2.Component
38
39 k8sComponents, err := devfileObj.Data.GetComponents(parsercommon.DevfileOptions{
40 ComponentOptions: parsercommon.ComponentOptions{ComponentType: v1alpha2.KubernetesComponentType},
41 })
42 if err != nil {
43 return nil, err
44 }
45 allK8sAndOcComponents = append(allK8sAndOcComponents, k8sComponents...)
46
47 ocComponents, err := devfileObj.Data.GetComponents(parsercommon.DevfileOptions{
48 ComponentOptions: parsercommon.ComponentOptions{ComponentType: v1alpha2.OpenshiftComponentType},
49 })
50 if err != nil {
51 return nil, err
52 }
53 allK8sAndOcComponents = append(allK8sAndOcComponents, ocComponents...)
54
55 allApplyCommands, err := devfileObj.Data.GetCommands(parsercommon.DevfileOptions{
56 CommandOptions: parsercommon.CommandOptions{CommandType: v1alpha2.ApplyCommandType},
57 })
58 if err != nil {
59 return nil, err
60 }
61
62 m := make(map[string]v1alpha2.Component)
63 for _, comp := range allK8sAndOcComponents {
64 var k v1alpha2.K8sLikeComponent
65 if comp.Kubernetes != nil {
66 k = comp.Kubernetes.K8sLikeComponent
67 } else {
68 k = comp.Openshift.K8sLikeComponent
69 }
70 var add bool
71 if allowApply && IsComponentReferenced(allApplyCommands, comp.Name) {
72 add = true
73 } else if k.DeployByDefault == nil {
74
75 if !IsComponentReferenced(allApplyCommands, comp.Name) {
76 add = true
77 }
78 } else if *k.DeployByDefault {
79 add = true
80 }
81 if !add {
82 continue
83 }
84 if _, present := m[comp.Name]; !present {
85 m[comp.Name] = comp
86 }
87 }
88
89 var result []v1alpha2.Component
90 for _, comp := range m {
91 result = append(result, comp)
92 }
93 return result, nil
94 }
95
View as plain text