Skip to content
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

SidecarSet inject sidecar container to all Pods in some namespaces #1369

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/control/sidecarcontrol/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func PodMatchedSidecarSet(c client.Client, pod *corev1.Pod, sidecarSet *appsv1al
if err != nil {
return false, err
}
// if no selector set, return true
if selector.String() == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if selector.Empty() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selector.Empty() return false when no selector set, so I turned to selector.String() == ""

return true, nil
}

if !selector.Empty() && selector.Matches(labels.Set(pod.Labels)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the !selector.Empty()

return true, nil
Expand Down
26 changes: 26 additions & 0 deletions pkg/control/sidecarcontrol/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,32 @@ func TestPodMatchedSidecarSet(t *testing.T) {
},
expect: false,
},
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need modidy the sidecarSet webhook and controller.

And you must add e2e for this scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please review my latest pr, thanks

name: "test6",
getSidecarSet: func() *appsv1alpha1.SidecarSet {
demo := &appsv1alpha1.SidecarSet{
ObjectMeta: metav1.ObjectMeta{Name: "sidecarset-test"},
Spec: appsv1alpha1.SidecarSetSpec{
Namespace: "app1",
},
}
return demo
},
getPod: func() *corev1.Pod {
demo := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod",
Labels: map[string]string{"app": "nginx"},
Namespace: "app1",
},
}
return demo
},
getNs: func() []*corev1.Namespace {
return nil
},
expect: true,
},
}

for _, cs := range cases {
Expand Down
Loading