in pkg/gateway/model_build_access_log_subscription.go [60:113]
func (t *accessLogSubscriptionModelBuildTask) run(ctx context.Context) error {
var eventType = core.CreateEvent
if t.accessLogPolicy.DeletionTimestamp != nil {
eventType = core.DeleteEvent
} else if _, ok := t.accessLogPolicy.Annotations[anv1alpha1.AccessLogSubscriptionAnnotationKey]; ok {
eventType = core.UpdateEvent
}
sourceType := model.ServiceSourceType
if t.accessLogPolicy.Spec.TargetRef.Kind == "Gateway" {
sourceType = model.ServiceNetworkSourceType
}
sourceName, err := utils.TargetRefToLatticeResourceName(t.accessLogPolicy.Spec.TargetRef, t.accessLogPolicy.Namespace)
if err != nil && eventType != core.DeleteEvent {
return err
}
destinationArn := t.accessLogPolicy.Spec.DestinationArn
if destinationArn == nil {
if eventType != core.DeleteEvent {
return fmt.Errorf("access log policy's destinationArn cannot be nil")
}
destinationArn = aws.String("")
}
var status *model.AccessLogSubscriptionStatus
if eventType != core.CreateEvent {
value, exists := t.accessLogPolicy.Annotations[anv1alpha1.AccessLogSubscriptionAnnotationKey]
if exists {
status = &model.AccessLogSubscriptionStatus{
Arn: value,
}
} else {
t.log.Debugf(ctx, "access log policy is missing %s annotation during %s event",
anv1alpha1.AccessLogSubscriptionAnnotationKey, eventType)
}
}
alsSpec := model.AccessLogSubscriptionSpec{
SourceType: sourceType,
SourceName: sourceName,
DestinationArn: *destinationArn,
ALPNamespacedName: t.accessLogPolicy.GetNamespacedName(),
EventType: eventType,
}
t.accessLogSubscription = model.NewAccessLogSubscription(t.stack, alsSpec, status)
err = t.stack.AddResource(t.accessLogSubscription)
if err != nil {
return err
}
return nil
}