@@ -18,28 +18,13 @@ package app
18
18
19
19
import (
20
20
"crypto/tls"
21
- "encoding/json"
22
- "io/ioutil"
23
- "net/http"
24
21
25
22
"github.com/golang/glog"
26
- "volcano.sh/volcano/pkg/client/clientset/versioned"
27
23
28
- "k8s.io/api/admission/v1beta1"
29
- "k8s.io/apimachinery/pkg/runtime"
30
24
"k8s.io/client-go/kubernetes"
31
25
restclient "k8s.io/client-go/rest"
32
-
33
26
appConf "volcano.sh/volcano/cmd/admission/app/configure"
34
- admissioncontroller "volcano.sh/volcano/pkg/admission"
35
- )
36
-
37
- const (
38
- //CONTENTTYPE http content-type
39
- CONTENTTYPE = "Content-Type"
40
-
41
- //APPLICATIONJSON json content
42
- APPLICATIONJSON = "application/json"
27
+ "volcano.sh/volcano/pkg/client/clientset/versioned"
43
28
)
44
29
45
30
// GetClient Get a clientset with restConfig.
@@ -51,7 +36,7 @@ func GetClient(restConfig *restclient.Config) *kubernetes.Clientset {
51
36
return clientset
52
37
}
53
38
54
- //GetKubeBatchClient get a clientset for kubebatch
39
+ // GetKubeBatchClient get a clientset for volcano
55
40
func GetKubeBatchClient (restConfig * restclient.Config ) * versioned.Clientset {
56
41
clientset , err := versioned .NewForConfig (restConfig )
57
42
if err != nil {
@@ -89,52 +74,3 @@ func ConfigTLS(config *appConf.Config, restConfig *restclient.Config) *tls.Confi
89
74
glog .Fatal ("tls: failed to find any tls config data" )
90
75
return & tls.Config {}
91
76
}
92
-
93
- //Serve the http request
94
- func Serve (w http.ResponseWriter , r * http.Request , admit admissioncontroller.AdmitFunc ) {
95
- var body []byte
96
- if r .Body != nil {
97
- if data , err := ioutil .ReadAll (r .Body ); err == nil {
98
- body = data
99
- }
100
- }
101
-
102
- // verify the content type is accurate
103
- contentType := r .Header .Get (CONTENTTYPE )
104
- if contentType != APPLICATIONJSON {
105
- glog .Errorf ("contentType=%s, expect application/json" , contentType )
106
- return
107
- }
108
-
109
- var reviewResponse * v1beta1.AdmissionResponse
110
- ar := v1beta1.AdmissionReview {}
111
- deserializer := admissioncontroller .Codecs .UniversalDeserializer ()
112
- if _ , _ , err := deserializer .Decode (body , nil , & ar ); err != nil {
113
- reviewResponse = admissioncontroller .ToAdmissionResponse (err )
114
- } else {
115
- reviewResponse = admit (ar )
116
- }
117
- glog .V (3 ).Infof ("sending response: %v" , reviewResponse )
118
-
119
- response := createResponse (reviewResponse , & ar )
120
- resp , err := json .Marshal (response )
121
- if err != nil {
122
- glog .Error (err )
123
- }
124
- if _ , err := w .Write (resp ); err != nil {
125
- glog .Error (err )
126
- }
127
- }
128
-
129
- func createResponse (reviewResponse * v1beta1.AdmissionResponse , ar * v1beta1.AdmissionReview ) v1beta1.AdmissionReview {
130
- response := v1beta1.AdmissionReview {}
131
- if reviewResponse != nil {
132
- response .Response = reviewResponse
133
- response .Response .UID = ar .Request .UID
134
- }
135
- // reset the Object and OldObject, they are not needed in a response.
136
- ar .Request .Object = runtime.RawExtension {}
137
- ar .Request .OldObject = runtime.RawExtension {}
138
-
139
- return response
140
- }
0 commit comments