Documentation ¶
Index ¶
- Constants
- Variables
- func ReleaseName(input string) string
- func ValidateCharts(charts []Chart) error
- type Chart
- type ChartError
- type CompletedCallback
- type FailedPod
- type HealthIndication
- type InstallCallback
- type InstallCallbackAction
- type InstallOption
- type K8sClient
- type LogFunc
- type Manager
- type ReleaseMap
- type ValueOverridesMap
Constants ¶
const DefaultDeploymentTimeout = 10 * time.Minute
DefaultDeploymentTimeout indicates the default time to wait for a deployment to be healthy
const DefaultK8sNamespace = "default"
DefaultK8sNamespace is the k8s namespace to install a chart graph into if not specified
Variables ¶
var ChartWaitPollInterval = 10 * time.Second
ChartWaitPollInterval is the amount of time spent between polling attempts when checking if a deployment is healthy
var MaxPodLogLines = uint(500)
MaxPodLogLines is the maximum number of failed pod log lines to return in the event of chart install/upgrade failure
Functions ¶
func ReleaseName ¶
releaseName returns a release name of not more than 53 characters. If the input is truncated, a random number is added to ensure uniqueness.
func ValidateCharts ¶
ValidateCharts verifies that a set of charts is constructed properly, particularly with respect to dependencies. It does not check to see if the referenced charts exist in the local filesystem.
Types ¶
type Chart ¶
type Chart struct { Title string // unique name for this chart (must not collide with any dependencies) Location string // local filesystem location ValueOverrides []byte // value overrides as raw YAML stream WaitUntilHelmSaysItsReady bool // wait until Helm thinks the chart is ready. This overrides WaitUntilDeployment and DeploymentHealthIndication. WaitUntilDeployment string // Deployment name that, when healthy, indicates chart install has succeeded WaitTimeout time.Duration // how long to wait for the deployment to become healthy. If unset, DefaultDeploymentTimeout is used DeploymentHealthIndication HealthIndication // How to determine if a deployment is healthy DependencyList []string }
Chart models a single installable Helm chart
func (*Chart) Dependencies ¶
func (*Chart) ToYAMLStream ¶
func (c *Chart) ToYAMLStream(overrides ValueOverridesMap) error
ToYAMLStream takes overrides and serializes into a raw YAML stream that is assigned to c.ValueOverrides
type ChartError ¶
type ChartError struct { // HelmError is the original error returned by Helm // We always omit this value when json marshaling/unmarshaling since we would otherwise have to implement the UnmarshalJSON and MarshalJSON methods. HelmError error `json:"-"` // HelmErrorString is the error string of the original error returned by Helm HelmErrorString string `json:"helm_error_string"` // Level is the chart level (zero-indexed) at which the error occurred Level uint `json:"level"` // FailedDaemonSets is map of DaemonSet name to failed pods FailedDaemonSets map[string][]FailedPod `json:"failed_daemon_sets"` // FailedDeployments is map of Deployment name to failed pods FailedDeployments map[string][]FailedPod `json:"failed_deployments"` // FailedJobs is map of Job name to failed pods FailedJobs map[string][]FailedPod `json:"failed_jobs"` }
ChartError is a chart install/upgrade error due to failing Kubernetes resources. It contains all Deployment, Job or DaemonSet-related pods that appear to be in a failed state, including up to MaxPodLogLines of log data for each.
func NewChartError ¶
func NewChartError(err error) ChartError
NewChartError returns an initialized empty ChartError
func (ChartError) PopulateFromDeployment ¶
func (ce ChartError) PopulateFromDeployment(ctx context.Context, namespace, deploymentName string, kc K8sClient, maxloglines uint) error
PopulateFromDeployment finds the failed pods for a deployment and fills ChartError with names and logs of the failed pods
func (ChartError) PopulateFromRelease ¶
func (ce ChartError) PopulateFromRelease(ctx context.Context, rls *release.Release, kc K8sClient, maxloglines uint) error
PopulateFromRelease finds the failed Jobs and Pods for a given release and fills ChartError with names and logs of the failed resources
type CompletedCallback ¶
CompletedCallback is a function that is called upon completion of each individual chart upgrade/install. The error returned by Helm (if any) will be included. This will be called concurrently from multiple goroutines, so make sure everything is threadsafe. Also make sure to return promptly, as execution will block waiting for the callback to complete.
type FailedPod ¶
type FailedPod struct { Name string `json:"name"` Phase string `json:"phase"` Message string `json:"message"` Reason string `json:"reason"` Conditions []corev1.PodCondition `json:"conditions"` ContainerStatuses []corev1.ContainerStatus `json:"container_statuses"` // Logs is a map of container name to raw log (stdout/stderr) output Logs map[string][]byte `json:"logs"` }
FailedPod models a single failed pod with metadata and logs
type HealthIndication ¶
type HealthIndication int
HealthIndication describes how to decide if a deployment is successful
const ( // IgnorePodHealth indicates that we don't care about pod health IgnorePodHealth HealthIndication = iota // AllPodsHealthy indeicates that all pods are OK AllPodsHealthy // AtLeastOnePodHealthy indicates >= 1 pods are OK AtLeastOnePodHealthy )
type InstallCallback ¶
type InstallCallback func(Chart) InstallCallbackAction
InstallCallback is a function that decides whether to proceed with an individual chart installation This will be called concurrently from multiple goroutines, so make sure everything is threadsafe
type InstallCallbackAction ¶
type InstallCallbackAction int
CallbackAction indicates the decision made by the callback
const ( // Continue indicates the installation should proceed immediately Continue InstallCallbackAction = iota // Wait means the install should not happen right now but should be retried at some point in the future. The callback will be invoked again on the retry. Wait // Abort means the installation should not be attempted Abort )
type InstallOption ¶
type InstallOption func(*options)
func WithCompletedCallback ¶
func WithCompletedCallback(cb CompletedCallback) InstallOption
WithCompletedCallback specifies a callback function that will be invoked immediately after each chart installation completes
func WithInstallCallback ¶
func WithInstallCallback(cb InstallCallback) InstallOption
WithInstallCallback specifies a callback function that will be invoked immediately prior to each chart installation
func WithK8sNamespace ¶
func WithK8sNamespace(ns string) InstallOption
WithK8sNamespace specifies the kubernetes namespace to install a chart graph into. DefaultK8sNamespace is used otherwise.
func WithReleaseNamePrefix ¶
func WithReleaseNamePrefix(pfx string) InstallOption
WithReleaseNamePrefix specifies a prefix to use in Helm release names (useful for when multiple instances of a chart graph are installed into the same namespace)
func WithTimeout ¶
func WithTimeout(timeout time.Duration) InstallOption
WithTimeout sets a timeout for all chart installations/upgrades to complete. If the timeout is reached, chart operations are aborted and an error is returned.
type K8sClient ¶
type K8sClient interface { AppsV1() appsv1.AppsV1Interface // ExtensionsV1beta1() v1beta1.ExtensionsV1beta1Interface CoreV1() corev1.CoreV1Interface BatchV1() batchv1.BatchV1Interface }
K8sClient describes an object that functions as a Kubernetes client
type LogFunc ¶
type LogFunc func(string, ...interface{})
LogFunc is a function that logs a formatted string somewhere
type Manager ¶
type Manager struct { K8c kubernetes.Interface HCfg *action.Configuration LogF LogFunc }
Manager is an object that manages installation of chart graphs
func (*Manager) Install ¶
func (m *Manager) Install(ctx context.Context, charts []Chart, opts ...InstallOption) (ReleaseMap, error)
Install installs charts in order according to dependencies and returns the names of the releases, or error. In the event of an error, the client can check if the error returned is of type ChartError, which then provides information on the kubernetes objects that caused failure, if this can be determined. A helm error unrelated to pod failure may return either a non-ChartError error value or an empty ChartError.
func (*Manager) Upgrade ¶
func (m *Manager) Upgrade(ctx context.Context, rmap ReleaseMap, charts []Chart, opts ...InstallOption) error
Upgrade upgrades charts in order according to dependencies, using the release names in rmap. ValueOverrides will be used in the upgrade. In the event of an error, the client can check if the error returned is of type ChartError, which then provides information on the kubernetes objects that caused failure, if this can be determined. A helm error unrelated to pod failure may return either a non-ChartError error value or an empty ChartError.
type ReleaseMap ¶
ReleaseMap is a map of chart title to installed release name
type ValueOverridesMap ¶
ValueOverridesMap represents a set of chart YAML overrides, a map of YAML path to value, in the same format as accepted by the helm CLI: "foo.bar=value" except in a map.