template

package
v1.11.0-cni-plu...-aa3fb74 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptySrc = errors.New("empty src template")
View Source
var NodeName = os.Getenv("NODENAME")

Functions

func BGPFilterBIRDFuncs

func BGPFilterBIRDFuncs(pairs memkv.KVPairs, version int) ([]string, error)

BGPFilterBIRDFuncs generates a set of BIRD functions for BGPFilter resources that have been packaged into KVPairs. By doing the formatting inside of this function we eliminate the need to copy and paste repeated blocks of golang template code into our BIRD config templates that is both difficult to read and prone to errors

e.g. for a BGPFilter resource specified as follows:

kind: BGPFilter apiVersion: projectcalico.org/v3 metadata:

name: test-bgpfilter

spec:

exportV4:
  - action: Accept
    matchOperator: In
    cidr: 77.0.0.0/16
  - action: Reject
    matchOperator: In
    cidr: 77.1.0.0/16
importV4:
  - action: Accept
    matchOperator: In
    cidr: 44.0.0.0/16
  - action: Reject
    matchOperator: In
    cidr: 44.1.0.0/16

Would produce the following string array that can be easily output via BIRD config template:

[]string{
  "# v4 BGPFilter test-bgpfilter",
  "function 'bgp_test-bgpfilter_importFilterV4'() {",
  "  if ((net ~ 44.0.0.0/16)) then { accept; }",
  "  if ((net ~ 44.1.0.0/16)) then { reject; }",
  "}",
  "function 'bgp_test-bgpfilter_exportFilterV4'() {",
  "  if ((net ~ 77.0.0.0/16)) then { accept; }",
  "  if ((net ~ 77.1.0.0/16)) then { reject; }",
  "}",
 }

func BGPFilterFunctionName

func BGPFilterFunctionName(filterName, direction, version string) (string, error)

BGPFilterFunctionName returns a formatted name for use as a BIRD function, truncating and hashing if the provided name would result in a function name longer than the max allowable length of 64 chars. e.g. input of ("my-bgp-filter", "import", "4") would result in output of "'bgp_my-bpg-filter_importFilterV4'"

func Base64Decode

func Base64Decode(data string) (string, error)

func Base64Encode

func Base64Encode(data string) string

func CreateMap

func CreateMap(values ...interface{}) (map[string]interface{}, error)

CreateMap creates a key-value map of string -> interface{} The i'th is the key and the i+1 is the value

func Getenv

func Getenv(key string, v ...string) string

Getenv retrieves the value of the environment variable named by the key. It returns the value, which will the default value if the variable is not present. If no default value was given - returns "".

func LookupIP

func LookupIP(data string) []string

func LookupSRV

func LookupSRV(service, proto, name string) []*net.SRV

func Process

func Process(config Config) error

func UnmarshalJsonArray

func UnmarshalJsonArray(data string) ([]interface{}, error)

func UnmarshalJsonObject

func UnmarshalJsonObject(data string) (map[string]interface{}, error)

Types

type Config

type Config struct {
	ConfDir       string
	ConfigDir     string
	KeepStageFile bool
	Noop          bool
	Prefix        string
	StoreClient   backends.StoreClient
	SyncOnly      bool
	TemplateDir   string
}

type Processor

type Processor interface {
	Process()
}

func WatchProcessor

func WatchProcessor(config Config, stopChan, doneChan chan bool, errChan chan error) Processor

type TemplateResource

type TemplateResource struct {
	CheckCmd     string `toml:"check_cmd"`
	Dest         string
	FileMode     os.FileMode
	Gid          int
	Keys         []string
	Mode         string
	Prefix       string
	ReloadCmd    string `toml:"reload_cmd"`
	Src          string
	StageFile    *os.File
	Uid          int
	ExpandedKeys []string
	// contains filtered or unexported fields
}

TemplateResource is the representation of a parsed template resource.

func NewTemplateResource

func NewTemplateResource(path string, config Config) (*TemplateResource, error)

NewTemplateResource creates a TemplateResource.

type TemplateResourceConfig

type TemplateResourceConfig struct {
	TemplateResource TemplateResource `toml:"template"`
}

TemplateResourceConfig holds the parsed template resource.

Jump to

Keyboard shortcuts

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