This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Adds log plumbing for basic container tasks only. 2. Sets up some basic helper code that reads configs in order to create log links. This will be refactored later.
- Loading branch information
1 parent
01a95bf
commit 37a7609
Showing
8 changed files
with
239 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package k8splugins | ||
|
||
import ( | ||
logUtils "github.com/lyft/flyteidl/clients/go/coreutils/logs" | ||
"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core" | ||
plugins "github.com/lyft/flyteplugins/go/tasks/v1" | ||
"k8s.io/api/core/v1" | ||
) | ||
|
||
var GetLogConfig = plugins.GetLogConfig | ||
|
||
func GetLogsForContainerInPod(pod *v1.Pod, index uint32, nameSuffix string) ([]*core.TaskLog, error) { | ||
var logs []*core.TaskLog | ||
logConfig := GetLogConfig() | ||
|
||
if logConfig.IsKubernetesEnabled { | ||
k8sLog, err := logUtils.NewKubernetesLogPlugin(logConfig.KubernetesUrl).GetTaskLog( | ||
pod.Name, | ||
pod.Namespace, | ||
pod.Spec.Containers[index].Name, | ||
pod.Status.ContainerStatuses[index].ContainerID, | ||
"Kubernetes Logs"+nameSuffix) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
logs = append(logs, &k8sLog) | ||
} | ||
|
||
if logConfig.IsCloudwatchEnabled { | ||
cwLogs, err := logUtils.NewCloudwatchLogPlugin(logConfig.AwsRegion).GetTaskLog( | ||
pod.Name, | ||
pod.Namespace, | ||
pod.Spec.Containers[index].Name, | ||
pod.Status.ContainerStatuses[index].ContainerID, | ||
"Cloudwatch Logs"+nameSuffix) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
logs = append(logs, &cwLogs) | ||
} | ||
|
||
return logs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package k8splugins | ||
|
||
import ( | ||
plugins "github.com/lyft/flyteplugins/go/tasks/v1" | ||
"github.com/stretchr/testify/assert" | ||
"k8s.io/api/core/v1" | ||
"testing" | ||
) | ||
|
||
func TestGetLogsForContainerInPod_NoLogs(t *testing.T) { | ||
oldGetConfig := GetLogConfig | ||
|
||
// TODO: Refactor for dependency injection and remove | ||
defer func() { GetLogConfig = oldGetConfig }() | ||
|
||
GetLogConfig = func() *plugins.LogConfig { | ||
return &plugins.LogConfig{} | ||
} | ||
|
||
logs, err := GetLogsForContainerInPod(nil, 0, " Suffix") | ||
assert.Nil(t, err) | ||
assert.Len(t, logs, 0) | ||
} | ||
|
||
func TestGetLogsForContainerInPod_Cloudwatch(t *testing.T) { | ||
oldGetConfig := GetLogConfig | ||
|
||
// TODO: Refactor for dependency injection and remove | ||
defer func() { GetLogConfig = oldGetConfig }() | ||
|
||
GetLogConfig = func() *plugins.LogConfig { | ||
return &plugins.LogConfig{ | ||
IsCloudwatchEnabled: true, | ||
AwsRegion: "us-east-1", | ||
} | ||
} | ||
|
||
pod := &v1.Pod{ | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "ContainerName", | ||
}, | ||
}, | ||
}, | ||
Status: v1.PodStatus{ | ||
ContainerStatuses: []v1.ContainerStatus{ | ||
{ | ||
ContainerID: "ContainerID", | ||
}, | ||
}, | ||
}, | ||
} | ||
pod.Name = "PodName" | ||
|
||
logs, err := GetLogsForContainerInPod(pod, 0, " Suffix") | ||
assert.Nil(t, err) | ||
assert.Len(t, logs, 1) | ||
} | ||
|
||
func TestGetLogsForContainerInPod_K8s(t *testing.T) { | ||
oldGetConfig := GetLogConfig | ||
|
||
// TODO: Refactor for dependency injection and remove | ||
defer func() { GetLogConfig = oldGetConfig }() | ||
|
||
GetLogConfig = func() *plugins.LogConfig { | ||
return &plugins.LogConfig{ | ||
IsKubernetesEnabled: true, | ||
KubernetesUrl: "k8s.com", | ||
} | ||
} | ||
|
||
pod := &v1.Pod{ | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "ContainerName", | ||
}, | ||
}, | ||
}, | ||
Status: v1.PodStatus{ | ||
ContainerStatuses: []v1.ContainerStatus{ | ||
{ | ||
ContainerID: "ContainerID", | ||
}, | ||
}, | ||
}, | ||
} | ||
pod.Name = "PodName" | ||
|
||
logs, err := GetLogsForContainerInPod(pod, 0, " Suffix") | ||
assert.Nil(t, err) | ||
assert.Len(t, logs, 1) | ||
} | ||
|
||
func TestGetLogsForContainerInPod_All(t *testing.T) { | ||
oldGetConfig := GetLogConfig | ||
|
||
// TODO: Refactor for dependency injection and remove | ||
defer func() { GetLogConfig = oldGetConfig }() | ||
|
||
GetLogConfig = func() *plugins.LogConfig { | ||
return &plugins.LogConfig{ | ||
IsKubernetesEnabled: true, | ||
KubernetesUrl: "k8s.com", | ||
IsCloudwatchEnabled: true, | ||
AwsRegion: "us-east-1", | ||
} | ||
} | ||
|
||
pod := &v1.Pod{ | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "ContainerName", | ||
}, | ||
}, | ||
}, | ||
Status: v1.PodStatus{ | ||
ContainerStatuses: []v1.ContainerStatus{ | ||
{ | ||
ContainerID: "ContainerID", | ||
}, | ||
}, | ||
}, | ||
} | ||
pod.Name = "PodName" | ||
|
||
logs, err := GetLogsForContainerInPod(pod, 0, " Suffix") | ||
assert.Nil(t, err) | ||
assert.Len(t, logs, 2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.