@@ -4,8 +4,10 @@ import (
4
4
"bytes"
5
5
"context"
6
6
"encoding/json"
7
+ "fmt"
7
8
"io/ioutil"
8
9
"net/http"
10
+ "os"
9
11
"strings"
10
12
11
13
common "github.com/CARV-ICS-FORTH/knoc/common"
@@ -18,7 +20,7 @@ import (
18
20
19
21
var NoReq uint8
20
22
21
- func createRequest (pod commonIL.Request ) []byte {
23
+ func createRequest (pod commonIL.Request , token string ) []byte {
22
24
var returnValue , _ = json .Marshal (commonIL.PodStatus {PodStatus : commonIL .UNKNOWN })
23
25
24
26
bodyBytes , err := json .Marshal (pod )
@@ -29,6 +31,7 @@ func createRequest(pod commonIL.Request) []byte {
29
31
log .L .Error (err )
30
32
}
31
33
34
+ req .Header .Add ("Authorization" , "Bearer " + token )
32
35
resp , err := http .DefaultClient .Do (req )
33
36
if err != nil {
34
37
log .L .Error (err )
@@ -41,7 +44,7 @@ func createRequest(pod commonIL.Request) []byte {
41
44
return returnValue
42
45
}
43
46
44
- func deleteRequest (pod commonIL.Request ) []byte {
47
+ func deleteRequest (pod commonIL.Request , token string ) []byte {
45
48
var returnValue , _ = json .Marshal (commonIL.PodStatus {PodStatus : commonIL .UNKNOWN })
46
49
47
50
bodyBytes , err := json .Marshal (pod )
@@ -51,6 +54,7 @@ func deleteRequest(pod commonIL.Request) []byte {
51
54
log .L .Error (err )
52
55
}
53
56
57
+ req .Header .Add ("Authorization" , "Bearer " + token )
54
58
resp , err := http .DefaultClient .Do (req )
55
59
if err != nil {
56
60
log .L .Error (err )
@@ -63,7 +67,7 @@ func deleteRequest(pod commonIL.Request) []byte {
63
67
return returnValue
64
68
}
65
69
66
- func statusRequest (podsList commonIL.Request ) []byte {
70
+ func statusRequest (podsList commonIL.Request , token string ) []byte {
67
71
var returnValue []byte
68
72
var response []commonIL.StatusResponse
69
73
@@ -76,6 +80,8 @@ func statusRequest(podsList commonIL.Request) []byte {
76
80
77
81
log .L .Println (string (bodyBytes ))
78
82
83
+ req .Header .Add ("Authorization" , "Bearer " + token )
84
+
79
85
resp , err := http .DefaultClient .Do (req )
80
86
if err != nil {
81
87
log .L .Error (err )
@@ -91,26 +97,32 @@ func RemoteExecution(p *VirtualKubeletProvider, ctx context.Context, mode int8,
91
97
var req commonIL.Request
92
98
req .Pods = map [string ]* v1.Pod {pod .Name : pod }
93
99
100
+ b , err := os .ReadFile (commonIL .InterLinkConfigInst .VKTokenFile ) // just pass the file name
101
+ if err != nil {
102
+ fmt .Print (err )
103
+ }
104
+ token := string (b )
105
+
94
106
switch mode {
95
107
case common .CREATE :
96
108
//v1.Pod used only for secrets and volumes management; TO BE IMPLEMENTED
97
- returnVal := createRequest (req )
109
+ returnVal := createRequest (req , token )
98
110
log .L .Println (string (returnVal ))
99
111
break
100
112
101
113
case common .DELETE :
102
114
if NoReq > 0 {
103
115
NoReq --
104
116
} else {
105
- returnVal := deleteRequest (req )
117
+ returnVal := deleteRequest (req , token )
106
118
log .L .Println (string (returnVal ))
107
119
}
108
120
break
109
121
}
110
122
return nil
111
123
}
112
124
113
- func checkPodsStatus (p * VirtualKubeletProvider , ctx context.Context ) {
125
+ func checkPodsStatus (p * VirtualKubeletProvider , ctx context.Context , token string ) {
114
126
if len (p .pods ) == 0 {
115
127
return
116
128
}
@@ -119,7 +131,7 @@ func checkPodsStatus(p *VirtualKubeletProvider, ctx context.Context) {
119
131
var PodsList commonIL.Request
120
132
PodsList .Pods = p .pods
121
133
122
- returnVal = statusRequest (PodsList )
134
+ returnVal = statusRequest (PodsList , token )
123
135
json .Unmarshal (returnVal , & ret )
124
136
125
137
for podIndex , podStatus := range ret .PodStatus {
0 commit comments