...
1 package component
2
3 import (
4 "errors"
5 "fmt"
6 "strings"
7
8 devfile "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
9 "github.com/devfile/library/v2/pkg/devfile/parser"
10 devfilefs "github.com/devfile/library/v2/pkg/testingutil/filesystem"
11
12 "github.com/redhat-developer/odo/pkg/kclient"
13 "github.com/redhat-developer/odo/pkg/libdevfile"
14 )
15
16
17 func ValidateResourcesExist(client kclient.ClientInterface, devfileObj parser.DevfileObj, k8sComponents []devfile.Component, context string) error {
18 if len(k8sComponents) == 0 {
19 return nil
20 }
21
22 var unsupportedResources []string
23 for _, c := range k8sComponents {
24 kindErr, err := ValidateResourcesExistInK8sComponent(client, devfileObj, c, context)
25 if err != nil {
26 if kindErr != "" {
27 unsupportedResources = append(unsupportedResources, kindErr)
28 } else {
29 return err
30 }
31 }
32 }
33
34 if len(unsupportedResources) > 0 {
35
36 return fmt.Errorf("following resource(s) in the devfile are not supported by your cluster; please install corresponding Operator(s) before doing \"odo dev\": %s", strings.Join(unsupportedResources, ", "))
37 }
38 return nil
39 }
40
41
42 func ValidateResourcesExistInK8sComponent(client kclient.ClientInterface, devfileObj parser.DevfileObj, k8sComponent devfile.Component, context string) (kindErr string, err error) {
43
44 uList, err := libdevfile.GetK8sComponentAsUnstructuredList(devfileObj, k8sComponent.Name, context, devfilefs.DefaultFs{})
45 if err != nil {
46 return "", err
47 }
48 for _, u := range uList {
49 _, err = client.GetRestMappingFromUnstructured(u)
50 if err != nil && u.GetKind() != "ServiceBinding" {
51
52
53
54 return u.GetKind(), errors.New("resource not supported")
55 }
56 }
57 return "", nil
58 }
59
View as plain text