github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/helmfile/helmfile.go (about)

     1  package helmfile
     2  
     3  // Originally authored in the roboll/helmfile repo https://github.com/roboll/helmfile/blob/fc75f25293055003d8159a841940313e56a164c6/pkg/state/state.go
     4  // copied here to avoid issues go module dependency issues
     5  // changed from yaml: to json: annotations so we can marshal struct and omit unset values
     6  
     7  // HelmState structure for the helmfile
     8  type HelmState struct {
     9  	FilePath string `json:"filePath,omitempty"`
    10  
    11  	// DefaultValues is the default values to be overrode by environment values and command-line overrides
    12  	DefaultValues []interface{} `json:"values,omitempty"`
    13  
    14  	Environments map[string]EnvironmentSpec `json:"environments,omitempty"`
    15  
    16  	Bases              []string          `json:"bases,omitempty"`
    17  	HelmDefaults       HelmSpec          `json:"helmDefaults,omitempty"`
    18  	Helmfiles          []SubHelmfileSpec `json:"helmfiles,omitempty"`
    19  	DeprecatedContext  string            `json:"context,omitempty"`
    20  	DeprecatedReleases []ReleaseSpec     `json:"charts,omitempty"`
    21  	OverrideNamespace  string            `json:"namespace,omitempty"`
    22  	Repositories       []RepositorySpec  `json:"repositories,omitempty"`
    23  	Releases           []ReleaseSpec     `json:"releases,omitempty"`
    24  	Selectors          []string          `json:"-"`
    25  	APIVersions        []string          `json:"apiVersions,omitempty"`
    26  
    27  	Templates map[string]TemplateSpec `json:"templates,omitempty"`
    28  
    29  	Env Environment `json:"-"`
    30  }
    31  
    32  // SubHelmfileSpec defines the subhelmfile path and options
    33  type SubHelmfileSpec struct {
    34  	//path or glob pattern for the sub helmfiles
    35  	Path string `json:"path,omitempty"`
    36  	//chosen selectors for the sub helmfiles
    37  	Selectors []string `json:"selectors,omitempty"`
    38  	//do the sub helmfiles inherits from parent selectors
    39  	SelectorsInherited bool `json:"selectorsInherited,omitempty"`
    40  
    41  	Environment SubhelmfileEnvironmentSpec
    42  }
    43  
    44  // SubhelmfileEnvironmentSpec overrides
    45  type SubhelmfileEnvironmentSpec struct {
    46  	OverrideValues []interface{} `json:"values,omitempty"`
    47  }
    48  
    49  // HelmSpec to defines helmDefault values
    50  type HelmSpec struct {
    51  	KubeContext     string   `json:"kubeContext,omitempty"`
    52  	TillerNamespace string   `json:"tillerNamespace,omitempty"`
    53  	Tillerless      bool     `json:"tillerless"`
    54  	Args            []string `json:"args,omitempty"`
    55  	Verify          bool     `json:"verify"`
    56  	// Devel, when set to true, use development versions, too. Equivalent to version '>0.0.0-0'
    57  	Devel bool `json:"devel"`
    58  	// Wait, if set to true, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful
    59  	Wait bool `json:"wait"`
    60  	// Timeout is the time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks, and waits on pod/pvc/svc/deployment readiness) (default 300)
    61  	Timeout int `json:"timeout"`
    62  	// RecreatePods, when set to true, instruct helmfile to perform pods restart for the resource if applicable
    63  	RecreatePods bool `json:"recreatePods"`
    64  	// Force, when set to true, forces resource update through delete/recreate if needed
    65  	Force bool `json:"force"`
    66  	// Atomic, when set to true, restore previous state in case of a failed install/upgrade attempt
    67  	Atomic bool `json:"atomic"`
    68  	// CleanupOnFail, when set to true, the --cleanup-on-fail helm flag is passed to the upgrade command
    69  	CleanupOnFail bool `json:"cleanupOnFail,omitempty"`
    70  	// HistoryMax, limit the maximum number of revisions saved per release. Use 0 for no limit (default 10)
    71  	HistoryMax *int `json:"historyMax,omitempty"`
    72  
    73  	TLS       bool   `json:"tls"`
    74  	TLSCACert string `json:"tlsCACert,omitempty"`
    75  	TLSKey    string `json:"tlsKey,omitempty"`
    76  	TLSCert   string `json:"tlsCert,omitempty"`
    77  }
    78  
    79  // RepositorySpec that defines values for a helm repo
    80  type RepositorySpec struct {
    81  	Name     string `json:"name,omitempty"`
    82  	URL      string `json:"url,omitempty"`
    83  	CaFile   string `json:"caFile,omitempty"`
    84  	CertFile string `json:"certFile,omitempty"`
    85  	KeyFile  string `json:"keyFile,omitempty"`
    86  	Username string `json:"username,omitempty"`
    87  	Password string `json:"password,omitempty"`
    88  }
    89  
    90  // ReleaseSpec defines the structure of a helm release
    91  type ReleaseSpec struct {
    92  	// Chart is the name of the chart being installed to create this release
    93  	Chart   string `json:"chart,omitempty"`
    94  	Version string `json:"version,omitempty"`
    95  	Verify  *bool  `json:"verify,omitempty"`
    96  	// Devel, when set to true, use development versions, too. Equivalent to version '>0.0.0-0'
    97  	Devel *bool `json:"devel,omitempty"`
    98  	// Wait, if set to true, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment are in a ready state before marking the release as successful
    99  	Wait *bool `json:"wait,omitempty"`
   100  	// Timeout is the time in seconds to wait for any individual Kubernetes operation (like Jobs for hooks, and waits on pod/pvc/svc/deployment readiness) (default 300)
   101  	Timeout *int `json:"timeout,omitempty"`
   102  	// RecreatePods, when set to true, instruct helmfile to perform pods restart for the resource if applicable
   103  	RecreatePods *bool `json:"recreatePods,omitempty"`
   104  	// Force, when set to true, forces resource update through delete/recreate if needed
   105  	Force *bool `json:"force,omitempty"`
   106  	// Installed, when set to true, `delete --purge` the release
   107  	Installed *bool `json:"installed,omitempty"`
   108  	// Atomic, when set to true, restore previous state in case of a failed install/upgrade attempt
   109  	Atomic *bool `json:"atomic,omitempty"`
   110  	// CleanupOnFail, when set to true, the --cleanup-on-fail helm flag is passed to the upgrade command
   111  	CleanupOnFail *bool `json:"cleanupOnFail,omitempty"`
   112  	// HistoryMax, limit the maximum number of revisions saved per release. Use 0 for no limit (default 10)
   113  	HistoryMax *int `json:"historyMax,omitempty"`
   114  
   115  	// MissingFileHandler is set to either "Error" or "Warn". "Error" instructs helmfile to fail when unable to find a values or secrets file. When "Warn", it prints the file and continues.
   116  	// The default value for MissingFileHandler is "Error".
   117  	MissingFileHandler *string `json:"missingFileHandler,omitempty"`
   118  	// Needs is the [TILLER_NS/][NS/]NAME representations of releases that this release depends on.
   119  	Needs []string `json:"needs,omitempty"`
   120  
   121  	// Hooks is a list of extension points paired with operations, that are executed in specific points of the lifecycle of releases defined in helmfile
   122  	Hooks []Hook `json:"hooks,omitempty"`
   123  
   124  	// Name is the name of this release
   125  	Name      string            `json:"name,omitempty"`
   126  	Namespace string            `json:"namespace,omitempty"`
   127  	Labels    map[string]string `json:"labels,omitempty"`
   128  	// JENKINS X comment - changed from the original []interface{} so we can unmarshall string array
   129  	Values    []string   `json:"values,omitempty"`
   130  	Secrets   []string   `json:"secrets,omitempty"`
   131  	SetValues []SetValue `json:"set,omitempty"`
   132  
   133  	ValuesTemplate    []interface{} `json:"valuesTemplate,omitempty"`
   134  	SetValuesTemplate []SetValue    `json:"setTemplate,omitempty"`
   135  
   136  	// The 'env' section is not really necessary any longer, as 'set' would now provide the same functionality
   137  	EnvValues []SetValue `json:"env,omitempty"`
   138  
   139  	ValuesPathPrefix string `json:"valuesPathPrefix,omitempty"`
   140  
   141  	TillerNamespace string `json:"tillerNamespace,omitempty"`
   142  	Tillerless      *bool  `json:"tillerless,omitempty"`
   143  
   144  	KubeContext string `json:"kubeContext,omitempty"`
   145  
   146  	TLS       *bool  `json:"tls,omitempty"`
   147  	TLSCACert string `json:"tlsCACert,omitempty"`
   148  	TLSKey    string `json:"tlsKey,omitempty"`
   149  	TLSCert   string `json:"tlsCert,omitempty"`
   150  
   151  	// These values are used in templating
   152  	TillerlessTemplate *string `json:"tillerlessTemplate,omitempty"`
   153  	VerifyTemplate     *string `json:"verifyTemplate,omitempty"`
   154  	WaitTemplate       *string `json:"waitTemplate,omitempty"`
   155  	InstalledTemplate  *string `json:"installedTemplate,omitempty"`
   156  
   157  	// These settings requires helm-x integration to work
   158  	Dependencies          []Dependency  `json:"dependencies,omitempty"`
   159  	JSONPatches           []interface{} `json:"jsonPatches,omitempty"`
   160  	StrategicMergePatches []interface{} `json:"strategicMergePatches,omitempty"`
   161  	Adopt                 []string      `json:"adopt,omitempty"`
   162  }
   163  
   164  // Release for helm
   165  type Release struct {
   166  	ReleaseSpec
   167  
   168  	Filtered bool
   169  }
   170  
   171  // SetValue are the key values to set on a helm release
   172  type SetValue struct {
   173  	Name   string   `json:"name,omitempty"`
   174  	Value  string   `json:"value,omitempty"`
   175  	File   string   `json:"file,omitempty"`
   176  	Values []string `json:"values,omitempty"`
   177  }
   178  
   179  // AffectedReleases hold the list of released that where updated, deleted, or in error
   180  type AffectedReleases struct {
   181  	Upgraded []*ReleaseSpec
   182  	Deleted  []*ReleaseSpec
   183  	Failed   []*ReleaseSpec
   184  }
   185  
   186  // EnvironmentSpec envs
   187  type EnvironmentSpec struct {
   188  	Values  []interface{} `json:"values,omitempty"`
   189  	Secrets []string      `json:"secrets,omitempty"`
   190  
   191  	// MissingFileHandler instructs helmfile to fail when unable to find a environment values file listed
   192  	// under `environments.NAME.values`.
   193  	//
   194  	// Possible values are  "Error", "Warn", "Info", "Debug". The default is "Error".
   195  	//
   196  	// Use "Warn", "Info", or "Debug" if you want helmfile to not fail when a values file is missing, while just leaving
   197  	// a message about the missing file at the log-level.
   198  	MissingFileHandler *string `json:"missingFileHandler,omitempty"`
   199  }
   200  
   201  // TemplateSpec defines the structure of a reusable and composable template for helm releases.
   202  type TemplateSpec struct {
   203  	ReleaseSpec `json:",inline"`
   204  }
   205  
   206  // EnvironmentTemplateData provides variables accessible while executing golang text/template expressions in helmfile and values YAML files
   207  type EnvironmentTemplateData struct {
   208  	// Environment is accessible as `.Environment` from any template executed by the renderer
   209  	Environment Environment
   210  	// Namespace is accessible as `.Namespace` from any non-values template executed by the renderer
   211  	Namespace string
   212  	// Values is accessible as `.Values` and it contains default state values overrode by environment values and override values.
   213  	Values map[string]interface{}
   214  }
   215  
   216  // Dependency deps
   217  type Dependency struct {
   218  	Chart   string `json:"chart"`
   219  	Version string `json:"version"`
   220  	Alias   string `json:"alias"`
   221  }
   222  
   223  // Hook hooks
   224  type Hook struct {
   225  	Name     string   `json:"name"`
   226  	Events   []string `json:"events"`
   227  	Command  string   `json:"command"`
   228  	Args     []string `json:"args"`
   229  	ShowLogs bool     `json:"showlogs"`
   230  }
   231  
   232  // Environment vars
   233  type Environment struct {
   234  	Name     string
   235  	Values   map[string]interface{}
   236  	Defaults map[string]interface{}
   237  }