application

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: Apache-2.0 Imports: 14 Imported by: 13

Documentation

Overview

package application provides wrapper types around the concept of an App and its associated values ConfigMap.

A standard Application type is available as well as a Cluster helper type that encapsulates both the cluster app and the associated default-apps and their values ConfigMaps. The Cluster type also handles setting the required labels and annotations on the relevant App and ConfigMap resources.

Creating an App

app := application.New("test-installation", "external-dns").
	WithNamespace("default").
	WithVersion("").
	MustWithValuesFile("./test_data/externaldns_values.yaml", &application.ValuesTemplateVars{})

appCR, configMap, err := app.Build()

Creating a Cluster

cluster = application.NewClusterApp(utils.GenerateRandomName("t"), application.ProviderGCP).
	WithOrg(organization.NewRandomOrg()).
	WithAppValuesFile(path.Clean("./test_data/cluster_values.yaml"), path.Clean("./test_data/default-apps_values.yaml"))

clusterApp, clusterConfigMap, defaultAppsApp, defaultAppsConfigMap, err := cluster.Build()

App Versions

When specifing the App version there are a couple special cases that you can take advantage of:

  1. Using the value `latest` as the App version will cause the latest released version found on GitHub to be used.
  2. Setting the version to an empty string will allow for overriding the version from an environment variable. The environment variable `E2E_OVERRIDE_VERSIONS` can be used to provide a comma seperated list of app version overrides in the format `app-name=version` (e.g. `cluster-aws=v1.2.3,cluster-gcp=v1.2.3-2hehdu`). If no such environemnt variable is found then it will fallback to the same logic as `latest` above.

Combining these two features together allows for creating scenarios that test upgrading an App from the current latest to the version being worked on in a PR.

Example:

Assuming the `E2E_OVERRIDE_VERSIONS` env var is set to override cluster-aws with a valid version then the following will install cluster-aws as the lastest released version then later install (upgrade) again with the version overridden from the environment variable.

appCR, configMap, err := application.New("upgrade-test", "cluster-aws").WithVersion("latest").Build()

// ... apply manifests and wait for install to complete...

appCR, configMap, err = application.New("upgrade-test", "cluster-aws").WithVersion("").Build()

// ... apply manifests and wait for upgrade to complete...

Index

Constants

View Source
const VersionOverrideEnvVar = "E2E_OVERRIDE_VERSIONS"

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application struct {
	InstallName          string
	AppName              string
	Version              string
	Catalog              string
	Values               string
	InCluster            bool
	Namespace            string
	UserConfigSecretName string

	AppLabels       map[string]string
	ConfigMapLabels map[string]string
}

Application contains all details for creating an App and its values ConfigMap

func New

func New(installName string, appName string) *Application

New creates a new Application

func (*Application) Build

Build generates the App and ConfigMap resources

func (*Application) MustWithValuesFile

func (a *Application) MustWithValuesFile(filePath string, config *ValuesTemplateVars) *Application

MustWithValuesFile wraps around WithValuesFile but panics if an error occurs. It is intended to allow for chaining functions when you're sure the file will template successfully.

func (*Application) WithAppLabels

func (a *Application) WithAppLabels(labels map[string]string) *Application

WithAppLabels adds the provided labels to the generated App resource

func (*Application) WithCatalog

func (a *Application) WithCatalog(catalog string) *Application

WithCatalog sets the Catalog value

func (*Application) WithConfigMapLabels

func (a *Application) WithConfigMapLabels(labels map[string]string) *Application

WithConfigMapLabels adds the provided labels to the generated ConfigMap resource

func (*Application) WithInCluster

func (a *Application) WithInCluster(inCluster bool) *Application

WithInCluster sets the InCluster value

func (*Application) WithNamespace

func (a *Application) WithNamespace(namespace string) *Application

WithNamespace sets the Namespace value

func (*Application) WithUserConfigSecretName added in v0.0.9

func (a *Application) WithUserConfigSecretName(name string) *Application

WithUserConfigSecretName sets the provided name of the secret as UserConfigSecretName

func (*Application) WithValues

func (a *Application) WithValues(values string, config *ValuesTemplateVars) *Application

WithValues sets the Values value

The values supports templating using Go template strings and uses values provided in `config` to replace placeholders.

func (*Application) WithValuesFile

func (a *Application) WithValuesFile(filePath string, config *ValuesTemplateVars) (*Application, error)

WithValuesFile sets the Values property based on the contents found in the provided file path

The file supports templating using Go template strings and uses values provided in `config` to replace placeholders.

func (*Application) WithVersion

func (a *Application) WithVersion(version string) *Application

WithVersion sets the Version value

If set to the value `latest“ then the version will be fetched from the latest release on GitHub. If set to an empty string (the default) then the environment variables will first be checked for a matching override var and if not found then the logic will fall back to the same as `latest“.

If the version provided is suffixed with a commit sha then the `Catalog` use for the Apps will be updated to `cluster-test`.

type Cluster

type Cluster struct {
	Name           string
	Namespace      string
	ClusterApp     *Application
	DefaultAppsApp *Application
	Organization   *organization.Org
}

Cluster is a wrapper around Cluster and Default-apps Apps that makes creating them together easier

func NewClusterApp

func NewClusterApp(clusterName string, provider Provider) *Cluster

NewClusterApp generates a new Cluster object to handle creation of Cluster related apps

func (*Cluster) Build

Build defaults and populates some required values on the apps then generated the App and Configmap pairs for both the cluster and default-apps apps.

func (*Cluster) WithAppValues

func (c *Cluster) WithAppValues(clusterValues string, defaultAppsValues string) *Cluster

WithAppValues sets the App Values values

The values supports templating using Go template strings to replace things like the cluster name and namespace

func (*Cluster) WithAppValuesFile

func (c *Cluster) WithAppValuesFile(clusterValuesFile string, defaultAppsValuesFile string) *Cluster

WithAppValuesFile sets the App Values values from the provided file paths

The values supports templating using Go template strings to replace things like the cluster name and namespace

func (*Cluster) WithAppVersions

func (c *Cluster) WithAppVersions(clusterVersion string, defaultAppsVersion string) *Cluster

WithAppVersions sets the Version values

If the versions are set to the value `latest` then the version will be fetched from the latest release on GitHub. If set to an empty string (the default) then the environment variables will first be checked for a matching override var and if not found then the logic will fall back to the same as `latest`.

If the version provided is suffixed with a commit sha then the `Catalog` use for the Apps will be updated to `cluster-test`.

func (*Cluster) WithNamespace

func (c *Cluster) WithNamespace(namespace string) *Cluster

WithNamespace sets the Namespace value

Note: this may be overwritten if Cluster.WithOrg is used after.

func (*Cluster) WithOrg

func (c *Cluster) WithOrg(org *organization.Org) *Cluster

WithOrg sets the Organization for the cluster and updates the namespace to that specified by the provided Org

func (*Cluster) WithUserConfigSecret added in v0.0.9

func (c *Cluster) WithUserConfigSecret(secretName string) *Cluster

WithUserConfigSecret sets the name of the referenced Secret under userConfig section

type Provider

type Provider string

Provider is the supported cluster provider name used to determine the cluster and default-apps to use

const (
	ProviderAWS           Provider = "aws"
	ProviderGCP           Provider = "gcp"
	ProviderAzure         Provider = "azure"
	ProviderCloudDirector Provider = "cloud-director"
	ProviderOpenStack     Provider = "openstack"
	ProviderVSphere       Provider = "vsphere"
)

type ValuesTemplateVars

type ValuesTemplateVars struct {
	ClusterName  string
	Namespace    string
	Organization string
}

ValuesTemplateVars is the properties made available to the Values string when templating.

The Values string if parsed as a Go text template and will replace these properties if found.

Jump to

Keyboard shortcuts

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