...
1 package fake
2
3 import (
4 "os"
5 "path/filepath"
6
7 admissionv1beta1 "k8s.io/api/admission/v1beta1"
8 appsv1 "k8s.io/api/apps/v1"
9 corev1 "k8s.io/api/core/v1"
10 "sigs.k8s.io/yaml"
11 )
12
13
14 const (
15 DefaultControllerNamespace = "linkerd"
16 DefaultNamespace = "default"
17 )
18
19
20
21 type Factory struct {
22 rootDir string
23 }
24
25
26 func NewFactory(rootDir string) *Factory {
27 return &Factory{rootDir: rootDir}
28 }
29
30
31
32
33 func (f *Factory) FileContents(filename string) ([]byte, error) {
34 return os.ReadFile(filepath.Join(f.rootDir, filename))
35 }
36
37
38
39
40
41
42 func (f *Factory) AdmissionReview(filename string) (*admissionv1beta1.AdmissionReview, error) {
43 b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
44 if err != nil {
45 return nil, err
46 }
47 var admissionReview admissionv1beta1.AdmissionReview
48 if err := yaml.Unmarshal(b, &admissionReview); err != nil {
49 return nil, err
50 }
51
52 return &admissionReview, nil
53 }
54
55
56
57
58
59
60 func (f *Factory) Deployment(filename string) (*appsv1.Deployment, error) {
61 b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
62 if err != nil {
63 return nil, err
64 }
65
66 var deployment appsv1.Deployment
67 if err := yaml.Unmarshal(b, &deployment); err != nil {
68 return nil, err
69 }
70
71 return &deployment, nil
72 }
73
74
75
76
77
78
79 func (f *Factory) Container(filename string) (*corev1.Container, error) {
80 b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
81 if err != nil {
82 return nil, err
83 }
84
85 var container corev1.Container
86 if err := yaml.Unmarshal(b, &container); err != nil {
87 return nil, err
88 }
89
90 return &container, nil
91 }
92
93
94
95
96
97
98 func (f *Factory) ConfigMap(filename string) (*corev1.ConfigMap, error) {
99 b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
100 if err != nil {
101 return nil, err
102 }
103
104 var configMap corev1.ConfigMap
105 if err := yaml.Unmarshal(b, &configMap); err != nil {
106 return nil, err
107 }
108
109 return &configMap, nil
110 }
111
112
113
114
115
116
117 func (f *Factory) Namespace(filename string) (*corev1.Namespace, error) {
118 b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
119 if err != nil {
120 return nil, err
121 }
122
123 var namespace corev1.Namespace
124 if err := yaml.Unmarshal(b, &namespace); err != nil {
125 return nil, err
126 }
127
128 return &namespace, nil
129 }
130
131
132
133
134
135
136 func (f *Factory) Volume(filename string) (*corev1.Volume, error) {
137 b, err := os.ReadFile(filepath.Join(f.rootDir, filename))
138 if err != nil {
139 return nil, err
140 }
141
142 var volume corev1.Volume
143 if err := yaml.Unmarshal(b, &volume); err != nil {
144 return nil, err
145 }
146
147 return &volume, nil
148 }
149
View as plain text