domain

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: AGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoClusterAttached = errors.New("cluster not attached")
View Source
var Module = fx.Module("domain",
	fx.Provide(func(
		k8sClient k8s.Client,

		producer MessageDispatcher,

		iamClient iam.IAMClient,
		infraSvc ports.InfraService,
		platformEdgeClient platform_edge.PlatformEdgeClient,
		accountsSvc AccountsSvc,

		environmentRepo repos.DbRepo[*entities.Environment],
		registryImageRepo repos.DbRepo[*entities.RegistryImage],

		appRepo repos.DbRepo[*entities.App],
		externalAppRepo repos.DbRepo[*entities.ExternalApp],
		configRepo repos.DbRepo[*entities.Config],
		secretRepo repos.DbRepo[*entities.Secret],
		routerRepo repos.DbRepo[*entities.Router],
		mresRepo repos.DbRepo[*entities.ManagedResource],
		importedMresRepo repos.DbRepo[*entities.ImportedManagedResource],
		ipsRepo repos.DbRepo[*entities.ImagePullSecret],
		resourceMappingRepo repos.DbRepo[*entities.ResourceMapping],
		serviceBindingRepo repos.DbRepo[*entities.ServiceBinding],
		clusterManagedServiceRepo repos.DbRepo[*entities.ClusterManagedService],

		logger logging.Logger,
		resourceEventPublisher ResourceEventPublisher,

		ev *env.Env,

		consoleCacheStore ConsoleCacheStore,
	) Domain {
		return &domain{
			k8sClient: k8sClient,

			producer: producer,

			iamClient:          iamClient,
			infraSvc:           infraSvc,
			platformEdgeClient: platformEdgeClient,
			AccountsSvc:        accountsSvc,

			logger: logger,

			environmentRepo:           environmentRepo,
			appRepo:                   appRepo,
			externalAppRepo:           externalAppRepo,
			configRepo:                configRepo,
			routerRepo:                routerRepo,
			secretRepo:                secretRepo,
			mresRepo:                  mresRepo,
			importedMresRepo:          importedMresRepo,
			pullSecretsRepo:           ipsRepo,
			resourceMappingRepo:       resourceMappingRepo,
			serviceBindingRepo:        serviceBindingRepo,
			clusterManagedServiceRepo: clusterManagedServiceRepo,
			registryImageRepo:         registryImageRepo,

			envVars: ev,

			resourceEventPublisher: resourceEventPublisher,
			consoleCacheStore:      consoleCacheStore,
		}
	}))

Functions

This section is empty.

Types

type AccountsSvc

type AccountsSvc interface {
	GetAccountRegion(ctx context.Context, userId string, accountName string) (string, error)
}

type ApplyK8sResourceArgs

type ApplyK8sResourceArgs struct {
	ClusterName   string
	Object        client.Object
	RecordVersion int

	Dispatcher MessageDispatcher
}

type CheckNameAvailabilityOutput

type CheckNameAvailabilityOutput struct {
	Result         bool     `json:"result"`
	SuggestedNames []string `json:"suggestedNames,omitempty"`
}

type CloneEnvironmentArgs

type CloneEnvironmentArgs struct {
	SourceEnvName      string
	DestinationEnvName string
	DisplayName        string
	EnvRoutingMode     crdsv1.EnvironmentRoutingMode
	ClusterName        string
}

type CloneEnvironmentTemplateArgs

type CloneEnvironmentTemplateArgs struct {
	SourceAccountName  string
	SourceEnvName      string
	DestinationEnvName string
	DisplayName        string
	EnvRoutingMode     crdsv1.EnvironmentRoutingMode
}

type CloneManagedServiceArgs

type CloneManagedServiceArgs struct {
	SourceMsvcName      string
	DestinationMsvcName string
	DisplayName         string
	ClusterName         string
}

type ClusterManagedService

type ClusterManagedService interface {
	ListClusterManagedServices(ctx ConsoleContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.ClusterManagedService], error)

	GetClusterManagedService(ctx ConsoleContext, serviceName string) (*entities.ClusterManagedService, error)

	CreateClusterManagedService(ctx ConsoleContext, cmsvc entities.ClusterManagedService) (*entities.ClusterManagedService, error)
	// CloneClusterManagedService(ctx ConsoleContext, args CloneManagedServiceArgs) (*entities.ClusterManagedService, error)
	UpdateClusterManagedService(ctx ConsoleContext, cmsvc entities.ClusterManagedService) (*entities.ClusterManagedService, error)
	DeleteClusterManagedService(ctx ConsoleContext, name string) error
	ArchiveClusterManagedServicesForCluster(ctx ConsoleContext, clusterName string) (bool, error)

	OnClusterManagedServiceApplyError(ctx ConsoleContext, clusterName, name, errMsg string, opts UpdateAndDeleteOpts) error
	OnClusterManagedServiceDeleteMessage(ctx ConsoleContext, clusterName string, service entities.ClusterManagedService) error
	OnClusterManagedServiceUpdateMessage(ctx ConsoleContext, clusterName string, service entities.ClusterManagedService, status types.ResourceStatus, opts UpdateAndDeleteOpts) error
}

type ConfigKeyRef

type ConfigKeyRef struct {
	ConfigName string `json:"configName"`
	Key        string `json:"key"`
}

type ConfigKeyValueRef

type ConfigKeyValueRef struct {
	ConfigName string `json:"configName"`
	Key        string `json:"key"`
	Value      string `json:"value"`
}

type ConsoleCacheStore

type ConsoleCacheStore kv.BinaryDataRepo

type ConsoleContext

type ConsoleContext struct {
	context.Context
	AccountName string

	UserId    repos.ID
	UserEmail string
	UserName  string
}

func NewConsoleContext

func NewConsoleContext(parent context.Context, userId repos.ID, accountName string) ConsoleContext

func (ConsoleContext) GetAccountName

func (c ConsoleContext) GetAccountName() string

func (ConsoleContext) GetUserEmail

func (c ConsoleContext) GetUserEmail() string

func (ConsoleContext) GetUserId

func (c ConsoleContext) GetUserId() repos.ID

func (ConsoleContext) GetUserName

func (c ConsoleContext) GetUserName() string

type CreateAndApplyImportedManagedResourceArgs

type CreateAndApplyImportedManagedResourceArgs struct {
	ImportedManagedResourceName string
	ManagedResourceRefID        repos.ID
}

type Domain

type Domain interface {
	AccountsSvc

	CheckNameAvailability(ctx context.Context, accountName string, environmentName *string, msvcName *string, resType entities.ResourceType, name string) (*CheckNameAvailabilityOutput, error)

	ListEnvironments(ctx ConsoleContext, search map[string]repos.MatchFilter, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.Environment], error)
	GetEnvironment(ctx ConsoleContext, name string) (*entities.Environment, error)

	SetupDefaultEnvTemplate(ctx ConsoleContext) error
	CreateEnvironment(ctx ConsoleContext, env entities.Environment) (*entities.Environment, error)
	CloneEnvironment(ctx ConsoleContext, args CloneEnvironmentArgs) (*entities.Environment, error)
	UpdateEnvironment(ctx ConsoleContext, env entities.Environment) (*entities.Environment, error)
	DeleteEnvironment(ctx ConsoleContext, name string) error
	ArchiveEnvironmentsForCluster(ctx ConsoleContext, clusterName string) (bool, error)

	OnEnvironmentApplyError(ctx ConsoleContext, errMsg, namespace, name string, opts UpdateAndDeleteOpts) error
	OnEnvironmentDeleteMessage(ctx ConsoleContext, env entities.Environment) error
	OnEnvironmentUpdateMessage(ctx ConsoleContext, env entities.Environment, status types.ResourceStatus, opts UpdateAndDeleteOpts) error

	ResyncEnvironment(ctx ConsoleContext, name string) error

	GetRegistryImageURL(ctx ConsoleContext) (*entities.RegistryImageURL, error)
	GetRegistryImage(ctx ConsoleContext, image string) (*entities.RegistryImage, error)
	DeleteRegistryImage(ctx ConsoleContext, image string) error
	UpsertRegistryImage(ctx context.Context, accountName string, image string, meta map[string]any) (*entities.RegistryImage, error)
	ListRegistryImages(ctx ConsoleContext, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.RegistryImage], error)
	SearchRegistryImages(ctx ConsoleContext, query string) ([]*entities.RegistryImage, error)

	ListApps(ctx ResourceContext, search map[string]repos.MatchFilter, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.App], error)
	GetApp(ctx ResourceContext, name string) (*entities.App, error)

	CreateApp(ctx ResourceContext, app entities.App) (*entities.App, error)
	UpdateApp(ctx ResourceContext, app entities.App) (*entities.App, error)
	DeleteApp(ctx ResourceContext, name string) error

	InterceptApp(ctx ResourceContext, appName string, deviceName string, intercept bool, portMappings []crdsv1.AppInterceptPortMappings) (bool, error)
	InterceptAppOnLocalCluster(ctx ResourceContext, appName string, clusterName string, ipAddr string, intercept bool, portMappings []crdsv1.AppInterceptPortMappings) (bool, error)
	RestartApp(ctx ResourceContext, appName string) error
	RemoveDeviceIntercepts(ctx ResourceContext, deviceName string) error

	OnAppApplyError(ctx ResourceContext, errMsg string, name string, opts UpdateAndDeleteOpts) error
	OnAppDeleteMessage(ctx ResourceContext, app entities.App) error
	OnAppUpdateMessage(ctx ResourceContext, app entities.App, status types.ResourceStatus, opts UpdateAndDeleteOpts) error

	ResyncApp(ctx ResourceContext, name string) error
	RolloutAppsByImage(ctx ConsoleContext, imageName string) error

	ListConfigs(ctx ResourceContext, search map[string]repos.MatchFilter, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.Config], error)
	GetConfig(ctx ResourceContext, name string) (*entities.Config, error)
	GetConfigEntries(ctx ResourceContext, keyrefs []ConfigKeyRef) ([]*ConfigKeyValueRef, error)

	CreateConfig(ctx ResourceContext, config entities.Config) (*entities.Config, error)
	UpdateConfig(ctx ResourceContext, config entities.Config) (*entities.Config, error)
	DeleteConfig(ctx ResourceContext, name string) error

	OnConfigApplyError(ctx ResourceContext, errMsg, name string, opts UpdateAndDeleteOpts) error
	OnConfigDeleteMessage(ctx ResourceContext, config entities.Config) error
	OnConfigUpdateMessage(ctx ResourceContext, config entities.Config, status types.ResourceStatus, opts UpdateAndDeleteOpts) error

	ResyncConfig(ctx ResourceContext, name string) error

	ListSecrets(ctx ResourceContext, search map[string]repos.MatchFilter, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.Secret], error)
	GetSecret(ctx ResourceContext, name string) (*entities.Secret, error)
	GetSecretEntries(ctx ResourceContext, keyrefs []SecretKeyRef) ([]*SecretKeyValueRef, error)

	CreateSecret(ctx ResourceContext, secret entities.Secret) (*entities.Secret, error)
	UpdateSecret(ctx ResourceContext, secret entities.Secret) (*entities.Secret, error)
	DeleteSecret(ctx ResourceContext, name string) error

	OnSecretApplyError(ctx ResourceContext, errMsg, name string, opts UpdateAndDeleteOpts) error
	OnSecretDeleteMessage(ctx ResourceContext, secret entities.Secret) error
	OnSecretUpdateMessage(ctx ResourceContext, secret entities.Secret, status types.ResourceStatus, opts UpdateAndDeleteOpts) error

	ResyncSecret(ctx ResourceContext, name string) error

	ListRouters(ctx ResourceContext, search map[string]repos.MatchFilter, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.Router], error)
	GetRouter(ctx ResourceContext, name string) (*entities.Router, error)

	CreateRouter(ctx ResourceContext, router entities.Router) (*entities.Router, error)
	UpdateRouter(ctx ResourceContext, router entities.Router) (*entities.Router, error)
	DeleteRouter(ctx ResourceContext, name string) error

	OnRouterApplyError(ctx ResourceContext, errMsg string, name string, opts UpdateAndDeleteOpts) error
	OnRouterDeleteMessage(ctx ResourceContext, router entities.Router) error
	OnRouterUpdateMessage(ctx ResourceContext, router entities.Router, status types.ResourceStatus, opts UpdateAndDeleteOpts) error

	ResyncRouter(ctx ResourceContext, name string) error

	ListManagedResources(ctx ConsoleContext, search map[string]repos.MatchFilter, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.ManagedResource], error)
	GetManagedResource(ctx ManagedResourceContext, name string) (*entities.ManagedResource, error)
	GetManagedResourceByID(ctx ConsoleContext, id repos.ID) (*entities.ManagedResource, error)

	GetManagedResourceOutputKeys(ctx ManagedResourceContext, name string) ([]string, error)
	GetImportedManagedResourceOutputKeys(ctx ResourceContext, name string) ([]string, error)
	GetManagedResourceOutputKVs(ctx ManagedResourceContext, keyrefs []ManagedResourceKeyRef) ([]*ManagedResourceKeyValueRef, error)
	GetImportedManagedResourceOutputKVs(ctx ResourceContext, keyrefs []ManagedResourceKeyRef) ([]*ManagedResourceKeyValueRef, error)

	CreateManagedResource(ctx ManagedResourceContext, mres entities.ManagedResource) (*entities.ManagedResource, error)
	UpdateManagedResource(ctx ManagedResourceContext, mres entities.ManagedResource) (*entities.ManagedResource, error)
	DeleteManagedResource(ctx ManagedResourceContext, name string) error

	// ImportManagedResource(ctx ManagedResourceContext, mresName string, importName string) (*entities.ManagedResource, error)
	ImportManagedResource(ctx ManagedResourceContext, mresName string, importName string) (*entities.ImportedManagedResource, error)
	// ListImportedManagedResources(ctx ConsoleContext, search map[string]repos.MatchFilter, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.ManagedResource], error)
	ListImportedManagedResources(ctx ConsoleContext, envName string, search map[string]repos.MatchFilter, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.ImportedManagedResource], error)
	DeleteImportedManagedResource(ctx ResourceContext, importName string) error

	OnManagedResourceApplyError(ctx ConsoleContext, errMsg string, msvcName string, name string, opts UpdateAndDeleteOpts) error
	OnManagedResourceDeleteMessage(ctx ConsoleContext, msvcName string, mres crdsv1.ManagedResource) error
	OnManagedResourceUpdateMessage(ctx ConsoleContext, msvcName string, mres crdsv1.ManagedResource, outputSecret *corev1.Secret, status types.ResourceStatus, opts UpdateAndDeleteOpts) error

	ResyncManagedResource(ctx ConsoleContext, msvcName string, name string) error

	/// External Apps
	ListExternalApps(ctx ResourceContext, search map[string]repos.MatchFilter, pq repos.CursorPagination) (*repos.PaginatedRecord[*entities.ExternalApp], error)
	GetExternalApp(ctx ResourceContext, name string) (*entities.ExternalApp, error)

	CreateExternalApp(ctx ResourceContext, externalApp entities.ExternalApp) (*entities.ExternalApp, error)
	UpdateExternalApp(ctx ResourceContext, externalAppIn entities.ExternalApp) (*entities.ExternalApp, error)
	DeleteExternalApp(ctx ResourceContext, name string) error

	InterceptExternalApp(ctx ResourceContext, externalAppName string, deviceName string, intercept bool, portMappings []crdsv1.AppInterceptPortMappings) (bool, error)

	OnExternalAppApplyError(ctx ResourceContext, errMsg string, name string, opts UpdateAndDeleteOpts) error
	OnExternalAppDeleteMessage(ctx ResourceContext, externalApp entities.ExternalApp) error
	OnExternalAppUpdateMessage(ctx ResourceContext, externalApp entities.ExternalApp, status types.ResourceStatus, opts UpdateAndDeleteOpts) error

	ResyncExternalApp(ctx ResourceContext, name string) error

	// image pull secrets
	ListImagePullSecrets(ctx ConsoleContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.ImagePullSecret], error)
	GetImagePullSecret(ctx ConsoleContext, name string) (*entities.ImagePullSecret, error)
	CreateImagePullSecret(ctx ConsoleContext, secret entities.ImagePullSecret) (*entities.ImagePullSecret, error)
	UpdateImagePullSecret(ctx ConsoleContext, secret entities.ImagePullSecret) (*entities.ImagePullSecret, error)
	DeleteImagePullSecret(ctx ConsoleContext, name string) error

	OnImagePullSecretApplyError(ctx ConsoleContext, errMsg string, name string, opts UpdateAndDeleteOpts) error
	OnImagePullSecretDeleteMessage(ctx ConsoleContext, ips entities.ImagePullSecret) error
	OnImagePullSecretUpdateMessage(ctx ConsoleContext, ips entities.ImagePullSecret, status types.ResourceStatus, opts UpdateAndDeleteOpts) error

	ResyncImagePullSecret(ctx ConsoleContext, name string) error

	GetEnvironmentResourceMapping(ctx ConsoleContext, resType entities.ResourceType, clusterName string, namespace string, name string) (*entities.ResourceMapping, error)

	ServiceBinding
	ClusterManagedService
}

type ImageHookPayload

type ImageHookPayload struct {
	Image       string         `json:"image"`
	AccountName string         `json:"accountName"`
	Meta        map[string]any `json:"meta"`
}

type K8sContext

type K8sContext interface {
	context.Context
	GetUserId() repos.ID
	GetUserEmail() string
	GetUserName() string
	GetAccountName() string
}

type ManagedResourceContext

type ManagedResourceContext struct {
	ConsoleContext
	ManagedServiceName *string
	EnvironmentName    *string
}

func NewManagedResourceContext

func NewManagedResourceContext(ctx ConsoleContext, msvcName string) ManagedResourceContext

func (ManagedResourceContext) MresDBFilters

func (m ManagedResourceContext) MresDBFilters() (*repos.Filter, error)

type ManagedResourceKeyRef

type ManagedResourceKeyRef struct {
	MresName string `json:"mresName"`
	Key      string `json:"key"`
}

type ManagedResourceKeyValueRef

type ManagedResourceKeyValueRef struct {
	MresName string `json:"mresName"`
	Key      string `json:"key"`
	Value    string `json:"value"`
}

type MessageDispatcher

type MessageDispatcher messaging.Producer

type PublishMsg

type PublishMsg string
const (
	PublishAdd    PublishMsg = "added"
	PublishDelete PublishMsg = "deleted"
	PublishUpdate PublishMsg = "updated"
)

type ResType

type ResType string

type ResourceContext

type ResourceContext struct {
	ConsoleContext
	EnvironmentName string
}

func (ResourceContext) DBFilters

func (r ResourceContext) DBFilters() repos.Filter

type ResourceDispatcher

type ResourceDispatcher interface {
	ApplyResource()
	DeleteResource()
	RestartResource()
}

type ResourceEventPublisher

type ResourceEventPublisher interface {
	PublishConsoleEvent(ctx ConsoleContext, resourceType entities.ResourceType, name string, update PublishMsg)
	PublishEnvironmentResourceEvent(ctx ConsoleContext, envName string, resourceType entities.ResourceType, name string, update PublishMsg)
	PublishResourceEvent(ctx ResourceContext, resourceType entities.ResourceType, name string, update PublishMsg)
	PublishClusterManagedServiceEvent(ctx ConsoleContext, msvcName string, resourceType entities.ResourceType, name string, update PublishMsg)
}

type SecretKeyRef

type SecretKeyRef struct {
	SecretName string `json:"secretName"`
	Key        string `json:"key"`
}

type SecretKeyValueRef

type SecretKeyValueRef struct {
	SecretName string `json:"secretName"`
	Key        string `json:"key"`
	Value      string `json:"value"`
}

type ServiceBinding

type ServiceBinding interface {
	OnServiceBindingUpdateMessage(ctx ConsoleContext, svcb *networkingv1.ServiceBinding, status types.ResourceStatus, opts UpdateAndDeleteOpts) error
	OnServiceBindingDeleteMessage(ctx ConsoleContext, svcb *networkingv1.ServiceBinding) error
}

type ServiceBindingDomain

type ServiceBindingDomain interface {
	FindServiceBindingByHostname(ctx context.Context, accountName string, hostname string) (*entities.ServiceBinding, error)
}

func NewSvcBindingDomain

func NewSvcBindingDomain(svcBindingRepo repos.DbRepo[*entities.ServiceBinding]) ServiceBindingDomain

type UpdateAndDeleteOpts

type UpdateAndDeleteOpts struct {
	MessageTimestamp time.Time
	ClusterName      string
}

type UserAndAccountsContext

type UserAndAccountsContext struct {
	context.Context
	AccountName string
	UserId      repos.ID
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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