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:
- Using the value `latest` as the App version will cause the latest released version found on GitHub to be used.
- 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
- func GetLatestAppVersion(applicationName string) (string, error)
- type AppPair
- type Application
- func (a *Application) Build() (*applicationv1alpha1.App, *corev1.ConfigMap, error)
- func (a *Application) GetInstallNamespace() string
- func (a *Application) GetNamespace() string
- func (a *Application) IsUnifiedClusterAppWithDefaultApps() (bool, error)
- func (a *Application) MustWithValues(values string, config *TemplateValues) *Application
- func (a *Application) MustWithValuesFile(filePath string, config *TemplateValues) *Application
- func (a *Application) WithAppLabels(labels map[string]string) *Application
- func (a *Application) WithCatalog(catalog string) *Application
- func (a *Application) WithClusterName(clusterName string) *Application
- func (a *Application) WithConfigMapLabels(labels map[string]string) *Application
- func (a *Application) WithExtraConfigs(extraConfigs []applicationv1alpha1.AppExtraConfig) *Application
- func (a *Application) WithInCluster(inCluster bool) *Application
- func (a *Application) WithInstallNamespace(namespace string) *Application
- func (a *Application) WithOrganization(organization organization.Org) *Application
- func (a *Application) WithRepoName(repoName string) *Application
- func (a *Application) WithUserConfigSecretName(name string) *Application
- func (a *Application) WithValues(values string, config *TemplateValues) (*Application, error)
- func (a *Application) WithValuesFile(filePath string, config *TemplateValues) (*Application, error)
- func (a *Application) WithVersion(version string) *Application
- type BuiltCluster
- type Cluster
- func (c *Cluster) Build() (*BuiltCluster, error)
- func (c *Cluster) GetNamespace() string
- func (c *Cluster) GetRelease() (*releases.Release, error)
- func (c *Cluster) IsDefaultApp(app Application) (bool, error)
- func (c *Cluster) UsesUnifiedClusterApp() (bool, error)
- func (c *Cluster) WithAppOverride(app Application) *Cluster
- func (c *Cluster) WithAppValues(clusterValues string, defaultAppsValues string, templateValues *TemplateValues) *Cluster
- func (c *Cluster) WithAppValuesFile(clusterValuesFile string, defaultAppsValuesFile string, ...) *Cluster
- func (c *Cluster) WithAppVersions(clusterVersion string, defaultAppsVersion string) *Cluster
- func (c *Cluster) WithExtraConfigs(extraConfigs []applicationv1alpha1.AppExtraConfig) *Cluster
- func (c *Cluster) WithOrg(org *organization.Org) *Cluster
- func (c *Cluster) WithRelease(releasePair ReleasePair) *Cluster
- func (c *Cluster) WithUserConfigSecret(secretName string) *Cluster
- type ClusterValues
- type ControlPlane
- type NodePool
- type NodePools
- type Provider
- type ReleasePair
- type TemplateValues
Constants ¶
const ReleaseLatest = "latest"
ReleaseLatest is the value to use when fetching whatever the latest Release version is
Variables ¶
This section is empty.
Functions ¶
func GetLatestAppVersion ¶
GetLatestAppVersion returns the latest version (tag) name for a given repos release.
This function attempts to check for repos both with and without the `-app` suffix of the provided `applicationName`. The provided `applicationName` is used as preference when looking up releases but if fails will fallback to the suffix variation.
The function includes retry logic with exponential backoff to handle transient network issues or GitHub API rate limiting. It will give up after a maximum of 1 minute.
Types ¶
type AppPair ¶
type AppPair struct {
App *applicationv1alpha1.App
ConfigMap *corev1.ConfigMap
}
AppPair wraps an App and it's ConfigMap into a single struct
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 (*Application) Build ¶
func (a *Application) Build() (*applicationv1alpha1.App, *corev1.ConfigMap, error)
Build generates the App and ConfigMap resources
func (*Application) GetInstallNamespace ¶
func (a *Application) GetInstallNamespace() string
GetInstallNamespace returns the namespace the Helm chart will be installed into.
func (*Application) GetNamespace ¶
func (a *Application) GetNamespace() string
GetNamespace returns the namespace the App CR will be applied in.
func (*Application) IsUnifiedClusterAppWithDefaultApps ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (a *Application) WithOrganization(organization organization.Org) *Application
WithOrganization sets the Organization value
func (*Application) WithRepoName ¶
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 ¶
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 ¶
type BuiltCluster struct {
SourceCluster *Cluster
Cluster *AppPair
DefaultApps *AppPair
Release *releases.Release
}
BuiltCluster represents a Cluster after built into the resources that will be applied to Kubernetes
type Cluster ¶
type Cluster struct {
Name string
Provider Provider
ClusterApp *Application
DefaultAppsApp *Application
Organization *organization.Org
Release ReleasePair
// contains filtered or unexported fields
}
Cluster is a wrapper around Cluster and Default-apps Apps that makes creating them together easier
func NewClusterApp ¶
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 ¶
GetNamespace returns the cluster organization namespace.
func (*Cluster) GetRelease ¶
GetRelease builds the Release for the Cluster If `Release.Version` or `Release.Commit` are empty string this will attempt to use the override release values from environment variables, if found. If `Release.Version` is set to `latest` then the environment variables will be ignored and the latest available Release will be used.
func (*Cluster) IsDefaultApp ¶
func (c *Cluster) IsDefaultApp(app Application) (bool, error)
IsDefaultApp checks if the provided Application is defined as a default app in the Release
func (*Cluster) UsesUnifiedClusterApp ¶
UsesUnifiedClusterApp returns a flag that indicates if the cluster is deployed with the unified cluster-$provider app that deploys all default apps.
func (*Cluster) WithAppOverride ¶
func (c *Cluster) WithAppOverride(app Application) *Cluster
WithAppOverride uses the provided Application to override a default app when creating the cluster
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 ¶
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 ¶
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) WithRelease ¶
func (c *Cluster) WithRelease(releasePair ReleasePair) *Cluster
WithRelease sets the release version and commit to use for this Cluster
func (*Cluster) WithUserConfigSecret ¶
WithUserConfigSecret sets the name of the referenced Secret under userConfig section
type ClusterValues ¶
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 ¶
func (cv *ClusterValues) UnmarshalJSON(b []byte) error
UnmarshalJSON implements a custom unmarshaller that handles both the old and new schema structures
type ControlPlane ¶
type ControlPlane struct {
Replicas int `yaml:"replicas"`
}
ControlPlane contains the minimum require values for the Control Plane values
type NodePool ¶
type NodePool struct {
Replicas int `yaml:"replicas"`
MaxSize int `yaml:"maxSize"`
MinSize int `yaml:"minSize"`
Name *string `yaml:"name"`
}
NodePool contains the minimum required values for a Node Pools values
type NodePools ¶
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 ¶
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" ProviderUnknown Provider = "UNKNOWN" )
nolint:revive
func ProviderFromClusterApplication ¶
func ProviderFromClusterApplication(app *applicationv1alpha1.App) Provider
ProviderFromClusterApplication returns the appropriate Provider related to the given cluster app
type ReleasePair ¶
ReleasePair contains the Version and Commit sha for a specific Release
type TemplateValues ¶
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.