Skip to content

Commit

Permalink
OCPBUGS-4959: oc-mirror error on second synchronisation with no change (
Browse files Browse the repository at this point in the history
  • Loading branch information
lmzuccarelli committed Apr 24, 2023
1 parent d5a930d commit 90ac82c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/cli/mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,16 @@ func (o *MirrorOptions) diskToMirrorWrapper(ctx context.Context, cleanup cleanup
// Publish from disk to registry
// this takes care of syncing the metadata to the
// registry backends.

mapping, err := o.Publish(ctx)
if err != nil {
// OCPBUGS-4959 for automation processes to end gracefully
// when we have the same sequence - i.e nothing to do
msqErr := &ErrMirrorSequence{}
if errors.As(err, &msqErr) {
klog.Info("No diff from previous mirror (sequence is the same), nothing to do")
return cleanup()
}
serr := &ErrInvalidSequence{}
if errors.As(err, &serr) {
return fmt.Errorf("error during publishing, expecting imageset with prefix mirror_seq%d: %v", serr.wantSeq, err)
Expand Down
12 changes: 12 additions & 0 deletions pkg/cli/mirror/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ type ErrInvalidSequence struct {
gotSeq int
}

type ErrMirrorSequence struct {
msg string
}

func (s *ErrInvalidSequence) Error() string {
return fmt.Sprintf("invalid mirror sequence order, want %v, got %v", s.wantSeq, s.gotSeq)
}

func (s *ErrMirrorSequence) Error() string {
return fmt.Sprintf(s.msg)
}

func (o *MirrorOptions) checkSequence(incoming, current v1alpha2.Metadata, backendErr error) error {
switch {
case backendErr != nil && !errors.Is(backendErr, storage.ErrMetadataNotExist):
Expand All @@ -40,6 +48,10 @@ func (o *MirrorOptions) checkSequence(incoming, current v1alpha2.Metadata, backe
klog.V(3).Info("Checking metadata sequence number")
currRun := current.PastMirror
incomingRun := incoming.PastMirror
// OCPBUGS-4959
if incomingRun.Sequence == currRun.Sequence {
return &ErrMirrorSequence{msg: "mirror sequence is the same"}
}
if incomingRun.Sequence != (currRun.Sequence + 1) {
return &ErrInvalidSequence{currRun.Sequence + 1, incomingRun.Sequence}
}
Expand Down

0 comments on commit 90ac82c

Please sign in to comment.