Skip to content

Commit

Permalink
handle draining endpoints for stateful header sessions (#52305) (mais…
Browse files Browse the repository at this point in the history
…tra#1063)

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>
Co-authored-by: Rama Chavali <rama.rao@salesforce.com>
  • Loading branch information
yxun and ramaraochavali authored Sep 18, 2024
1 parent 7c3121b commit bff3e35
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pilot/pkg/model/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func (s *Service) CmpOpts() []cmp.Option {
return serviceCmpOpts
}

func (s *Service) SupportsDrainingEndpoints() bool {
return (features.PersistentSessionLabel != "" && s.Attributes.Labels[features.PersistentSessionLabel] != "") ||
(features.PersistentSessionHeaderLabel != "" && s.Attributes.Labels[features.PersistentSessionHeaderLabel] != "")
}

// Resolution indicates how the service instances need to be resolved before routing traffic.
type Resolution int

Expand Down
2 changes: 1 addition & 1 deletion pilot/pkg/networking/core/v1alpha3/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (configgen *ConfigGeneratorImpl) buildOutboundClusters(cb *ClusterBuilder,
// if the service uses persistent sessions, override status allows
// DRAINING endpoints to be kept as 'UNHEALTHY' coarse status in envoy.
// Will not be used for normal traffic, only when explicit override.
if service.Attributes.Labels[features.PersistentSessionLabel] != "" {
if service.SupportsDrainingEndpoints() {
// Default is UNKNOWN, HEALTHY, DEGRADED. Without this change, Envoy will drop endpoints with any other
// status received in EDS. With this setting, the DRAINING and UNHEALTHY endpoints are kept - both marked
// as UNHEALTHY ('coarse state'), which is what will show in config dumps.
Expand Down
3 changes: 1 addition & 2 deletions pilot/pkg/networking/grpcgen/cds.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"

networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pilot/pkg/features"
"istio.io/istio/pilot/pkg/model"
corexds "istio.io/istio/pilot/pkg/networking/core/v1alpha3"
"istio.io/istio/pilot/pkg/networking/util"
Expand Down Expand Up @@ -130,7 +129,7 @@ func (b *clusterBuilder) build() []*cluster.Cluster {
var defaultCluster *cluster.Cluster
if b.filter.Contains(b.defaultClusterName) {
defaultCluster = edsCluster(b.defaultClusterName)
if b.svc.Attributes.Labels[features.PersistentSessionLabel] != "" {
if b.svc.SupportsDrainingEndpoints() {
// see core/v1alpha3/cluster.go
defaultCluster.CommonLbConfig.OverrideHostStatus = &core.HealthStatusSet{
Statuses: []core.HealthStatus{
Expand Down
4 changes: 1 addition & 3 deletions pilot/pkg/serviceregistry/kube/controller/endpointslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ func endpointHealthStatus(svc *model.Service, e v1.Endpoint) model.HealthStatus
return model.Healthy
}

if features.PersistentSessionLabel != "" &&
svc != nil &&
svc.Attributes.Labels[features.PersistentSessionLabel] != "" &&
if svc != nil && svc.SupportsDrainingEndpoints() &&
(e.Conditions.Serving == nil || *e.Conditions.Serving) &&
(e.Conditions.Terminating == nil || *e.Conditions.Terminating) {
return model.Draining
Expand Down

0 comments on commit bff3e35

Please sign in to comment.