From 86c5c25d134b1e7480e626eacb0e7b2661f58065 Mon Sep 17 00:00:00 2001 From: Steve Kriss Date: Wed, 9 Jan 2019 14:31:04 -0700 Subject: [PATCH] code review: remove obsolete commented code Signed-off-by: Steve Kriss --- pkg/restore/pod_action.go | 156 ---------------------------------- pkg/restore/service_action.go | 31 ------- 2 files changed, 187 deletions(-) diff --git a/pkg/restore/pod_action.go b/pkg/restore/pod_action.go index 21bc6044a..4164056f6 100644 --- a/pkg/restore/pod_action.go +++ b/pkg/restore/pod_action.go @@ -97,159 +97,3 @@ func (a *podAction) Execute(obj runtime.Unstructured, restore *api.Restore) (run return &unstructured.Unstructured{Object: res}, nil, nil } - -// func (a *podAction) Execute(obj runtime.Unstructured, restore *api.Restore) (runtime.Unstructured, error, error) { -// unstructured.RemoveNestedField(obj.UnstructuredContent(), "spec", "nodeName") -// unstructured.RemoveNestedField(obj.UnstructuredContent(), "spec", "priority") - -// // if there are no volumes, then there can't be any volume mounts, so we're done. -// res, found, err := unstructured.NestedFieldNoCopy(obj.UnstructuredContent(), "spec", "volumes") -// if err != nil { -// return nil, nil, errors.WithStack(err) -// } -// if !found { -// return obj, nil, nil -// } -// volumes, ok := res.([]interface{}) -// if !ok { -// return nil, nil, errors.Errorf("unexpected type for .spec.volumes %T", res) -// } - -// serviceAccountName, found, err := unstructured.NestedString(obj.UnstructuredContent(), "spec", "serviceAccountName") -// if err != nil { -// return nil, nil, errors.WithStack(err) -// } -// if !found { -// return nil, nil, errors.New(".spec.serviceAccountName not found") -// } - -// prefix := serviceAccountName + "-token-" - -// var preservedVolumes []interface{} -// for _, obj := range volumes { -// volume, ok := obj.(map[string]interface{}) -// if !ok { -// return nil, nil, errors.Errorf("unexpected type for volume %T", obj) -// } - -// name, found, err := unstructured.NestedString(volume, "name") -// if err != nil { -// return nil, nil, errors.WithStack(err) -// } -// if !found { -// return nil, nil, errors.New("no name found for volume") -// } - -// if !strings.HasPrefix(name, prefix) { -// preservedVolumes = append(preservedVolumes, volume) -// } -// } - -// if err := unstructured.SetNestedSlice(obj.UnstructuredContent(), preservedVolumes, "spec", "volumes"); err != nil { -// return nil, nil, errors.WithStack(err) -// } - -// containers, err := nestedSliceRef(obj.UnstructuredContent(), "spec", "containers") -// if err != nil { -// return nil, nil, err -// } - -// for _, obj := range containers { -// container, ok := obj.(map[string]interface{}) -// if !ok { -// return nil, nil, errors.Errorf("unexpected type for container %T", obj) -// } - -// volumeMounts, err := nestedSliceRef(container, "volumeMounts") -// if err != nil { -// return nil, nil, err -// } - -// var preservedVolumeMounts []interface{} -// for _, obj := range volumeMounts { -// mount, ok := obj.(map[string]interface{}) -// if !ok { -// return nil, nil, errors.Errorf("unexpected type for volume mount %T", obj) -// } - -// name, found, err := unstructured.NestedString(mount, "name") -// if err != nil { -// return nil, nil, errors.WithStack(err) -// } -// if !found { -// return nil, nil, errors.New("no name found for volume mount") -// } - -// if !strings.HasPrefix(name, prefix) { -// preservedVolumeMounts = append(preservedVolumeMounts, mount) -// } -// } - -// container["volumeMounts"] = preservedVolumeMounts -// } - -// res, found, err = unstructured.NestedFieldNoCopy(obj.UnstructuredContent(), "spec", "initContainers") -// if err != nil { -// return nil, nil, errors.WithStack(err) -// } -// if !found { -// return obj, nil, nil -// } -// initContainers, ok := res.([]interface{}) -// if !ok { -// return nil, nil, errors.Errorf("unexpected type for .spec.initContainers %T", res) -// } - -// for _, obj := range initContainers { -// initContainer, ok := obj.(map[string]interface{}) -// if !ok { -// return nil, nil, errors.Errorf("unexpected type for init container %T", obj) -// } - -// volumeMounts, err := nestedSliceRef(initContainer, "volumeMounts") -// if err != nil { -// return nil, nil, err -// } - -// var preservedVolumeMounts []interface{} -// for _, obj := range volumeMounts { -// mount, ok := obj.(map[string]interface{}) -// if !ok { -// return nil, nil, errors.Errorf("unexpected type for volume mount %T", obj) -// } - -// name, found, err := unstructured.NestedString(mount, "name") -// if err != nil { -// return nil, nil, errors.WithStack(err) -// } -// if !found { -// return nil, nil, errors.New("no name found for volume mount") -// } - -// if !strings.HasPrefix(name, prefix) { -// preservedVolumeMounts = append(preservedVolumeMounts, mount) -// } -// } - -// initContainer["volumeMounts"] = preservedVolumeMounts -// } - -// return obj, nil, nil -// } - -// func nestedSliceRef(obj map[string]interface{}, fields ...string) ([]interface{}, error) { -// val, found, err := unstructured.NestedFieldNoCopy(obj, fields...) -// if err != nil { -// return nil, errors.WithStack(err) -// } -// if !found { -// return nil, errors.Errorf(".%s not found", strings.Join(fields, ".")) -// } - -// slice, ok := val.([]interface{}) -// if !ok { -// return nil, errors.Errorf("unexpected type for .%s %T", strings.Join(fields, "."), val) -// } - -// return slice, nil -// } diff --git a/pkg/restore/service_action.go b/pkg/restore/service_action.go index 4d59f9fdf..b9d2b0d2a 100644 --- a/pkg/restore/service_action.go +++ b/pkg/restore/service_action.go @@ -118,35 +118,4 @@ func deleteNodePorts(service *corev1api.Service) error { } return nil - - // preservedPorts, err := getPreservedPorts(obj) - // if err != nil { - // return err - // } - - // res, found, err := unstructured.NestedFieldNoCopy(obj.UnstructuredContent(), "spec", "ports") - // if err != nil { - // return errors.WithStack(err) - // } - // if !found { - // return errors.New(".spec.ports not found") - // } - - // ports, ok := res.([]interface{}) - // if !ok { - // return errors.Errorf("unexpected type for .spec.ports %T", res) - // } - - // for _, port := range ports { - // p := port.(map[string]interface{}) - // var name string - // if nameVal, ok := p["name"]; ok { - // name = nameVal.(string) - // } - // if preservedPorts[name] { - // continue - // } - // delete(p, "nodePort") - // } - // return nil }