Enable kubectl logs po

This commit is contained in:
Rita Zhang
2017-12-11 20:25:54 -08:00
parent 57996b44c4
commit e0c9da5d95
5 changed files with 123 additions and 3 deletions

View File

@@ -31,6 +31,7 @@ type ACIProvider struct {
cpu string
memory string
pods string
internalIP string
}
// AuthConfig is the secret returned from an ImageRegistryCredential
@@ -45,7 +46,7 @@ type AuthConfig struct {
}
// NewACIProvider creates a new ACIProvider.
func NewACIProvider(config string, rm *manager.ResourceManager, nodeName, operatingSystem string) (*ACIProvider, error) {
func NewACIProvider(config string, rm *manager.ResourceManager, nodeName, operatingSystem string, internalIP string) (*ACIProvider, error) {
var p ACIProvider
var err error
@@ -89,6 +90,7 @@ func NewACIProvider(config string, rm *manager.ResourceManager, nodeName, operat
p.operatingSystem = operatingSystem
p.nodeName = nodeName
p.internalIP = internalIP
return &p, err
}
@@ -193,6 +195,40 @@ func (p *ACIProvider) GetPod(namespace, name string) (*v1.Pod, error) {
return containerGroupToPod(cg)
}
// GetPodLogs returns the logs of a pod by name that is running inside ACI.
func (p *ACIProvider) GetPodLogs(namespace, name string) (string, error) {
logContent := ""
cg, err := p.aciClient.GetContainerGroup(p.resourceGroup, name)
if err != nil {
// Trap error for 404 and return gracefully
if strings.Contains(err.Error(), "ResourceNotFound") {
return logContent, nil
}
return logContent, err
}
if cg.Tags["NodeName"] != p.nodeName {
return logContent, nil
}
// get logs from cg
retry := 10
for i := 0; i < retry; i++ {
cLogs, err := p.aciClient.GetContainerLogs(p.resourceGroup, cg.Name, name, 10)
if err != nil {
log.Println(err)
time.Sleep(5000 * time.Millisecond)
} else {
break
logContent = cLogs.Content
return logContent, nil
}
}
// create pod logs
return logContent, err
}
// GetPodStatus returns the status of a pod by name that is running inside ACI
// returns nil if a pod by that name is not found.
func (p *ACIProvider) GetPodStatus(namespace, name string) (*v1.PodStatus, error) {
@@ -290,6 +326,18 @@ func (p *ACIProvider) NodeConditions() []v1.NodeCondition {
}
}
// NodeAddresses returns a list of addresses for the node status
// within Kuberentes.
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,
},
}
}
// OperatingSystem returns the operating system that was provided by the config.
func (p *ACIProvider) OperatingSystem() string {
return p.operatingSystem

View File

@@ -139,6 +139,11 @@ func (p *HyperProvider) GetPod(namespace, name string) (*v1.Pod, error) {
return nil, nil
}
// GetPodLogs returns the logs of a pod by name.
func (p *HyperProvider) GetPodLogs(namespace, name string) (string, error) {
return "", nil
}
// GetPodStatus returns the status of a pod by name that is running inside hyper.sh
// returns nil if a pod by that name is not found.
func (p *HyperProvider) GetPodStatus(namespace, name string) (*v1.PodStatus, error) {
@@ -224,6 +229,12 @@ func (p *HyperProvider) NodeConditions() []v1.NodeCondition {
}
// NodeAddresses returns a list of addresses for the node status
// within Kuberentes.
func (p *HyperProvider) NodeAddresses() []v1.NodeAddress {
return nil
}
// OperatingSystem returns the operating system for this provider.
// This is a noop to default to Linux for now.
func (p *HyperProvider) OperatingSystem() string {