admission plugins: simplify deepcopy calls

This commit is contained in:
Dr. Stefan Schimanski 2017-08-15 14:16:15 +02:00
parent ce55939465
commit 42b40ddc0f
3 changed files with 7 additions and 23 deletions

View File

@ -729,12 +729,8 @@ func TestExclusionNoAdmit(t *testing.T) {
}, },
}, },
} }
originalPod, err := api.Scheme.Copy(pod) originalPod := pod.DeepCopy()
if err != nil { err := admitPod(pod, pip)
t.Fatal(err)
}
err = admitPod(pod, pip)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -797,12 +793,8 @@ func TestAdmitEmptyPodNamespace(t *testing.T) {
}, },
}, },
} }
originalPod, err := api.Scheme.Copy(pod) originalPod := pod.DeepCopy()
if err != nil { err := admitPod(pod, pip)
t.Fatal(err)
}
err = admitPod(pod, pip)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -320,11 +320,7 @@ func (e *quotaEvaluator) checkQuotas(quotas []api.ResourceQuota, admissionAttrib
func copyQuotas(in []api.ResourceQuota) ([]api.ResourceQuota, error) { func copyQuotas(in []api.ResourceQuota) ([]api.ResourceQuota, error) {
out := make([]api.ResourceQuota, 0, len(in)) out := make([]api.ResourceQuota, 0, len(in))
for _, quota := range in { for _, quota := range in {
copied, err := api.Scheme.Copy(&quota) out = append(out, *quota.DeepCopy())
if err != nil {
return nil, err
}
out = append(out, *copied.(*api.ResourceQuota))
} }
return out, nil return out, nil

View File

@ -191,11 +191,7 @@ func TestAdmission(t *testing.T) {
glog.V(4).Infof("starting test %q", test.name) glog.V(4).Infof("starting test %q", test.name)
// clone the claim, it's going to be modified // clone the claim, it's going to be modified
clone, err := api.Scheme.DeepCopy(test.claim) claim := test.claim.DeepCopy()
if err != nil {
t.Fatalf("Cannot clone claim: %v", err)
}
claim := clone.(*api.PersistentVolumeClaim)
ctrl := newPlugin() ctrl := newPlugin()
informerFactory := informers.NewSharedInformerFactory(nil, controller.NoResyncPeriodFunc()) informerFactory := informers.NewSharedInformerFactory(nil, controller.NoResyncPeriodFunc())
@ -214,7 +210,7 @@ func TestAdmission(t *testing.T) {
admission.Create, admission.Create,
nil, // userInfo nil, // userInfo
) )
err = ctrl.Admit(attrs) err := ctrl.Admit(attrs)
glog.Infof("Got %v", err) glog.Infof("Got %v", err)
if err != nil && !test.expectError { if err != nil && !test.expectError {
t.Errorf("Test %q: unexpected error received: %v", test.name, err) t.Errorf("Test %q: unexpected error received: %v", test.name, err)