1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-01 07:27:46 +00:00

chaging it replace apiVersion and kind from input to schema

This commit is contained in:
gehrkefc
2024-09-12 14:23:53 -03:00
parent cc1b580a18
commit e20157f2d9
4 changed files with 12 additions and 254 deletions

View File

@@ -446,15 +446,7 @@ func (s *Store) Create(apiOp *types.APIRequest, schema *types.APISchema, params
}
gvk := attributes.GVK(schema)
apiVersion, kind := gvk.ToAPIVersionAndKind()
if value, found := input["apiVersion"]; !found || value == "" {
input["apiVersion"] = apiVersion
}
if value, found := input["kind"]; !found || value == "" {
input["kind"] = kind
}
input["apiVersion"], input["kind"] = gvk.ToAPIVersionAndKind()
buffer := WarningBuffer{}
k8sClient, err := metricsStore.Wrap(s.clientGetter.TableClient(apiOp, schema, namespace, &buffer))
@@ -528,15 +520,7 @@ func (s *Store) Update(apiOp *types.APIRequest, schema *types.APISchema, params
}
gvk := attributes.GVK(schema)
apiVersion, kind := gvk.ToAPIVersionAndKind()
if value, found := input["apiVersion"]; !found || value == "" {
input["apiVersion"] = apiVersion
}
if value, found := input["kind"]; !found || value == "" {
input["kind"] = kind
}
input["apiVersion"], input["kind"] = gvk.ToAPIVersionAndKind()
opts := metav1.UpdateOptions{}
if err := decodeParams(apiOp, &opts); err != nil {

View File

@@ -521,6 +521,7 @@ func TestUpdate(t *testing.T) {
Schema: &schemas.Schema{
ID: "testing",
Attributes: map[string]interface{}{
"kind": "Secret",
"version": "v1",
"namespaced": true,
},
@@ -570,13 +571,15 @@ func TestUpdate(t *testing.T) {
Schema: &schemas.Schema{
ID: "testing",
Attributes: map[string]interface{}{
"version": "v2",
"kind": "Secret",
"namespaced": true,
},
},
},
params: types.APIObject{
Object: map[string]interface{}{
"apiVersion": "v2",
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "testing-secret",
@@ -646,114 +649,6 @@ func TestUpdate(t *testing.T) {
err: fmt.Errorf(errResourceVersionRequired),
},
},
{
name: "update - missing apiVersion (should copy from schema)",
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
return false, ret, nil
},
createInput: &sampleCreateInput,
updateInput: input{
apiOp: &types.APIRequest{
Request: &http.Request{
URL: &url.URL{},
Method: http.MethodPut,
},
Schema: &types.APISchema{
Schema: &schemas.Schema{
ID: "testing",
},
},
Method: http.MethodPut,
},
schema: &types.APISchema{
Schema: &schemas.Schema{
ID: "testing",
Attributes: map[string]interface{}{
"version": "v2",
"namespaced": true,
},
},
},
params: types.APIObject{
Object: map[string]interface{}{
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "testing-secret",
"namespace": "testing-ns",
"resourceVersion": "1",
},
},
},
},
expected: expected{
value: &unstructured.Unstructured{Object: map[string]interface{}{
"apiVersion": "v2",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "testing-secret",
"namespace": "testing-ns",
"resourceVersion": "1",
},
}},
warning: []types.Warning{},
err: nil,
},
},
{
name: "update - missing kind (should copy from schema)",
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
return false, ret, nil
},
createInput: &sampleCreateInput,
updateInput: input{
apiOp: &types.APIRequest{
Request: &http.Request{
URL: &url.URL{},
Method: http.MethodPut,
},
Schema: &types.APISchema{
Schema: &schemas.Schema{
ID: "testing",
},
},
Method: http.MethodPut,
},
schema: &types.APISchema{
Schema: &schemas.Schema{
ID: "testing",
Attributes: map[string]interface{}{
"kind": "Secret",
"namespaced": true,
},
},
},
params: types.APIObject{
Object: map[string]interface{}{
"apiVersion": "v2",
"metadata": map[string]interface{}{
"name": "testing-secret",
"namespace": "testing-ns",
"resourceVersion": "1",
},
},
},
},
expected: expected{
value: &unstructured.Unstructured{Object: map[string]interface{}{
"apiVersion": "v2",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "testing-secret",
"namespace": "testing-ns",
"resourceVersion": "1",
},
}},
warning: []types.Warning{},
err: nil,
},
},
{
name: "update - error request",
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {

View File

@@ -529,15 +529,7 @@ func (s *Store) Create(apiOp *types.APIRequest, schema *types.APISchema, params
}
gvk := attributes.GVK(schema)
apiVersion, kind := gvk.ToAPIVersionAndKind()
if value, found := input["apiVersion"]; !found || value == "" {
input["apiVersion"] = apiVersion
}
if value, found := input["kind"]; !found || value == "" {
input["kind"] = kind
}
input["apiVersion"], input["kind"] = gvk.ToAPIVersionAndKind()
buffer := WarningBuffer{}
k8sClient, err := metricsStore.Wrap(s.clientGetter.TableClient(apiOp, schema, namespace, &buffer))
@@ -611,15 +603,7 @@ func (s *Store) Update(apiOp *types.APIRequest, schema *types.APISchema, params
}
gvk := attributes.GVK(schema)
apiVersion, kind := gvk.ToAPIVersionAndKind()
if value, found := input["apiVersion"]; !found || value == "" {
input["apiVersion"] = apiVersion
}
if value, found := input["kind"]; !found || value == "" {
input["kind"] = kind
}
input["apiVersion"], input["kind"] = gvk.ToAPIVersionAndKind()
opts := metav1.UpdateOptions{}
if err := decodeParams(apiOp, &opts); err != nil {

View File

@@ -1136,6 +1136,7 @@ func TestUpdate(t *testing.T) {
Schema: &schemas.Schema{
ID: "testing",
Attributes: map[string]interface{}{
"kind": "Secret",
"version": "v1",
"namespaced": true,
},
@@ -1185,13 +1186,15 @@ func TestUpdate(t *testing.T) {
Schema: &schemas.Schema{
ID: "testing",
Attributes: map[string]interface{}{
"version": "v2",
"kind": "Secret",
"namespaced": true,
},
},
},
params: types.APIObject{
Object: map[string]interface{}{
"apiVersion": "v2",
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "testing-secret",
@@ -1261,114 +1264,6 @@ func TestUpdate(t *testing.T) {
err: fmt.Errorf(errResourceVersionRequired),
},
},
{
name: "update - missing apiVersion (should copy from schema)",
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
return false, ret, nil
},
createInput: &sampleCreateInput,
updateInput: input{
apiOp: &types.APIRequest{
Request: &http.Request{
URL: &url.URL{},
Method: http.MethodPut,
},
Schema: &types.APISchema{
Schema: &schemas.Schema{
ID: "testing",
},
},
Method: http.MethodPut,
},
schema: &types.APISchema{
Schema: &schemas.Schema{
ID: "testing",
Attributes: map[string]interface{}{
"version": "v2",
"namespaced": true,
},
},
},
params: types.APIObject{
Object: map[string]interface{}{
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "testing-secret",
"namespace": "testing-ns",
"resourceVersion": "1",
},
},
},
},
expected: expected{
value: &unstructured.Unstructured{Object: map[string]interface{}{
"apiVersion": "v2",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "testing-secret",
"namespace": "testing-ns",
"resourceVersion": "1",
},
}},
warning: []types.Warning{},
err: nil,
},
},
{
name: "update - missing kind (should copy from schema)",
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {
return false, ret, nil
},
createInput: &sampleCreateInput,
updateInput: input{
apiOp: &types.APIRequest{
Request: &http.Request{
URL: &url.URL{},
Method: http.MethodPut,
},
Schema: &types.APISchema{
Schema: &schemas.Schema{
ID: "testing",
},
},
Method: http.MethodPut,
},
schema: &types.APISchema{
Schema: &schemas.Schema{
ID: "testing",
Attributes: map[string]interface{}{
"kind": "Secret",
"namespaced": true,
},
},
},
params: types.APIObject{
Object: map[string]interface{}{
"apiVersion": "v2",
"metadata": map[string]interface{}{
"name": "testing-secret",
"namespace": "testing-ns",
"resourceVersion": "1",
},
},
},
},
expected: expected{
value: &unstructured.Unstructured{Object: map[string]interface{}{
"apiVersion": "v2",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "testing-secret",
"namespace": "testing-ns",
"resourceVersion": "1",
},
}},
warning: []types.Warning{},
err: nil,
},
},
{
name: "update - error request",
updateCallbackFunc: func(action clientgotesting.Action) (handled bool, ret runtime.Object, err error) {