Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reprule trigger validation fix #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apis/registryman/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func (rtt *ReplicationTriggerType) UnmarshalText(text []byte) error {
*rtt = ManualReplicationTriggerType
case "event_based":
*rtt = EventBasedReplicationTriggerType
case "cron":
case "scheduled", "cron":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change shall be reconsidered.

*rtt = CronReplicationTriggerType
default:
*rtt = UndefinedRepliationTriggerType
Expand Down
8 changes: 6 additions & 2 deletions pkg/config/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ var ErrValidationRegistryNameNotUnique error = errors.New("validation error: mul
// non-existing Scanner.
var ErrValidationScannerNameReference error = errors.New("validation error: multiple registries present with the same name")

// ErrValidationScannerNameReference error indicates that a project refers to a
// non-existing Scanner.
// ErrValidationGroupWithoutDN error indicates that a project group member
// doesn't have its DN field set.
var ErrValidationGroupWithoutDN error = errors.New("validation error: project group member with missing DN field")

// ErrValidationReplicationRuleWrongSchedule error indicates that the replication rule's
// schedule field isn't empty while the replication type is not 'cron'.
var ErrValidationReplicationRuleWrongSchedule error = errors.New("validation error: replication rule with incorrect schedule field")
4 changes: 4 additions & 0 deletions pkg/config/local_file_aos.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ func checkProject(project *api.Project) error {
err = ErrValidationGroupWithoutDN
}
}
if project.Spec.Trigger.Schedule != "" &&
project.Spec.Trigger.TriggerType() != api.CronReplicationTriggerType {
return ErrValidationReplicationRuleWrongSchedule
}
return err
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/harbor/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ func (p *project) GetReplicationRules(ctx context.Context, trigger globalregistr
)
if replRule.GetProjectName() == p.Name {
p.registry.logger.V(1).Info("project name matches, replication rule stored")
if trigger != nil && trigger != replRule.Trigger() {
if trigger != nil &&
trigger.TriggerType() != replRule.Trigger().TriggerType() &&
trigger.TriggerSchedule() != replRule.Trigger().TriggerSchedule() {
Comment on lines +299 to +300
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should rather be an or relation:

trigger.TriggerType() != replRule.Trigger().TriggerType() ||
				trigger.TriggerSchedule() != replRule.Trigger().TriggerSchedule()

continue
}
if direction != "" && direction != replRule.Direction() {
Expand Down