kubernetes

package
v0.4.26 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var (
	ErrApplyManifestCode                  = "11021"
	ErrServiceDiscoveryCode               = "11022"
	ErrApplyHelmChartCode                 = "11023"
	ErrNewKubeClientCode                  = "11024"
	ErrNewDynClientCode                   = "11025"
	ErrNewDiscoveryCode                   = "11026"
	ErrNewInformerCode                    = "11027"
	ErrEndpointNotFoundCode               = "11028"
	ErrInvalidAPIServerCode               = "11029"
	ErrLoadConfigCode                     = "11030"
	ErrValidateConfigCode                 = "11031"
	ErrCreatingHelmIndexCode              = "11032"
	ErrEntryWithAppVersionNotExistsCode   = "11033"
	ErrHelmRepositoryNotFoundCode         = "11034"
	ErrDecodeYamlCode                     = "11035"
	ErrEntryWithChartVersionNotExistsCode = "11036"
	ErrEndpointNotFound                   = mesherrors.New(ErrEndpointNotFoundCode, mesherrors.Alert, []string{"Unable to discover an endpoint"}, []string{}, []string{}, []string{})
	ErrInvalidAPIServer                   = mesherrors.New(ErrInvalidAPIServerCode, mesherrors.Alert, []string{"Invalid API Server URL"}, []string{}, []string{}, []string{})
)

Functions

func DetectKubeConfig

func DetectKubeConfig(configfile []byte) (*rest.Config, error)

DetectKubeConfig detects the kubeconfig for the Kubernetes cluster and returns the information

func ErrApplyHelmChart

func ErrApplyHelmChart(err error) error

ErrApplyHelmChart is the error which occurs in the process of applying helm chart

func ErrApplyManifest

func ErrApplyManifest(err error) error

func ErrCreatingHelmIndex

func ErrCreatingHelmIndex(err error) error

ErrCreatingHelmIndex is the error for creating helm index ErrCreatingHelmIndexCode represents the errors which are generated during creation of helm index

func ErrDecodeYaml

func ErrDecodeYaml(err error) error

ErrDecodeYaml is the error when the yaml unmarshal fails ErrDecodeYamlCode represents the error which is generated when yaml decode process fails

func ErrEntryWithAppVersionNotExists

func ErrEntryWithAppVersionNotExists(entry, appVersion string) error

ErrEntryWithAppVersionNotExists is the error when an entry with the given app version is not found ErrEntryWithAppVersionNotExistsCode represents the error which is generated when no entry is found with specified name and app version

func ErrEntryWithChartVersionNotExists

func ErrEntryWithChartVersionNotExists(entry, appVersion string) error

ErrEntryWithChartVersionNotExists is the error when an entry with the given chart version is not found ErrEntryWithChartVersionNotExistsCode represents the error which is generated when no entry is found with specified name and app version

func ErrHelmRepositoryNotFound

func ErrHelmRepositoryNotFound(repo string, err error) error

ErrHelmRepositoryNotFound is the error when no valid remote helm repository is found ErrHelmRepositoryNotFoundCode represents the error which is generated when no valid helm repository is found

func ErrLoadConfig

func ErrLoadConfig(err error) error

ErrLoadConfig is the error which occurs in the process of loading a kubernetes config

func ErrNewDiscovery

func ErrNewDiscovery(err error) error

ErrApplyHelmChart is the error which occurs in the process of applying helm chart

func ErrNewDynClient

func ErrNewDynClient(err error) error

ErrApplyHelmChart is the error which occurs in the process of applying helm chart

func ErrNewInformer

func ErrNewInformer(err error) error

ErrApplyHelmChart is the error which occurs in the process of applying helm chart

func ErrNewKubeClient

func ErrNewKubeClient(err error) error

ErrApplyHelmChart is the error which occurs in the process of applying helm chart

func ErrServiceDiscovery

func ErrServiceDiscovery(err error) error

ErrServiceDiscovery returns an error of type "ErrServiceDiscovery" along with the passed error

func ErrValidateConfig

func ErrValidateConfig(err error) error

ErrValidateConfig is the error which occurs in the process of validating a kubernetes config

func GetManifestsFromHelm

func GetManifestsFromHelm(url string) (string, error)

func GetObjectFromManifest

func GetObjectFromManifest(manifest string) (runtime.Object, *unstructured.Unstructured, error)

func HelmAppVersionToChartVersion

func HelmAppVersionToChartVersion(repo, chart, appVersion string) (string, error)

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

func HelmChartVersionToAppVersion(repo, chart, chartVersion string) (string, error)

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

func HelmConvertAppVersionToChartVersion(repo, chart, appVersion string) (string, error)

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

	// 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 ApplyOptions struct {
	Namespace    string
	Update       bool
	Delete       bool
	IgnoreErrors bool
}

type Client

type Client struct {
	RestConfig        *rest.Config
	KubeClient        *kubernetes.Clientset
	DynamicKubeClient dynamic.Interface
}

func New

func New(kubeconfig []byte) (*Client, error)

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(mesherykube.ApplyHelmChartConfig{
	Namespace:       request.Namespace,
	CreateNamespace: true,
	Delete:          request.IsDeleteOperation,
	ChartLocation: mesherykube.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.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL