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

Fix linkerd-cni when using native sidecars #362

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
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
27 changes: 18 additions & 9 deletions cni-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ func cmdAdd(args *skel.CmdArgs) error {
return err
}

containsLinkerdProxy := false
for _, container := range pod.Spec.Containers {
if container.Name == "linkerd-proxy" {
containsLinkerdProxy = true
break
}
}

containsInitContainer := false
for _, container := range pod.Spec.InitContainers {
if container.Name == "linkerd-init" {
Expand All @@ -208,7 +200,7 @@ func cmdAdd(args *skel.CmdArgs) error {
}
}

if containsLinkerdProxy && !containsInitContainer {
if !containsInitContainer && containsLinkerdProxy(&pod.Spec) {
logEntry.Debugf("linkerd-cni: setting up iptables firewall for %s/%s", namespace, pod)
options := cmd.RootOptions{
IncomingProxyPort: conf.ProxyInit.IncomingProxyPort,
Expand Down Expand Up @@ -345,6 +337,23 @@ func cmdDel(_ *skel.CmdArgs) error {
return nil
}

func containsLinkerdProxy(spec *v1.PodSpec) bool {
for _, container := range spec.Containers {
if container.Name == "linkerd-proxy" {
return true
}
}

// native sidecar proxy
for _, container := range spec.InitContainers {
if container.Name == "linkerd-proxy" {
return true
}
}

return false
}

func getAPIServerPorts(ctx context.Context, api *kubernetes.Clientset) ([]string, error) {
service, err := api.CoreV1().Services("default").Get(ctx, "kubernetes", metav1.GetOptions{})
if err != nil {
Expand Down
Loading