Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit b80c8a9

Browse files
committed
more tests
Signed-off-by: Kevin Su <pingsutw@apache.org>
1 parent 10be909 commit b80c8a9

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package k8s
2+
3+
import (
4+
"testing"
5+
6+
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s"
7+
"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/flytek8s/config"
8+
"gotest.tools/assert"
9+
v1 "k8s.io/api/core/v1"
10+
)
11+
12+
func TestGetTaskContainerTask(t *testing.T) {
13+
pod := &v1.Pod{
14+
Spec: v1.PodSpec{
15+
Containers: []v1.Container{
16+
{
17+
Name: "PrimaryContainer",
18+
},
19+
},
20+
},
21+
}
22+
index, err := getTaskContainerIndex(pod)
23+
assert.NilError(t, err)
24+
assert.Equal(t, index, 0)
25+
26+
pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{Name: config.GetK8sPluginConfig().CoPilot.NamePrefix + flytek8s.Sidecar})
27+
index, err = getTaskContainerIndex(pod)
28+
assert.NilError(t, err)
29+
assert.Equal(t, index, 0)
30+
31+
pod.Annotations = map[string]string{flytek8s.PrimaryContainerKey: "PrimaryContainer"}
32+
index, err = getTaskContainerIndex(pod)
33+
assert.NilError(t, err)
34+
assert.Equal(t, index, 0)
35+
36+
pod.Spec.Containers[0].Name = "SecondaryContainer"
37+
_, err = getTaskContainerIndex(pod)
38+
assert.ErrorContains(t, err, "Couldn't find any container matching the primary container")
39+
40+
}

go/tasks/plugins/k8s/pod/plugin.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,10 @@ func (p plugin) GetTaskPhase(ctx context.Context, pluginContext k8s.PluginContex
146146

147147
func (plugin) GetTaskPhaseWithLogs(ctx context.Context, pluginContext k8s.PluginContext, r client.Object, logPlugin tasklog.Plugin, logSuffix string) (pluginsCore.PhaseInfo, error) {
148148
pluginState := k8s.PluginState{}
149-
var err error
150-
//_, err := pluginContext.PluginStateReader().Get(&pluginState)
151-
//if err != nil {
152-
// logger.Errorf(ctx, "kevin test [%v]", err)
153-
// return pluginsCore.PhaseInfoUndefined, err
154-
//}
149+
_, err := pluginContext.PluginStateReader().Get(&pluginState)
150+
if err != nil {
151+
return pluginsCore.PhaseInfoUndefined, err
152+
}
155153

156154
pod := r.(*v1.Pod)
157155

0 commit comments

Comments
 (0)