func()

in pkg/deploy/lattice/listener_manager.go [139:182]


func (d *defaultListenerManager) getLatticeListenerDefaultAction(ctx context.Context, stackListener *model.Listener) (*vpclattice.RuleAction, error) {
	if stackListener.Spec.DefaultAction.FixedResponseStatusCode != nil {
		return &vpclattice.RuleAction{
			FixedResponse: &vpclattice.FixedResponseAction{
				StatusCode: stackListener.Spec.DefaultAction.FixedResponseStatusCode,
			},
		}, nil
	}
	hasValidTargetGroup := false
	for _, tg := range stackListener.Spec.DefaultAction.Forward.TargetGroups {
		if tg.LatticeTgId != model.InvalidBackendRefTgId {
			hasValidTargetGroup = true
			break
		}
	}
	if !hasValidTargetGroup {
		if stackListener.Spec.Protocol == vpclattice.ListenerProtocolTlsPassthrough {
			return nil, fmt.Errorf("TLSRoute %s/%s must have at least one valid backendRef target group", stackListener.Spec.K8SRouteNamespace, stackListener.Spec.K8SRouteName)
		} else {
			return nil, fmt.Errorf("unreachable code, since the defaultAction for non-TLS_PASSTHROUGH listener is always the FixedResponse 404")
		}
	}

	var latticeTGs []*vpclattice.WeightedTargetGroup
	for _, modelTg := range stackListener.Spec.DefaultAction.Forward.TargetGroups {
		// skip any invalid TGs - eventually VPC Lattice may support weighted fixed response
		// and this logic can be more in line with the spec
		if modelTg.LatticeTgId == model.InvalidBackendRefTgId {
			continue
		}
		latticeTG := vpclattice.WeightedTargetGroup{
			TargetGroupIdentifier: aws.String(modelTg.LatticeTgId),
			Weight:                aws.Int64(modelTg.Weight),
		}
		latticeTGs = append(latticeTGs, &latticeTG)
	}

	d.log.Debugf(ctx, "DefaultAction Forward target groups: %v", latticeTGs)
	return &vpclattice.RuleAction{
		Forward: &vpclattice.ForwardAction{
			TargetGroups: latticeTGs,
		},
	}, nil
}