Skip to content

Commit eefb161

Browse files
Merge pull request #519 from openshift/revert-508-validate-delete
OCPBUGS-56736: Revert "OCPBUGS-38120: project: run validation function when deleting an object"
2 parents ff78d5a + 28133f9 commit eefb161

File tree

2 files changed

+2
-63
lines changed

2 files changed

+2
-63
lines changed

pkg/project/apiserver/registry/project/proxy/proxy.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -214,26 +214,5 @@ func (s *REST) Delete(ctx context.Context, name string, objectFunc rest.Validate
214214
if options != nil {
215215
opts = *options
216216
}
217-
if objectFunc != nil {
218-
obj, err := s.Get(ctx, name, &metav1.GetOptions{})
219-
if err != nil {
220-
return nil, false, err
221-
}
222-
projectObj, ok := obj.(*projectapi.Project)
223-
if !ok || projectObj == nil {
224-
return nil, false, fmt.Errorf("not a project: %#v", obj)
225-
}
226-
227-
// Make sure the object hasn't changed between Get and Delete - pass UID and RV to delete options
228-
if opts.Preconditions == nil {
229-
opts.Preconditions = &metav1.Preconditions{}
230-
}
231-
opts.Preconditions.UID = &projectObj.UID
232-
opts.Preconditions.ResourceVersion = &projectObj.ResourceVersion
233-
234-
if err := objectFunc(ctx, obj); err != nil {
235-
return nil, false, err
236-
}
237-
}
238217
return &metav1.Status{Status: metav1.StatusSuccess}, false, s.client.Delete(ctx, name, opts)
239218
}

pkg/project/apiserver/registry/project/proxy/proxy_test.go

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package proxy
22

33
import (
4-
"context"
54
"strings"
65
"testing"
76

87
corev1 "k8s.io/api/core/v1"
98
"k8s.io/apimachinery/pkg/api/errors"
109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1110
"k8s.io/apimachinery/pkg/labels"
12-
"k8s.io/apimachinery/pkg/runtime"
1311
"k8s.io/apiserver/pkg/authentication/user"
1412
apirequest "k8s.io/apiserver/pkg/endpoints/request"
1513
"k8s.io/apiserver/pkg/registry/rest"
@@ -103,27 +101,6 @@ func TestCreateProjectOK(t *testing.T) {
103101
}
104102
}
105103

106-
func TestCreateProjectValidation(t *testing.T) {
107-
mockClient := &fake.Clientset{}
108-
storage := NewREST(mockClient.CoreV1().Namespaces(), &mockLister{}, nil, nil)
109-
110-
validationCalled := false
111-
validationFunc := func(ctx context.Context, obj runtime.Object) error {
112-
validationCalled = true
113-
return nil
114-
}
115-
116-
_, err := storage.Create(apirequest.NewContext(), &projectapi.Project{
117-
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
118-
}, validationFunc, &metav1.CreateOptions{})
119-
if err != nil {
120-
t.Errorf("Unexpected non-nil error: %#v", err)
121-
}
122-
if !validationCalled {
123-
t.Errorf("Expected validation function to be called")
124-
}
125-
}
126-
127104
func TestGetProjectOK(t *testing.T) {
128105
mockClient := fake.NewSimpleClientset(&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
129106
storage := NewREST(mockClient.CoreV1().Namespaces(), &mockLister{}, nil, nil)
@@ -159,26 +136,9 @@ func TestDeleteProject(t *testing.T) {
159136
t.Errorf("Expected status=success, got: %#v", status)
160137
}
161138
if len(mockClient.Actions()) != 1 {
162-
t.Errorf("Expected client action for delete, got %v", mockClient.Actions())
139+
t.Errorf("Expected client action for delete")
163140
}
164141
if !mockClient.Actions()[0].Matches("delete", "namespaces") {
165-
t.Errorf("Expected call to delete-namespace, got %#v", mockClient.Actions()[0])
166-
}
167-
}
168-
169-
func TestDeleteProjectValidation(t *testing.T) {
170-
mockClient := &fake.Clientset{}
171-
storage := REST{
172-
client: mockClient.CoreV1().Namespaces(),
173-
}
174-
validationCalled := false
175-
validationFunc := func(ctx context.Context, obj runtime.Object) error {
176-
validationCalled = true
177-
return nil
178-
}
179-
180-
storage.Delete(apirequest.NewContext(), "foo", validationFunc, &metav1.DeleteOptions{})
181-
if !validationCalled {
182-
t.Errorf("Expected validation function to be called")
142+
t.Errorf("Expected call to delete-namespace")
183143
}
184144
}

0 commit comments

Comments
 (0)