application

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: Apache-2.0 Imports: 25 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").
	WithOrganization("giantswarm").
	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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppPair added in v1.0.0

type AppPair struct {
	App       *applicationv1alpha1.App
	ConfigMap *corev1.ConfigMap
}

type Application

type Application struct {
	InstallName          string
	AppName              string
	Version              string
	Catalog              string
	Values               string
	InCluster            bool
	ClusterName          string
	Organization         organization.Org
	UserConfigSecretName string
	ExtraConfigs         []applicationv1alpha1.AppExtraConfig
	RepoName             string
	InstallNamespace     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) GetInstallNamespace added in v0.7.0

func (a *Application) GetInstallNamespace() string

GetInstallNamespace returns the namespace the Helm chart will be installed into.

func (*Application) GetNamespace added in v0.3.0

func (a *Application) GetNamespace() string

GetNamespace returns the namespace the App CR will be applied in.

func (*Application) IsUnifiedClusterAppWithDefaultApps added in v0.21.0

func (a *Application) IsUnifiedClusterAppWithDefaultApps() (bool, error)

IsUnifiedClusterAppWithDefaultApps returns a flag that indicates if a cluster-$provider app with specified version is a unified cluster-$provider app that deploys all default apps.

func (*Application) MustWithValues added in v0.2.0

func (a *Application) MustWithValues(values string, config *TemplateValues) *Application

MustWithValues wraps around WithValues 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) MustWithValuesFile

func (a *Application) MustWithValuesFile(filePath string, config *TemplateValues) *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) WithClusterName added in v0.6.0

func (a *Application) WithClusterName(clusterName string) *Application

WithClusterName sets the name of the cluster the app with be installed into. This is used for populating the appropriate labels on the App resources.

func (*Application) WithConfigMapLabels

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

WithConfigMapLabels adds the provided labels to the generated ConfigMap resource

func (*Application) WithExtraConfigs added in v0.0.13

func (a *Application) WithExtraConfigs(extraConfigs []applicationv1alpha1.AppExtraConfig) *Application

WithExtraConfigs sets the array of AppExtraConfigs to .spec.extraConfigs

func (*Application) WithInCluster

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

WithInCluster sets the InCluster value

func (*Application) WithInstallNamespace added in v0.6.0

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

WithInstallNamespace sets the namespace used by helm to install the chart This can be different to the namespace the App CR is in.

func (*Application) WithOrganization added in v0.3.0

func (a *Application) WithOrganization(organization organization.Org) *Application

WithOrganization sets the Organization value

func (*Application) WithRepoName added in v0.5.0

func (a *Application) WithRepoName(repoName string) *Application

WithRepoName sets the GitHub repository name associated with this application

This is usually not needed and currently only required if using the `latest` version and the repo name is vastly different to the App name (not just the `-app` suffix)

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 *TemplateValues) (*Application, error)

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 *TemplateValues) (*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 BuiltCluster added in v1.0.0

type BuiltCluster struct {
	SourceCluster *Cluster
	Cluster       *AppPair
	DefaultApps   *AppPair
	Release       *releases.Release
}

type Cluster

type Cluster struct {
	Name           string
	Provider       Provider
	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

func (c *Cluster) Build() (*BuiltCluster, error)

Build defaults and populates some required values on the apps then generated the App and Configmap pairs for both the cluster and default-apps (if applicable) apps as well as the Release CR.

func (*Cluster) GetNamespace added in v0.3.0

func (c *Cluster) GetNamespace() string

GetNamespace returns the cluster organization namespace.

func (*Cluster) UsesUnifiedClusterApp added in v0.21.0

func (c *Cluster) UsesUnifiedClusterApp() (bool, error)

UsesUnifiedClusterApp returns a flag that indicates if the cluster is deployed with the unified cluster-$provider app that deploys all default apps.

func (*Cluster) WithAppValues

func (c *Cluster) WithAppValues(clusterValues string, defaultAppsValues string, templateValues *TemplateValues) *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, templateValues *TemplateValues) *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) WithExtraConfigs added in v0.0.13

func (c *Cluster) WithExtraConfigs(extraConfigs []applicationv1alpha1.AppExtraConfig) *Cluster

WithExtraConfigs sets the array of AppExtraConfigs to .spec.extraConfigs

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 ClusterValues added in v0.0.10

type ClusterValues struct {
	BaseDomain   string       `yaml:"baseDomain"`
	ControlPlane ControlPlane `yaml:"controlPlane"`
	NodePools    NodePools    `yaml:"nodePools"`
}

ClusterValues holds common values for cluster-<provider> charts. These are the provider independent values and are present for all the charts

The `NodePools` property supports both the []Nodepool and map[string]NodePool types in the yaml values files and will handle both correctly as a map.

func (*ClusterValues) UnmarshalJSON added in v0.13.0

func (cv *ClusterValues) UnmarshalJSON(b []byte) error

UnmarshalJSON implements a custom unmarshaller that handles both the old and new schema structures

type ControlPlane added in v0.0.10

type ControlPlane struct {
	Replicas int `yaml:"replicas"`
}

type NodePool added in v0.0.10

type NodePool struct {
	Replicas int     `yaml:"replicas"`
	MaxSize  int     `yaml:"maxSize"`
	MinSize  int     `yaml:"minSize"`
	Name     *string `yaml:"name"`
}

type NodePools added in v0.3.1

type NodePools map[string]NodePool

NodePools is a special type containing a custom unmarshaller that can handle both []Nodepool and map[string]NodePool types in the yaml values.

func (*NodePools) UnmarshalJSON added in v0.3.1

func (np *NodePools) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom unmarshaller than handles both types of NodePools that our apps use: []Nodepool and map[string]NodePool. Both will be unmarshalled into a map[string]NodePool

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"
	ProviderEKS           Provider = "eks"
	ProviderGCP           Provider = "gcp"
	ProviderAzure         Provider = "azure"
	ProviderCloudDirector Provider = "cloud-director"
	ProviderOpenStack     Provider = "openstack"
	ProviderVSphere       Provider = "vsphere"
)

type TemplateValues added in v0.2.0

type TemplateValues struct {
	ClusterName  string
	Namespace    string
	Organization string

	ExtraValues map[string]string
}

TemplateValues 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