parser

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 11 Imported by: 3

Documentation

Overview

Package parser contains implementations of the framework.TemplateParser and framework.SchemaParser interfaces. Typically, you would use these in a framework.TemplateProcessor.

Example:

processor := framework.TemplateProcessor{
	ResourceTemplates: []framework.ResourceTemplate{{
		Templates: parser.TemplateFiles("path/to/templates"),
	}},
	PatchTemplates: []framework.PatchTemplate{
		&framework.ResourcePatchTemplate{
			Templates: parser.TemplateFiles("path/to/patches/ingress.template.yaml"),
		},
	},
	AdditionalSchemas: parser.SchemaFiles("path/to/crd-schemas"),
}

All the parser in this file are compatible with embed.FS filesystems. To load from an embed.FS instead of local disk, use `.FromFS`. For example, if you embed filesystems as follows:

//go:embed resources/* patches/* var templateFS embed.FS //go:embed schemas/* var schemaFS embed.FS

Then you can use them like so:

processor := framework.TemplateProcessor{
	ResourceTemplates: []framework.ResourceTemplate{{
		Templates: parser.TemplateFiles("resources").FromFS(templateFS),
	}},
	PatchTemplates: []framework.PatchTemplate{
		&framework.ResourcePatchTemplate{
			Templates: parser.TemplateFiles("patches/ingress.template.yaml").FromFS(templateFS),
		},
	},
	AdditionalSchemas: parser.SchemaFiles("schemas").FromFS(schemaFS),
}

Index

Constants

View Source
const (
	// SchemaExtension is the file extension this package requires schema files to have
	SchemaExtension = ".json"
)
View Source
const (
	// TemplateExtension is the file extension this package requires template files to have
	TemplateExtension = ".template.yaml"
)

Variables

This section is empty.

Functions

func SchemaStrings

func SchemaStrings(data ...string) framework.SchemaParser

SchemaStrings returns a SchemaParser that will parse the schemas in the given strings.

This is a helper for use with framework.TemplateProcessor#AdditionalSchemas. Example:

	processor := framework.TemplateProcessor{
		//...
		AdditionalSchemas: parser.SchemaStrings(`
       {
         "definitions": {
           "com.example.v1.Foo": {
              ...
           }
         }
       }
		`),

func TemplateStrings

func TemplateStrings(data ...string) framework.TemplateParser

TemplateStrings returns a TemplateParser that will parse the templates from the given strings.

This is a helper for use with framework.TemplateProcessor's template subfields. Example:

 processor := framework.TemplateProcessor{
	ResourceTemplates: []framework.ResourceTemplate{{
		Templates: parser.TemplateStrings(`
			apiVersion: apps/v1
			kind: Deployment
			metadata:
			 name: foo
			 namespace: default
			 annotations:
			   {{ .Key }}: {{ .Value }}
			`)
	}},
 }

Types

type SchemaParser

type SchemaParser struct {
	// contains filtered or unexported fields
}

SchemaParser is a framework.SchemaParser that can parse files or directories containing openapi schemas.

func SchemaFiles

func SchemaFiles(paths ...string) SchemaParser

SchemaFiles returns a SchemaParser that will parse the schemas in the given files. This is a helper for use with framework.TemplateProcessor#AdditionalSchemas.

processor := framework.TemplateProcessor{
	//...
	AdditionalSchemas: parser.SchemaFiles("path/to/crd-schemas", "path/to/special-schema.json),
}

func (SchemaParser) FromFS

func (l SchemaParser) FromFS(fs iofs.FS) SchemaParser

FromFS allows you to replace the filesystem in which the parser will look up the given paths. For example, you can use an embed.FS.

func (SchemaParser) Parse

func (l SchemaParser) Parse() ([]*spec.Definitions, error)

Parse implements framework.SchemaParser

type TemplateParser

type TemplateParser struct {
	// contains filtered or unexported fields
}

TemplateParser is a framework.TemplateParser that can parse files or directories containing Go templated YAML.

func TemplateFiles

func TemplateFiles(paths ...string) TemplateParser

TemplateFiles returns a TemplateParser that will parse the templates from the given files or directories. Only immediate children of any given directories will be parsed. All files must end in .template.yaml.

This is a helper for use with framework.TemplateProcessor's template subfields. Example:

	 processor := framework.TemplateProcessor{
		ResourceTemplates: []framework.ResourceTemplate{{
			Templates: parser.TemplateFiles("path/to/templates", "path/to/special.template.yaml")
		}},
  }

func (TemplateParser) FromFS

func (l TemplateParser) FromFS(fs iofs.FS) TemplateParser

FromFS allows you to replace the filesystem in which the parser will look up the given paths. For example, you can use an embed.FS.

func (TemplateParser) Parse

func (l TemplateParser) Parse() ([]*template.Template, error)

Parse implements framework.TemplateParser

func (TemplateParser) WithExtensions added in v0.13.7

func (l TemplateParser) WithExtensions(ext ...string) TemplateParser

WithExtensions allows you to replace the extension the parser accept on the input files.

Jump to

Keyboard shortcuts

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