Skip to content

Commit 63904d2

Browse files
authored
Merge pull request #1989 from Adirio/v2-controller-doc
📖 Add documentation to v2 controllers
2 parents 90344af + 95466c5 commit 63904d2

File tree

21 files changed

+140
-1
lines changed

21 files changed

+140
-1
lines changed

pkg/plugins/golang/v2/scaffolds/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (s *apiScaffolder) scaffold() error {
122122
if err := machinery.NewScaffold(s.plugins...).Execute(
123123
s.newUniverse(),
124124
&controllers.SuiteTest{Force: s.force},
125-
&controllers.Controller{Force: s.force},
125+
&controllers.Controller{ControllerRuntimeVersion: ControllerRuntimeVersion, Force: s.force},
126126
); err != nil {
127127
return fmt.Errorf("error scaffolding controller: %v", err)
128128
}

pkg/plugins/golang/v2/scaffolds/internal/templates/controllers/controller.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type Controller struct {
3333
file.BoilerplateMixin
3434
file.ResourceMixin
3535

36+
ControllerRuntimeVersion string
37+
3638
Force bool
3739
}
3840

@@ -85,6 +87,15 @@ type {{ .Resource.Kind }}Reconciler struct {
8587
//+kubebuilder:rbac:groups={{ .Resource.QualifiedGroup }},resources={{ .Resource.Plural }},verbs=get;list;watch;create;update;patch;delete
8688
//+kubebuilder:rbac:groups={{ .Resource.QualifiedGroup }},resources={{ .Resource.Plural }}/status,verbs=get;update;patch
8789
90+
// Reconcile is part of the main kubernetes reconciliation loop which aims to
91+
// move the current state of the cluster closer to the desired state.
92+
// TODO(user): Modify the Reconcile function to compare the state specified by
93+
// the {{ .Resource.Kind }} object against the actual cluster state, and then
94+
// perform operations to make the cluster state reflect the state specified by
95+
// the user.
96+
//
97+
// For more details, check Reconcile and its Result here:
98+
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@{{ .ControllerRuntimeVersion }}/pkg/reconcile
8899
func (r *{{ .Resource.Kind }}Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
89100
_ = context.Background()
90101
_ = r.Log.WithValues("{{ .Resource.Kind | lower }}", req.NamespacedName)
@@ -94,6 +105,7 @@ func (r *{{ .Resource.Kind }}Reconciler) Reconcile(req ctrl.Request) (ctrl.Resul
94105
return ctrl.Result{}, nil
95106
}
96107
108+
// SetupWithManager sets up the controller with the Manager.
97109
func (r *{{ .Resource.Kind }}Reconciler) SetupWithManager(mgr ctrl.Manager) error {
98110
return ctrl.NewControllerManagedBy(mgr).
99111
{{ if .Resource.HasAPI -}}

plugins/addon/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type {{ .Resource.Kind }}Reconciler struct {
6565
//+kubebuilder:rbac:groups={{ .Resource.QualifiedGroup }},resources={{ .Resource.Plural }},verbs=get;list;watch;create;update;patch;delete
6666
//+kubebuilder:rbac:groups={{ .Resource.QualifiedGroup }},resources={{ .Resource.Plural }}/status,verbs=get;update;patch
6767
68+
// SetupWithManager sets up the controller with the Manager.
6869
func (r *{{ .Resource.Kind }}Reconciler) SetupWithManager(mgr ctrl.Manager) error {
6970
addon.Init()
7071

testdata/project-v2-addon/controllers/admiral_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type AdmiralReconciler struct {
4747
//+kubebuilder:rbac:groups=crew.testproject.org,resources=admirals,verbs=get;list;watch;create;update;patch;delete
4848
//+kubebuilder:rbac:groups=crew.testproject.org,resources=admirals/status,verbs=get;update;patch
4949

50+
// SetupWithManager sets up the controller with the Manager.
5051
func (r *AdmiralReconciler) SetupWithManager(mgr ctrl.Manager) error {
5152
addon.Init()
5253

testdata/project-v2-addon/controllers/captain_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type CaptainReconciler struct {
4747
//+kubebuilder:rbac:groups=crew.testproject.org,resources=captains,verbs=get;list;watch;create;update;patch;delete
4848
//+kubebuilder:rbac:groups=crew.testproject.org,resources=captains/status,verbs=get;update;patch
4949

50+
// SetupWithManager sets up the controller with the Manager.
5051
func (r *CaptainReconciler) SetupWithManager(mgr ctrl.Manager) error {
5152
addon.Init()
5253

testdata/project-v2-addon/controllers/firstmate_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type FirstMateReconciler struct {
4747
//+kubebuilder:rbac:groups=crew.testproject.org,resources=firstmates,verbs=get;list;watch;create;update;patch;delete
4848
//+kubebuilder:rbac:groups=crew.testproject.org,resources=firstmates/status,verbs=get;update;patch
4949

50+
// SetupWithManager sets up the controller with the Manager.
5051
func (r *FirstMateReconciler) SetupWithManager(mgr ctrl.Manager) error {
5152
addon.Init()
5253

testdata/project-v2-multigroup/controllers/apps/pod_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ type PodReconciler struct {
3535
//+kubebuilder:rbac:groups=apps,resources=pods,verbs=get;list;watch;create;update;patch;delete
3636
//+kubebuilder:rbac:groups=apps,resources=pods/status,verbs=get;update;patch
3737

38+
// Reconcile is part of the main kubernetes reconciliation loop which aims to
39+
// move the current state of the cluster closer to the desired state.
40+
// TODO(user): Modify the Reconcile function to compare the state specified by
41+
// the Pod object against the actual cluster state, and then
42+
// perform operations to make the cluster state reflect the state specified by
43+
// the user.
44+
//
45+
// For more details, check Reconcile and its Result here:
46+
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
3847
func (r *PodReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
3948
_ = context.Background()
4049
_ = r.Log.WithValues("pod", req.NamespacedName)
@@ -44,6 +53,7 @@ func (r *PodReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
4453
return ctrl.Result{}, nil
4554
}
4655

56+
// SetupWithManager sets up the controller with the Manager.
4757
func (r *PodReconciler) SetupWithManager(mgr ctrl.Manager) error {
4858
return ctrl.NewControllerManagedBy(mgr).
4959
// Uncomment the following line adding a pointer to an instance of the controlled resource as an argument

testdata/project-v2-multigroup/controllers/crew/captain_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ type CaptainReconciler struct {
3737
//+kubebuilder:rbac:groups=crew.testproject.org,resources=captains,verbs=get;list;watch;create;update;patch;delete
3838
//+kubebuilder:rbac:groups=crew.testproject.org,resources=captains/status,verbs=get;update;patch
3939

40+
// Reconcile is part of the main kubernetes reconciliation loop which aims to
41+
// move the current state of the cluster closer to the desired state.
42+
// TODO(user): Modify the Reconcile function to compare the state specified by
43+
// the Captain object against the actual cluster state, and then
44+
// perform operations to make the cluster state reflect the state specified by
45+
// the user.
46+
//
47+
// For more details, check Reconcile and its Result here:
48+
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
4049
func (r *CaptainReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
4150
_ = context.Background()
4251
_ = r.Log.WithValues("captain", req.NamespacedName)
@@ -46,6 +55,7 @@ func (r *CaptainReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
4655
return ctrl.Result{}, nil
4756
}
4857

58+
// SetupWithManager sets up the controller with the Manager.
4959
func (r *CaptainReconciler) SetupWithManager(mgr ctrl.Manager) error {
5060
return ctrl.NewControllerManagedBy(mgr).
5161
For(&crewv1.Captain{}).

testdata/project-v2-multigroup/controllers/foo.policy/healthcheckpolicy_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ type HealthCheckPolicyReconciler struct {
3737
//+kubebuilder:rbac:groups=foo.policy.testproject.org,resources=healthcheckpolicies,verbs=get;list;watch;create;update;patch;delete
3838
//+kubebuilder:rbac:groups=foo.policy.testproject.org,resources=healthcheckpolicies/status,verbs=get;update;patch
3939

40+
// Reconcile is part of the main kubernetes reconciliation loop which aims to
41+
// move the current state of the cluster closer to the desired state.
42+
// TODO(user): Modify the Reconcile function to compare the state specified by
43+
// the HealthCheckPolicy object against the actual cluster state, and then
44+
// perform operations to make the cluster state reflect the state specified by
45+
// the user.
46+
//
47+
// For more details, check Reconcile and its Result here:
48+
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
4049
func (r *HealthCheckPolicyReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
4150
_ = context.Background()
4251
_ = r.Log.WithValues("healthcheckpolicy", req.NamespacedName)
@@ -46,6 +55,7 @@ func (r *HealthCheckPolicyReconciler) Reconcile(req ctrl.Request) (ctrl.Result,
4655
return ctrl.Result{}, nil
4756
}
4857

58+
// SetupWithManager sets up the controller with the Manager.
4959
func (r *HealthCheckPolicyReconciler) SetupWithManager(mgr ctrl.Manager) error {
5060
return ctrl.NewControllerManagedBy(mgr).
5161
For(&foopolicyv1.HealthCheckPolicy{}).

testdata/project-v2-multigroup/controllers/sea-creatures/kraken_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ type KrakenReconciler struct {
3737
//+kubebuilder:rbac:groups=sea-creatures.testproject.org,resources=krakens,verbs=get;list;watch;create;update;patch;delete
3838
//+kubebuilder:rbac:groups=sea-creatures.testproject.org,resources=krakens/status,verbs=get;update;patch
3939

40+
// Reconcile is part of the main kubernetes reconciliation loop which aims to
41+
// move the current state of the cluster closer to the desired state.
42+
// TODO(user): Modify the Reconcile function to compare the state specified by
43+
// the Kraken object against the actual cluster state, and then
44+
// perform operations to make the cluster state reflect the state specified by
45+
// the user.
46+
//
47+
// For more details, check Reconcile and its Result here:
48+
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
4049
func (r *KrakenReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
4150
_ = context.Background()
4251
_ = r.Log.WithValues("kraken", req.NamespacedName)
@@ -46,6 +55,7 @@ func (r *KrakenReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
4655
return ctrl.Result{}, nil
4756
}
4857

58+
// SetupWithManager sets up the controller with the Manager.
4959
func (r *KrakenReconciler) SetupWithManager(mgr ctrl.Manager) error {
5060
return ctrl.NewControllerManagedBy(mgr).
5161
For(&seacreaturesv1beta1.Kraken{}).

0 commit comments

Comments
 (0)