Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertHelmChartToK8sManifest(cfg ApplyHelmChartConfig) (manifest []byte, err error)
- func DetectKubeConfig(configfile []byte) (config *rest.Config, err error)
- func ErrApplyHelmChart(err error) error
- func ErrApplyManifest(err error) error
- func ErrCreatingHelmIndex(err error) error
- func ErrDecodeYaml(err error) error
- func ErrEntryWithAppVersionNotExists(entry, appVersion string) error
- func ErrEntryWithChartVersionNotExists(entry, appVersion string) error
- func ErrHelmRepositoryNotFound(repo string, err error) error
- func ErrLoadConfig(err error) error
- func ErrNewDiscovery(err error) error
- func ErrNewDynClient(err error) error
- func ErrNewInformer(err error) error
- func ErrNewKubeClient(err error) error
- func ErrServiceDiscovery(err error) error
- func ErrValidateConfig(err error) error
- func GetEndpoint(ctx context.Context, opts *ServiceOptions, obj *corev1.Service) (*utils.Endpoint, error)
- func GetManifestsFromHelm(url string) (string, error)
- func GetObjectFromManifest(manifest string) (runtime.Object, *unstructured.Unstructured, error)
- func GetServiceEndpoint(ctx context.Context, client kubernetes.Interface, opts *ServiceOptions) (*utils.Endpoint, error)
- func HelmAppVersionToChartVersion(repo, chart, appVersion string) (string, error)
- func HelmChartVersionToAppVersion(repo, chart, chartVersion string) (string, error)
- func HelmConvertAppVersionToChartVersion(repo, chart, appVersion string) (string, error)
- type ApplyHelmChartConfig
- type ApplyOptions
- type Client
- type HelmChartAction
- type HelmChartLocation
- type HelmDriver
- type HelmEntries
- type HelmEntryMetadata
- type HelmIndex
- type ServiceOptions
Constants ¶
const ( // Stable is the default repository for helm v3 Stable = "https://charts.helm.sh/stable" // Latest is the default version for helm charts Latest = ">0.0.0-0" )
Variables ¶
var ( ErrApplyManifestCode = "11021" ErrServiceDiscoveryCode = "11022" ErrApplyHelmChartCode = "11023" ErrNewKubeClientCode = "11024" ErrNewDynClientCode = "11025" ErrNewDiscoveryCode = "11026" ErrNewInformerCode = "11027" ErrEndpointNotFoundCode = "11028" ErrInvalidAPIServerCode = "11029" ErrLoadConfigCode = "11030" ErrValidateConfigCode = "11031" // ErrCreatingHelmIndexCode represents the errors which are generated // during creation of helm index ErrCreatingHelmIndexCode = "11032" // ErrEntryWithAppVersionNotExistsCode represents the error which is generated // when no entry is found with specified name and app version ErrEntryWithAppVersionNotExistsCode = "11033" // ErrHelmRepositoryNotFoundCode represents the error which is generated when // no valid helm repository is found ErrHelmRepositoryNotFoundCode = "11034" // ErrDecodeYamlCode represents the error which is generated when yaml // decode process fails ErrDecodeYamlCode = "11035" // ErrEntryWithChartVersionNotExistsCode represents the error which is generated // when no entry is found with specified name and app version ErrEntryWithChartVersionNotExistsCode = "11036" ErrEndpointNotFound = errors.New(ErrEndpointNotFoundCode, errors.Alert, []string{"Unable to discover an endpoint"}, []string{}, []string{}, []string{}) ErrInvalidAPIServer = errors.New(ErrInvalidAPIServerCode, errors.Alert, []string{"Invalid API Server URL"}, []string{}, []string{}, []string{}) )
Functions ¶
func ConvertHelmChartToK8sManifest ¶
func ConvertHelmChartToK8sManifest(cfg ApplyHelmChartConfig) (manifest []byte, err error)
Though we are using the same config that is used for installing/uninstalling helm charts. We will only make use of URL/ChartLocation/LocalPath to get and load the helm chart
func DetectKubeConfig ¶
DetectKubeConfig detects the kubeconfig for the kubernetes cluster and returns it
func ErrApplyHelmChart ¶
ErrApplyHelmChart is the error which occurs in the process of applying helm chart
func ErrApplyManifest ¶
func ErrCreatingHelmIndex ¶
ErrCreatingHelmIndex is the error for creating helm index
func ErrDecodeYaml ¶
ErrDecodeYaml is the error when the yaml unmarshal fails
func ErrEntryWithAppVersionNotExists ¶
ErrEntryWithAppVersionNotExists is the error when an entry with the given app version is not found
func ErrEntryWithChartVersionNotExists ¶
ErrEntryWithChartVersionNotExists is the error when an entry with the given chart version is not found
func ErrHelmRepositoryNotFound ¶
ErrHelmRepositoryNotFound is the error when no valid remote helm repository is found
func ErrLoadConfig ¶
ErrLoadConfig is the error which occurs in the process of loading a kubernetes config
func ErrNewDiscovery ¶
ErrApplyHelmChart is the error which occurs in the process of applying helm chart
func ErrNewDynClient ¶
ErrApplyHelmChart is the error which occurs in the process of applying helm chart
func ErrNewInformer ¶
ErrApplyHelmChart is the error which occurs in the process of applying helm chart
func ErrNewKubeClient ¶
ErrApplyHelmChart is the error which occurs in the process of applying helm chart
func ErrServiceDiscovery ¶
ErrServiceDiscovery returns an error of type "ErrServiceDiscovery" along with the passed error
func ErrValidateConfig ¶
ErrValidateConfig is the error which occurs in the process of validating a kubernetes config
func GetEndpoint ¶
func GetEndpoint(ctx context.Context, opts *ServiceOptions, obj *corev1.Service) (*utils.Endpoint, error)
GetEndpoint returns those endpoints in the given service which match the selector. Eg: service name = "client"
func GetManifestsFromHelm ¶
func GetObjectFromManifest ¶
func GetObjectFromManifest(manifest string) (runtime.Object, *unstructured.Unstructured, error)
func GetServiceEndpoint ¶
func GetServiceEndpoint(ctx context.Context, client kubernetes.Interface, opts *ServiceOptions) (*utils.Endpoint, error)
GetServiceEndpoint returns the endpoint for the given service
func HelmAppVersionToChartVersion ¶
HelmAppVersionToChartVersion takes in the repo, chart and app version and returns the corresponding chart version for the same without normalizing the app version
func HelmChartVersionToAppVersion ¶
HelmChartVersionToAppVersion takes in the repo, chart and chart version and returns the corresponding app version for the same without normalizing the app version
func HelmConvertAppVersionToChartVersion ¶
HelmConvertAppVersionToChartVersion takes in the repo, chart and app version and returns the corresponding chart version for the same
Types ¶
type ApplyHelmChartConfig ¶
type ApplyHelmChartConfig struct { // ChartLocation is the remote location of the helm chart // // Either ChartLocation or URL can be defined, if both of them // are defined then URL is given the preferenece ChartLocation HelmChartLocation // ReleaseName for deploying charts ReleaseName string // SkipCRDs while installation SkipCRDs bool // Skip upgrade, if release is already installed SkipUpgradeIfInstalled bool // URL is the url for charts // // Either ChartLocation or URL can be defined, if both of them // are defined then URL is given the preferenece URL string // LocalPath is the local path where the routine can find the helm chart // // If this is provided then both URL and ChartLocation will be completely // ignored LocalPath string // HelmDriver is used to determine the backend // information used by helm for managing release // // Defaults to Secret HelmDriver HelmDriver // SQLConnectionString is the connection uri // for the postgresql database which will be used if // the HelmDriver is set to SQL SQLConnectionString string // Namespace in which the resources are supposed to // be deployed // // Defaults to "default" Namespace string // CreateNamespace creates namespace if it doesn't exist // // Defaults to false CreateNamespace bool // OverrideValues are used during installation // to override the values present in Values.yaml // it is equivalent to --set or --set-file helm flag OverrideValues map[string]interface{} // Action indicates if the requested action is UNINSTALL, UPGRADE or INSTALL // // If this is not provided, it performs an INSTALL operation Action HelmChartAction // Logger that will be used by the client to print the logs // // If nothing is provided then a dummy logger is used Logger func(string, ...interface{}) // DryRun will skip actual run, useful for testing DryRun bool // DownloadLocation defines the location where the user wants to download the helm charts // If this is not provided, the helm chart is downloaded to the "/tmp" folder DownloadLocation string }
ApplyHelmChartConfig defines the options that ApplyHelmChart can take
type ApplyOptions ¶
type Client ¶
type Client struct { RestConfig rest.Config `json:"restconfig,omitempty"` KubeClient *kubernetes.Clientset `json:"kubeclient,omitempty"` DynamicKubeClient dynamic.Interface `json:"dynamic_kubeclient,omitempty"` }
func (*Client) ApplyHelmChart ¶
func (client *Client) ApplyHelmChart(cfg ApplyHelmChartConfig) error
ApplyHelmChart takes in the url for the helm chart and applies that chart as per the ApplyHelmChartOptions
The Helm library requires the environment variable KUBECONFIG to be set.
ApplyHelmChart supports:
- Installation and uninstallation of charts.
- All storage drivers.
- Chart location as a url as well as in form of repository (url) and chart name.
- Override values (equivalent to --set, --set-file, --values in helm).
Examples:
Install Traefik Mesh using URL:
err = client.ApplyHelmChart(k8s.ApplyHelmChartConfig{ Namespace: "traefik-mesh", CreateNamespace: true, URL: "https://helm.traefik.io/mesh/traefik-mesh-3.0.6.tgz", })
Install Traefik Mesh using repository:
err = cl.ApplyHelmChart(k8s.ApplyHelmChartConfig{ ChartLocation: k8s.HelmChartLocation{ Repository: "https://helm.traefik.io/mesh", Chart: "traefik-mesh", }, Namespace: "traefik-mesh", CreateNamespace: true, })
Install Consul Service Mesh overriding values using a values file (equivalent to -f/--values in helm):
p := getter.All(cli.New()) valueOpts := &values.Options{} if valuesFile, ok := operation.AdditionalProperties[config.HelmChartValuesFileKey]; ok { valueOpts.ValueFiles = []string{path.Join("consul", "config_templates", valuesFile)} } vals, err := valueOpts.MergeValues(p) err = kubeClient.ApplyHelmChart(meshplaykube.ApplyHelmChartConfig{ Namespace: request.Namespace, CreateNamespace: true, Delete: request.IsDeleteOperation, ChartLocation: meshplaykube.HelmChartLocation{ Repository: operation.AdditionalProperties[config.HelmChartRepositoryKey], Chart: operation.AdditionalProperties[config.HelmChartChartKey], Version: operation.AdditionalProperties[config.HelmChartVersionKey], }, OverrideValues: vals, })
func (*Client) ApplyManifest ¶
func (client *Client) ApplyManifest(contents []byte, recvOptions ApplyOptions) error
ApplyManifest applies, updates or deletes resources as specified in ApplyOptions. The namespace specified in ApplyOptions is used, if no namespace is specified then the namespace from manifest is used. If the the namespace does not exists, it will be created.
func (*Client) GetCurrentContext ¶
func (*Client) GetKubeConfig ¶
func (c *Client) GetKubeConfig() (*models.Kubeconfig, error)
type HelmChartAction ¶
type HelmChartAction int64
HelmChartAction is the type for helm chart actions
const ( INSTALL HelmChartAction = iota UPGRADE UNINSTALL )
type HelmChartLocation ¶
type HelmChartLocation struct { // Repository is the url of the helm repository // // Defaults to https://charts.helm.sh/stable Repository string // Chart is the name of the chart that is supposed // to be installed. This chart must me present in the // https://REPOSITORY/index.yaml Chart string // Version is the chart version. This version // must be present in the https://REPOSITORY/index.yaml // // Defaults to Latest Version string // AppVersion unlike the Version is the actual version of the // application. This app version must be present in the // https://REPOSITORY/index.yaml // // If this is defined then chart version will be ignored AppVersion string }
HelmChartLocation describes the structure for defining the location for helm chart
type HelmDriver ¶
type HelmDriver string
HelmDriver is the type for helm drivers
const ( // ConfigMap HelmDriver can be used to instruct // helm to use configmaps as backend ConfigMap HelmDriver = "configmap" // Secret HelmDriver can be used to instruct // helm to use secrets as backend Secret HelmDriver = "secret" // SQL HelmDriver can be used to instruct // helm to use sql as backend // // This should be used when release information // is expected to be greater than 1MB SQL HelmDriver = "sql" )
type HelmEntries ¶
type HelmEntries map[string][]HelmEntryMetadata
HelmEntries holds the data for all of the entries present in the helm repository
func (HelmEntries) GetEntryWithAppVersion ¶
func (helmEntries HelmEntries) GetEntryWithAppVersion(entry, appVersion string) (HelmEntryMetadata, bool)
GetEntryWithAppVersion takes in the entry name and the appversion and returns the corresponding metadata for the parameters if it exists
func (HelmEntries) GetEntryWithChartVersion ¶
func (helmEntries HelmEntries) GetEntryWithChartVersion(entry, chartVersion string) (HelmEntryMetadata, bool)
GetEntryWithAppVersion takes in the entry name and the appversion and returns the corresponding metadata for the parameters if it exists
type HelmEntryMetadata ¶
type HelmEntryMetadata struct { APIVersion string `yaml:"apiVersion"` AppVersion string `yaml:"appVersion"` Name string `yaml:"name"` Version string `yaml:"version"` }
HelmEntryMetadata is the struct for holding the metadata associated with a helm repositories' entry
type HelmIndex ¶
type HelmIndex struct { APIVersion string `yaml:"apiVersion"` Entries HelmEntries `yaml:"entries"` }
HelmIndex holds the index.yaml data in the struct format
type ServiceOptions ¶
type ServiceOptions struct { Name string // Name of the kubernetes service Namespace string // Namespace of the kubernetes service PortSelector string // To specify the name of the kubernetes service port APIServerURL string // Kubernetes api-server URL (Used in-case of minikube) WorkerNodeIP string // Kubernetes worker node IP address (Any), in case of a kubeadm based cluster orchestration Mock *utils.MockOptions }
ServiceOptions give control of which service to discover and which port to discover.