Skip to content

Commit

Permalink
SidecarSet inject sidecar container to all Pods in some namespaces
Browse files Browse the repository at this point in the history
Signed-off-by: pingjiang <xiangpingjiang1998@gmail.com>
  • Loading branch information
xiangpingjiang committed Aug 15, 2023
1 parent 321c991 commit 05ffe4a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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 ture

Check warning on line 106 in pkg/control/sidecarcontrol/util.go

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"ture" should be "true".
if selector.String() == "" {
return true, nil
}

if !selector.Empty() && selector.Matches(labels.Set(pod.Labels)) {
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,
},
{
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

0 comments on commit 05ffe4a

Please sign in to comment.