/
converting.go
58 lines (42 loc) · 1.14 KB
/
converting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Copyright © 2024 Patrick Hermann patrick.hermann@sva.de
*/
package k8s
import (
"fmt"
"github.com/ghodss/yaml"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
v1Apps "k8s.io/api/apps/v1"
batch "k8s.io/api/batch/v1"
"k8s.io/client-go/kubernetes/scheme"
)
func VerifyYamlJobDefinition(jobManifest string) (bool, error) {
job := &batch.Job{}
err := yaml.Unmarshal([]byte(jobManifest), job)
if err != nil {
return false, err
}
return true, nil
}
func ConvertYAMLtoDeployment(yamlString string) (bool, *v1Apps.Deployment) {
fmt.Println(yamlString)
decode := scheme.Codecs.UniversalDeserializer().Decode
obj, _, err := decode([]byte(yamlString), nil, nil)
if err != nil {
fmt.Printf("%#v", err)
}
fmt.Println(obj)
deployment := obj.(*v1Apps.Deployment)
fmt.Printf("%#v\n", deployment)
return true, deployment
}
func ConvertYAMLtoPipelineRun(yamlString string) (bool, *v1.PipelineRun, error) {
pipelienRun := &v1.PipelineRun{}
fmt.Println(yamlString)
err := yaml.Unmarshal([]byte(yamlString), pipelienRun)
if err != nil {
return false, nil, err
}
fmt.Printf("%#v\n", pipelienRun)
return true, pipelienRun, err
}