implementation.go.tmpl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package {{.PackageName}} provides functionality for {{.Description}}.
  14. package {{.PackageName}}
  15. import (
  16. "context"
  17. "fmt"
  18. apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
  19. "sigs.k8s.io/controller-runtime/pkg/client"
  20. "sigs.k8s.io/yaml"
  21. genv1alpha1 "github.com/external-secrets/external-secrets/apis/generators/v1alpha1"
  22. )
  23. // Generator implements {{.Description}} functionality.
  24. type Generator struct{}
  25. // Generate creates the output for this generator.
  26. func (g *Generator) Generate(_ context.Context, jsonSpec *apiextensions.JSON, _ client.Client, _ string) (map[string][]byte, genv1alpha1.GeneratorProviderState, error) {
  27. if jsonSpec == nil {
  28. return nil, nil, fmt.Errorf("no spec provided")
  29. }
  30. spec, err := parseSpec(jsonSpec.Raw)
  31. if err != nil {
  32. return nil, nil, fmt.Errorf("failed to parse spec: %w", err)
  33. }
  34. // TODO: Implement your generator logic here
  35. _ = spec
  36. // Example return - replace with your actual implementation
  37. return map[string][]byte{
  38. "result": []byte("TODO: implement {{.PackageName}} generator"),
  39. }, nil, nil
  40. }
  41. // Cleanup performs any necessary cleanup after generation.
  42. func (g *Generator) Cleanup(_ context.Context, _ *apiextensions.JSON, _ genv1alpha1.GeneratorProviderState, _ client.Client, _ string) error {
  43. // TODO: Implement cleanup if needed
  44. return nil
  45. }
  46. func parseSpec(data []byte) (*genv1alpha1.{{.GeneratorName}}, error) {
  47. var spec genv1alpha1.{{.GeneratorName}}
  48. err := yaml.Unmarshal(data, &spec)
  49. return &spec, err
  50. }
  51. // NewGenerator creates a new Generator instance.
  52. func NewGenerator() genv1alpha1.Generator {
  53. return &Generator{}
  54. }
  55. // Kind returns the generator kind.
  56. func Kind() string {
  57. return string(genv1alpha1.{{.GeneratorKind}})
  58. }