metagraf

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Store added in v0.0.16

func Store(filepath string, mg *MetaGraf)

Types

type Config

type Config struct {
	Name string `json:"name"`
	Type string `json:"type"`
	// If this is set to true, this will just be a refernce to a existing ConfigMap
	Global bool `json:"global,omitempty"`
	// Controls the mount point for the ConfigMap
	MountPath   string        `json:"mountpath,omitempty"`
	Description string        `json:"description,omitempty"`
	Options     []ConfigParam `json:"options,omitempty"`
}

type ConfigParam

type ConfigParam struct {
	Name        string `json:"name"`
	Required    bool   `json:"required"`
	Dynamic     bool   `json:"dynamic,omitempty"`
	Description string `json:"description"`
	Type        string `json:"type"`
	Default     string `json:"default"`
	SecretFrom  string `json:"secretfrom,omitempty"` // References a value from a k8s secret resource
}

type EnvironmentVar

type EnvironmentVar struct {
	Name     string `json:"name"`
	Required bool   `json:"required"`

	Type string `json:"type,omitempty"`

	// Expose environment variables from ConfigMap resources.
	// All keys, value pairs in secret will be exported from
	// the ConfigMap into a running Pod.  The Environment.Name
	// will just be a placeholder value.
	EnvFrom string `json:"envfrom,omitempty"`

	// Expose  contents of a kubernets Secret as environment variables
	// exported into a running container. The values are only available
	// inside a running Pod or if you have access to view secrets in the
	// namespace. Exposes all key, values from the Secret. The
	// EnvironmentVar.Name will just be a placeholder.
	SecretFrom string `json:"secretfrom,omitempty"`

	// When exporting environment variables from a Secret or Configmap resource, you
	// have the option to specify the name of a key to export. If provided
	// the value from the referenced key will appear as EnvironmentVar.Name
	// inside the running Pod.
	Key string `json:"key,omitempty"`

	// Description of the EnvironmentVar. What is it used for.
	Description string `json:"description"`

	// Field to hold the Default value. Take care with Default values in the spec. A good practice is to not use them.
	Default string `json:"default,omitempty"`

	// Textual field for describing an example value.
	Example string `json:"example,omitempty"`
}

func (*EnvironmentVar) GetType added in v0.1.0

func (e *EnvironmentVar) GetType() string

func (*EnvironmentVar) ToEnvVar added in v0.1.0

func (e *EnvironmentVar) ToEnvVar() corev1.EnvVar

type Generator added in v0.1.0

type Generator interface {
}

type MGProperties added in v0.1.0

type MGProperties map[string]MGProperty

map for holding MGProperty structs, should be keyed by MGProperty.Source + ":" + MGProperty.Key

func (MGProperties) GetByKey added in v0.1.0

func (mgp MGProperties) GetByKey(key string) (MGProperty, error)

Returns a MGProperty by key (name) from MGProperties collection.

func (MGProperties) GetRequired added in v0.1.0

func (mgp MGProperties) GetRequired() MGProperties

Returns the MGProperty.Required = true

func (MGProperties) KeyMap added in v0.1.0

func (mgp MGProperties) KeyMap() map[string]string

Returns a map of key,values

func (MGProperties) Keys added in v0.1.0

func (mgp MGProperties) Keys() []string

Returns a slice of Keys

func (MGProperties) SourceKeyMap added in v0.1.0

func (mgp MGProperties) SourceKeyMap(required bool) map[string]string

Returns a map of MGProperty.Source+Key, MGProperty.Value It takes a boolean as argument. Return only required or all keys?

func (MGProperties) SourceKeys added in v0.1.0

func (mgp MGProperties) SourceKeys(required bool) []string

Return a slice of property keys. If required == true only return required keys.

type MGProperty added in v0.1.0

type MGProperty struct {
	Source   string `json:"source"`
	Key      string `json:"key"`
	Value    string `json:"value,omitempty"`
	Required bool   `json:"required,omitempty"`
	Default  string `json:"default,omitempty"`
}

Structure to hold specification section sourced parameters from input. Should solve key collisions and generally be a more workable solution.

func (*MGProperty) DefaultValueAsValue added in v0.1.0

func (mgp *MGProperty) DefaultValueAsValue()

Sets the MGProperty Value to the Default value.

func (*MGProperty) MGKey added in v0.1.0

func (mgp *MGProperty) MGKey() string

Returns a metagraf adressable key for a property.

func (*MGProperty) ToEnvironmentVar added in v0.1.0

func (mgp *MGProperty) ToEnvironmentVar() EnvironmentVar

Map a MGProperty to metaGraf EnvironmentVar

type MetaGraf

type MetaGraf struct {
	Kind     string `json:"kind"`
	Metadata struct {
		Name              string            `json:"name"`
		ResourceVersion   string            `json:"resourceversion"`
		Namespace         string            `json:"namespace"`
		CreationTimestamp string            `json:"creationtimestamp,omitempty"`
		Labels            map[string]string `json:"labels,omitempty"`
		Annotations       map[string]string `json:"annotations,omitempty"`
	} `json:"metadata"`
	Spec struct {
		// Describes the type of metaGraf specification. What types we have are not formalized yet.
		Type        string `json:"type"`
		Version     string `json:"version"`
		Description string `json:"description"`
		// Ports is a map keyed on protocol name (string) with port as it's value.
		Ports map[string]int32 `json:"ports,omitempty"`
		// Git repository URL for the source code of the described software component.
		Repository string `json:"repository,omitempty"`
		// Repository Secret Reference, git pull secret
		RepSecRef string `json:"repsecref,omitempty"`

		// Check out and build code from another branch than master. Defaults to master if
		// not provided.
		Branch string `json:"branch,omitempty"`

		// When a spec.image is specified, we want to deliver an existing image with
		// manifest generation provided with tools like mg.
		Image string `json:"image,omitempty"`

		// When spec.dockerfile is provided we will attempt to build the container image
		// with local tools, if present. Image and Dockerfile are mutually exclusive
		Dockerfile string `json:"dockerfile,omitempty"`

		// Image used to build the software referenced in Repository.
		BuildImage string `json:"buildimage,omitempty"`

		// Image to inject artifacts from above build.
		BaseRunImage string `json:"baserunimage,omitempty"`

		// StartupProbe, a v1.Probe{} definition from upstream Kubernetes.
		StartupProbe v1.Probe `json:"startupProbe,omitempty"`
		// LivenessProbe, a v1.Probe{} definition from upstream Kubernetes.
		LivenessProbe v1.Probe `json:"livenessProbe,omitempty"`
		// ReadinessProbe, a v1.Probe{} definition from upstream Kubernetes.
		ReadinessProbe v1.Probe `json:"readinessProbe,omitempty"`
		// Slice of Resource structs for holding information about attached resources.
		Resources []Resource `json:"resources,omitempty"`
		// Slice of strings to reference kubernetes resources manually maintained within the
		// repository in Spec.Resource. Downstream tooling may care about these.
		LocalManifests []string `json:"localManifests,omitempty"`

		// Structure for holding diffrent kind of environment variables.
		Environment struct {
			// Slice for holding environmentvariables for the build process.
			Build []EnvironmentVar `json:"build,omitempty"`
			// Environment variables that should be set on the Deployment resource.
			Local []EnvironmentVar `json:"local,omitempty"`
			// Environment variables or configuration keys that comes from some kind of
			// central configuration mechanism. Redis, etcd, your solution.
			External struct {
				// Slice for holding environment variable or configuration keys  that
				// are introduces to a central configuration solution.
				Introduces []EnvironmentVar `json:"introduces,omitempty"`
				// Slice of environment variable or configuration keys that this
				// compoent consumes from the central configuration solution.
				Consumes []EnvironmentVar `json:"consumes,omitempty"`
			} `json:"external,omitempty"`
		} `json:"environment,omitempty"`

		Config []Config `json:"config,omitempty"`

		// Slice of metagraf.Secret's for describing secrets needed in execution context.
		Secret []Secret `json:"secret,omitempty"`

		// Volume definitions for describing PersistentVolumes used by the component.
		Volume []Volume `json:"volume,omitempty"`

		// Slice of metagraf.Secret's needed in build context.
		BuildSecret []Secret `json:"buildsecret,omitempty"`
	} `json:"spec"`
}

JSON structure for a MetaGraf entity

func Parse

func Parse(filepath string) MetaGraf

func (MetaGraf) BuildSecretsToVolumeMounts added in v0.1.0

func (mg MetaGraf) BuildSecretsToVolumeMounts() []corev1.VolumeMount

Creates a slice of corev1.VolumeMount{} definitions from buildsecrets defined in the metaGraf specification.

func (MetaGraf) BuildSecretsToVolumes added in v0.1.0

func (mg MetaGraf) BuildSecretsToVolumes() []corev1.Volume

Creates a slice of corev1.Volume{} definitions from buildsecrets defined in the metaGraf specification.

func (MetaGraf) BuildVars added in v0.1.0

func (mg MetaGraf) BuildVars() []EnvironmentVar

Returns slice of MetaGraf.EnvironmentVar's from specification.

func (MetaGraf) DefaultServicePorts added in v0.1.4

func (mg MetaGraf) DefaultServicePorts() []corev1.ServicePort

Returns the mg tool's opinionated default if ports in a metagraf spec or the container image has no default exposed ports.

func (MetaGraf) GetConfigByName added in v0.0.18

func (mg MetaGraf) GetConfigByName(name string) (Config, error)

func (MetaGraf) GetDockerImageURL added in v0.1.4

func (mg MetaGraf) GetDockerImageURL() string

func (MetaGraf) GetEnvVarByType added in v0.1.0

func (mg MetaGraf) GetEnvVarByType(envtype string) []EnvironmentVar

func (*MetaGraf) GetProperties added in v0.1.0

func (mg *MetaGraf) GetProperties() MGProperties

Returns a struct (MGProperties) of all MGProperty addressable in the metaGraf specification.

func (MetaGraf) GetResourceByName added in v0.0.18

func (mg MetaGraf) GetResourceByName(name string) (Resource, error)

func (MetaGraf) GetSecretByName added in v0.0.18

func (mg MetaGraf) GetSecretByName(name string) (Secret, error)

func (MetaGraf) GetServicePorts added in v0.1.4

func (mg MetaGraf) GetServicePorts() []corev1.ServicePort

func (MetaGraf) GroupKinds added in v0.1.0

func (mg MetaGraf) GroupKinds() []metav1.GroupKind

Returns a list of GroupKind's described by the parsed metaGraf specification

func (MetaGraf) HasServicePorts added in v0.1.4

func (mg MetaGraf) HasServicePorts() bool

func (MetaGraf) ImagePorts added in v0.1.4

func (mg MetaGraf) ImagePorts() []corev1.ServicePort

func (MetaGraf) KubernetesBuildVars added in v0.1.0

func (mg MetaGraf) KubernetesBuildVars() []corev1.EnvVar

Returns slice of corev1.EnvVar's for all build

func (MetaGraf) Labels added in v0.1.0

func (mg MetaGraf) Labels(name string) map[string]string

func (MetaGraf) Name added in v0.1.0

func (mg MetaGraf) Name(oname string, version string) string

Returns the basename of a metagraf component based on conventions around semver version.

func (MetaGraf) SecretsToVolumeMounts added in v0.1.0

func (mg MetaGraf) SecretsToVolumeMounts() []corev1.VolumeMount

Creates a slice of corev1.VolumeMount{} definitions from secrets defined in the metaGraf specification.

func (MetaGraf) SecretsToVolumes added in v0.1.0

func (mg MetaGraf) SecretsToVolumes() []corev1.Volume

Creates a slice of corev1.Volume{} definitions from secrets defined in the metaGraf specification.

func (MetaGraf) ServicePorts added in v0.1.4

func (mg MetaGraf) ServicePorts() []corev1.ServicePort

func (MetaGraf) ServicePortsByAnnotation added in v0.1.0

func (mg MetaGraf) ServicePortsByAnnotation() []corev1.ServicePort

Checks the metagraf specification for k8s.io namespaced port information. Format: <protocol>.service.k8s.io/port : value

func (MetaGraf) ServicePortsBySpec added in v0.1.0

func (mg MetaGraf) ServicePortsBySpec() []corev1.ServicePort

func (MetaGraf) Volumes added in v0.1.2

func (mg MetaGraf) Volumes() []v1.Volume

func (MetaGraf) VolumesToVolumeMounts added in v0.1.2

func (mg MetaGraf) VolumesToVolumeMounts() []v1.VolumeMount

Retruns a slice of v1.VolumeMount{} for Volumes defined in metaGraf specification.

type MetagrafType added in v0.1.0

type MetagrafType string
const (
	Application   MetagrafType = "application"
	Configuration MetagrafType = "config"
)

type Resource

type Resource struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Type        string `json:"type"`
	Required    bool   `json:"required"`
	External    bool   `json:"external"`
	Semop       string `json:"semop,omitempty"` // Semantic operator, how to evaluate version match/requirements.

	Semver string `json:"semver,omitempty"` // Semantic version to evaluate for attached resource
	EnvRef string `json:"envref,omitempty"` // Reference an Environment variable

	// Used when we need to generate configuration for connection to the described attached resource.
	Template    string `json:"template,omitempty"`    // Go txt template string for generating resource configuration.
	TemplateRef string `json:"templateref,omitempty"` // ConfigMap Reference, OUTDATED Use ConfigRef
	ConfigRef   string `json:"configref,omitempty"`   // ConfigMap Reference, Replaces TemplateRef which was not a good name.
	User        string `json:"user,omitempty"`
	Secret      string `json:"secret,omitempty"` // k8s Secret reference
}

Describes attached resources for a component. Ref, 12 factor app. This section is currently a mess because of "lift and shift" approach we should never have done. Going forward all attached resources should become a Kubernets Service of some kind.

type ResourceType added in v0.1.0

type ResourceType string
const (
	ClusterService ResourceType = "clusterservice"
	ExternalName   ResourceType = "externalname"
)

type Secret added in v0.0.12

type Secret struct {
	Name        string `json:"name"`
	Global      bool   `json:"global,omitempty"`
	Description string `json:"description,omitempty"`

	// Indicated where in the filesystem we would like to mount the Secret.
	MountPath string `json:"mountpath,omitempty"`

	// Using Kubernetes v1.KeyToPath struct for mapping individual secret key's to filenames.
	Items []v1.KeyToPath `json:"items,omitempty"`
}

func (Secret) VolumeName added in v0.1.0

func (s Secret) VolumeName() string

type Volume added in v0.1.2

type Volume struct {
	// Name of the volume.
	Name string `json:"name"`
	// A description of the volume. What is this volume used for.
	Description string `json:"description,omitempty"`
	// Indicated where in the Pod filesystem we would like to mount the Volume.
	MountPath string `json:"mountpath,omitempty"`
	// A list of PersistentVolumeAccessMode's
	AccessModes []v1.PersistentVolumeAccessMode `json:"accessmodes"`
	// Declare the size of persistent storage to claim.
	Capacity []v1.ResourceList `json:"capacity,omitempty"`
	// Describe a hostPath based volume.
	HostPath v1.HostPathVolumeSource `json:"hostPath,omitempty"`
}

The structure for defining volumes to used by the component.

Jump to

Keyboard shortcuts

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