diff --git a/pkg/docs/operator/docs.go b/pkg/docs/operator/docs.go index babfdb4..231c78d 100644 --- a/pkg/docs/operator/docs.go +++ b/pkg/docs/operator/docs.go @@ -36,13 +36,8 @@ const docTemplate = `{ "type": "string", "description": "sink name", "name": "name", - "in": "path" - }, - { - "type": "string", - "description": "sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "query" + "in": "path", + "required": true } ], "responses": { @@ -173,239 +168,8 @@ const docTemplate = `{ "type": "string", "description": "log export rule name to delete", "name": "rule", - "in": "path" - }, - { - "type": "string", - "description": "deprecated;metric rule name to delete", - "name": "ruleName", - "in": "query" - }, - { - "type": "string", - "description": "deprecated;bucket name to delete", - "name": "bucketName", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "400": { - "description": "Invalid parameters", - "schema": { - "type": "string" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "string" - } - }, - "405": { - "description": "Method not allowed", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Failed to delete sink", - "schema": { - "type": "string" - } - } - } - } - }, - "/api/v1/namespaces/{namespace}/sinks/{name}/{type}": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Get" - ], - "summary": "List sinks", - "deprecated": true, - "parameters": [ - { - "type": "string", - "description": "namespace name", - "name": "namespace", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "sink name", - "name": "name", - "in": "path" - }, - { - "type": "string", - "description": "deprecated;sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "path" - }, - { - "type": "string", - "description": "sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/v1.Sink" - } - } - }, - "400": { - "description": "Invalid parameters", - "schema": { - "type": "string" - } - }, - "405": { - "description": "Method not allowed", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Failed to get sink", - "schema": { - "type": "string" - } - } - } - }, - "put": { - "consumes": [ - "application/json" - ], - "tags": [ - "Put" - ], - "summary": "Put log sink", - "deprecated": true, - "parameters": [ - { - "type": "string", - "description": "namespace name", - "name": "namespace", "in": "path", "required": true - }, - { - "type": "string", - "description": "sink name", - "name": "name", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "deprecated;sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "path" - }, - { - "description": "sink contentd; Each content in array must be unique", - "name": "sink", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/v1.Sink" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "201": { - "description": "Created successfully", - "schema": { - "type": "string" - } - }, - "400": { - "description": "Invalid parameters", - "schema": { - "type": "string" - } - }, - "405": { - "description": "Method not allowed", - "schema": { - "type": "string" - } - }, - "422": { - "description": "Restricted by limits", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Failed to get sink content", - "schema": { - "type": "string" - } - } - } - }, - "delete": { - "tags": [ - "Delete" - ], - "summary": "Delete sink", - "deprecated": true, - "parameters": [ - { - "type": "string", - "description": "namespace name", - "name": "namespace", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "sink name", - "name": "name", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "deprecated;sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "path" - }, - { - "type": "string", - "description": "deprecated;metric rule name to delete", - "name": "ruleName", - "in": "query" - }, - { - "type": "string", - "description": "deprecated;bucket name to delete", - "name": "bucketName", - "in": "query" } ], "responses": { diff --git a/pkg/docs/operator/swagger.json b/pkg/docs/operator/swagger.json index f9d3a18..98acea1 100644 --- a/pkg/docs/operator/swagger.json +++ b/pkg/docs/operator/swagger.json @@ -28,13 +28,8 @@ "type": "string", "description": "sink name", "name": "name", - "in": "path" - }, - { - "type": "string", - "description": "sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "query" + "in": "path", + "required": true } ], "responses": { @@ -165,239 +160,8 @@ "type": "string", "description": "log export rule name to delete", "name": "rule", - "in": "path" - }, - { - "type": "string", - "description": "deprecated;metric rule name to delete", - "name": "ruleName", - "in": "query" - }, - { - "type": "string", - "description": "deprecated;bucket name to delete", - "name": "bucketName", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "400": { - "description": "Invalid parameters", - "schema": { - "type": "string" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "string" - } - }, - "405": { - "description": "Method not allowed", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Failed to delete sink", - "schema": { - "type": "string" - } - } - } - } - }, - "/api/v1/namespaces/{namespace}/sinks/{name}/{type}": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Get" - ], - "summary": "List sinks", - "deprecated": true, - "parameters": [ - { - "type": "string", - "description": "namespace name", - "name": "namespace", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "sink name", - "name": "name", - "in": "path" - }, - { - "type": "string", - "description": "deprecated;sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "path" - }, - { - "type": "string", - "description": "sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/v1.Sink" - } - } - }, - "400": { - "description": "Invalid parameters", - "schema": { - "type": "string" - } - }, - "405": { - "description": "Method not allowed", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Failed to get sink", - "schema": { - "type": "string" - } - } - } - }, - "put": { - "consumes": [ - "application/json" - ], - "tags": [ - "Put" - ], - "summary": "Put log sink", - "deprecated": true, - "parameters": [ - { - "type": "string", - "description": "namespace name", - "name": "namespace", "in": "path", "required": true - }, - { - "type": "string", - "description": "sink name", - "name": "name", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "deprecated;sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "path" - }, - { - "description": "sink contentd; Each content in array must be unique", - "name": "sink", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/v1.Sink" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "201": { - "description": "Created successfully", - "schema": { - "type": "string" - } - }, - "400": { - "description": "Invalid parameters", - "schema": { - "type": "string" - } - }, - "405": { - "description": "Method not allowed", - "schema": { - "type": "string" - } - }, - "422": { - "description": "Restricted by limits", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Failed to get sink content", - "schema": { - "type": "string" - } - } - } - }, - "delete": { - "tags": [ - "Delete" - ], - "summary": "Delete sink", - "deprecated": true, - "parameters": [ - { - "type": "string", - "description": "namespace name", - "name": "namespace", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "sink name", - "name": "name", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "deprecated;sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "path" - }, - { - "type": "string", - "description": "deprecated;metric rule name to delete", - "name": "ruleName", - "in": "query" - }, - { - "type": "string", - "description": "deprecated;bucket name to delete", - "name": "bucketName", - "in": "query" } ], "responses": { diff --git a/pkg/docs/operator/swagger.yaml b/pkg/docs/operator/swagger.yaml index 2c878dc..1dbd113 100644 --- a/pkg/docs/operator/swagger.yaml +++ b/pkg/docs/operator/swagger.yaml @@ -172,153 +172,8 @@ paths: - description: sink name in: path name: name - type: string - - description: sink type (logMetricRules, logExportRules) - in: query - name: type - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/v1.Sink' - type: array - "400": - description: Invalid parameters - schema: - type: string - "405": - description: Method not allowed - schema: - type: string - "500": - description: Failed to get sink - schema: - type: string - summary: List sinks - tags: - - Get - put: - consumes: - - application/json - parameters: - - description: namespace name - in: path - name: namespace required: true type: string - - description: sink name - in: path - name: name - required: true - type: string - - description: sink contentd; Each content in array must be unique - in: body - name: sink - required: true - schema: - $ref: '#/definitions/v1.Sink' - responses: - "200": - description: OK - schema: - type: string - "201": - description: Created successfully - schema: - type: string - "400": - description: Invalid parameters - schema: - type: string - "405": - description: Method not allowed - schema: - type: string - "422": - description: Restricted by limits - schema: - type: string - "500": - description: Failed to get sink content - schema: - type: string - summary: Put log sink - tags: - - Put - /api/v1/namespaces/{namespace}/sinks/{name}/{type}: - delete: - deprecated: true - parameters: - - description: namespace name - in: path - name: namespace - required: true - type: string - - description: sink name - in: path - name: name - required: true - type: string - - description: deprecated;sink type (logMetricRules, logExportRules) - in: path - name: type - type: string - - description: deprecated;metric rule name to delete - in: query - name: ruleName - type: string - - description: deprecated;bucket name to delete - in: query - name: bucketName - type: string - responses: - "200": - description: OK - schema: - type: string - "400": - description: Invalid parameters - schema: - type: string - "404": - description: Not found - schema: - type: string - "405": - description: Method not allowed - schema: - type: string - "500": - description: Failed to delete sink - schema: - type: string - summary: Delete sink - tags: - - Delete - get: - deprecated: true - parameters: - - description: namespace name - in: path - name: namespace - required: true - type: string - - description: sink name - in: path - name: name - type: string - - description: deprecated;sink type (logMetricRules, logExportRules) - in: path - name: type - type: string - - description: sink type (logMetricRules, logExportRules) - in: query - name: type - type: string produces: - application/json responses: @@ -346,7 +201,6 @@ paths: put: consumes: - application/json - deprecated: true parameters: - description: namespace name in: path @@ -358,10 +212,6 @@ paths: name: name required: true type: string - - description: deprecated;sink type (logMetricRules, logExportRules) - in: path - name: type - type: string - description: sink contentd; Each content in array must be unique in: body name: sink @@ -412,14 +262,7 @@ paths: - description: log export rule name to delete in: path name: rule - type: string - - description: deprecated;metric rule name to delete - in: query - name: ruleName - type: string - - description: deprecated;bucket name to delete - in: query - name: bucketName + required: true type: string responses: "200": diff --git a/pkg/operator/server/controller/controller.go b/pkg/operator/server/controller/controller.go index 98793d8..1c199a2 100644 --- a/pkg/operator/server/controller/controller.go +++ b/pkg/operator/server/controller/controller.go @@ -161,7 +161,7 @@ func (c SinkController) Delete(namespace, name string) error { }) } -func (c SinkController) DeleteContent(namespace, name, ruleName, bucketName string) error { +func (c SinkController) DeleteContent(namespace, name, ruleName string) error { ctx, cancel := context.WithTimeout(context.TODO(), defaultTimeout) defer cancel() diff --git a/pkg/operator/server/handler/handler.go b/pkg/operator/server/handler/handler.go index 2652bc7..4305914 100644 --- a/pkg/operator/server/handler/handler.go +++ b/pkg/operator/server/handler/handler.go @@ -37,17 +37,13 @@ const ( PathSinks = "/namespaces/{namespace}/sinks" PathSpecificSink = "/namespaces/{namespace}/sinks/{name}" PathSinkContentsRule = "/namespaces/{namespace}/sinks/{name}/rules/{rule}" - - PathSinkContents = "/namespaces/{namespace}/sinks/{name}/{type}" // deprecated ) type sinkParam struct { - Namespace string - Name string - Type string - Rule string - RuleName string - BucketName string // deprecated + Namespace string + Name string + Type string + Rule string } type SinkHandler struct { @@ -79,19 +75,16 @@ func (h SinkHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // handleGet // -// @Summary List sinks -// @Tags Get -// @Produce json -// @Param namespace path string true "namespace name" -// @Param name path string false "sink name" -// @Param type path string false "deprecated;sink type (logMetricRules, logExportRules)" -// @Param type query string false "sink type (logMetricRules, logExportRules)" -// @Success 200 {object} []v1.Sink -// @Failure 400 {string} string "Invalid parameters" -// @Failure 405 {string} string "Method not allowed" -// @Failure 500 {string} string "Failed to get sink" -// @DeprecatedRouter /api/v1/namespaces/{namespace}/sinks/{name}/{type} [get] -// @Router /api/v1/namespaces/{namespace}/sinks/{name} [get] +// @Summary List sinks +// @Tags Get +// @Produce json +// @Param namespace path string true "namespace name" +// @Param name path string true "sink name" +// @Success 200 {object} []v1.Sink +// @Failure 400 {string} string "Invalid parameters" +// @Failure 405 {string} string "Method not allowed" +// @Failure 500 {string} string "Failed to get sink" +// @Router /api/v1/namespaces/{namespace}/sinks/{name} [get] func (h SinkHandler) handleGet(w http.ResponseWriter, r *http.Request) { p, err := parseParam(r) if err != nil { @@ -118,21 +111,19 @@ func (h SinkHandler) handleGet(w http.ResponseWriter, r *http.Request) { // handlePut // -// @Summary Put log sink -// @Tags Put -// @Accept json -// @Param namespace path string true "namespace name" -// @Param name path string true "sink name" -// @Param type path string false "deprecated;sink type (logMetricRules, logExportRules)" -// @Param sink body v1.Sink true "sink contentd; Each content in array must be unique" -// @Success 200 {string} string "" -// @Success 201 {string} string "Created successfully" -// @Failure 400 {string} string "Invalid parameters" -// @Failure 422 {string} string "Restricted by limits" -// @Failure 405 {string} string "Method not allowed" -// @Failure 500 {string} string "Failed to get sink content" -// @DeprecatedRouter /api/v1/namespaces/{namespace}/sinks/{name}/{type} [put] -// @Router /api/v1/namespaces/{namespace}/sinks/{name} [put] +// @Summary Put log sink +// @Tags Put +// @Accept json +// @Param namespace path string true "namespace name" +// @Param name path string true "sink name" +// @Param sink body v1.Sink true "sink contentd; Each content in array must be unique" +// @Success 200 {string} string "" +// @Success 201 {string} string "Created successfully" +// @Failure 400 {string} string "Invalid parameters" +// @Failure 422 {string} string "Restricted by limits" +// @Failure 405 {string} string "Method not allowed" +// @Failure 500 {string} string "Failed to get sink content" +// @Router /api/v1/namespaces/{namespace}/sinks/{name} [put] func (h SinkHandler) handlePut(w http.ResponseWriter, r *http.Request) { p, err := parseParam(r) if err != nil { @@ -154,7 +145,6 @@ func (h SinkHandler) handlePut(w http.ResponseWriter, r *http.Request) { sink := v1.Sink{ Namespace: p.Namespace, Name: p.Name, - Type: p.Type, // TODO: remove this } if err := json.Unmarshal(data, &sink); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) @@ -176,23 +166,19 @@ func (h SinkHandler) handlePut(w http.ResponseWriter, r *http.Request) { } } -// handleDelete +// handleDeleteRule // -// @Summary Delete sink -// @Tags Delete -// @Param namespace path string true "namespace name" -// @Param name path string true "sink name" -// @Param type path string false "deprecated;sink type (logMetricRules, logExportRules)" -// @Param rule path string false "log export rule name to delete" -// @Param ruleName query string false "deprecated;metric rule name to delete" -// @Param bucketName query string false "deprecated;bucket name to delete" -// @Success 200 {string} string "" -// @Failure 400 {string} string "Invalid parameters" -// @Failure 404 {string} string "Not found" -// @Failure 405 {string} string "Method not allowed" -// @Failure 500 {string} string "Failed to delete sink" -// @DeprecatedRouter /api/v1/namespaces/{namespace}/sinks/{name}/{type} [delete] -// @Router /api/v1/namespaces/{namespace}/sinks/{name}/rules/{rule} [delete] +// @Summary Delete sink +// @Tags Delete +// @Param namespace path string true "namespace name" +// @Param name path string true "sink name" +// @Param rule path string true "log export rule name to delete" +// @Success 200 {string} string "" +// @Failure 400 {string} string "Invalid parameters" +// @Failure 404 {string} string "Not found" +// @Failure 405 {string} string "Method not allowed" +// @Failure 500 {string} string "Failed to delete sink" +// @Router /api/v1/namespaces/{namespace}/sinks/{name}/rules/{rule} [delete] func (h SinkHandler) handleDelete(w http.ResponseWriter, r *http.Request) { p, err := parseParam(r) if err != nil { @@ -212,7 +198,7 @@ func (h SinkHandler) handleDelete(w http.ResponseWriter, r *http.Request) { return } - if err := h.Ctrl.DeleteContent(p.Namespace, p.Name, p.Rule, p.BucketName); err != nil { + if err := h.Ctrl.DeleteContent(p.Namespace, p.Name, p.Rule); err != nil { handleError(w, err) } } @@ -220,22 +206,10 @@ func (h SinkHandler) handleDelete(w http.ResponseWriter, r *http.Request) { func parseParam(r *http.Request) (sinkParam, error) { vars := mux.Vars(r) p := sinkParam{ - Namespace: vars["namespace"], - Name: vars["name"], - Type: vars["type"], // TODO: UI에서 type 제거 후 path 대신 query param을 쓰도록 변경(get에서만 사용) - Rule: vars["rule"], - RuleName: r.URL.Query().Get("ruleName"), // TODO: /rule path 사용 후 제거 - BucketName: r.URL.Query().Get("bucketName"), // TODO: /rule path 사용 후 제거 - } - - // TODO: UI에서 query param 대신 path를 쓰도록 변경 후 제거 - if len(p.Rule) == 0 { - p.Rule = p.RuleName - } - - // TODO: UI에서 type 제거 후 path 대신 query param을 쓰도록 변경 후 제거 - if len(p.Type) == 0 { - p.Type = r.URL.Query().Get("type") + Namespace: vars["namespace"], + Name: vars["name"], + Rule: vars["rule"], + Type: r.URL.Query().Get("type"), } if len(p.Namespace) == 0 { diff --git a/pkg/operator/server/server.go b/pkg/operator/server/server.go index cabf197..e347d49 100644 --- a/pkg/operator/server/server.go +++ b/pkg/operator/server/server.go @@ -92,7 +92,6 @@ func setupRouter(sinkClient client.Client, logger logr.Logger) *mux.Router { routerV1 := router.PathPrefix(handler.PathApi).Subrouter() routerV1.Handle(handler.PathSinks, handler.SinkHandler{Ctrl: ctrl, Logger: logger}) routerV1.Handle(handler.PathSpecificSink, handler.SinkHandler{Ctrl: ctrl, Logger: logger}) - routerV1.Handle(handler.PathSinkContents, handler.SinkHandler{Ctrl: ctrl, Logger: logger}) routerV1.Handle(handler.PathSinkContentsRule, handler.SinkHandler{Ctrl: ctrl, Logger: logger}).Methods(http.MethodDelete) return router diff --git a/web/static/docs/operator/swagger.json b/web/static/docs/operator/swagger.json index f9d3a18..98acea1 100644 --- a/web/static/docs/operator/swagger.json +++ b/web/static/docs/operator/swagger.json @@ -28,13 +28,8 @@ "type": "string", "description": "sink name", "name": "name", - "in": "path" - }, - { - "type": "string", - "description": "sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "query" + "in": "path", + "required": true } ], "responses": { @@ -165,239 +160,8 @@ "type": "string", "description": "log export rule name to delete", "name": "rule", - "in": "path" - }, - { - "type": "string", - "description": "deprecated;metric rule name to delete", - "name": "ruleName", - "in": "query" - }, - { - "type": "string", - "description": "deprecated;bucket name to delete", - "name": "bucketName", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "400": { - "description": "Invalid parameters", - "schema": { - "type": "string" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "string" - } - }, - "405": { - "description": "Method not allowed", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Failed to delete sink", - "schema": { - "type": "string" - } - } - } - } - }, - "/api/v1/namespaces/{namespace}/sinks/{name}/{type}": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "Get" - ], - "summary": "List sinks", - "deprecated": true, - "parameters": [ - { - "type": "string", - "description": "namespace name", - "name": "namespace", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "sink name", - "name": "name", - "in": "path" - }, - { - "type": "string", - "description": "deprecated;sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "path" - }, - { - "type": "string", - "description": "sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/v1.Sink" - } - } - }, - "400": { - "description": "Invalid parameters", - "schema": { - "type": "string" - } - }, - "405": { - "description": "Method not allowed", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Failed to get sink", - "schema": { - "type": "string" - } - } - } - }, - "put": { - "consumes": [ - "application/json" - ], - "tags": [ - "Put" - ], - "summary": "Put log sink", - "deprecated": true, - "parameters": [ - { - "type": "string", - "description": "namespace name", - "name": "namespace", "in": "path", "required": true - }, - { - "type": "string", - "description": "sink name", - "name": "name", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "deprecated;sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "path" - }, - { - "description": "sink contentd; Each content in array must be unique", - "name": "sink", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/v1.Sink" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "201": { - "description": "Created successfully", - "schema": { - "type": "string" - } - }, - "400": { - "description": "Invalid parameters", - "schema": { - "type": "string" - } - }, - "405": { - "description": "Method not allowed", - "schema": { - "type": "string" - } - }, - "422": { - "description": "Restricted by limits", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Failed to get sink content", - "schema": { - "type": "string" - } - } - } - }, - "delete": { - "tags": [ - "Delete" - ], - "summary": "Delete sink", - "deprecated": true, - "parameters": [ - { - "type": "string", - "description": "namespace name", - "name": "namespace", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "sink name", - "name": "name", - "in": "path", - "required": true - }, - { - "type": "string", - "description": "deprecated;sink type (logMetricRules, logExportRules)", - "name": "type", - "in": "path" - }, - { - "type": "string", - "description": "deprecated;metric rule name to delete", - "name": "ruleName", - "in": "query" - }, - { - "type": "string", - "description": "deprecated;bucket name to delete", - "name": "bucketName", - "in": "query" } ], "responses": {