Integrate apiserver with provider GetContainerLogs
This commit is contained in:
@@ -31,7 +31,7 @@ type ACIProvider struct {
|
||||
cpu string
|
||||
memory string
|
||||
pods string
|
||||
internalIP string
|
||||
internalIP string
|
||||
}
|
||||
|
||||
// AuthConfig is the secret returned from an ImageRegistryCredential
|
||||
@@ -196,9 +196,9 @@ func (p *ACIProvider) GetPod(namespace, name string) (*v1.Pod, error) {
|
||||
}
|
||||
|
||||
// GetPodLogs returns the logs of a pod by name that is running inside ACI.
|
||||
func (p *ACIProvider) GetPodLogs(namespace, name string) (string, error) {
|
||||
func (p *ACIProvider) GetContainerLogs(namespace, podName, containerName string) (string, error) {
|
||||
logContent := ""
|
||||
cg, err := p.aciClient.GetContainerGroup(p.resourceGroup, name)
|
||||
cg, err := p.aciClient.GetContainerGroup(p.resourceGroup, fmt.Sprintf("%s-%s", namespace, podName))
|
||||
if err != nil {
|
||||
// Trap error for 404 and return gracefully
|
||||
if strings.Contains(err.Error(), "ResourceNotFound") {
|
||||
@@ -213,18 +213,15 @@ func (p *ACIProvider) GetPodLogs(namespace, name string) (string, error) {
|
||||
// get logs from cg
|
||||
retry := 10
|
||||
for i := 0; i < retry; i++ {
|
||||
cLogs, err := p.aciClient.GetContainerLogs(p.resourceGroup, cg.Name, name, 10)
|
||||
|
||||
cLogs, err := p.aciClient.GetContainerLogs(p.resourceGroup, cg.Name, containerName, 10)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
time.Sleep(5000 * time.Millisecond)
|
||||
} else {
|
||||
break
|
||||
logContent = cLogs.Content
|
||||
return logContent, nil
|
||||
break
|
||||
}
|
||||
}
|
||||
// create pod logs
|
||||
|
||||
return logContent, err
|
||||
}
|
||||
@@ -332,8 +329,8 @@ func (p *ACIProvider) NodeAddresses() []v1.NodeAddress {
|
||||
// TODO: Make these dynamic and augment with custom ACI specific conditions of interest
|
||||
return []v1.NodeAddress{
|
||||
{
|
||||
Type: "InternalIP",
|
||||
Address: p.internalIP,
|
||||
Type: "InternalIP",
|
||||
Address: p.internalIP,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,19 @@ package vkubelet
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
//"k8s.io/api/core/v1"
|
||||
"strings"
|
||||
)
|
||||
var p Provider
|
||||
|
||||
func ApiServerStart() error {
|
||||
http.HandleFunc("/", HelloServer)
|
||||
func ApiserverStart(provider Provider) error {
|
||||
p = provider
|
||||
http.HandleFunc("/", ApiServerHandler)
|
||||
certValue64 := os.Getenv("APISERVER_CERT")
|
||||
keyValue64 := os.Getenv("APISERVER_KEY")
|
||||
certValue, err := base64.StdEncoding.DecodeString(certValue64)
|
||||
@@ -42,9 +45,23 @@ func ApiServerStart() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func HelloServer(w http.ResponseWriter, req *http.Request) {
|
||||
log.Println("handler called")
|
||||
///containerLogs/{namespace}/{pd}/{container}
|
||||
log.Println(req)
|
||||
io.WriteString(w, "ack!\n")
|
||||
func ApiServerHandler(w http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "GET" {
|
||||
if strings.ContainsAny(req.RequestURI, "containerLogs" ) {
|
||||
reqParts := strings.Split(req.RequestURI, "/")
|
||||
if len(reqParts) == 5 {
|
||||
namespace := reqParts[2]
|
||||
pod := reqParts[3]
|
||||
container := reqParts[4]
|
||||
podsLogs, err := p.GetContainerLogs(namespace, pod, container)
|
||||
if err != nil {
|
||||
fmt.Errorf("Error getting logs for pod '%s': %s", pod, err)
|
||||
io.WriteString(w, err.Error())
|
||||
} else {
|
||||
io.WriteString(w, podsLogs)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,8 @@ type Provider interface {
|
||||
// GetPod retrieves a pod by name from the provider (can be cached).
|
||||
GetPod(namespace, name string) (*v1.Pod, error)
|
||||
|
||||
// GetPodLogs retrieves the logs of a pod by name from the provider.
|
||||
GetPodLogs(namespace, name string) (string, error)
|
||||
// GetContainerLogs retrieves the logs of a container by name from the provider.
|
||||
GetContainerLogs(namespace, podName, containerName string) (string, error)
|
||||
|
||||
// GetPodStatus retrieves the status of a pod by name from the provider.
|
||||
GetPodStatus(namespace, name string) (*v1.PodStatus, error)
|
||||
|
||||
@@ -60,8 +60,6 @@ func New(nodeName, operatingSystem, namespace, kubeConfig, taint, provider, prov
|
||||
}
|
||||
|
||||
rm := manager.NewResourceManager(clientset)
|
||||
go ApiServerStart()
|
||||
log.Println("vkubelet apiserver started")
|
||||
|
||||
var p Provider
|
||||
switch provider {
|
||||
@@ -93,6 +91,8 @@ func New(nodeName, operatingSystem, namespace, kubeConfig, taint, provider, prov
|
||||
return s, err
|
||||
}
|
||||
|
||||
go ApiserverStart(p)
|
||||
|
||||
tick := time.Tick(5 * time.Second)
|
||||
go func() {
|
||||
for range tick {
|
||||
|
||||
Reference in New Issue
Block a user