-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(controller): Use different container runtime executors for each workflow. Close #4254 #4998
Changes from 6 commits
510cbc0
d60a1e8
72cbf95
dd82cd5
8b0f787
750a37a
9d56520
0dba822
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package config | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
) | ||
|
||
type ContainerRuntimeExecutors []ContainerRuntimeExecutor | ||
|
||
// select the correct executor to use | ||
// this may return an empty string of there is not executor found | ||
func (e ContainerRuntimeExecutors) Select(labels labels.Labels) (string, error) { | ||
for _, c := range e { | ||
ok, err := c.Matches(labels) | ||
if err != nil { | ||
return "", err | ||
} | ||
if ok { | ||
return c.Name, nil | ||
} | ||
} | ||
return "", nil | ||
} | ||
|
||
type ContainerRuntimeExecutor struct { | ||
Name string `json:"name"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that "type" and "name" are synonymous. I.e. there is only one executor of type "pns", it is the "pns" executor. I'm not sure about the correct term here, but I'd like to leave this called "name" unless you feel strongly? |
||
Selector metav1.LabelSelector `json:"selector"` | ||
} | ||
|
||
func (e ContainerRuntimeExecutor) Matches(labels labels.Labels) (bool, error) { | ||
x, err := metav1.LabelSelectorAsSelector(&e.Selector) | ||
if err != nil { | ||
return false, err | ||
} | ||
return x.Matches(labels), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
) | ||
|
||
func TestContainerRuntimeExecutors(t *testing.T) { | ||
t.Run("Empty", func(t *testing.T) { | ||
x := ContainerRuntimeExecutors{} | ||
e, err := x.Select(labels.Set{}) | ||
assert.NoError(t, err) | ||
assert.Empty(t, e) | ||
}) | ||
t.Run("Select", func(t *testing.T) { | ||
x := ContainerRuntimeExecutors{ | ||
{ | ||
Name: "foo", | ||
Selector: metav1.LabelSelector{ | ||
MatchLabels: map[string]string{"bar": ""}, | ||
}, | ||
}, | ||
} | ||
e, err := x.Select(labels.Set(map[string]string{"bar": ""})) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "foo", e) | ||
}) | ||
t.Run("Error", func(t *testing.T) { | ||
x := ContainerRuntimeExecutors{ | ||
{ | ||
Name: "foo", | ||
Selector: metav1.LabelSelector{ | ||
MatchLabels: map[string]string{"!": "!"}, | ||
}, | ||
}, | ||
} | ||
_, err := x.Select(labels.Set(map[string]string{"bar": ""})) | ||
assert.Error(t, err) | ||
}) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we log the error if it is not nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to re-write this confusing code to make it clearer and less "clever"