mirror of
https://github.com/status-im/consul.git
synced 2025-01-23 03:59:18 +00:00
92aab7ea31
[OG Author: michael.zalimeni@hashicorp.com, rebase needed a separate PR] * v2: support virtual port in Service port references In addition to Service target port references, allow users to specify a port by stringified virtual port value. This is useful in environments such as Kubernetes where typical configuration is written in terms of Service virtual ports rather than workload (pod) target port names. Retaining the option of referencing target ports by name supports VMs, Nomad, and other use cases where virtual ports are not used by default. To support both uses cases at once, we will strictly interpret port references based on whether the value is numeric. See updated `ServicePort` docs for more details. * v2: update service ref docs for virtual port support Update proto and generated .go files with docs reflecting virtual port reference support. * v2: add virtual port references to L7 topo test Add coverage for mixed virtual and target port references to existing test. * update failover policy controller tests to work with computed failover policy and assert error conditions against FailoverPolicy and ComputedFailoverPolicy resources * accumulate services; don't overwrite them in enterprise --------- Co-authored-by: Michael Zalimeni <michael.zalimeni@hashicorp.com> Co-authored-by: R.B. Boyer <rb@hashicorp.com>
100 lines
4.3 KiB
Go
100 lines
4.3 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package catalog
|
|
|
|
import (
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers"
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers/endpoints"
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers/failover"
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers/nodehealth"
|
|
"github.com/hashicorp/consul/internal/catalog/internal/controllers/workloadhealth"
|
|
"github.com/hashicorp/consul/internal/catalog/internal/types"
|
|
"github.com/hashicorp/consul/internal/controller"
|
|
"github.com/hashicorp/consul/internal/resource"
|
|
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v2beta1"
|
|
"github.com/hashicorp/consul/proto-public/pbresource"
|
|
)
|
|
|
|
var (
|
|
// Controller Statuses
|
|
NodeHealthStatusKey = nodehealth.StatusKey
|
|
NodeHealthStatusConditionHealthy = nodehealth.StatusConditionHealthy
|
|
NodeHealthConditions = nodehealth.Conditions
|
|
|
|
WorkloadHealthStatusKey = workloadhealth.ControllerID
|
|
WorkloadHealthStatusConditionHealthy = workloadhealth.StatusConditionHealthy
|
|
WorkloadHealthConditions = workloadhealth.WorkloadConditions
|
|
WorkloadAndNodeHealthConditions = workloadhealth.NodeAndWorkloadConditions
|
|
|
|
EndpointsStatusKey = endpoints.ControllerID
|
|
EndpointsStatusConditionEndpointsManaged = endpoints.StatusConditionEndpointsManaged
|
|
EndpointsStatusConditionManaged = endpoints.ConditionManaged
|
|
EndpointsStatusConditionUnmanaged = endpoints.ConditionUnmanaged
|
|
StatusConditionBoundIdentities = endpoints.StatusConditionBoundIdentities
|
|
StatusReasonWorkloadIdentitiesFound = endpoints.StatusReasonWorkloadIdentitiesFound
|
|
StatusReasonNoWorkloadIdentitiesFound = endpoints.StatusReasonNoWorkloadIdentitiesFound
|
|
|
|
FailoverStatusKey = failover.ControllerID
|
|
FailoverStatusConditionAccepted = failover.StatusConditionAccepted
|
|
FailoverStatusConditionAcceptedOKReason = failover.OKReason
|
|
FailoverStatusConditionAcceptedMissingServiceReason = failover.MissingServiceReason
|
|
FailoverStatusConditionAcceptedUnknownPortReason = failover.UnknownPortReason
|
|
FailoverStatusConditionAcceptedMissingDestinationServiceReason = failover.MissingDestinationServiceReason
|
|
FailoverStatusConditionAcceptedUnknownDestinationPortReason = failover.UnknownDestinationPortReason
|
|
FailoverStatusConditionAcceptedUsingMeshDestinationPortReason = failover.UsingMeshDestinationPortReason
|
|
)
|
|
|
|
// RegisterTypes adds all resource types within the "catalog" API group
|
|
// to the given type registry
|
|
func RegisterTypes(r resource.Registry) {
|
|
types.Register(r)
|
|
}
|
|
|
|
// RegisterControllers registers controllers for the catalog types with
|
|
// the given controller Manager.
|
|
func RegisterControllers(mgr *controller.Manager) {
|
|
controllers.Register(mgr)
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
|
|
// ValidateLocalServiceRefNoSection ensures the following:
|
|
//
|
|
// - ref is non-nil
|
|
// - type is ServiceType
|
|
// - section is empty
|
|
// - tenancy is set and partition/namespace are both non-empty
|
|
// - peer_name must be "local"
|
|
//
|
|
// Each possible validation error is wrapped in the wrapErr function before
|
|
// being collected in a multierror.Error.
|
|
func ValidateLocalServiceRefNoSection(ref *pbresource.Reference, wrapErr func(error) error) error {
|
|
return types.ValidateLocalServiceRefNoSection(ref, wrapErr)
|
|
}
|
|
|
|
// ValidateSelector ensures that the selector has at least one exact or prefix
|
|
// match constraint, and that if a filter is present it is valid.
|
|
//
|
|
// The selector can be nil, and have zero exact/prefix matches if allowEmpty is
|
|
// set to true.
|
|
func ValidateSelector(sel *pbcatalog.WorkloadSelector, allowEmpty bool) error {
|
|
return types.ValidateSelector(sel, allowEmpty)
|
|
}
|
|
|
|
func ValidateServicePortID(id string) error {
|
|
return types.ValidateServicePortID(id)
|
|
}
|
|
|
|
func IsValidUnixSocketPath(host string) bool {
|
|
return types.IsValidUnixSocketPath(host)
|
|
}
|
|
|
|
func ValidateProtocol(protocol pbcatalog.Protocol) error {
|
|
return types.ValidateProtocol(protocol)
|
|
}
|