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

Commit

Permalink
Adding Code Generate source files
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hein <me@christopherhein.com>
  • Loading branch information
christopherhein committed Oct 16, 2018
1 parent 4678e80 commit d7704b0
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 19 deletions.
105 changes: 105 additions & 0 deletions code-generation/pkg/codegen/assets/aws-service-operator.yaml.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
apiVersion: v1
kind: List
items:
- kind: Namespace
apiVersion: v1
metadata:
name: aws-service-operator
{{range $index, $element := .Items}}
- apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: {{$element.Spec.Resource.Plural}}.service-operator.aws
spec:
group: service-operator.aws
names:
kind: {{$element.Spec.Kind}}
listKind: {{$element.Spec.Kind}}List
plural: {{$element.Spec.Resource.Plural}}
shortNames:
{{- range $index, $elem := $element.Spec.Resource.Shortnames}}
- {{$elem.Name}}
{{- end}}
singular: {{$element.Spec.Resource.Plural}}
scope: Namespaced
version: v1alpha1
{{end}}
- kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: aws-service-operator
rules:
- apiGroups:
- ""
resources:
- secrets
- pods
- configmaps
- services
verbs:
- get
- list
- watch
- create
- delete
- update
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- list
- watch
- create
- delete
- apiGroups:
- service-operator.aws
resources:
- "*"
verbs:
- "*"

- kind: ServiceAccount
apiVersion: v1
metadata:
name: aws-service-operator
namespace: aws-service-operator

- kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: aws-service-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: aws-service-operator
subjects:
- kind: ServiceAccount
name: aws-service-operator
namespace: aws-service-operator

- kind: Deployment
apiVersion: apps/v1beta1
metadata:
name: aws-service-operator
namespace: aws-service-operator
spec:
replicas: 1
template:
metadata:
annotations:
iam.amazonaws.com/role: aws-service-operator
labels:
app: aws-service-operator
spec:
serviceAccountName: aws-service-operator
containers:
- name: aws-service-operator
image: awsserviceoperator/aws-service-operator:v0.0.1-alpha2
imagePullPolicy: Always
args:
- server
- --cluster-name=<CLUSTER_NAME>
- --region=<REGION>
- --account-id=<ACCOUNT_ID>
13 changes: 9 additions & 4 deletions code-generation/pkg/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,18 @@ func (c *Codegen) Run() error {
if (Customizations{}) == parsedModel.Spec.Customizations {
createFile(rootPath, "cft.go", "cft.go", operatorPath+"/", parsedModel)
}
createFile(rootPath, "controller.go", "controller.go", operatorPath+"/", parsedModel)
createFile(rootPath, "operator.go", "operator.go", operatorPath+"/", parsedModel)

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

}
}

helpersPath := rootPath + "pkg/helpers"
configPath := rootPath + "configs"

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

return nil
}
Expand Down Expand Up @@ -188,9 +190,12 @@ func createFile(rootPath string, fileName string, templateName string, path stri
return
}

formatted, err := format.Source(bf.Bytes())
if err != nil {
log.Fatalf("Error formatting resolved template: %+v", err)
formatted := bf.Bytes()
if templateName[len(templateName)-3:] == ".go" {
formatted, err = format.Source(bf.Bytes())
if err != nil {
log.Fatalf("Error formatting resolved template: %+v", err)
}
}

f, err := os.Create(path + fileName)
Expand Down
Loading

0 comments on commit d7704b0

Please sign in to comment.