...
1 package component
2
3 import (
4 "fmt"
5
6 devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
7 "github.com/devfile/library/v2/pkg/devfile/parser"
8 devfilefs "github.com/devfile/library/v2/pkg/testingutil/filesystem"
9 "k8s.io/klog"
10
11 "github.com/redhat-developer/odo/pkg/kclient"
12 odolabels "github.com/redhat-developer/odo/pkg/labels"
13 "github.com/redhat-developer/odo/pkg/libdevfile"
14 "github.com/redhat-developer/odo/pkg/log"
15 "github.com/redhat-developer/odo/pkg/service"
16 )
17
18
19
20
21
22
23
24
25 func ApplyKubernetes(
26 mode string,
27 appName string,
28 componentName string,
29 devfile parser.DevfileObj,
30 kubernetes devfilev1.Component,
31 kubeClient kclient.ClientInterface,
32 path string,
33 ) error {
34
35
36 kind, err := ValidateResourcesExistInK8sComponent(kubeClient, devfile, kubernetes, path)
37 if err != nil {
38 return fmt.Errorf("%s: %w", kind, err)
39 }
40
41
42
43 runtime := GetComponentRuntimeFromDevfileMetadata(devfile.Data.GetMetadata())
44 labels := odolabels.GetLabels(componentName, appName, runtime, mode, false)
45
46 klog.V(4).Infof("Injecting labels: %+v into k8s artifact", labels)
47
48
49
50 annotations := make(map[string]string)
51 odolabels.SetProjectType(annotations, GetComponentTypeFromDevfileMetadata(devfile.Data.GetMetadata()))
52
53
54 uList, err := libdevfile.GetK8sComponentAsUnstructuredList(devfile, kubernetes.Name, path, devfilefs.DefaultFs{})
55 if err != nil {
56 return err
57 }
58 for _, u := range uList {
59
60 log.Sectionf("Deploying Kubernetes Component: %s", u.GetName())
61 err = service.PushKubernetesResource(kubeClient, u, labels, annotations, mode)
62 if err != nil {
63 return fmt.Errorf("failed to create service(s) associated with the component: %w", err)
64 }
65 }
66 return nil
67 }
68
View as plain text