resync

package
v0.0.0-...-6d13c91 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 61 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// TenantOnDemandProvider is the name of the business tenant mapping provider used when the tenant is not found in the events service
	TenantOnDemandProvider = "lazily-tenant-fetcher"
	// TenantRegionCtxKey region context key
	TenantRegionCtxKey contextKey = "tenantsRegion"
)
View Source
const (
	// DefaultScenario is the name of the default scenario
	DefaultScenario = "DEFAULT"
)
View Source
const GlobalAccountRegex = "^GLOBALACCOUNT_.*|GlobalAccount"

GlobalAccountRegex determines whether event entity type is global account

Variables

This section is empty.

Functions

func GetJobNames

func GetJobNames(envVars map[string]string) []string

GetJobNames retrieves the names of tenant fetchers jobs

func NewSynchronizerBuilder

func NewSynchronizerBuilder(jobConfig JobConfig, featuresConfig features.Config, transact persistence.Transactioner, directorClient *graphqlclient.Director, aggregationFailurePusher AggregationFailurePusher) *synchronizerBuilder

NewSynchronizerBuilder returns an entity that will use the provided configuration to create a tenant synchronizer.

func NewTenantFetcherJobEnvironment

func NewTenantFetcherJobEnvironment(ctx context.Context, name string, environmentVars map[string]string) *job

NewTenantFetcherJobEnvironment used for job configuration read from environment

func ReadFromEnvironment

func ReadFromEnvironment(environ []string) map[string]string

ReadFromEnvironment returns a key-value map of environment variables

Types

type APIEndpointsConfig

type APIEndpointsConfig struct {
	EndpointTenantCreated     string `envconfig:"ENDPOINT_TENANT_CREATED"`
	EndpointTenantDeleted     string `envconfig:"ENDPOINT_TENANT_DELETED"`
	EndpointTenantUpdated     string `envconfig:"ENDPOINT_TENANT_UPDATED"`
	EndpointSubaccountCreated string `envconfig:"ENDPOINT_SUBACCOUNT_CREATED"`
	EndpointSubaccountDeleted string `envconfig:"ENDPOINT_SUBACCOUNT_DELETED"`
	EndpointSubaccountUpdated string `envconfig:"ENDPOINT_SUBACCOUNT_UPDATED"`
	EndpointSubaccountMoved   string `envconfig:"ENDPOINT_SUBACCOUNT_MOVED"`
}

APIEndpointsConfig missing godoc

type AggregationFailurePusher

type AggregationFailurePusher interface {
	ReportAggregationFailure(ctx context.Context, err error)
}

AggregationFailurePusher takes care of pushing aggregation failures to Prometheus.

type AuthMappingConfig

type AuthMappingConfig struct {
	ClientIDPath      string `envconfig:"CLIENT_ID_PATH" required:"true"`
	ClientSecretPath  string `envconfig:"CLIENT_SECRET_PATH"`
	TokenEndpointPath string `envconfig:"TOKEN_ENDPOINT_PATH" required:"true"`
	CertPath          string `envconfig:"CERT_PATH"`
	KeyPath           string `envconfig:"CERT_KEY_PATH"`
}

AuthMappingConfig is the mapping configuration between auth details and their paths in the auth secret file.

type AuthProviderConfig

type AuthProviderConfig struct {
	AuthMappingConfig

	SecretFilePath    string `envconfig:"FILE_PATH" default:"/tmp/keyConfig"`
	TokenPath         string `envconfig:"TOKEN_PATH" required:"true"`
	SkipSSLValidation bool   `envconfig:"OAUTH_SKIP_SSL_VALIDATION" default:"false"`
}

AuthProviderConfig is the configuration of the authentication secret used by tenants aggregator. The auth secret contains auth details for different regions. Each region reads its auth config from the secret file by given a specific key.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements the communication with the service

func NewClient

func NewClient(oAuth2Config OAuth2Config, authMode oauth.AuthMode, clientConfig ClientConfig, timeout time.Duration) (*Client, error)

NewClient missing godoc

func (*Client) FetchTenantEventsPage

func (c *Client) FetchTenantEventsPage(ctx context.Context, eventsType EventsType, additionalQueryParams QueryParams) (*EventsPage, error)

FetchTenantEventsPage missing godoc

func (*Client) GetHTTPClient

func (c *Client) GetHTTPClient() *http.Client

GetHTTPClient returns the underlying HTTP client

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(client *http.Client)

SetHTTPClient sets the underlying HTTP client

type ClientConfig

type ClientConfig struct {
	TenantProvider      string
	APIConfig           APIEndpointsConfig
	FieldMapping        TenantFieldMapping
	MovedSAFieldMapping MovedSubaccountsFieldMapping
}

ClientConfig is the client specific configuration of the Events API

type DirectorGraphQLClient

type DirectorGraphQLClient interface {
	WriteTenants(context.Context, []graphql.BusinessTenantMappingInput) error
	DeleteTenants(ctx context.Context, tenants []graphql.BusinessTenantMappingInput) error
	UpdateTenant(ctx context.Context, id string, tenant graphql.BusinessTenantMappingInput) error
}

DirectorGraphQLClient expects graphql implementation

type EventAPIClient

type EventAPIClient interface {
	FetchTenantEventsPage(ctx context.Context, eventsType EventsType, additionalQueryParams QueryParams) (*EventsPage, error)
}

EventAPIClient missing godoc

type EventsAPIConfig

type EventsAPIConfig struct {
	APIEndpointsConfig
	TenantFieldMapping
	MovedSubaccountsFieldMapping

	RegionName          string         `envconfig:"REGION_NAME" required:"true"`
	AuthConfigSecretKey string         `envconfig:"AUTH_CONFIG_SECRET_KEY" required:"true"`
	AuthMode            oauth.AuthMode `envconfig:"AUTH_MODE" required:"true"`
	ClientTimeout       time.Duration  `envconfig:"TIMEOUT" default:"1m"`
	OAuthConfig         OAuth2Config   `ignored:"true"`
}

EventsAPIConfig holds information about the Tenant Events API - its endpoints, mappings to Compass tenants, and API client configurations

func (EventsAPIConfig) Validate

func (c EventsAPIConfig) Validate(tenantType tenant.Type) error

Validate checks if the current configuration contains all required information in order to successfully synchronize tenants of the given type

type EventsConfig

type EventsConfig struct {
	QueryConfig
	PagingConfig

	RegionalAuthConfigSecret AuthProviderConfig          `envconfig:"SECRET"`
	RegionalAPIConfigs       map[string]*EventsAPIConfig `ignored:"true"`
	APIConfig                EventsAPIConfig             `envconfig:"API"`
	PageWorkers              int                         `envconfig:"PAGE_WORKERS" default:"2"`
	TenantOperationChunkSize int                         `envconfig:"TENANT_INSERT_CHUNK_SIZE" default:"500"`
	RetryAttempts            uint                        `envconfig:"RETRY_ATTEMPTS" default:"7"`
}

EventsConfig contains configuration for Events API requests

func (EventsConfig) Validate

func (ec EventsConfig) Validate(tenantType tenant.Type) error

Validate checks if the current configuration contains all required information in order to successfully synchronize tenants of the given type

type EventsPage

type EventsPage struct {
	FieldMapping                 TenantFieldMapping
	MovedSubaccountsFieldMapping MovedSubaccountsFieldMapping
	ProviderName                 string
	Payload                      []byte
}

EventsPage represents a page returned by the Events API - its payload, along with the mappings required for converting the page to a set of tenants

func (EventsPage) GetMovedSubaccounts

func (ep EventsPage) GetMovedSubaccounts(ctx context.Context) []model.MovedSubaccountMappingInput

GetMovedSubaccounts parses the data from the page payload to MovedSubaccountMappingInput

func (EventsPage) GetTenantMappings

func (ep EventsPage) GetTenantMappings(ctx context.Context, eventsType EventsType) []model.BusinessTenantMappingInput

GetTenantMappings parses the data from the page payload to BusinessTenantMappingInput

type EventsType

type EventsType int

EventsType missing godoc

const (
	// CreatedAccountType missing godoc
	CreatedAccountType EventsType = iota
	// DeletedAccountType missing godoc
	DeletedAccountType
	// UpdatedAccountType missing godoc
	UpdatedAccountType
	// CreatedSubaccountType missing godoc
	CreatedSubaccountType
	// DeletedSubaccountType missing godoc
	DeletedSubaccountType
	// UpdatedSubaccountType missing godoc
	UpdatedSubaccountType
	// MovedSubaccountType missing godoc
	MovedSubaccountType
)

func (EventsType) String

func (e EventsType) String() string

String missing godoc

type JobConfig

type JobConfig struct {
	EventsConfig
	ResyncConfig
	KubeConfig

	JobName        string      `envconfig:"JOB_NAME" required:"true"`
	TenantProvider string      `envconfig:"TENANT_PROVIDER" required:"true"`
	TenantType     tenant.Type `envconfig:"TENANT_TYPE" required:"true"`
	RegionPrefix   string      `envconfig:"REGION_PREFIX"`
}

JobConfig contains tenant fetcher job configuration read from environment

func (*JobConfig) Validate

func (jc *JobConfig) Validate() error

Validate checks if the current configuration contains all required information in order to successfully synchronize tenants of the configured type

type KubeClient

type KubeClient interface {
	GetTenantFetcherConfigMapData(ctx context.Context) (string, string, error)
	UpdateTenantFetcherConfigMapData(ctx context.Context, lastRunTimestamp, lastResyncTimestamp string) error
}

KubeClient missing godoc

func NewKubernetesClient

func NewKubernetesClient(ctx context.Context, cfg KubeConfig) (KubeClient, error)

NewKubernetesClient missing godoc

type KubeConfig

type KubeConfig struct {
	UseKubernetes string `envconfig:"USE_KUBERNETES"`

	ConfigMapNamespace            string `envconfig:"CONFIGMAP_NAMESPACE" default:"compass-system"`
	ConfigMapName                 string `envconfig:"LAST_EXECUTION_TIME_CONFIG_MAP_NAME" default:"tenant-fetcher-config"`
	ConfigMapTimestampField       string `envconfig:"CONFIGMAP_TIMESTAMP_FIELD" default:"lastConsumedTenantTimestamp"`
	ConfigMapResyncTimestampField string `envconfig:"CONFIGMAP_RESYNC_TIMESTAMP_FIELD" default:"lastFullResyncTimestamp"`

	PollInterval time.Duration `envconfig:"APP_KUBERNETES_POLL_INTERVAL" default:"2s"`
	PollTimeout  time.Duration `envconfig:"APP_KUBERNETES_POLL_TIMEOUT" default:"1m"`
	Timeout      time.Duration `envconfig:"APP_KUBERNETES_TIMEOUT" default:"2m"`
}

KubeConfig missing godoc

type LabelRepo

type LabelRepo interface {
	GetScenarioLabelsForRuntimes(ctx context.Context, tenantID string, runtimesIDs []string) ([]model.Label, error)
}

LabelRepo missing godoc

type MovedSubaccountsFieldMapping

type MovedSubaccountsFieldMapping struct {
	SubaccountID string `envconfig:"MAPPING_FIELD_ID"`
	SourceTenant string `envconfig:"MOVED_SUBACCOUNT_SOURCE_TENANT_FIELD"`
	TargetTenant string `envconfig:"MOVED_SUBACCOUNT_TARGET_TENANT_FIELD"`
}

MovedSubaccountsFieldMapping missing godoc

type OAuth2Config

type OAuth2Config struct {
	X509Config
	ClientID           string
	ClientSecret       string
	OAuthTokenEndpoint string
	TokenPath          string
	SkipSSLValidation  bool
}

OAuth2Config is the auth configuration used by Tenant Events API clients.

func (OAuth2Config) Validate

func (c OAuth2Config) Validate(oauthMode oauth.AuthMode) error

Validate checks if the configuration is considered valid against the given auth mode. The configuration is considered valid if it contains all needed auth details for the given mode.

type PageConfig

type PageConfig struct {
	TotalPagesField   string
	TotalResultsField string
	PageNumField      string
	PageWorkers       int
}

PageConfig missing godoc

type PagingConfig

type PagingConfig struct {
	TotalPagesField   string `envconfig:"TENANT_TOTAL_PAGES_FIELD" default:"pages"`
	TotalResultsField string `envconfig:"TENANT_TOTAL_RESULTS_FIELD" default:"totalResults"`
}

PagingConfig holds information about Events API pagination

type QueryConfig

type QueryConfig struct {
	RegionField    string `envconfig:"QUERY_REGION_FIELD"`
	PageNumField   string `envconfig:"QUERY_PAGE_NUM_FIELD" default:"pageNum"`
	PageSizeField  string `envconfig:"QUERY_PAGE_SIZE_FIELD" default:"pageSize"`
	TimestampField string `envconfig:"QUERY_TIMESTAMP_FIELD" default:"timestamp"`
	PageStartValue string `envconfig:"QUERY_PAGE_START" default:"0"`
	PageSizeValue  string `envconfig:"QUERY_PAGE_SIZE" default:"150"`
	EntityField    string `envconfig:"QUERY_ENTITY_FIELD" default:"entityId"`
}

QueryConfig contains the name of query parameters fields and default/start values

type QueryParams

type QueryParams map[string]string

QueryParams describes the key and the corresponding value for query parameters when requesting the service

type ResyncConfig

type ResyncConfig struct {
	TenantFetcherJobIntervalMins time.Duration `envconfig:"TENANT_FETCHER_JOB_INTERVAL" default:"5m"`
	FullResyncInterval           time.Duration `envconfig:"FULL_RESYNC_INTERVAL" default:"12h"`
}

ResyncConfig holds information about tenant synchronizing intervals

type RuntimeService

type RuntimeService interface {
	ListByFilters(ctx context.Context, filters []*labelfilter.LabelFilter) ([]*model.Runtime, error)
}

RuntimeService missing godoc

type TenantConverter

type TenantConverter interface {
	MultipleInputToGraphQLInput([]model.BusinessTenantMappingInput) []graphql.BusinessTenantMappingInput
	ToGraphQLInput(model.BusinessTenantMappingInput) graphql.BusinessTenantMappingInput
}

TenantConverter expects tenant converter implementation

type TenantCreator

type TenantCreator interface {
	FetchTenants(ctx context.Context, externalTenantID string) ([]model.BusinessTenantMappingInput, error)
	TenantsToCreate(ctx context.Context, region, fromTimestamp string) ([]model.BusinessTenantMappingInput, error)
	CreateTenants(ctx context.Context, eventsTenants []model.BusinessTenantMappingInput) error
}

TenantCreator takes care of retrieving tenants from external tenant registry and storing them in Director

type TenantDeleter

type TenantDeleter interface {
	TenantsToDelete(ctx context.Context, region, fromTimestamp string) ([]model.BusinessTenantMappingInput, error)
	DeleteTenants(ctx context.Context, eventsTenants []model.BusinessTenantMappingInput) error
}

TenantDeleter takes care of retrieving no longer used tenants from external tenant registry and delete them from Director

type TenantEventsResponse

type TenantEventsResponse []byte

TenantEventsResponse missing godoc

type TenantFieldMapping

type TenantFieldMapping struct {
	EventsField string `envconfig:"TENANT_EVENTS_FIELD" default:"events"`

	NameField                     string `envconfig:"MAPPING_FIELD_NAME" default:"name"`
	IDField                       string `envconfig:"MAPPING_FIELD_ID" default:"id"`
	GlobalAccountGUIDField        string `envconfig:"MAPPING_FIELD_GLOBAL_ACCOUNT_GUID" default:"globalAccountGUID"`
	SubaccountIDField             string `envconfig:"MAPPING_FIELD_SUBACCOUNT_ID" default:"subaccountId"`
	CustomerIDField               string `envconfig:"MAPPING_FIELD_CUSTOMER_ID" default:"customerId"`
	SubdomainField                string `envconfig:"MAPPING_FIELD_SUBDOMAIN" default:"subdomain"`
	CostObjectIDField             string `envconfig:"MAPPING_FIELD_COST_OBJECT_ID" default:"costObject"`
	DetailsField                  string `envconfig:"MAPPING_FIELD_DETAILS" default:"details"`
	LabelsField                   string `envconfig:"MAPPING_FIELD_LABELS" default:"labels"`
	SubaccountCostObjectIDField   string `envconfig:"MAPPING_FIELD_SUBACCOUNT_COST_OBJECT_ID" default:"costObjectId"`
	SubaccountCostObjectTypeField string `envconfig:"MAPPING_FIELD_SUBACCOUNT_COST_OBJECT_TYPE" default:"costObjectType"`

	DiscriminatorField string `envconfig:"MAPPING_FIELD_DISCRIMINATOR"`
	DiscriminatorValue string `envconfig:"MAPPING_VALUE_DISCRIMINATOR"`

	RegionField      string `envconfig:"MAPPING_FIELD_REGION" default:"region"`
	EntityIDField    string `envconfig:"MAPPING_FIELD_ENTITY_ID" default:"entityId"`
	EntityTypeField  string `envconfig:"MAPPING_FIELD_ENTITY_TYPE" default:"entityType"`
	LicenseTypeField string `envconfig:"MAPPING_FIELD_LICENSE_TYPE" default:"licenseType"`

	// This is not a value from the actual event but the key under which the GlobalAccountGUIDField will be stored to avoid collisions
	GlobalAccountKey string `envconfig:"GLOBAL_ACCOUNT_KEY" default:"gaID"`
}

TenantFieldMapping missing godoc

type TenantMover

type TenantMover interface {
	TenantsToMove(ctx context.Context, region, fromTimestamp string) ([]model.MovedSubaccountMappingInput, error)
	MoveTenants(ctx context.Context, movedSubaccountMappings []model.MovedSubaccountMappingInput) error
}

TenantMover takes care of moving tenants from one parent tenant to another.

func NewSubaccountsMover

func NewSubaccountsMover(jobConfig JobConfig, transact persistence.Transactioner, directorClient DirectorGraphQLClient, eventAPIClient EventAPIClient, tenantConverter TenantConverter, storageSvc TenantStorageService, runtimeSvc RuntimeService, labelRepo LabelRepo) TenantMover

NewSubaccountsMover returns a new etity responsible for retrieving moved tenants from one parent tenant to another from an external registry, and proceeding with moving said tenants across parents if possible

type TenantStorageService

type TenantStorageService interface {
	List(ctx context.Context) ([]*model.BusinessTenantMapping, error)
	GetTenantByExternalID(ctx context.Context, id string) (*model.BusinessTenantMapping, error)
	ListsByExternalIDs(ctx context.Context, ids []string) ([]*model.BusinessTenantMapping, error)
	ListByIDsAndType(ctx context.Context, ids []string, tenantType tenant.Type) ([]*model.BusinessTenantMapping, error)
	ListByIDs(ctx context.Context, ids []string) ([]*model.BusinessTenantMapping, error)
}

TenantStorageService missing godoc

type TenantsManager

type TenantsManager struct {
	// contains filtered or unexported fields
}

TenantsManager is responsible for creating, updating and deleting tenants associated with an external tenants registry

func NewTenantsManager

func NewTenantsManager(jobConfig JobConfig, directorClient DirectorGraphQLClient, universalClient EventAPIClient, regionalDetails map[string]EventAPIClient, tenantConverter TenantConverter) (*TenantsManager, error)

NewTenantsManager returns a new tenants manager built with the provided configurations and API clients

func (*TenantsManager) CreateTenants

func (tm *TenantsManager) CreateTenants(ctx context.Context, tenants []model.BusinessTenantMappingInput) error

CreateTenants takes care of creating all missing tenants in Compass by calling Director in chunks

func (*TenantsManager) DeleteTenants

func (tm *TenantsManager) DeleteTenants(ctx context.Context, tenantsToDelete []model.BusinessTenantMappingInput) error

DeleteTenants takes care of deleting all tenants marked as deleted in the external tenants registry

func (*TenantsManager) FetchTenants

func (tm *TenantsManager) FetchTenants(ctx context.Context, externalTenantID string) ([]model.BusinessTenantMappingInput, error)

FetchTenants retrieves a given tenant from all available regions and updates or creates it in Compass. It may also return a cost object tenant alongside the global account or the subaccount

func (*TenantsManager) TenantsToCreate

func (tm *TenantsManager) TenantsToCreate(ctx context.Context, region, fromTimestamp string) ([]model.BusinessTenantMappingInput, error)

TenantsToCreate returns all tenants that are missing in Compass but are present in the external tenants registry

func (*TenantsManager) TenantsToDelete

func (tm *TenantsManager) TenantsToDelete(ctx context.Context, region, fromTimestamp string) ([]model.BusinessTenantMappingInput, error)

TenantsToDelete returns all tenants that are no longer associated with their parent tenant and should be moved from one parent tenant to another

type TenantsSynchronizer

type TenantsSynchronizer struct {
	// contains filtered or unexported fields
}

TenantsSynchronizer takes care of synchronizing tenants with external tenant registry. It creates, updates, deletes and moves tenants that were created, updated, deleted or moved in that external registry.

func NewTenantSynchronizer

func NewTenantSynchronizer(config JobConfig, transact persistence.Transactioner, tenantStorageService TenantStorageService, creator TenantCreator, mover TenantMover, deleter TenantDeleter, kubeClient KubeClient, metricsReporter AggregationFailurePusher) *TenantsSynchronizer

NewTenantSynchronizer returns a new tenants synchronizer.

func (*TenantsSynchronizer) Name

func (ts *TenantsSynchronizer) Name() string

Name returns the name set to the tenants synchronizer.

func (*TenantsSynchronizer) ResyncInterval

func (ts *TenantsSynchronizer) ResyncInterval() time.Duration

ResyncInterval returns the interval that the synchronizer is supposed to make a regular tenants resync with the external tenants registry.

func (*TenantsSynchronizer) Synchronize

func (ts *TenantsSynchronizer) Synchronize(ctx context.Context) error

Synchronize is responsible for synchronizing the tenants of the configured type in Compass and the configured external tenants registry. When a tenant is created in the external registry, it is also greated in Compass. Same applies for updated, deleted and moved tenants.

func (*TenantsSynchronizer) SynchronizeTenant

func (ts *TenantsSynchronizer) SynchronizeTenant(ctx context.Context, parentTenantID, tenantID string) error

SynchronizeTenant is responsible for updating the given tenant with the values available in the external registry, or creating it if it does not exist in Compass. All available regions are checked for the existence of the tenant.

func (*TenantsSynchronizer) TenantType

func (ts *TenantsSynchronizer) TenantType() tenant.Type

TenantType returns the tenant type the tenants synchronizer is responsible for.

type X509Config

type X509Config struct {
	Cert string
	Key  string
}

X509Config is X509 configuration for getting an OAuth token via mtls same as struct in pkg/oauth but with different envconfig

func (*X509Config) ParseCertificate

func (c *X509Config) ParseCertificate() (*tls.Certificate, error)

ParseCertificate parses the TLS certificate contained in the X509Config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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