2023-05-08 19:36:35 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-05-08 19:36:35 +00:00
|
|
|
|
|
|
|
package catalog
|
|
|
|
|
|
|
|
import (
|
2023-05-15 13:55:03 +00:00
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers"
|
2023-06-16 16:58:53 +00:00
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers/endpoints"
|
2023-08-09 16:02:17 +00:00
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers/failover"
|
2023-06-16 16:58:53 +00:00
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers/nodehealth"
|
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers/workloadhealth"
|
2023-08-09 16:02:17 +00:00
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/mappers/failovermapper"
|
2023-05-19 17:53:29 +00:00
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/mappers/nodemapper"
|
2023-06-06 21:09:48 +00:00
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/mappers/selectiontracker"
|
2023-05-08 19:36:35 +00:00
|
|
|
"github.com/hashicorp/consul/internal/catalog/internal/types"
|
2023-05-15 13:55:03 +00:00
|
|
|
"github.com/hashicorp/consul/internal/controller"
|
2023-05-08 19:36:35 +00:00
|
|
|
"github.com/hashicorp/consul/internal/resource"
|
2023-08-08 19:42:43 +00:00
|
|
|
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v1alpha1"
|
2023-08-09 16:02:17 +00:00
|
|
|
"github.com/hashicorp/consul/proto-public/pbresource"
|
2023-05-08 19:36:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// API Group Information
|
|
|
|
|
|
|
|
APIGroup = types.GroupName
|
|
|
|
VersionV1Alpha1 = types.VersionV1Alpha1
|
|
|
|
CurrentVersion = types.CurrentVersion
|
|
|
|
|
|
|
|
// Resource Kind Names.
|
|
|
|
|
|
|
|
WorkloadKind = types.WorkloadKind
|
|
|
|
ServiceKind = types.ServiceKind
|
|
|
|
ServiceEndpointsKind = types.ServiceEndpointsKind
|
|
|
|
VirtualIPsKind = types.VirtualIPsKind
|
|
|
|
NodeKind = types.NodeKind
|
|
|
|
HealthStatusKind = types.HealthStatusKind
|
|
|
|
HealthChecksKind = types.HealthChecksKind
|
|
|
|
DNSPolicyKind = types.DNSPolicyKind
|
2023-08-03 18:42:04 +00:00
|
|
|
FailoverPolicyKind = types.FailoverPolicyKind
|
2023-05-08 19:36:35 +00:00
|
|
|
|
|
|
|
// Resource Types for the v1alpha1 version.
|
|
|
|
|
|
|
|
WorkloadV1Alpha1Type = types.WorkloadV1Alpha1Type
|
|
|
|
ServiceV1Alpha1Type = types.ServiceV1Alpha1Type
|
|
|
|
ServiceEndpointsV1Alpha1Type = types.ServiceEndpointsV1Alpha1Type
|
|
|
|
VirtualIPsV1Alpha1Type = types.VirtualIPsV1Alpha1Type
|
|
|
|
NodeV1Alpha1Type = types.NodeV1Alpha1Type
|
|
|
|
HealthStatusV1Alpha1Type = types.HealthStatusV1Alpha1Type
|
|
|
|
HealthChecksV1Alpha1Type = types.HealthChecksV1Alpha1Type
|
|
|
|
DNSPolicyV1Alpha1Type = types.DNSPolicyV1Alpha1Type
|
2023-08-03 18:42:04 +00:00
|
|
|
FailoverPolicyV1Alpha1Type = types.FailoverPolicyV1Alpha1Type
|
|
|
|
|
|
|
|
// Resource Types for the latest version.
|
|
|
|
|
|
|
|
WorkloadType = types.WorkloadType
|
|
|
|
ServiceType = types.ServiceType
|
|
|
|
ServiceEndpointsType = types.ServiceEndpointsType
|
|
|
|
VirtualIPsType = types.VirtualIPsType
|
|
|
|
NodeType = types.NodeType
|
|
|
|
HealthStatusType = types.HealthStatusType
|
|
|
|
HealthChecksType = types.HealthChecksType
|
|
|
|
DNSPolicyType = types.DNSPolicyType
|
|
|
|
FailoverPolicyType = types.FailoverPolicyType
|
2023-06-16 16:58:53 +00:00
|
|
|
|
|
|
|
// Controller Statuses
|
|
|
|
NodeHealthStatusKey = nodehealth.StatusKey
|
|
|
|
NodeHealthStatusConditionHealthy = nodehealth.StatusConditionHealthy
|
|
|
|
NodeHealthConditions = nodehealth.Conditions
|
|
|
|
|
|
|
|
WorkloadHealthStatusKey = workloadhealth.StatusKey
|
|
|
|
WorkloadHealthStatusConditionHealthy = workloadhealth.StatusConditionHealthy
|
|
|
|
WorkloadHealthConditions = workloadhealth.WorkloadConditions
|
|
|
|
WorkloadAndNodeHealthConditions = workloadhealth.NodeAndWorkloadConditions
|
|
|
|
|
|
|
|
EndpointsStatusKey = endpoints.StatusKey
|
|
|
|
EndpointsStatusConditionEndpointsManaged = endpoints.StatusConditionEndpointsManaged
|
|
|
|
EndpointsStatusConditionManaged = endpoints.ConditionManaged
|
|
|
|
EndpointsStatusConditionUnmanaged = endpoints.ConditionUnmanaged
|
2023-08-09 16:02:17 +00:00
|
|
|
|
|
|
|
FailoverStatusKey = failover.StatusKey
|
|
|
|
FailoverStatusConditionAccepted = failover.StatusConditionAccepted
|
|
|
|
FailoverStatusConditionAcceptedOKReason = failover.OKReason
|
|
|
|
FailoverStatusConditionAcceptedMissingServiceReason = failover.MissingServiceReason
|
|
|
|
FailoverStatusConditionAcceptedUnknownPortReason = failover.UnknownPortReason
|
|
|
|
FailoverStatusConditionAcceptedMissingDestinationServiceReason = failover.MissingDestinationServiceReason
|
|
|
|
FailoverStatusConditionAcceptedUnknownDestinationPortReason = failover.UnknownDestinationPortReason
|
|
|
|
FailoverStatusConditionAcceptedUsingMeshDestinationPortReason = failover.UsingMeshDestinationPortReason
|
2023-05-08 19:36:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// RegisterTypes adds all resource types within the "catalog" API group
|
|
|
|
// to the given type registry
|
|
|
|
func RegisterTypes(r resource.Registry) {
|
|
|
|
types.Register(r)
|
|
|
|
}
|
2023-05-15 13:55:03 +00:00
|
|
|
|
2023-05-19 17:53:29 +00:00
|
|
|
type ControllerDependencies = controllers.Dependencies
|
|
|
|
|
|
|
|
func DefaultControllerDependencies() ControllerDependencies {
|
|
|
|
return ControllerDependencies{
|
|
|
|
WorkloadHealthNodeMapper: nodemapper.New(),
|
2023-06-06 21:09:48 +00:00
|
|
|
EndpointsWorkloadMapper: selectiontracker.New(),
|
2023-08-09 16:02:17 +00:00
|
|
|
FailoverMapper: failovermapper.New(),
|
2023-05-19 17:53:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-15 13:55:03 +00:00
|
|
|
// RegisterControllers registers controllers for the catalog types with
|
|
|
|
// the given controller Manager.
|
2023-05-19 17:53:29 +00:00
|
|
|
func RegisterControllers(mgr *controller.Manager, deps ControllerDependencies) {
|
|
|
|
controllers.Register(mgr, deps)
|
2023-05-15 13:55:03 +00:00
|
|
|
}
|
2023-08-08 19:42:43 +00:00
|
|
|
|
|
|
|
// SimplifyFailoverPolicy fully populates the PortConfigs map and clears the
|
|
|
|
// Configs map using the provided Service.
|
|
|
|
func SimplifyFailoverPolicy(svc *pbcatalog.Service, failover *pbcatalog.FailoverPolicy) *pbcatalog.FailoverPolicy {
|
|
|
|
return types.SimplifyFailoverPolicy(svc, failover)
|
|
|
|
}
|
2023-08-09 16:02:17 +00:00
|
|
|
|
|
|
|
// FailoverPolicyMapper maintains the bidirectional tracking relationship of a
|
|
|
|
// FailoverPolicy to the Services related to it.
|
|
|
|
type FailoverPolicyMapper interface {
|
2023-08-22 00:20:19 +00:00
|
|
|
TrackFailover(failover *resource.DecodedResource[*pbcatalog.FailoverPolicy])
|
2023-08-09 16:02:17 +00:00
|
|
|
UntrackFailover(failoverID *pbresource.ID)
|
|
|
|
FailoverIDsByService(svcID *pbresource.ID) []*pbresource.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewFailoverPolicyMapper() FailoverPolicyMapper {
|
|
|
|
return failovermapper.New()
|
|
|
|
}
|