mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-15 19:56:06 +00:00
Add skip log and improve test coverage
- Log when SkipDefaultResourceModifier skips the default modifier - Add test for unsupported ResourceModifier Kind (warns, does not apply default) - Add test for default ConfigMap with invalid rules (validation failure is non-fatal) - loadResourceModifierConfigMap now at 100% coverage Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>
This commit is contained in:
@@ -444,8 +444,12 @@ func (r *restoreReconciler) validateAndComplete(ctx context.Context, restore *ap
|
||||
} else {
|
||||
r.logger.Warnf("Unsupported resource modifier kind %q, only %q is supported", restore.Spec.ResourceModifier.Kind, resourcemodifiers.ConfigmapRefType)
|
||||
}
|
||||
} else if r.defaultResourceModifierConfigMap != "" && !boolptr.IsSetToTrue(restore.Spec.SkipDefaultResourceModifier) {
|
||||
resourceModifiers = r.loadResourceModifierConfigMap(ctx, restore, r.defaultResourceModifierConfigMap, true)
|
||||
} else if r.defaultResourceModifierConfigMap != "" {
|
||||
if boolptr.IsSetToTrue(restore.Spec.SkipDefaultResourceModifier) {
|
||||
r.logger.Infof("Skipping default resource modifier configmap %s/%s as SkipDefaultResourceModifier is set", restore.Namespace, r.defaultResourceModifierConfigMap)
|
||||
} else {
|
||||
resourceModifiers = r.loadResourceModifierConfigMap(ctx, restore, r.defaultResourceModifierConfigMap, true)
|
||||
}
|
||||
}
|
||||
|
||||
return info, resourceModifiers, restoreResPolicies
|
||||
|
||||
@@ -1260,6 +1260,38 @@ func TestValidateAndCompleteWithDefaultResourceModifier(t *testing.T) {
|
||||
assert.Nil(t, rm)
|
||||
assert.Empty(t, restore.Status.ValidationErrors)
|
||||
})
|
||||
|
||||
t.Run("unsupported resource modifier kind does not apply default", func(t *testing.T) {
|
||||
r := setupReconciler(t, "default-rm")
|
||||
require.NoError(t, r.kbClient.Create(t.Context(), &corev1api.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "default-rm", Namespace: velerov1api.DefaultNamespace},
|
||||
Data: validCMData,
|
||||
}))
|
||||
|
||||
restore := newRestore("", nil)
|
||||
restore.Spec.ResourceModifier = &corev1api.TypedLocalObjectReference{
|
||||
Kind: "Secret",
|
||||
Name: "some-secret",
|
||||
}
|
||||
_, rm, _ := r.validateAndComplete(t.Context(), restore)
|
||||
assert.Nil(t, rm)
|
||||
assert.Empty(t, restore.Status.ValidationErrors)
|
||||
})
|
||||
|
||||
t.Run("default modifier validation failure is non-fatal", func(t *testing.T) {
|
||||
r := setupReconciler(t, "invalid-validation")
|
||||
require.NoError(t, r.kbClient.Create(t.Context(), &corev1api.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "invalid-validation", Namespace: velerov1api.DefaultNamespace},
|
||||
Data: map[string]string{
|
||||
"modifiers.yaml": "version: v1\nresourceModifierRules:\n- conditions:\n groupResource: pods\n patches:\n - operation: invalid\n path: \"/spec\"\n value: \"test\"\n",
|
||||
},
|
||||
}))
|
||||
|
||||
restore := newRestore("", nil)
|
||||
_, rm, _ := r.validateAndComplete(t.Context(), restore)
|
||||
assert.Nil(t, rm)
|
||||
assert.Empty(t, restore.Status.ValidationErrors)
|
||||
})
|
||||
}
|
||||
|
||||
func TestBackupXorScheduleProvided(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user