@@ -17,27 +17,27 @@ limitations under the License.
1717package { { .groupVersion } }
1818
1919import (
20- "context"
21-
2220 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2321 runtime "k8s.io/apimachinery/pkg/runtime"
24- "sigs.k8s.io/controller-runtime/pkg/client"
2522
2623 "github.com/sap/component-operator-runtime/pkg/component"
2724 componentoperatorruntimetypes "github.com/sap/component-operator-runtime/pkg/types"
2825)
2926
3027// { { .kind } }Spec defines the desired state of { { .kind } }
3128type { { .kind } }Spec struct {
32- // You can remove component.Spec, but then you have to provide your own (meaningful)
33- // implementations of GetDeploymentNamespace() and GetDeploymentName() below.
34- component.Spec `json:" ,inline" `
29+ // Uncomment the following if you want to make deployment namespace and name configurable
30+ // here in the spec (independently of the component' s metadata.namespace and metadata.name);
31+ // if you do, also review the implementations of GetDeploymentNamespace() and GetDeploymentName() below.
32+ // component.Spec `json:",inline"`
33+
3534 // Add your own fields here, describing the deployment of the managed component.
3635}
3736
3837// {{ .kind }}Status defines the observed state of {{ .kind }}
3938type {{ .kind }}Status struct {
4039 component.Status `json:",inline"`
40+
4141 // You may add your own fields here; this is rarely needed.
4242}
4343
@@ -76,16 +76,18 @@ func (s *{{ .kind }}Spec) ToUnstructured() map[string]any {
7676}
7777
7878func (c *{{ .kind }}) GetDeploymentNamespace() string {
79- if c.Spec.Namespace != " " {
80- return c.Spec.Namespace
81- }
79+ // Uncomment the following if you allow specification of deployment namespace via the component spec.
80+ // if c.Spec.Namespace != "" {
81+ // return c.Spec.Namespace
82+ // }
8283 return c.Namespace
8384}
8485
8586func (c *{{ .kind }}) GetDeploymentName() string {
86- if c.Spec.Name != " " {
87- return c.Spec.Name
88- }
87+ // Uncomment the following if you allow specification of deployment name via the component spec.
88+ // if c.Spec.Name != "" {
89+ // return c.Spec.Name
90+ // }
8991 return c.Name
9092}
9193
@@ -97,22 +99,6 @@ func (c *{{ .kind }}) GetStatus() *component.Status {
9799 return &c.Status.Status
98100}
99101
100- // The following post read hook ensures that Spec.Namespace and Spec.Name are properly defaulted (as metadata.namespace/metadata.name).
101- // The hook will be called by the reconciler after retrieving the component object from the Kubernetes API.
102- // Of course, the same could be (better) achieved by a mutating admission webhook, but we strive to build component operators
103- // without admission webhooks.
104- // You can remove this hook (and its registration in pkg/operator/operator.go) if you do not use .Spec.Namespace or .Spec.Name anywhere,
105- // or if you have chosen not to include component.Spec in { {.kind} }Spec above.
106- func PostReadHook(ctx context.Context, client client.Client, c *{ { .kind } }) error {
107- if c.Spec.Namespace == " " {
108- c.Spec.Namespace = c.Namespace
109- }
110- if c.Spec.Name == "" {
111- c.Spec.Name = c.Name
112- }
113- return nil
114- }
115-
116102func init() {
117103 SchemeBuilder.Register(&{{ .kind }}{}, &{{ .kind }}List{})
118104}
0 commit comments