Skip to content
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

Merged
merged 1 commit into from
Feb 22, 2018
Merged

pkg/generator: auto-gen for apis/../types.go #37

merged 1 commit into from
Feb 22, 2018

Conversation

fanminshi
Copy link
Contributor

@fanminshi fanminshi commented Feb 22, 2018

this pr adds auto-gen for apis/../types.go.

@fanminshi
Copy link
Contributor Author

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
}

@fanminshi
Copy link
Contributor Author

cc/ @hongchaodeng @hasbro17

@hongchaodeng
Copy link
Contributor

Hence, I just create a .tmpl file and let template.ParseFiles from it instead.

This would require to distribute the "tmpl" files along with the binary, right?
Initially we would distribute ONLY the binary.

Use this trick:

`...` + "`" + `json:"xxx,inline" + "`"


type {{.Kind}}Status struct {
// Fills me
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

@fanminshi
Copy link
Contributor Author

This would require to distribute the "tmpl" files along with the binary, right? Initially we would distribute ONLY the binary.
You are right on this. Let me try your trick!

@fanminshi
Copy link
Contributor Author

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
}

@fanminshi
Copy link
Contributor Author

PTAL cc/ @hongchaodeng @hasbro17
Due to hacking around backtick, the template looks a bit messy. FYI.

@fanminshi fanminshi mentioned this pull request Feb 22, 2018
21 tasks
@hongchaodeng
Copy link
Contributor

LGTM

@hongchaodeng hongchaodeng merged commit b5a1d8a into operator-framework:master Feb 22, 2018
@hongchaodeng hongchaodeng deleted the gen_apis_types branch February 22, 2018 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants