public async Task Two_Namespace_Will_Create_A_Error() { // Arrange var namespaceName = "namespace-from-test"; var awsRoleName = "awsRoleName"; var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); var client = new k8s.Kubernetes(config); var sut = new NamespaceRespoitory(client); try { await sut.CreateNamespace(namespaceName, awsRoleName); // Act var ex = await Assert.ThrowsAsync <Exception>(async() => await sut.CreateNamespace(namespaceName, awsRoleName)); // Assert var expectedStart = "Error occured while communicating with k8s:"; Assert.StartsWith(expectedStart, ex.Message); } finally { client.DeleteNamespace( body: new V1DeleteOptions(), name: namespaceName ); } }
public async Task Create_A_Role_For_A_Existing_Namespace() { // Arrange var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); var client = new k8s.Kubernetes(config); var wrapper = new KubernetesWrapper(client); var namespaceRepository = new NamespaceRepository(wrapper); var subjectNameSpace = "namespace-with-role-test-" + Guid.NewGuid().ToString().Substring(0, 5); var awsRoleName = "notUSed"; var sut = new WebApi.Repositories.Kubernetes.RoleRepository(wrapper); try { // Act await namespaceRepository.CreateNamespaceAsync(subjectNameSpace, awsRoleName); await sut.CreateNamespaceFullAccessRole(subjectNameSpace); // Assert client.ListNamespacedRole(subjectNameSpace).Items.Single(); } finally { client.DeleteNamespace( body: new V1DeleteOptions(), name: subjectNameSpace ); } }
public async Task A_Created_Namespace_Will_Have_the_KIAM_Annotation() { // Arrange var namespaceName = "namespace-from-test"; var awsRoleName = "awsRoleName"; var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); var client = new k8s.Kubernetes(config); var sut = new NamespaceRespoitory(client); try { // act await sut.CreateNamespace(namespaceName, awsRoleName); // Assert var namespaces = await client.ListNamespaceAsync(); var @namespace = namespaces.Items.Single(n => n.Metadata.Name == namespaceName); var annotationValue = @namespace.Metadata.Annotations["iam.amazonaws.com/permitted"]; Assert.Equal(awsRoleName, annotationValue); } finally { client.DeleteNamespace( body: new V1DeleteOptions(), name: namespaceName ); } }
public async Task Create_already_existing_role_should_result_in_typed_exception() { // Arrange var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); var client = new k8s.Kubernetes(config); var wrapper = new KubernetesWrapper(client); var namespaceRepository = new NamespaceRepository(wrapper); var subjectNameSpace = "namespace-with-role-test-" + Guid.NewGuid().ToString().Substring(0, 5); var awsRoleName = "notUSed"; var sut = new WebApi.Repositories.Kubernetes.RoleRepository(wrapper); try { // Act await namespaceRepository.CreateNamespaceAsync(subjectNameSpace, awsRoleName); await sut.CreateNamespaceFullAccessRole(subjectNameSpace); // Assert await Assert.ThrowsAsync <RoleAlreadyExistException>(() => sut.CreateNamespaceFullAccessRole(subjectNameSpace)); } finally { client.DeleteNamespace( body: new V1DeleteOptions(), name: subjectNameSpace ); } }
public async Task Two_Namespace_Will_Create_A_Error() { // Arrange var namespaceName = "namespace-from-test-" + Guid.NewGuid().ToString().Substring(0, 5); var awsRoleName = "awsRoleName"; var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); var client = new k8s.Kubernetes(config); var sut = new NamespaceRepository(new KubernetesWrapper(client)); try { await sut.CreateNamespaceAsync(namespaceName, awsRoleName); // Act / Assert await Assert.ThrowsAsync <NamespaceAlreadyExistException>(async() => await sut.CreateNamespaceAsync(namespaceName, awsRoleName)); } finally { client.DeleteNamespace( body: new V1DeleteOptions(), name: namespaceName ); } }
public async Task Bind_To_A_Existing_Namespace() { var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); var client = new k8s.Kubernetes(config); var wrapper = new KubernetesWrapper(client); var namespaceRepository = new NamespaceRespoitory(client); var roleRepository = new WebApi.Repositories.Kubernetes.RoleRepository(wrapper); var sut = new WebApi.Repositories.Kubernetes.RoleBindingRepository(client); var subjectNameSpace = "namespace-with-role-test"; var awsRoleName = "notUSed"; var groupName = "a-test-group"; try { await namespaceRepository.CreateNamespace(subjectNameSpace, awsRoleName); var roleName = await roleRepository.CreateNamespaceFullAccessRole(subjectNameSpace); // Act await sut.BindNamespaceRoleToGroup( subjectNameSpace, roleName, groupName ); // Assert var roleBindings = await client.ListNamespacedRoleBindingAsync(subjectNameSpace); roleBindings.Items.Single(); } finally { client.DeleteNamespace( body: new V1DeleteOptions(), name: subjectNameSpace ); } }
public async Task AddAnnotations_will_not_override_annotations() { // Arrange var namespaceName = NamespaceName.Create("namespace-from-test-" + Guid.NewGuid().ToString().Substring(0, 5)); var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); var client = new k8s.Kubernetes(config); var sut = new NamespaceRepository(client); try { await sut.CreateNamespaceAsync(namespaceName); var annotationsRoundOne = new Dictionary <string, string> { { "type-a", "ab" }, { "type-b", "bc" } }; await sut.AddAnnotations(namespaceName, annotationsRoundOne); var annotationsRoundTwo = new Dictionary <string, string> { { "type-a", "not ab" } }; // Act / Assert Assert.ThrowsAsync <Exception>(async() => await sut.AddAnnotations(namespaceName, annotationsRoundTwo)); } finally { client.DeleteNamespace( body: new V1DeleteOptions(), name: namespaceName ); } }
public async Task AddAnnotations_can_add_annotations_when_none_exits() { var namespaceName = NamespaceName.Create("namespace-from-test-" + Guid.NewGuid().ToString().Substring(0, 5)); var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); var client = new k8s.Kubernetes(config); var sut = new NamespaceRepository(client); try { await sut.CreateNamespaceAsync(namespaceName); var annotations = new Dictionary <string, string> { { "type-a", "ab" }, { "type-b", "bc" } }; // Act await sut.AddAnnotations(namespaceName, annotations); // Assert var resultNamespace = client.ReadNamespace(namespaceName); var resultAnnotations = resultNamespace.Metadata.Annotations; Assert.Equal(annotations, resultAnnotations); } finally { client.DeleteNamespace( body: new V1DeleteOptions(), name: namespaceName ); } }