provider

package
v0.0.0-...-0db00f2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 107 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// Container event reason list
	CreatedContainer        = "Created"
	StartedContainer        = "Started"
	FailedToCreateContainer = "Failed"
	FailedToStartContainer  = "Failed"
	KillingContainer        = "Killing"
	PreemptContainer        = "Preempting"
	BackOffStartContainer   = "BackOff"
	ExceededGracePeriod     = "ExceededGracePeriod"

	// Pod event reason list
	FailedToKillPod                = "FailedKillPod"
	FailedToCreatePodContainer     = "FailedCreatePodContainer"
	FailedToMakePodDataDirectories = "Failed"
	NetworkNotReady                = "NetworkNotReady"

	// Image event reason list
	PullingImage            = "Pulling"
	PulledImage             = "Pulled"
	FailedToPullImage       = "Failed"
	FailedToInspectImage    = "InspectFailed"
	ErrImageNeverPullPolicy = "ErrImageNeverPull"
	BackOffPullImage        = "BackOff"
)

Constants below are copied from "k8s.io/kubernetes/pkg/kubelet/events" to avoid introducing the huge dependency. Remove them once k8s.io/kubernetes added as a dependency.

View Source
const (
	EnvModelAgentCAASServiceName      = "SERVICE_NAME"
	EnvModelAgentCAASServiceNamespace = "SERVICE_NAMESPACE"
	EnvModelAgentHTTPPort             = "HTTP_PORT"

	OperatorModelTarget = "model"
)
View Source
const (

	// InformerResyncPeriod is the default resync period set on IndexInformers
	InformerResyncPeriod = time.Minute * 5
)

Variables

View Source
var CheckJujuOfficial = envtools.JujudVersion

For testing.

View Source
var (

	// ExecRBACResourceName is the model's exec RBAC resource name.
	ExecRBACResourceName = "model-exec"
)
View Source
var NewK8sClients = func(c *rest.Config) (
	k8sClient kubernetes.Interface,
	apiextensionsclient apiextensionsclientset.Interface,
	dynamicClient dynamic.Interface,
	err error,
) {
	k8sClient, err = kubernetes.NewForConfig(c)
	if err != nil {
		return nil, nil, nil, err
	}
	apiextensionsclient, err = apiextensionsclientset.NewForConfig(c)
	if err != nil {
		return nil, nil, nil, err
	}
	dynamicClient, err = dynamic.NewForConfig(c)
	if err != nil {
		return nil, nil, nil, err
	}
	return k8sClient, apiextensionsclient, dynamicClient, nil
}

NewK8sClients returns the k8s clients to access a cluster. Override for testing.

View Source
var (
	// TemplateFileNameServerPEM is the template server.pem file name.
	TemplateFileNameServerPEM = "template-" + mongo.FileNameDBSSLKey
)

Functions

func AppNameForServiceAccount

func AppNameForServiceAccount(sa *core.ServiceAccount) (string, error)

AppNameForServiceAccount returns the juju application name associated with a given ServiceAccount. If app name cannot be obtained from the service account, errors.NotFound is returned.

func BaseKubeCloudOpenParams

func BaseKubeCloudOpenParams(cloud cloud.Cloud, credential cloud.Credential) (environs.OpenParams, error)

BaseKubeCloudOpenParams provides a basic OpenParams for a cluster

func CaasServiceToK8s

func CaasServiceToK8s(in caas.ServiceType) (core.ServiceType, error)

CaasServiceToK8s translates a caas service type to a k8s one.

func CloudSpecToK8sRestConfig

func CloudSpecToK8sRestConfig(cloudSpec environscloudspec.CloudSpec) (*rest.Config, error)

CloudSpecToK8sRestConfig translates cloudspec to k8s rest config.

func DecideControllerNamespace

func DecideControllerNamespace(controllerName string) string

DecideControllerNamespace decides the namespace name to use for a new controller.

func GetClusterMetadata

func GetClusterMetadata(
	ctx context.Context,
	nominatedStorageClass string,
	nodeI core.NodeInterface,
	storageClassI storage.StorageClassInterface,
) (*kubernetes.ClusterMetadata, error)

GetClusterMetadata is responsible for gather a Kubernetes cluster metadata for Juju to make decisions. This relates to the cloud the cluster may or may not be running in + storage available. Split out from the main kubernetesClient struct so that it can be tested correctly.

func IsClusterQueryError

func IsClusterQueryError(err error) bool

IsClusterQueryError returns true if err is a ClusterQueryError.

func IsNoRecommendedStorageError

func IsNoRecommendedStorageError(err error) bool

IsNoRecommendedStorageError returns true if err is a NoRecommendedStorageError

func MaskError

func MaskError(err error) bool

MaskError is used to signify that an error should not be reported back to the caller.

func RBACLabels

func RBACLabels(appName, model string, global, legacy bool) map[string]string

RBACLabels returns a set of labels that should be present for RBAC objects.

func UpdateKubeCloudWithStorage

func UpdateKubeCloudWithStorage(k8sCloud cloud.Cloud, storageParams KubeCloudStorageParams) (cloud.Cloud, error)

UpdateKubeCloudWithStorage updates the passed Cloud with storage details retrieved from the cloud's cluster.

Types

type ClientConfigFuncGetter

type ClientConfigFuncGetter func(string) (clientconfig.ClientConfigFunc, error)

ClientConfigFuncGetter returns a function returning az reader that will read a k8s cluster config for a given cluster type

type ClusterMetadataStorageChecker

type ClusterMetadataStorageChecker interface {
	k8s.ClusterMetadataChecker
	ListStorageClasses(ctx stdcontext.Context, selector k8slabels.Selector) ([]storagev1.StorageClass, error)
	ListPods(ctx stdcontext.Context, namespace string, selector k8slabels.Selector) ([]corev1.Pod, error)
}

ClusterMetadataStorageChecker provides functionalities for checking k8s cluster storage and pods details.

type ClusterQueryError

type ClusterQueryError struct {
	Message string
}

ClusterQueryError represents an issue when querying a cluster.

func (ClusterQueryError) Error

func (e ClusterQueryError) Error() string

type CommandRunner

type CommandRunner interface {
	RunCommands(run exec.RunParams) (*exec.ExecResponse, error)
	LookPath(string) (string, error)
}

CommandRunner allows to run commands on the underlying system

type GetClusterMetadataFunc

type GetClusterMetadataFunc func(KubeCloudStorageParams) (*k8s.ClusterMetadata, error)

GetClusterMetadataFunc returns the ClusterMetadata using the provided ClusterMetadataChecker

type KubeCloudParams

type KubeCloudParams struct {
	ClusterName string
	ContextName string
	CloudName   string
	// CredentialUID ensures RBAC resources are unique.
	CredentialUID      string
	HostCloudRegion    string
	CaasType           string
	ClientConfigGetter ClientConfigFuncGetter
	Clock              jujuclock.Clock
}

KubeCloudParams defines the parameters used to extract a k8s cluster definition from kubeconfig data.

type KubeCloudStorageParams

type KubeCloudStorageParams struct {
	WorkloadStorage        string
	HostCloudRegion        string
	MetadataChecker        k8s.ClusterMetadataChecker
	GetClusterMetadataFunc GetClusterMetadataFunc
}

KubeCloudStorageParams defines the parameters used to determine storage details for a k8s cluster.

type ModelOperatorBroker

type ModelOperatorBroker interface {
	// Client returns the Kubernetes client to use for model operator actions.
	Client() kubernetes.Interface

	// EnsureConfigMap ensures the supplied kubernetes config map exists in the
	// targeted cluster. Error returned if this action is not able to be
	// performed.
	EnsureConfigMap(context.Context, *core.ConfigMap) ([]func(), error)

	// EnsureDeployment ensures the supplied kubernetes deployment object exists
	// in the targeted cluster. Error returned if this action is not able to be
	// performed.
	EnsureDeployment(context.Context, *apps.Deployment) ([]func(), error)

	// EnsureRole ensures the supplied kubernetes role object exists in the
	// targeted clusters namespace
	EnsureRole(context.Context, *rbac.Role) ([]func(), error)

	// EnsureRoleBinding ensures the supplied kubernetes role binding object
	// exists in the targetes clusters namespace
	EnsureRoleBinding(context.Context, *rbac.RoleBinding) ([]func(), error)

	// EnsureService ensures the spplied kubernetes service object exists in the
	// targeted cluster. Error returned if the action is not able to be
	// performed.
	EnsureService(context.Context, *core.Service) ([]func(), error)

	// EnsureServiceAccount ensures the supplied the kubernetes service account
	// exists in the targets cluster.
	EnsureServiceAccount(context.Context, *core.ServiceAccount) ([]func(), error)

	// Model returns the name of the current model being deployed to for the
	// broker
	Model() string

	// Namespace returns the current default namespace targeted by this broker.
	Namespace() string

	// IsLegacyLabels indicates if this provider is operating on a legacy label schema
	IsLegacyLabels() bool
}

ModelOperatorBroker defines a broker for Executing Kubernetes ensure commands. This interfaces is scoped down to the exact components needed by the ensure model operator routines.

type NewK8sClientFunc

NewK8sClientFunc defines a function which returns a k8s client based on the supplied config.

type NewK8sRestClientFunc

type NewK8sRestClientFunc func(c *rest.Config) (rest.Interface, error)

NewK8sRestClientFunc defines a function which returns a k8s rest client based on the supplied config.

type NoRecommendedStorageError

type NoRecommendedStorageError struct {
	Message      string
	ProviderName string
}

NoRecommendedStorageError represents when Juju is unable to determine which storage a cluster uses (or should use)

func (NoRecommendedStorageError) Error

func (NoRecommendedStorageError) StorageProvider

func (e NoRecommendedStorageError) StorageProvider() string

type UpgradeCAASControllerBroker

type UpgradeCAASControllerBroker interface {
	// Client returns a Kubernetes client associated with the current broker's
	// cluster
	Client() kubernetes.Interface

	// IsLegacyLabels indicates if this provider is operating on a legacy label schema
	IsLegacyLabels() bool

	// Namespace returns the targeted Kubernetes namespace for this broker
	Namespace() string
}

UpgradeCAASControllerBroker describes the interface needed for upgrading Juju Kubernetes controllers

type UpgradeCAASModelOperatorBroker

type UpgradeCAASModelOperatorBroker interface {
	// Client returns a Kubernetes client associated with the current broker's
	// cluster
	Client() kubernetes.Interface

	// IsLegacyLabels indicates if this provider is operating on a legacy label schema
	IsLegacyLabels() bool

	// Namespace returns the targeted Kubernetes namespace for this broker
	Namespace() string
}

Directories

Path Synopsis
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package pebble defines constants (probe handlers, health check ports) to be used in Pebble container specs.
Package pebble defines constants (probe handlers, health check ports) to be used in Pebble container specs.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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