-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pkg/generator: auto-gen for apis/../types.go #37
pkg/generator: auto-gen for apis/../types.go #37
Conversation
Manual test: func TestGenTypes(t *testing.T) {
buf := &bytes.Buffer{}
if err := renderApisTypes(buf, "PlayService", "v1alpha1"); err != nil {
t.Error(err)
return
}
if err := ioutil.WriteFile("./types.go", buf.Bytes(), 0644); err != nil {
t.Error(err)
}
} Output: package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type PlayServiceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []PlayService `json:"items"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type PlayService struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec PlayServiceSpec `json:"spec"`
Status PlayServiceStatus `json:"status,omitempty"`
}
type PlayServiceSpec struct {
Replica int32 `json:"replica,omitempty"`
// Fills me
}
type PlayServiceStatus struct {
// Fills me
} |
This would require to distribute the "tmpl" files along with the binary, right? Use this trick: `...` + "`" + `json:"xxx,inline" + "`" |
pkg/generator/apis_types.tmpl
Outdated
|
||
type {{.Kind}}Status struct { | ||
// Fills me | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line
|
Latest Test Output: package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type PlayServiceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []PlayService `json:"items"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type PlayService struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec PlayServiceSpec `json:"spec"`
Status PlayServiceStatus `json:"status,omitempty"`
}
type PlayServiceSpec struct {
Replica int32 `json:"replica,omitempty"`
// Fills me
}
type PlayServiceStatus struct {
// Fills me
} |
PTAL cc/ @hongchaodeng @hasbro17 |
LGTM |
this pr adds auto-gen for apis/../types.go.