contrib

package
v0.39.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 6 Imported by: 5

README

Contributions

Contributions to skv2 are welcome! Extensions to skv2 which are common across projects but not intended to be universally applied should be placed int the contrib directory.

  • Templates should go in contrib/codegen/templates/ (e.g. contrib/codegen/templates/sets.go.tmpl)
  • Libraries imported by contrib templates should go in contrib/pkg/ (e.g. contrib/pkg/sets.go)
  • Test code should be added to contrib/tests/*_test.go where * is the name of the template (e.g. contrib/tests/sets_test.go)
  • A CustomTemplate should be added to contrib/custom_templates.go like so:
/*
Sets custom template
 */
const (
	SetOutputFilename     = "sets/sets.go"
	SetCustomTemplatePath = "sets/sets.gotmpl"
)

var Sets = func() model.CustomTemplates {
	templateContents, err := templatesBox.FindString(SetCustomTemplatePath)
	if err != nil {
		panic(err)
	}
	setsTemplates := model.CustomTemplates{
		Templates: map[string]string{SetOutputFilename: templateContents},
	}
	// register sets
	AllCustomTemplates = append(AllCustomTemplates, setsTemplates)

	return setsTemplates
}()

Note: to test generated

Documentation

Index

Constants

View Source
const (
	SetOutputFilename     = "sets/sets.go"
	SetCustomTemplatePath = "sets/sets.gotmpl"
)

Sets custom template

View Source
const (
	ClientProvidersOutputFilename     = "providers/client_providers.go"
	ClientProvidersCustomTemplatePath = "providers/client_providers.gotmpl"
)

ClientProviders custom template

View Source
const (
	HomogenousInputReconcilerCustomTemplatePath = "input/input_reconciler.gotmpl"
	HybridInputReconcilerCustomTemplatePath     = "input/hybrid_input_reconciler.gotmpl"
)

InputReconciler custom templates

View Source
const (
	InputSnapshotCustomTemplatePath = "input/input_snapshot.gotmpl"
)

InputSnapshot custom template

View Source
const (
	InputSnapshotManualBuilderCustomTemplatePath = "input/input_snapshot_manual_builder.gotmpl"
)

InputSnapshot test builder custom template

View Source
const (
	OutputSnapshotCustomTemplatePath = "output/output_snapshot.gotmpl"
)

OutputSnapshot custom template

Variables

View Source
var AllGroupCustomTemplates []model.CustomTemplates

use to get all group-level templates in contrib

View Source
var ClientProviders = func() model.CustomTemplates {
	templateContentsBytes, err := ioutil.ReadFile(templatesDir + ClientProvidersCustomTemplatePath)
	if err != nil {
		panic(err)
	}
	templateContents := string(templateContentsBytes)
	clientProvidersTemplate := model.CustomTemplates{
		Templates: map[string]string{ClientProvidersOutputFilename: templateContents},
	}

	AllGroupCustomTemplates = append(AllGroupCustomTemplates, clientProvidersTemplate)

	return clientProvidersTemplate
}()
View Source
var Sets = func() model.CustomTemplates {
	templateContentsBytes, err := ioutil.ReadFile(templatesDir + SetCustomTemplatePath)
	if err != nil {
		panic(err)
	}
	templateContents := string(templateContentsBytes)
	setsTemplates := model.CustomTemplates{
		Templates: map[string]string{SetOutputFilename: templateContents},
	}

	AllGroupCustomTemplates = append(AllGroupCustomTemplates, setsTemplates)

	return setsTemplates
}()

Functions

func InputReconciler

func InputReconciler(params SnapshotTemplateParameters) model.CustomTemplates

Returns the template for generating input reconcilers.

func InputSnapshot

func InputSnapshot(params SnapshotTemplateParameters) model.CustomTemplates

Returns the template for generating input snapshots.

func InputSnapshotManualBuilder added in v0.7.17

func InputSnapshotManualBuilder(params SnapshotTemplateParameters) model.CustomTemplates

Returns the template for generating input snapshots.

func OutputSnapshot

func OutputSnapshot(params SnapshotTemplateParameters) model.CustomTemplates

Returns the template for generating output snapshots.

Types

type HomogenousSnapshotResources added in v0.7.17

type HomogenousSnapshotResources struct {
	// a map of the GVKs to the resources which we want to include in the input snapshot.
	ResourcesToSelect map[schema.GroupVersion][]string
}

HomogenousSnapshotResources represents a set of snapshot resources read from a single source (either remote clusters or local cluster)

type HybridSnapshotResources added in v0.7.17

type HybridSnapshotResources struct {
	// a map of the GVKs to the resources which we want to include in the input snapshot.
	// these resourecs will be stored in the the local cluster where the controller is running.
	LocalResourcesToSelect map[schema.GroupVersion][]string

	// a map of the GVKs to the resources which we want to include in the input snapshot.
	// these resourecs will be stored in the the remote cluster which the controller manages.
	RemoteResourcesToSelect map[schema.GroupVersion][]string
}

HybridSnapshotResources represents a set of snapshot resources read from a both source remote clusters and the local cluster

type SnapshotResources added in v0.7.17

type SnapshotResources interface {
	// contains filtered or unexported methods
}

SnapshotResources acts as a "oneof" to encapsulate HybridSnapshot or a HomogenousSnapshot

type SnapshotTemplateParameters added in v0.7.17

type SnapshotTemplateParameters struct {
	// the path of the output file produced from this template. relative to project root.
	OutputFilename string

	// a map of Go modules to (a superset of) the imported codegen Groups. only required if the codegen group is defined in a different go module than the types (i.e. it is using a CustomTypesImportPath)
	SelectFromGroups map[string][]model.Group

	// the resources contained in the snapshot
	SnapshotResources SnapshotResources

	// name of the snapshot
	SnapshotName string
}

Parameters for constructing templates that span across multiple Groups.

func (SnapshotTemplateParameters) ConstructTemplate added in v0.7.17

func (p SnapshotTemplateParameters) ConstructTemplate(params SnapshotTemplateParameters, templateContents string, mockgenDirective bool) model.CustomTemplates

NOTE(awang): to use your template in a separate repo, use this function and pass in your own mockgenDirective and templateContents

Directories

Path Synopsis
codegen
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL