provider

package
v0.0.0-...-9ec3720 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: AGPL-3.0 Imports: 100 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JujuControllerStackName is the juju CAAS controller stack name.
	JujuControllerStackName = "controller"

	// ControllerServiceFQDNTemplate is the FQDN of the controller service using the cluster DNS.
	ControllerServiceFQDNTemplate = "controller-service.controller-%s.svc.cluster.local"
)
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 (
	PodReasonCompleted                = "Completed"
	PodReasonContainerCreating        = "ContainerCreating"
	PodReasonContainersNotInitialized = "ContainersNotInitialized"
	PodReasonContainersNotReady       = "ContainersNotReady"
	PodReasonCrashLoopBackoff         = "CrashLoopBackOff"
	PodReasonError                    = "Error"
	PodReasonImagePull                = "ErrImagePull"
	PodReasonInitializing             = "PodInitializing"
)
View Source
const (

	// InformerResyncPeriod is the default resync period set on IndexInformers
	InformerResyncPeriod = time.Minute * 5
)
View Source
const (
	// OperatorAppTarget is the constant used to describe the operator's target
	// in kubernetes. This allows us to differentiate between different
	// operators that would possible have the same labels otherwise
	OperatorAppTarget = "application"
)
View Source
const (
	ServiceTypeConfigKey = "kubernetes-service-type"
)

Variables

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 ConfigDefaults

func ConfigDefaults() schema.Defaults

ConfigDefaults returns the default values for a kubernetes configuration.

func ConfigSchema

func ConfigSchema() environschema.Fields

ConfigSchema returns the configuration schema for a kubernetes provider config.

func DecideControllerNamespace

func DecideControllerNamespace(controllerName string) string

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

func GetOperatorPodName

func GetOperatorPodName(
	podAPI typedcorev1.PodInterface,
	nsAPI typedcorev1.NamespaceInterface,
	appName string,
	namespace string,
) (string, error)

GetOperatorPodName returns operator pod name for an application.

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 IsUnknownClusterError

func IsUnknownClusterError(err error) bool

IsUnknownClusterError returns true if err is a UnknownClusterError

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 RequireOperatorStorage

func RequireOperatorStorage(charmMinJujuVersion version.Number) bool

RequireOperatorStorage returns true if the specified min-juju-version defined by a charm is such that the charm requires operator storage.

func UpdateKubeCloudWithStorage

func UpdateKubeCloudWithStorage(k8sCloud *cloud.Cloud, storageParams KubeCloudStorageParams) (storageMsg string, err error)

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

func ValidateStorageProvider

func ValidateStorageProvider(providerType jujustorage.ProviderType, attributes map[string]interface{}) error

ValidateStorageProvider returns an error if the storage type and config is not valid for a Kubernetes deployment.

Types

type CRDGetterInterface

type CRDGetterInterface interface {
	Get(string) (*apiextensionsv1.CustomResourceDefinition, error)
}

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 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)
}

CommandRunner allows to run commands on the underlying system

type DockerConfig

type DockerConfig map[string]DockerConfigEntry

DockerConfig represents the config file used by the docker CLI.

type DockerConfigEntry

type DockerConfigEntry struct {
	Username string
	Password string
	Email    string
}

DockerConfigEntry represents an Auth entry in the dockerconfigjson.

type DockerConfigJSON

type DockerConfigJSON struct {
	Auths DockerConfig `json:"auths"`
}

DockerConfigJSON represents ~/.docker/config.json file info.

type EventGetter

type EventGetter func() ([]core.Event, error)

type GetClusterMetadataFunc

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

GetClusterMetadataFunc returns the ClusterMetadata using the provided ClusterMetadataChecker

type KlogMessagePrefixes

type KlogMessagePrefixes []string

func (KlogMessagePrefixes) Matches

func (k KlogMessagePrefixes) Matches(log string) bool

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 {
	// EnsureConfigMap ensures the supplied kubernetes config map exists in the
	// targeted cluster. Error returned if this action is not able to be
	// performed.
	EnsureConfigMap(*core.ConfigMap) ([]func(), error)

	// EnsureClusterRole ensures that the provided cluster role exists in the
	// Kubernetes cluster
	EnsureClusterRole(*rbac.ClusterRole) ([]func(), error)

	// EnsureClusterRoleBinding ensures that the provided cluster role binding
	// exists in the Kubernetes cluster
	EnsureClusterRoleBinding(*rbac.ClusterRoleBinding) ([]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(*apps.Deployment) ([]func(), error)

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

	// EnsureRoleBinding ensures the supplied kubernetes role binding object
	// exists in the targetes clusters namespace
	EnsureRoleBinding(*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(*core.Service) ([]func(), error)

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

	// 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 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 UnknownClusterError

type UnknownClusterError struct {
	Message   string
	CloudName string
}

UnknownClusterError occurs when the provided cluster is not known to Juju.

func (UnknownClusterError) Error

func (e UnknownClusterError) Error() 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
}

type UpgradeCAASOperatorBroker

type UpgradeCAASOperatorBroker interface {
	// Clock provides the clock to use with this broker for time operations
	Clock() clock.Clock

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

	// Returns the deployment name use for the given application name, supports
	// finding legacy deployment names if set to True.
	DeploymentName(string, bool) string

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

	Namespace() string

	// Operator returns an Operator with current status and life details.
	Operator(string) (*caas.Operator, error)

	// OperatorName returns the operator name used for the operator deployment
	// for the supplied application.
	OperatorName(string) 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.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
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