in pkg/deploy/lattice/target_group_manager.go [62:124]
func (s *defaultTargetGroupManager) create(ctx context.Context, modelTg *model.TargetGroup) (model.TargetGroupStatus, error) {
var ipAddressType, protocolVersion *string
if modelTg.Spec.IpAddressType != "" {
ipAddressType = &modelTg.Spec.IpAddressType
}
if modelTg.Spec.ProtocolVersion == "" {
protocolVersion = nil
} else {
protocolVersion = &modelTg.Spec.ProtocolVersion
}
latticeTgCfg := &vpclattice.TargetGroupConfig{
Port: aws.Int64(int64(modelTg.Spec.Port)),
Protocol: &modelTg.Spec.Protocol,
ProtocolVersion: protocolVersion,
VpcIdentifier: &modelTg.Spec.VpcId,
IpAddressType: ipAddressType,
HealthCheck: modelTg.Spec.HealthCheckConfig,
}
latticeTgType := string(modelTg.Spec.Type)
latticeTgName := model.GenerateTgName(modelTg.Spec)
createInput := vpclattice.CreateTargetGroupInput{
Config: latticeTgCfg,
Name: &latticeTgName,
Type: &latticeTgType,
Tags: s.cloud.DefaultTags(),
}
createInput.Tags[model.K8SClusterNameKey] = &modelTg.Spec.K8SClusterName
createInput.Tags[model.K8SServiceNameKey] = &modelTg.Spec.K8SServiceName
createInput.Tags[model.K8SServiceNamespaceKey] = &modelTg.Spec.K8SServiceNamespace
createInput.Tags[model.K8SSourceTypeKey] = aws.String(string(modelTg.Spec.K8SSourceType))
createInput.Tags[model.K8SProtocolVersionKey] = &modelTg.Spec.ProtocolVersion
if modelTg.Spec.IsSourceTypeRoute() {
createInput.Tags[model.K8SRouteNameKey] = &modelTg.Spec.K8SRouteName
createInput.Tags[model.K8SRouteNamespaceKey] = &modelTg.Spec.K8SRouteNamespace
}
lattice := s.cloud.Lattice()
resp, err := lattice.CreateTargetGroupWithContext(ctx, &createInput)
if err != nil {
return model.TargetGroupStatus{},
fmt.Errorf("failed CreateTargetGroup %s due to %s", latticeTgName, err)
}
s.log.Infof(ctx, "Success CreateTargetGroup %s", latticeTgName)
latticeTgStatus := aws.StringValue(resp.Status)
if latticeTgStatus != vpclattice.TargetGroupStatusActive &&
latticeTgStatus != vpclattice.TargetGroupStatusCreateInProgress {
s.log.Infof(ctx, "Target group is not in the desired state. State is %s, will retry", latticeTgStatus)
return model.TargetGroupStatus{}, errors.New(LATTICE_RETRY)
}
// create-in-progress is considered success
// later, target reg may need to retry due to the state, and that's OK
return model.TargetGroupStatus{
Name: aws.StringValue(resp.Name),
Arn: aws.StringValue(resp.Arn),
Id: aws.StringValue(resp.Id)}, nil
}