-
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 3 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 |
---|---|---|
|
@@ -44,6 +44,8 @@ type Config struct { | |
// ContainerRuntimeExecutor specifies the container runtime interface to use, default is docker | ||
ContainerRuntimeExecutor string `json:"containerRuntimeExecutor,omitempty"` | ||
|
||
ContainerRuntimeExecutors ContainerRuntimeExecutors `json:"containerRuntimeExecutors,omitempty"` | ||
|
||
// KubeletPort is needed when using the kubelet containerRuntimeExecutor, default to 10250 | ||
KubeletPort int `json:"kubeletPort,omitempty"` | ||
|
||
|
@@ -99,6 +101,14 @@ type Config struct { | |
InitialDelay metav1.Duration `json:"initialDelay,omitempty"` | ||
} | ||
|
||
func (c Config) GetContainerRuntimeExecutor(labels labels.Labels) (string, error) { | ||
name, err := c.ContainerRuntimeExecutors.Select(labels) | ||
if name != "" { | ||
return name, err | ||
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. Looks like err is always nil in this case so return 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 know it is odd looking, but I think it is correct. 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. this is because it can return |
||
} | ||
return c.ContainerRuntimeExecutor, err | ||
} | ||
|
||
// PodSpecLogStrategy contains the configuration for logging the pod spec in controller log for debugging purpose | ||
type PodSpecLogStrategy struct { | ||
FailedPod bool `json:"failedPod,omitempty"` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package config | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
) | ||
|
||
type ContainerRuntimeExecutors []ContainerRuntimeExecutor | ||
|
||
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,45 @@ | ||
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{"!": "!"}, | ||
}, | ||
}, | ||
} | ||
e, err := x.Select(labels.Set(map[string]string{"bar": ""})) | ||
assert.Error(t, err) | ||
assert.Empty(t, e) | ||
}) | ||
|
||
} |
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"