mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 21:50:05 +00:00
Move handle* methods to their respective locations
Fix names
This commit is contained in:
@@ -17,8 +17,11 @@ limitations under the License.
|
||||
package apiserver
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"path"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -27,6 +30,47 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
func (s *APIServer) operationPrefix() string {
|
||||
return path.Join(s.prefix, "operations")
|
||||
}
|
||||
|
||||
func (s *APIServer) handleOperation(w http.ResponseWriter, req *http.Request) {
|
||||
opPrefix := s.operationPrefix()
|
||||
if !strings.HasPrefix(req.URL.Path, opPrefix) {
|
||||
notFound(w, req)
|
||||
return
|
||||
}
|
||||
trimmed := strings.TrimLeft(req.URL.Path[len(opPrefix):], "/")
|
||||
parts := strings.Split(trimmed, "/")
|
||||
if len(parts) > 1 {
|
||||
notFound(w, req)
|
||||
return
|
||||
}
|
||||
if req.Method != "GET" {
|
||||
notFound(w, req)
|
||||
return
|
||||
}
|
||||
if len(parts) == 0 {
|
||||
// List outstanding operations.
|
||||
list := s.ops.List()
|
||||
writeJSON(http.StatusOK, list, w)
|
||||
return
|
||||
}
|
||||
|
||||
op := s.ops.Get(parts[0])
|
||||
if op == nil {
|
||||
notFound(w, req)
|
||||
return
|
||||
}
|
||||
|
||||
obj, complete := op.StatusOrResult()
|
||||
if complete {
|
||||
writeJSON(http.StatusOK, obj, w)
|
||||
} else {
|
||||
writeJSON(http.StatusAccepted, obj, w)
|
||||
}
|
||||
}
|
||||
|
||||
// Operation represents an ongoing action which the server is performing.
|
||||
type Operation struct {
|
||||
ID string
|
||||
|
Reference in New Issue
Block a user