concepts

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2021 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ConceptFileName = "concept.json"
	// _ (underscore) is specifically not part of this list, as this will be our
	// replacement character for forming URLs
	ConceptIdentifierRegex                        = "^([a-z/\\-123456789]+)@([a-z\\-]+)$"
	ConceptStringInputType    InputTypeIdentifier = "string"
	ConceptSelectionInputType InputTypeIdentifier = "select"
	ConceptMapInputType       InputTypeIdentifier = "map"
	ConceptIntInputType       InputTypeIdentifier = "int"
	ConceptBoolInputType      InputTypeIdentifier = "bool"
	ConceptJsonnetType        ConceptType         = "jsonnet"
	ConceptJsonnetfile                            = "jsonnetfile.json"
	ConceptMainJsonnet                            = "main.jsonnet"
	ConceptMakefile                               = "Makefile"
	ConceptGitignorefile                          = ".gitignore"
	ConceptLibDir                                 = "lib/"
	ConceptVendorDir                              = "vendor/"
	ConceptKlibsonnet                             = "k.libsonnet"
	ConceptMainlibsonnet                          = "main.libsonnet"
	ConceptRenderFileName                         = "renderinfo.json"
)

Variables

View Source
var (
	IsValidConceptIdentifier = regexp.MustCompile(ConceptIdentifierRegex).MatchString
	JsonnetMainTemplate      = []byte(`local lib = import 'lib/main.libsonnet';

// Final JSON Output
lib.new(std.extVar("instanceName"))
`)
	JsonnetMainLibTemplate = []byte(`local kausal = import "ksonnet-util/kausal.libsonnet";

local deployment = kausal.apps.v1.deployment;
local container = kausal.core.v1.container;
local port = kausal.core.v1.containerPort;
local service = kausal.core.v1.service;

local grafanaDeploy(name) = deployment.new(
        name=name, replicas=2,
        containers=[
          container.new("grafana", "grafana/grafana")
          + container.withPorts([port.new("ui", 10330)]),
        ],
      );


// Final JSON Object
{
  new(name):: [
    grafanaDeploy(name),
    kausal.util.serviceFor(grafanaDeploy(name))
  ]
}
`)

	JsonnetLibTemplate = []byte(`(import "github.com/jsonnet-libs/k8s-alpha/1.14/main.libsonnet")
+ (import "github.com/jsonnet-libs/k8s-alpha/1.14/extensions/kausal-shim.libsonnet")
`)
	JsonnetDepTemplate = []byte(`{
  "version": 1,
  "dependencies": [
    {
      "source": {
        "git": {
          "remote": "https://github.com/grafana/jsonnet-libs.git",
          "subdir": "ksonnet-util"
        }
      },
      "version": "master"
    },
    {
      "source": {
        "git": {
          "remote": "https://github.com/jsonnet-libs/k8s-alpha.git",
          "subdir": "1.14"
        }
      },
      "version": "master"
    }
  ],
  "legacyImports": true
}
`)
	JsonnetMakeFile = []byte(`render:
	kable render -l . -o out/

install:
	jb install
`)
	JsonnetGitignoreFile = []byte(`out/
`)
)
View Source
var RenderNameIsValid = regexp.MustCompile(RenderNameRegexString).MatchString

Functions

func InitConcept

func InitConcept(workdir, name string, conceptType ConceptType) error

Types

type BoolValueType

type BoolValueType bool

func (BoolValueType) String

func (vt BoolValueType) String() string

func (BoolValueType) ValueTypeIdentifier

func (vt BoolValueType) ValueTypeIdentifier() string

type CRDTarget

type CRDTarget struct {
}

func (CRDTarget) Render

func (c CRDTarget) Render(path string, vals *RenderValues, cpt ConceptType, single bool) (*Render, error)

func (CRDTarget) TargetName

func (c CRDTarget) TargetName() string

type Concept

type Concept struct {
	ApiVersion int           `json:"apiVersion"`
	Type       ConceptType   `json:"type"`
	Meta       ConceptMeta   `json:"metadata"`
	Inputs     ConceptInputs `json:"inputs,omitempty"`
}

Concept defines model for Concept.

func GetConcept

func GetConcept(path string) (*Concept, error)

func GetRepoConcept

func GetRepoConcept(cid ConceptIdentifier) (*Concept, error)

func (*Concept) UnmarshalJSON added in v0.7.0

func (c *Concept) UnmarshalJSON(bytes []byte) error

type ConceptIdentifier

type ConceptIdentifier string

func ListConcepts

func ListConcepts() ([]ConceptIdentifier, error)

func NewConceptIdentifier

func NewConceptIdentifier(path, repoid string) ConceptIdentifier

func (ConceptIdentifier) Concept

func (ci ConceptIdentifier) Concept() string

func (ConceptIdentifier) IsValid

func (ci ConceptIdentifier) IsValid() bool

func (ConceptIdentifier) Repo

func (ci ConceptIdentifier) Repo() string

func (ConceptIdentifier) String

func (ci ConceptIdentifier) String() string

type ConceptInputs

type ConceptInputs struct {
	Mandatory map[string]InputType `json:"mandatory,omitempty"`
	Optional  map[string]InputType `json:"optional,omitempty"`
}

ConceptInputs defines model for ConceptInputs.

func (ConceptInputs) All added in v0.6.0

func (ci ConceptInputs) All() map[string]InputType

type ConceptMeta

type ConceptMeta struct {
	Name       string         `json:"name"`
	Tags       Tags           `json:"tags,omitempty"`
	Maintainer MaintainerInfo `json:"maintainer,omitempty"`
}

ConceptMeta defines model for ConceptMeta.

type ConceptOrigin

type ConceptOrigin struct {
	Repository string `json:"repository"`
	Ref        string `json:"ref"`
}

Origin defines the git source of origin

func GetConceptOriginFromRepository added in v0.8.0

func GetConceptOriginFromRepository(repositoryName string) (*ConceptOrigin, error)

type ConceptRepoInfo

type ConceptRepoInfo struct {
	Concept string
	Path    string
	RepoId  string
}

type ConceptType

type ConceptType string

func (ConceptType) IsSupported

func (ct ConceptType) IsSupported() bool

func (ConceptType) String added in v0.6.0

func (ct ConceptType) String() string

type File

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

func (File) String

func (f File) String() string

type InputType

type InputType struct {
	Type    InputTypeIdentifier `json:"type"`
	Options []string            `json:"options,omitempty"`
}

type InputTypeIdentifier

type InputTypeIdentifier string

func (InputTypeIdentifier) IsValid

func (iti InputTypeIdentifier) IsValid() bool

func (InputTypeIdentifier) String

func (iti InputTypeIdentifier) String() string

type IntValueType

type IntValueType int

func (IntValueType) String

func (vt IntValueType) String() string

func (IntValueType) ValueTypeIdentifier

func (vt IntValueType) ValueTypeIdentifier() string

type MaintainerInfo

type MaintainerInfo struct {
	Name  string `json:"name"`
	Email string `json:"email,omitempt"`
}

func (MaintainerInfo) String

func (mi MaintainerInfo) String() string

type MapValueType

type MapValueType map[string]interface{}

func (MapValueType) String

func (vt MapValueType) String() string

func (MapValueType) ValueTypeIdentifier

func (vt MapValueType) ValueTypeIdentifier() string

type Render

type Render struct {
	Info  *File
	Files []File
}

func RenderConcept

func RenderConcept(path string, avs *RenderValues, ttype TargetType, opts RenderOpts) (*Render, error)

func (Render) PrintFiles

func (r Render) PrintFiles() string

func (Render) Write

func (r Render) Write(baseDir string) error

func (Render) WriteFiles

func (r Render) WriteFiles(baseDir string) error

func (Render) WriteInfo

func (r Render) WriteInfo(baseDir string) error

type RenderInfoV1

type RenderInfoV1 struct {
	Version int            `json:"version"`
	Meta    RenderMeta     `json:"meta"`
	Origin  *ConceptOrigin `json:"origin,omitempty"`
	Values  *RenderValues  `json:"values,omitempty"`
}

RenderInfoV1 defines model for RenderInfoV1.

func NewRenderV1

func NewRenderV1(avs *RenderValues, origin *ConceptOrigin) (*RenderInfoV1, error)

func ParseRenderInfoV1FromFile

func ParseRenderInfoV1FromFile(path string) (*RenderInfoV1, error)

type RenderMeta

type RenderMeta struct {
	DateCreated string `json:"date"`
}

RenderMeta defines model for RenderMeta.

type RenderOpts

type RenderOpts struct {
	Local           bool
	WriteRenderInfo bool
	Single          bool
}

type RenderValues

type RenderValues map[string]ValueType

func (RenderValues) Map

func (rv RenderValues) Map() map[string]ValueType

func (RenderValues) UnmarshalJSON added in v0.8.0

func (rv RenderValues) UnmarshalJSON(bytes []byte) error

type StringValueType

type StringValueType string

func (StringValueType) String

func (vt StringValueType) String() string

func (StringValueType) ValueTypeIdentifier

func (vt StringValueType) ValueTypeIdentifier() string

type Tags added in v0.6.1

type Tags []string

type Target

type Target interface {
	TargetName() string
	Render(path string, vals *RenderValues, cpt ConceptType, single bool) (*Render, error)
}

Target is the interface for all Target implementations

type TargetType

type TargetType string
const (
	YamlTargetType TargetType = "yaml"
	CRDTargetType  TargetType = "crd"
)

type ValueType

type ValueType interface {
	ValueTypeIdentifier() string
	String() string
}

type ValueTypeIdentifier

type ValueTypeIdentifier string
const (
	RenderStringValueTypeIdentifier ValueTypeIdentifier = "string"
	RenderMapValueTypeIdentifier    ValueTypeIdentifier = "map"
	RenderIntValueTypeIdentifier    ValueTypeIdentifier = "int"
	RenderBoolValueTypeIdentifier   ValueTypeIdentifier = "bool"
	RenderNameRegexString                               = "^[a-z-_]+$"
)

type YamlTarget

type YamlTarget struct {
}

func (YamlTarget) Render

func (y YamlTarget) Render(path string, vals *RenderValues, cpt ConceptType, single bool) (*Render, error)

func (YamlTarget) TargetName

func (y YamlTarget) TargetName() string

Jump to

Keyboard shortcuts

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