diff --git a/api/types/load_traffic.go b/api/types/load_traffic.go index d5d9a3b..5b7a331 100644 --- a/api/types/load_traffic.go +++ b/api/types/load_traffic.go @@ -4,11 +4,7 @@ package types import ( - "encoding/json" "fmt" - "strings" - - apitypes "k8s.io/apimachinery/pkg/types" ) // ContentType represents the format of response. @@ -165,10 +161,6 @@ type RequestPatch struct { Name string `json:"name" yaml:"name"` // KeySpaceSize is used to generate random number as name's suffix. KeySpaceSize int `json:"keySpaceSize" yaml:"keySpaceSize"` - // PatchType is the type of patch, e.g. "json", "merge", "strategic-merge". - PatchType string `json:"patchType" yaml:"patchType"` - // Body is the request body, for fields to be changed. - Body string `json:"body" yaml:"body"` } // RequestGetPodLog defines GetLog request for target pod. @@ -339,21 +331,6 @@ func (m *KubeGroupVersionResource) Validate() error { return nil } -// GetPatchType returns the Kubernetes PatchType for a given patch type string. -// Returns the PatchType and an error if the patch type is invalid. -func GetPatchType(patchType string) (apitypes.PatchType, bool) { - switch patchType { - case "json": - return apitypes.JSONPatchType, true - case "merge": - return apitypes.MergePatchType, true - case "strategic-merge": - return apitypes.StrategicMergePatchType, true - default: - return "", false - } -} - // Validate validates RequestPatch type. func (r *RequestPatch) Validate() error { if err := r.KubeGroupVersionResource.Validate(); err != nil { @@ -362,24 +339,9 @@ func (r *RequestPatch) Validate() error { if r.Name == "" { return fmt.Errorf("name is required") } - if r.Body == "" { - return fmt.Errorf("body is required") - } - - // Validate patch type - _, ok := GetPatchType(r.PatchType) - if !ok { - return fmt.Errorf("unknown patch type: %s (valid types: json, merge, strategic-merge)", r.PatchType) - } - - // Validate JSON body and trim it - trimmed := strings.TrimSpace(r.Body) - if !json.Valid([]byte(trimmed)) { - return fmt.Errorf("invalid JSON in patch body: %q", r.Body) + if r.Resource == "" { + return fmt.Errorf("resource is required") } - - r.Body = trimmed // Store the trimmed body - return nil } diff --git a/contrib/internal/manifests/loadprofile/read_update.yaml b/contrib/internal/manifests/loadprofile/read_update.yaml index bdb43c9..11e33cc 100644 --- a/contrib/internal/manifests/loadprofile/read_update.yaml +++ b/contrib/internal/manifests/loadprofile/read_update.yaml @@ -20,15 +20,6 @@ loadProfile: version: v1 resource: configmaps namespace: default - patchType: merge name: runkperf-cm-kperf-read-update keySpaceSize: 100 - body: | - { - "metadata": { - "labels": { - "test-label": "mutation-test" - } - } - } shares: 50 diff --git a/request/random.go b/request/random.go index 32012e0..b488b16 100644 --- a/request/random.go +++ b/request/random.go @@ -61,7 +61,7 @@ func NewWeightedRandomRequests(spec *types.LoadProfileSpec) (*WeightedRandomRequ case r.GetPodLog != nil: builder = newRequestGetPodLogBuilder(r.GetPodLog, spec.MaxRetries) case r.Patch != nil: - builder = newRequestPatchBuilder(r.Patch, "", spec.MaxRetries) + builder = newRequestPatchBuilder(r.Patch, spec.MaxRetries) case r.PostDel != nil: builder = newRequestPostDelBuilder(r.PostDel, "", spec.MaxRetries) default: @@ -363,33 +363,25 @@ func (b *requestGetPodLogBuilder) Build(cli rest.Interface) Requester { } type requestPatchBuilder struct { - version schema.GroupVersion - resource string - resourceVersion string - namespace string - name string - keySpaceSize int - patchType apitypes.PatchType - body interface{} - maxRetries int + version schema.GroupVersion + resource string + namespace string + name string + keySpaceSize int + maxRetries int } -func newRequestPatchBuilder(src *types.RequestPatch, resourceVersion string, maxRetries int) *requestPatchBuilder { - patchType, _ := types.GetPatchType(src.PatchType) - +func newRequestPatchBuilder(src *types.RequestPatch, maxRetries int) *requestPatchBuilder { return &requestPatchBuilder{ version: schema.GroupVersion{ Group: src.Group, Version: src.Version, }, - resource: src.Resource, - resourceVersion: resourceVersion, - namespace: src.Namespace, - name: src.Name, - keySpaceSize: src.KeySpaceSize, - patchType: patchType, - body: []byte(src.Body), - maxRetries: maxRetries, + resource: src.Resource, + namespace: src.Namespace, + name: src.Name, + keySpaceSize: src.KeySpaceSize, + maxRetries: maxRetries, } } @@ -413,11 +405,13 @@ func (b *requestPatchBuilder) Build(cli rest.Interface) Requester { finalName := fmt.Sprintf("%s-%d", b.name, suffix) comps = append(comps, b.resource, finalName) + body := fmt.Sprintf(`{"metadata":{"annotations":{"force-update":"%d-%d"}}}`, suffix, time.Now().UnixNano()) + return &DiscardRequester{ BaseRequester: BaseRequester{ method: "PATCH", - req: cli.Patch(b.patchType).AbsPath(comps...). - Body(b.body). + req: cli.Patch(apitypes.MergePatchType).AbsPath(comps...). + Body([]byte(body)). MaxRetries(b.maxRetries), }, }