kubernetes

package
v0.7.23 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 35 Imported by: 21

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    = "meshkit-11190"
	ErrServiceDiscoveryCode = "meshkit-11191"
	ErrApplyHelmChartCode   = "meshkit-11192"
	ErrNewKubeClientCode    = "meshkit-11193"
	ErrNewDynClientCode     = "meshkit-11194"
	ErrNewDiscoveryCode     = "meshkit-11195"
	ErrNewInformerCode      = "meshkit-11196"
	ErrEndpointNotFoundCode = "meshkit-11197"
	ErrInvalidAPIServerCode = "meshkit-11198"
	ErrLoadConfigCode       = "meshkit-11199"
	ErrValidateConfigCode   = "meshkit-11200"
	// ErrCreatingHelmIndexCode represents the errors which are generated
	// during creation of helm index
	ErrCreatingHelmIndexCode = "meshkit-11201"

	// ErrEntryWithAppVersionNotExistsCode represents the error which is generated
	// when no entry is found with specified name and app version
	ErrEntryWithAppVersionNotExistsCode = "meshkit-11202"

	// ErrHelmRepositoryNotFoundCode represents the error which is generated when
	// no valid helm repository is found
	ErrHelmRepositoryNotFoundCode = "meshkit-11203"

	// ErrEntryWithChartVersionNotExistsCode represents the error which is generated
	// when no entry is found with specified name and app version
	ErrEntryWithChartVersionNotExistsCode = "meshkit-11204"
	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 added in v0.5.23

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 added in v0.1.27

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

DetectKubeConfig detects the kubeconfig for the kubernetes cluster and returns it

func ErrApplyHelmChart added in v0.1.31

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 added in v0.2.21

func ErrCreatingHelmIndex(err error) error

ErrCreatingHelmIndex is the error for creating helm index

func ErrEntryWithAppVersionNotExists added in v0.2.21

func ErrEntryWithAppVersionNotExists(entry, appVersion string) error

ErrEntryWithAppVersionNotExists is the error when an entry with the given app version is not found

func ErrEntryWithChartVersionNotExists added in v0.5.7

func ErrEntryWithChartVersionNotExists(entry, appVersion string) error

ErrEntryWithChartVersionNotExists is the error when an entry with the given chart version is not found

func ErrHelmRepositoryNotFound added in v0.2.21

func ErrHelmRepositoryNotFound(repo string, err error) error

ErrHelmRepositoryNotFound is the error when no valid remote helm repository is found

func ErrLoadConfig added in v0.2.13

func ErrLoadConfig(err error) error

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

func ErrNewDiscovery added in v0.2.1

func ErrNewDiscovery(err error) error

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

func ErrNewDynClient added in v0.2.1

func ErrNewDynClient(err error) error

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

func ErrNewInformer added in v0.2.1

func ErrNewInformer(err error) error

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

func ErrNewKubeClient added in v0.2.1

func ErrNewKubeClient(err error) error

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

func ErrServiceDiscovery added in v0.1.22

func ErrServiceDiscovery(err error) error

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

func ErrValidateConfig added in v0.2.13

func ErrValidateConfig(err error) error

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

func GetAllCustomResourcesInCluster added in v0.7.2

func GetAllCustomResourcesInCluster(ctx context.Context, client rest.Interface) ([]*schema.GroupVersionResource, error)

func GetEndpoint added in v0.2.3

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 GetGVRForCustomResources added in v0.7.2

func GetGVRForCustomResources(crd *CRDItem) *schema.GroupVersionResource

func GetManifestsFromHelm added in v0.2.24

func GetManifestsFromHelm(url string) (string, error)

func GetObjectFromManifest added in v0.1.32

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

func GetServiceEndpoint added in v0.2.3

func GetServiceEndpoint(ctx context.Context, client kubernetes.Interface, opts *ServiceOptions) (*utils.Endpoint, error)

GetServiceEndpoint returns the endpoint for the given service

func HelmAppVersionToChartVersion added in v0.2.23

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 added in v0.5.7

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 added in v0.2.21

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

func IsCRD added in v0.7.12

func IsCRD(manifest map[string]interface{}) bool

Types

type ApplyHelmChartConfig added in v0.1.31

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

type CRD added in v0.7.2

type CRD struct {
	Items []CRDItem `json:"items"`
}

type CRDItem added in v0.7.2

type CRDItem struct {
	Spec Spec `json:"spec"`
}

type Client added in v0.1.26

type Client struct {
	RestConfig        rest.Config           `json:"restconfig,omitempty"`
	KubeClient        *kubernetes.Clientset `json:"kubeclient,omitempty"`
	DynamicKubeClient dynamic.Interface     `json:"dynamic_kubeclient,omitempty"`
}

func New

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

func (*Client) ApplyHelmChart added in v0.1.31

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 added in v0.1.26

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 added in v0.5.9

func (c *Client) GetCurrentContext() (string, error)

func (*Client) GetKubeConfig added in v0.5.9

func (c *Client) GetKubeConfig() (*models.Kubeconfig, error)

type HelmChartAction added in v0.2.31

type HelmChartAction int64

HelmChartAction is the type for helm chart actions

const (
	INSTALL HelmChartAction = iota
	UPGRADE
	UNINSTALL
)

type HelmChartLocation added in v0.1.31

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 added in v0.1.31

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 added in v0.2.21

type HelmEntries map[string][]HelmEntryMetadata

HelmEntries holds the data for all of the entries present in the helm repository

func (HelmEntries) GetEntryWithAppVersion added in v0.2.21

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 added in v0.5.7

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 added in v0.2.21

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 added in v0.2.21

type HelmIndex struct {
	APIVersion string      `yaml:"apiVersion"`
	Entries    HelmEntries `yaml:"entries"`
}

HelmIndex holds the index.yaml data in the struct format

type ServiceOptions added in v0.2.3

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.

type Spec added in v0.7.2

type Spec struct {
	Names    names  `json:"names"`
	Group    string `json:"group"`
	Versions []struct {
		Name string `json:"name"`
	} `json:"versions"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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