-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kuma-cni): support port exclusion for UIDs (#8319)
* fix(kuma-cni): support for 'traffic.kuma.io/exclude-outbound-tcp-ports-for-uids' and 'traffic.kuma.io/exclude-outbound-udp-ports-for-uids' annotations Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com> * fix(kuma-cni): make check Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com> * fix(kuma-cni): fix test Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com> * fix(kuma-cni): remove node cleanup Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com> * fix(kuma-cni): replace with a single annotation Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com> * fix(kuma-cni): add comments, pass 'kuma.io/sidecar-uid' to CNI Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com> --------- Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
- Loading branch information
1 parent
3550457
commit c06cc52
Showing
7 changed files
with
174 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cni | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("NewIntermediateConfig", func() { | ||
It("should set UID to default value if annotation is not specified", func() { | ||
a := map[string]string{} | ||
cfg, err := NewIntermediateConfig(a) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(cfg.noRedirectUID).To(Equal(defaultNoRedirectUID)) | ||
}) | ||
|
||
It("should override UID when annotation is specified", func() { | ||
a := map[string]string{ | ||
"kuma.io/sidecar-uid": "1234", | ||
} | ||
cfg, err := NewIntermediateConfig(a) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(cfg.noRedirectUID).To(Equal("1234")) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package cni | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/gruntwork-io/terratest/modules/random" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
|
||
"github.com/kumahq/kuma/pkg/config/core" | ||
"github.com/kumahq/kuma/pkg/plugins/runtime/k8s/metadata" | ||
"github.com/kumahq/kuma/pkg/util/pointer" | ||
. "github.com/kumahq/kuma/test/framework" | ||
"github.com/kumahq/kuma/test/framework/deployments/testserver" | ||
) | ||
|
||
func ExcludeOutboundPort() { | ||
meshName := "exclude-outbound-port" | ||
|
||
namespace := "exclude-outbound-port" | ||
namespaceExternal := "exclude-outbound-port-external" | ||
|
||
var cluster Cluster | ||
var k8sCluster *K8sCluster | ||
|
||
BeforeAll(func() { | ||
k8sCluster = NewK8sCluster(NewTestingT(), Kuma1, Silent) | ||
cluster = k8sCluster. | ||
WithTimeout(6 * time.Second). | ||
WithRetries(60) | ||
|
||
releaseName := fmt.Sprintf("kuma-%s", strings.ToLower(random.UniqueId())) | ||
|
||
Expect(NewClusterSetup(). | ||
Install(Kuma(core.Standalone, | ||
WithInstallationMode(HelmInstallationMode), | ||
WithHelmReleaseName(releaseName), | ||
WithSkipDefaultMesh(true), // it's common case for HELM deployments that Mesh is also managed by HELM therefore it's not created by default | ||
WithHelmOpt("cni.delayStartupSeconds", "40"), | ||
WithHelmOpt("cni.logLevel", "debug"), | ||
WithCNI(), | ||
)). | ||
Install(MTLSMeshKubernetes(meshName)). | ||
Install(NamespaceWithSidecarInjection(namespace)). | ||
Install(Namespace(namespaceExternal)). | ||
Install(testserver.Install( | ||
testserver.WithName("test-server"), | ||
testserver.WithMesh(meshName), | ||
testserver.WithNamespace(namespaceExternal), | ||
)). | ||
Setup(cluster)).To(Succeed()) | ||
}) | ||
|
||
E2EAfterAll(func() { | ||
Expect(cluster.DeleteNamespace(namespace)).To(Succeed()) | ||
Expect(cluster.DeleteNamespace(namespaceExternal)).To(Succeed()) | ||
Expect(cluster.DeleteKuma()).To(Succeed()) | ||
Expect(cluster.DismissCluster()).To(Succeed()) | ||
}) | ||
|
||
It("should be able to use network from init container if we ignore ports for uid", func() { | ||
Expect(cluster.Install(testserver.Install( | ||
testserver.WithName("test-server"), | ||
testserver.WithMesh(meshName), | ||
testserver.WithNamespace(namespace), | ||
testserver.WithPodAnnotations(map[string]string{ | ||
metadata.KumaTrafficExcludeOutboundPortsForUIDs: "tcp:80:1234;udp:53:1234", | ||
}), | ||
testserver.AddInitContainer(corev1.Container{ | ||
Name: "init-test-server", | ||
Image: Config.GetUniversalImage(), | ||
ImagePullPolicy: "IfNotPresent", | ||
Command: []string{"curl"}, | ||
Args: []string{"-v", "-m", "3", "--fail", "test-server.exclude-outbound-port-external.svc.cluster.local:80"}, | ||
Resources: corev1.ResourceRequirements{ | ||
Limits: corev1.ResourceList{ | ||
"cpu": resource.MustParse("50m"), | ||
"memory": resource.MustParse("64Mi"), | ||
}, | ||
}, | ||
SecurityContext: &corev1.SecurityContext{ | ||
RunAsUser: pointer.To(int64(1234)), | ||
}, | ||
}), | ||
))).To(Succeed()) | ||
}) | ||
} |