Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit d7704b0

Browse files
Adding Code Generate source files
Signed-off-by: Christopher Hein <[email protected]>
1 parent 4678e80 commit d7704b0

File tree

4 files changed

+152
-19
lines changed

4 files changed

+152
-19
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
apiVersion: v1
2+
kind: List
3+
items:
4+
- kind: Namespace
5+
apiVersion: v1
6+
metadata:
7+
name: aws-service-operator
8+
{{range $index, $element := .Items}}
9+
- apiVersion: apiextensions.k8s.io/v1beta1
10+
kind: CustomResourceDefinition
11+
metadata:
12+
name: {{$element.Spec.Resource.Plural}}.service-operator.aws
13+
spec:
14+
group: service-operator.aws
15+
names:
16+
kind: {{$element.Spec.Kind}}
17+
listKind: {{$element.Spec.Kind}}List
18+
plural: {{$element.Spec.Resource.Plural}}
19+
shortNames:
20+
{{- range $index, $elem := $element.Spec.Resource.Shortnames}}
21+
- {{$elem.Name}}
22+
{{- end}}
23+
singular: {{$element.Spec.Resource.Plural}}
24+
scope: Namespaced
25+
version: v1alpha1
26+
{{end}}
27+
- kind: ClusterRole
28+
apiVersion: rbac.authorization.k8s.io/v1beta1
29+
metadata:
30+
name: aws-service-operator
31+
rules:
32+
- apiGroups:
33+
- ""
34+
resources:
35+
- secrets
36+
- pods
37+
- configmaps
38+
- services
39+
verbs:
40+
- get
41+
- list
42+
- watch
43+
- create
44+
- delete
45+
- update
46+
- apiGroups:
47+
- apiextensions.k8s.io
48+
resources:
49+
- customresourcedefinitions
50+
verbs:
51+
- get
52+
- list
53+
- watch
54+
- create
55+
- delete
56+
- apiGroups:
57+
- service-operator.aws
58+
resources:
59+
- "*"
60+
verbs:
61+
- "*"
62+
63+
- kind: ServiceAccount
64+
apiVersion: v1
65+
metadata:
66+
name: aws-service-operator
67+
namespace: aws-service-operator
68+
69+
- kind: ClusterRoleBinding
70+
apiVersion: rbac.authorization.k8s.io/v1beta1
71+
metadata:
72+
name: aws-service-operator
73+
roleRef:
74+
apiGroup: rbac.authorization.k8s.io
75+
kind: ClusterRole
76+
name: aws-service-operator
77+
subjects:
78+
- kind: ServiceAccount
79+
name: aws-service-operator
80+
namespace: aws-service-operator
81+
82+
- kind: Deployment
83+
apiVersion: apps/v1beta1
84+
metadata:
85+
name: aws-service-operator
86+
namespace: aws-service-operator
87+
spec:
88+
replicas: 1
89+
template:
90+
metadata:
91+
annotations:
92+
iam.amazonaws.com/role: aws-service-operator
93+
labels:
94+
app: aws-service-operator
95+
spec:
96+
serviceAccountName: aws-service-operator
97+
containers:
98+
- name: aws-service-operator
99+
image: awsserviceoperator/aws-service-operator:v0.0.1-alpha2
100+
imagePullPolicy: Always
101+
args:
102+
- server
103+
- --cluster-name=<CLUSTER_NAME>
104+
- --region=<REGION>
105+
- --account-id=<ACCOUNT_ID>

code-generation/pkg/codegen/codegen.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,18 @@ func (c *Codegen) Run() error {
122122
if (Customizations{}) == parsedModel.Spec.Customizations {
123123
createFile(rootPath, "cft.go", "cft.go", operatorPath+"/", parsedModel)
124124
}
125-
createFile(rootPath, "controller.go", "controller.go", operatorPath+"/", parsedModel)
125+
createFile(rootPath, "operator.go", "operator.go", operatorPath+"/", parsedModel)
126126

127127
createFile(rootPath, parsedModel.Spec.Resource.Name+".go", "types.go", apiPath+"/", parsedModel)
128128

129129
}
130130
}
131131

132132
helpersPath := rootPath + "pkg/helpers"
133+
configPath := rootPath + "configs"
133134

134135
createFile(rootPath, "template_functions.go", "template_functions.go", helpersPath+"/", models)
136+
createFile(rootPath, "aws-service-operator.yaml", "aws-service-operator.yaml", configPath+"/", models)
135137

136138
return nil
137139
}
@@ -188,9 +190,12 @@ func createFile(rootPath string, fileName string, templateName string, path stri
188190
return
189191
}
190192

191-
formatted, err := format.Source(bf.Bytes())
192-
if err != nil {
193-
log.Fatalf("Error formatting resolved template: %+v", err)
193+
formatted := bf.Bytes()
194+
if templateName[len(templateName)-3:] == ".go" {
195+
formatted, err = format.Source(bf.Bytes())
196+
if err != nil {
197+
log.Fatalf("Error formatting resolved template: %+v", err)
198+
}
194199
}
195200

196201
f, err := os.Create(path + fileName)

0 commit comments

Comments
 (0)