constellation/bootstrapper/internal/kubernetes/cloud_provider.go

221 lines
7.9 KiB
Go
Raw Normal View History

/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
2022-05-24 04:04:42 -04:00
package kubernetes
import (
"context"
2022-09-21 07:47:57 -04:00
"github.com/edgelesssys/constellation/v2/internal/cloud/metadata"
"github.com/edgelesssys/constellation/v2/internal/kubernetes"
"github.com/edgelesssys/constellation/v2/internal/versions"
2022-05-24 04:04:42 -04:00
k8s "k8s.io/api/core/v1"
)
// ProviderMetadata implementers read/write cloud provider metadata.
type ProviderMetadata interface {
// UID returns the unique identifier for the constellation.
UID(ctx context.Context) (string, error)
2022-05-24 04:04:42 -04:00
// List retrieves all instances belonging to the current Constellation.
2022-06-28 12:23:24 -04:00
List(ctx context.Context) ([]metadata.InstanceMetadata, error)
2022-05-24 04:04:42 -04:00
// Self retrieves the current instance.
2022-06-28 12:23:24 -04:00
Self(ctx context.Context) (metadata.InstanceMetadata, error)
2022-05-24 04:04:42 -04:00
// GetSubnetworkCIDR retrieves the subnetwork CIDR for the current instance.
GetSubnetworkCIDR(ctx context.Context) (string, error)
2022-08-01 10:51:34 -04:00
// GetLoadBalancerEndpoint retrieves the load balancer endpoint.
GetLoadBalancerEndpoint(ctx context.Context) (string, error)
2022-05-24 04:04:42 -04:00
// GetInstance retrieves an instance using its providerID.
2022-06-28 12:23:24 -04:00
GetInstance(ctx context.Context, providerID string) (metadata.InstanceMetadata, error)
2022-05-24 04:04:42 -04:00
// Supported is used to determine if metadata API is implemented for this cloud provider.
Supported() bool
}
// CloudControllerManager implementers provide configuration for the k8s cloud-controller-manager.
type CloudControllerManager interface {
// Image returns the container image used to provide cloud-controller-manager for the cloud-provider.
Image(k8sVersion versions.ValidK8sVersion) (string, error)
2022-05-24 04:04:42 -04:00
// Path returns the path used by cloud-controller-manager executable within the container image.
Path() string
// Name returns the cloud-provider name as used by k8s cloud-controller-manager (k8s.gcr.io/cloud-controller-manager).
Name() string
// ExtraArgs returns a list of arguments to append to the cloud-controller-manager command.
ExtraArgs() []string
// ConfigMaps returns a list of ConfigMaps to deploy together with the k8s cloud-controller-manager
// Reference: https://kubernetes.io/docs/concepts/configuration/configmap/ .
2022-09-26 08:11:24 -04:00
ConfigMaps() (kubernetes.ConfigMaps, error)
2022-05-24 04:04:42 -04:00
// Secrets returns a list of secrets to deploy together with the k8s cloud-controller-manager.
// Reference: https://kubernetes.io/docs/concepts/configuration/secret/ .
Secrets(ctx context.Context, providerID, cloudServiceAccountURI string) (kubernetes.Secrets, error)
2022-05-24 04:04:42 -04:00
// Volumes returns a list of volumes to deploy together with the k8s cloud-controller-manager.
// Reference: https://kubernetes.io/docs/concepts/storage/volumes/ .
Volumes() []k8s.Volume
// VolumeMounts a list of of volume mounts to deploy together with the k8s cloud-controller-manager.
VolumeMounts() []k8s.VolumeMount
// Env returns a list of k8s environment key-value pairs to deploy together with the k8s cloud-controller-manager.
Env() []k8s.EnvVar
// Supported is used to determine if cloud controller manager is implemented for this cloud provider.
Supported() bool
}
// CloudNodeManager implementers provide configuration for the k8s cloud-node-manager.
type CloudNodeManager interface {
// Image returns the container image used to provide cloud-node-manager for the cloud-provider.
Image(k8sVersion versions.ValidK8sVersion) (string, error)
2022-05-24 04:04:42 -04:00
// Path returns the path used by cloud-node-manager executable within the container image.
Path() string
// ExtraArgs returns a list of arguments to append to the cloud-node-manager command.
ExtraArgs() []string
// Supported is used to determine if cloud node manager is implemented for this cloud provider.
Supported() bool
}
// ClusterAutoscaler implementers provide configuration for the k8s cluster-autoscaler.
type ClusterAutoscaler interface {
// Name returns the cloud-provider name as used by k8s cluster-autoscaler.
Name() string
// Secrets returns a list of secrets to deploy together with the k8s cluster-autoscaler.
Secrets(providerID, cloudServiceAccountURI string) (kubernetes.Secrets, error)
2022-05-24 04:04:42 -04:00
// Volumes returns a list of volumes to deploy together with the k8s cluster-autoscaler.
Volumes() []k8s.Volume
// VolumeMounts returns a list of volume mounts to deploy together with the k8s cluster-autoscaler.
VolumeMounts() []k8s.VolumeMount
// Env returns a list of k8s environment key-value pairs to deploy together with the k8s cluster-autoscaler.
Env() []k8s.EnvVar
// Supported is used to determine if cluster autoscaler is implemented for this cloud provider.
Supported() bool
}
type stubProviderMetadata struct {
2022-08-01 10:51:34 -04:00
GetLoadBalancerEndpointErr error
GetLoadBalancerEndpointResp string
2022-05-24 04:04:42 -04:00
GetSubnetworkCIDRErr error
GetSubnetworkCIDRResp string
ListErr error
2022-06-28 12:23:24 -04:00
ListResp []metadata.InstanceMetadata
2022-05-24 04:04:42 -04:00
SelfErr error
2022-06-28 12:23:24 -04:00
SelfResp metadata.InstanceMetadata
2022-05-24 04:04:42 -04:00
GetInstanceErr error
2022-06-28 12:23:24 -04:00
GetInstanceResp metadata.InstanceMetadata
2022-05-24 04:04:42 -04:00
SupportedResp bool
SupportsLoadBalancerResp bool
UIDErr error
UIDResp string
2022-05-24 04:04:42 -04:00
}
2022-08-01 10:51:34 -04:00
func (m *stubProviderMetadata) GetLoadBalancerEndpoint(ctx context.Context) (string, error) {
return m.GetLoadBalancerEndpointResp, m.GetLoadBalancerEndpointErr
2022-05-24 04:04:42 -04:00
}
func (m *stubProviderMetadata) GetSubnetworkCIDR(ctx context.Context) (string, error) {
return m.GetSubnetworkCIDRResp, m.GetSubnetworkCIDRErr
}
2022-06-28 12:23:24 -04:00
func (m *stubProviderMetadata) List(ctx context.Context) ([]metadata.InstanceMetadata, error) {
2022-05-24 04:04:42 -04:00
return m.ListResp, m.ListErr
}
2022-06-28 12:23:24 -04:00
func (m *stubProviderMetadata) Self(ctx context.Context) (metadata.InstanceMetadata, error) {
2022-05-24 04:04:42 -04:00
return m.SelfResp, m.SelfErr
}
2022-06-28 12:23:24 -04:00
func (m *stubProviderMetadata) GetInstance(ctx context.Context, providerID string) (metadata.InstanceMetadata, error) {
2022-05-24 04:04:42 -04:00
return m.GetInstanceResp, m.GetInstanceErr
}
func (m *stubProviderMetadata) Supported() bool {
return m.SupportedResp
}
func (m *stubProviderMetadata) SupportsLoadBalancer() bool {
return m.SupportsLoadBalancerResp
}
func (m *stubProviderMetadata) UID(ctx context.Context) (string, error) {
return m.UIDResp, m.UIDErr
}
2022-05-24 04:04:42 -04:00
type stubCloudControllerManager struct {
SupportedResp bool
}
func (m *stubCloudControllerManager) Image(k8sVersion versions.ValidK8sVersion) (string, error) {
return "stub-image:latest", nil
2022-05-24 04:04:42 -04:00
}
func (m *stubCloudControllerManager) Path() string {
return "/stub-controller-manager"
}
func (m *stubCloudControllerManager) Name() string {
return "stub"
}
func (m *stubCloudControllerManager) ExtraArgs() []string {
return []string{}
}
2022-09-26 08:11:24 -04:00
func (m *stubCloudControllerManager) ConfigMaps() (kubernetes.ConfigMaps, error) {
2022-05-24 04:04:42 -04:00
return []*k8s.ConfigMap{}, nil
}
func (m *stubCloudControllerManager) Secrets(ctx context.Context, instance, cloudServiceAccountURI string) (kubernetes.Secrets, error) {
2022-05-24 04:04:42 -04:00
return []*k8s.Secret{}, nil
}
func (m *stubCloudControllerManager) Volumes() []k8s.Volume {
return []k8s.Volume{}
}
func (m *stubCloudControllerManager) VolumeMounts() []k8s.VolumeMount {
return []k8s.VolumeMount{}
}
func (m *stubCloudControllerManager) Env() []k8s.EnvVar {
return []k8s.EnvVar{}
}
func (m *stubCloudControllerManager) Supported() bool {
return m.SupportedResp
}
type stubClusterAutoscaler struct {
SupportedResp bool
}
func (a *stubClusterAutoscaler) Name() string {
return "stub"
}
// Secrets returns a list of secrets to deploy together with the k8s cluster-autoscaler.
func (a *stubClusterAutoscaler) Secrets(instance, cloudServiceAccountURI string) (kubernetes.Secrets, error) {
return kubernetes.Secrets{}, nil
2022-05-24 04:04:42 -04:00
}
// Volumes returns a list of volumes to deploy together with the k8s cluster-autoscaler.
func (a *stubClusterAutoscaler) Volumes() []k8s.Volume {
return []k8s.Volume{}
}
// VolumeMounts returns a list of volume mounts to deploy together with the k8s cluster-autoscaler.
func (a *stubClusterAutoscaler) VolumeMounts() []k8s.VolumeMount {
return []k8s.VolumeMount{}
}
// Env returns a list of k8s environment key-value pairs to deploy together with the k8s cluster-autoscaler.
func (a *stubClusterAutoscaler) Env() []k8s.EnvVar {
return []k8s.EnvVar{}
}
func (a *stubClusterAutoscaler) Supported() bool {
return a.SupportedResp
}