in pkg/deploy/lattice/rule_manager.go [92:144]
func (r *defaultRuleManager) buildLatticeRule(modelRule *model.Rule) (*vpclattice.GetRuleOutput, error) {
gro := vpclattice.GetRuleOutput{
IsDefault: aws.Bool(false),
Priority: aws.Int64(modelRule.Spec.Priority),
}
httpMatch := vpclattice.HttpMatch{}
updateMatchFromRule(&httpMatch, modelRule)
gro.Match = &vpclattice.RuleMatch{HttpMatch: &httpMatch}
// check if we have at least one valid target group
var hasValidTargetGroup bool
for _, tg := range modelRule.Spec.Action.TargetGroups {
if tg.LatticeTgId != model.InvalidBackendRefTgId {
hasValidTargetGroup = true
break
}
}
if hasValidTargetGroup {
var latticeTGs []*vpclattice.WeightedTargetGroup
for _, ruleTg := range modelRule.Spec.Action.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 ruleTg.LatticeTgId == model.InvalidBackendRefTgId {
continue
}
latticeTG := vpclattice.WeightedTargetGroup{
TargetGroupIdentifier: aws.String(ruleTg.LatticeTgId),
Weight: aws.Int64(ruleTg.Weight),
}
latticeTGs = append(latticeTGs, &latticeTG)
}
gro.Action = &vpclattice.RuleAction{
Forward: &vpclattice.ForwardAction{
TargetGroups: latticeTGs,
},
}
} else {
r.log.Debugf(context.TODO(), "There are no valid target groups, defaulting to 404 Fixed response")
gro.Action = &vpclattice.RuleAction{
FixedResponse: &vpclattice.FixedResponseAction{
StatusCode: aws.Int64(model.DefaultActionFixedResponseStatusCode),
},
}
}
gro.Name = aws.String(fmt.Sprintf("k8s-%d-rule-%d", modelRule.Spec.CreateTime.Unix(), modelRule.Spec.Priority))
return &gro, nil
}