Files
kubesphere/pkg/kapis/operations/v1alpha2/handler.go
KubeSphere CI Bot 447a51f08b feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0

Signed-off-by: ci-bot <ci-bot@kubesphere.io>

* feat: kubesphere 4.0

Signed-off-by: ci-bot <ci-bot@kubesphere.io>

---------

Signed-off-by: ci-bot <ci-bot@kubesphere.io>
Co-authored-by: ks-ci-bot <ks-ci-bot@example.com>
Co-authored-by: joyceliu <joyceliu@yunify.com>
2024-09-06 11:05:52 +08:00

49 lines
1.2 KiB
Go

/*
* Please refer to the LICENSE file in the root directory of the project.
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
*/
package v1alpha2
import (
"fmt"
"net/http"
"github.com/emicklei/go-restful/v3"
k8serr "k8s.io/apimachinery/pkg/api/errors"
"kubesphere.io/kubesphere/pkg/models/workloads"
"kubesphere.io/kubesphere/pkg/server/errors"
)
type handler struct {
jobRunner workloads.JobRunner
}
func (h *handler) JobReRun(request *restful.Request, response *restful.Response) {
var err error
job := request.PathParameter("job")
namespace := request.PathParameter("namespace")
action := request.QueryParameter("action")
resourceVersion := request.QueryParameter("resourceVersion")
switch action {
case "rerun":
err = h.jobRunner.JobReRun(namespace, job, resourceVersion)
default:
response.WriteHeaderAndEntity(http.StatusBadRequest, errors.Wrap(fmt.Errorf("invalid operation %s", action)))
return
}
if err != nil {
if k8serr.IsConflict(err) {
response.WriteHeaderAndEntity(http.StatusConflict, errors.Wrap(err))
return
}
response.WriteHeaderAndEntity(http.StatusInternalServerError, errors.Wrap(err))
return
}
response.WriteAsJson(errors.None)
}