remove legacy hook annotation support

Signed-off-by: Steve Kriss <krisss@vmware.com>
This commit is contained in:
Steve Kriss
2019-04-15 10:17:03 -06:00
parent 77e648eafa
commit b87de94723
2 changed files with 3 additions and 96 deletions
+3 -65
View File
@@ -149,12 +149,6 @@ const (
podBackupHookCommandAnnotationKey = "hook.backup.velero.io/command"
podBackupHookOnErrorAnnotationKey = "hook.backup.velero.io/on-error"
podBackupHookTimeoutAnnotationKey = "hook.backup.velero.io/timeout"
// TODO(1.0) remove all of the legacy ark annotations
arkPodBackupHookContainerAnnotationKey = "hook.backup.ark.heptio.com/container"
arkPodBackupHookCommandAnnotationKey = "hook.backup.ark.heptio.com/command"
arkPodBackupHookOnErrorAnnotationKey = "hook.backup.ark.heptio.com/on-error"
arkPodBackupHookTimeoutAnnotationKey = "hook.backup.ark.heptio.com/timeout"
)
func phasedKey(phase hookPhase, key string) string {
@@ -168,9 +162,9 @@ func getHookAnnotation(annotations map[string]string, key string, phase hookPhas
return annotations[phasedKey(phase, key)]
}
// TODO(1.0): rename this function to getPodExecHookFromAnnotations (see
// corresponding comment in getPodExecHookFromAnnotations)
func getVeleroPodExecHookFromAnnotations(annotations map[string]string, phase hookPhase) *api.ExecHook {
// getPodExecHookFromAnnotations returns an ExecHook based on the annotations, as long as the
// 'command' annotation is present. If it is absent, this returns nil.
func getPodExecHookFromAnnotations(annotations map[string]string, phase hookPhase) *api.ExecHook {
commandValue := getHookAnnotation(annotations, podBackupHookCommandAnnotationKey, phase)
if commandValue == "" {
return nil
@@ -210,62 +204,6 @@ func getVeleroPodExecHookFromAnnotations(annotations map[string]string, phase ho
}
}
// TODO(1.0) delete this function
func getArkPodExecHookFromAnnotations(annotations map[string]string, phase hookPhase) *api.ExecHook {
commandValue := getHookAnnotation(annotations, arkPodBackupHookCommandAnnotationKey, phase)
if commandValue == "" {
return nil
}
var command []string
// check for json array
if commandValue[0] == '[' {
if err := json.Unmarshal([]byte(commandValue), &command); err != nil {
command = []string{commandValue}
}
} else {
command = append(command, commandValue)
}
container := getHookAnnotation(annotations, arkPodBackupHookContainerAnnotationKey, phase)
onError := api.HookErrorMode(getHookAnnotation(annotations, arkPodBackupHookOnErrorAnnotationKey, phase))
if onError != api.HookErrorModeContinue && onError != api.HookErrorModeFail {
onError = ""
}
var timeout time.Duration
timeoutString := getHookAnnotation(annotations, arkPodBackupHookTimeoutAnnotationKey, phase)
if timeoutString != "" {
if temp, err := time.ParseDuration(timeoutString); err == nil {
timeout = temp
} else {
// TODO: log error that we couldn't parse duration
}
}
return &api.ExecHook{
Container: container,
Command: command,
OnError: onError,
Timeout: metav1.Duration{Duration: timeout},
}
}
// getPodExecHookFromAnnotations returns an ExecHook based on the annotations, as long as the
// 'command' annotation is present. If it is absent, this returns nil.
func getPodExecHookFromAnnotations(annotations map[string]string, phase hookPhase) *api.ExecHook {
// TODO(1.0): delete this function implementation, as
// getVeleroPodExecHookFromAnnotations will be renamed
// in order to replace this implementation.
if hook := getVeleroPodExecHookFromAnnotations(annotations, phase); hook != nil {
return hook
}
return getArkPodExecHookFromAnnotations(annotations, phase)
}
type resourceHook struct {
name string
namespaces *collections.IncludesExcludes
-31
View File
@@ -595,37 +595,6 @@ func TestGetPodExecHookFromAnnotations(t *testing.T) {
Command: []string{"/usr/bin/foo"},
},
},
{
name: "legacy ark-based annotations are supported",
annotations: map[string]string{
phasedKey(phase, arkPodBackupHookContainerAnnotationKey): "some-container",
phasedKey(phase, arkPodBackupHookCommandAnnotationKey): "/usr/bin/foo",
},
expectedHook: &v1.ExecHook{
Container: "some-container",
Command: []string{"/usr/bin/foo"},
},
},
{
name: "when both current and legacy ark-based annotations are specified, current takes precedence",
annotations: map[string]string{
phasedKey(phase, podBackupHookContainerAnnotationKey): "current-container",
phasedKey(phase, podBackupHookCommandAnnotationKey): "/usr/bin/current",
phasedKey(phase, podBackupHookOnErrorAnnotationKey): string(v1.HookErrorModeContinue),
phasedKey(phase, podBackupHookTimeoutAnnotationKey): "10m",
phasedKey(phase, arkPodBackupHookContainerAnnotationKey): "legacy-container",
phasedKey(phase, arkPodBackupHookCommandAnnotationKey): "/usr/bin/legacy",
phasedKey(phase, arkPodBackupHookOnErrorAnnotationKey): string(v1.HookErrorModeFail),
phasedKey(phase, arkPodBackupHookTimeoutAnnotationKey): "5m",
},
expectedHook: &v1.ExecHook{
Container: "current-container",
Command: []string{"/usr/bin/current"},
OnError: v1.HookErrorModeContinue,
Timeout: metav1.Duration{Duration: 10 * time.Minute},
},
},
}
for _, test := range tests {