Skip to content

Commit

Permalink
fix: pv syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Sep 24, 2024
1 parent 1eb301b commit 9d5aa1f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
26 changes: 23 additions & 3 deletions pkg/mappings/resources/persistentvolumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,36 @@ func CreatePersistentVolumesMapper(ctx *synccontext.RegisterContext) (synccontex
return generic.NewMirrorMapper(&corev1.PersistentVolume{})
}

return generic.NewMapperWithObject(ctx, &corev1.PersistentVolume{}, func(_ *synccontext.SyncContext, name, _ string, vObj client.Object) types.NamespacedName {
mapper, err := generic.NewMapperWithoutRecorder(ctx, &corev1.PersistentVolume{}, func(ctx *synccontext.SyncContext, vName, _ string, vObj client.Object) types.NamespacedName {

Check failure on line 18 in pkg/mappings/resources/persistentvolumes.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
if vObj == nil {
return types.NamespacedName{Name: name}
return types.NamespacedName{Name: vName}
}

vPv, ok := vObj.(*corev1.PersistentVolume)
if !ok || vPv.Annotations == nil || vPv.Annotations[constants.HostClusterPersistentVolumeAnnotation] == "" {
return types.NamespacedName{Name: translate.Default.HostNameCluster(name)}
return types.NamespacedName{Name: translate.Default.HostNameCluster(vName)}
}

return types.NamespacedName{Name: vPv.Annotations[constants.HostClusterPersistentVolumeAnnotation]}
})
if err != nil {
return nil, err
}

return generic.WithRecorder(&persistentVolumeMapper{
Mapper: mapper,
}), nil
}

type persistentVolumeMapper struct {
synccontext.Mapper
}

func (p *persistentVolumeMapper) HostToVirtual(ctx *synccontext.SyncContext, req types.NamespacedName, pObj client.Object) types.NamespacedName {
vName := p.Mapper.HostToVirtual(ctx, req, pObj)
if vName.Name != "" {
return vName
}

return types.NamespacedName{Name: req.Name}
}
26 changes: 23 additions & 3 deletions pkg/mappings/resources/volumesnapshotcontents.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,36 @@ func CreateVolumeSnapshotContentsMapper(ctx *synccontext.RegisterContext) (syncc
return nil, err
}

return generic.NewMapperWithObject(ctx, &volumesnapshotv1.VolumeSnapshotContent{}, func(_ *synccontext.SyncContext, name, _ string, vObj client.Object) types.NamespacedName {
mapper, err := generic.NewMapperWithoutRecorder(ctx, &volumesnapshotv1.VolumeSnapshotContent{}, func(ctx *synccontext.SyncContext, vName, _ string, vObj client.Object) types.NamespacedName {

Check failure on line 29 in pkg/mappings/resources/volumesnapshotcontents.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
if vObj == nil {
return types.NamespacedName{Name: name}
return types.NamespacedName{Name: vName}
}

vVSC, ok := vObj.(*volumesnapshotv1.VolumeSnapshotContent)
if !ok || vVSC.Annotations == nil || vVSC.Annotations[constants.HostClusterVSCAnnotation] == "" {
return types.NamespacedName{Name: translate.Default.HostNameCluster(name)}
return types.NamespacedName{Name: translate.Default.HostNameCluster(vName)}
}

return types.NamespacedName{Name: vVSC.Annotations[constants.HostClusterVSCAnnotation]}
})
if err != nil {
return nil, err
}

return generic.WithRecorder(&volumeSnapshotContentMapper{
Mapper: mapper,
}), nil
}

type volumeSnapshotContentMapper struct {
synccontext.Mapper
}

func (p *volumeSnapshotContentMapper) HostToVirtual(ctx *synccontext.SyncContext, req types.NamespacedName, pObj client.Object) types.NamespacedName {
vName := p.Mapper.HostToVirtual(ctx, req, pObj)
if vName.Name != "" {
return vName
}

return types.NamespacedName{Name: req.Name}
}

0 comments on commit 9d5aa1f

Please sign in to comment.