-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 #2399: Cannot change the type of the Service from ClusterIP to ExternalName #2472
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,13 @@ | |
import io.fabric8.commons.ReadyEntity; | ||
import io.fabric8.kubernetes.api.model.IntOrString; | ||
import io.fabric8.kubernetes.api.model.Service; | ||
import io.fabric8.kubernetes.api.model.ServiceBuilder; | ||
import io.fabric8.kubernetes.api.model.ServiceList; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import org.arquillian.cube.kubernetes.api.Session; | ||
import org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes; | ||
import org.arquillian.cube.requirement.ArquillianConditionalRunner; | ||
import org.assertj.core.internal.bytebuddy.build.ToStringPlugin; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
|
@@ -94,6 +96,135 @@ public void delete() { | |
assertTrue(bDeleted); | ||
} | ||
|
||
@Test | ||
public void testChangeServiceType() { | ||
// Given | ||
Service svc = client.services().inNamespace(session.getNamespace()).withName("service-change-service-type").get(); | ||
|
||
// When | ||
svc.getSpec().setType("ExternalName"); | ||
svc.getSpec().setExternalName("my.database.example.com"); | ||
svc.getSpec().setClusterIP(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No assertion for ClusterIP ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Services of type |
||
svc = client.services().inNamespace(session.getNamespace()).createOrReplace(svc); | ||
|
||
// Then | ||
assertNotNull(svc); | ||
assertEquals("ExternalName", svc.getSpec().getType()); | ||
assertEquals("my.database.example.com", svc.getSpec().getExternalName()); | ||
} | ||
|
||
@Test | ||
public void testClusterIPCreateOrReplace() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name is a bit misleading.. can we change it to testClusterIpServiceCreateOrReplace ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'll create a follow up PR with your suggested changes |
||
// Given | ||
Service clusterIPSvc = new ServiceBuilder() | ||
.withNewMetadata().withName("serviceit-clusterip-createorreplace").endMetadata() | ||
.withNewSpec() | ||
.addToSelector("app", "myapp") | ||
.addNewPort() | ||
.withName("http") | ||
.withProtocol("TCP") | ||
.withPort(80) | ||
.withTargetPort(new IntOrString(9376)) | ||
.endPort() | ||
.endSpec() | ||
.build(); | ||
|
||
// When | ||
// Create resource | ||
client.services().inNamespace(session.getNamespace()).createOrReplace(clusterIPSvc); | ||
// Modify resource | ||
clusterIPSvc.getSpec().getPorts().get(0).setTargetPort(new IntOrString(9380)); | ||
// Do createOrReplace again; resource should get updated | ||
clusterIPSvc = client.services().inNamespace(session.getNamespace()).createOrReplace(clusterIPSvc); | ||
|
||
// Then | ||
assertNotNull(clusterIPSvc); | ||
assertEquals("ClusterIP", clusterIPSvc.getSpec().getType()); | ||
assertEquals(9380, clusterIPSvc.getSpec().getPorts().get(0).getTargetPort().getIntVal().intValue()); | ||
} | ||
|
||
@Test | ||
public void testNodePortCreateOrReplace() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing with the name |
||
// Given | ||
Service clusterIPSvc = new ServiceBuilder() | ||
.withNewMetadata().withName("serviceit-nodeport-createorreplace").endMetadata() | ||
.withNewSpec() | ||
.withType("NodePort") | ||
.addToSelector("app", "myapp") | ||
.addNewPort() | ||
.withPort(80) | ||
.withTargetPort(new IntOrString(80)) | ||
.endPort() | ||
.endSpec() | ||
.build(); | ||
|
||
// When | ||
// Create resource | ||
client.services().inNamespace(session.getNamespace()).createOrReplace(clusterIPSvc); | ||
// Modify resource | ||
clusterIPSvc.getSpec().getPorts().get(0).setTargetPort(new IntOrString(81)); | ||
// Do createOrReplace again; resource should get updated | ||
clusterIPSvc = client.services().inNamespace(session.getNamespace()).createOrReplace(clusterIPSvc); | ||
|
||
// Then | ||
assertNotNull(clusterIPSvc); | ||
assertEquals("NodePort", clusterIPSvc.getSpec().getType()); | ||
assertEquals(81, clusterIPSvc.getSpec().getPorts().get(0).getTargetPort().getIntVal().intValue()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also check for the NodePort value created. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this assertion to check whether what I modified in When phase is actually reflected or not. But yes, I can try doing something with NodePort too |
||
} | ||
|
||
@Test | ||
public void testLoadBalancerCreateOrReplace() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. name |
||
// Given | ||
Service clusterIPSvc = new ServiceBuilder() | ||
.withNewMetadata().withName("serviceit-loadbalancer-createorreplace").endMetadata() | ||
.withNewSpec() | ||
.withType("LoadBalancer") | ||
.addToSelector("app", "myapp") | ||
.addNewPort() | ||
.withProtocol("TCP") | ||
.withPort(80) | ||
.withTargetPort(new IntOrString(9376)) | ||
.endPort() | ||
.endSpec() | ||
.build(); | ||
|
||
// When | ||
// Create resource | ||
client.services().inNamespace(session.getNamespace()).createOrReplace(clusterIPSvc); | ||
// Modify resource | ||
clusterIPSvc.getSpec().getPorts().get(0).setTargetPort(new IntOrString(9380)); | ||
// Do createOrReplace again; resource should get updated | ||
clusterIPSvc = client.services().inNamespace(session.getNamespace()).createOrReplace(clusterIPSvc); | ||
|
||
// Then | ||
assertNotNull(clusterIPSvc); | ||
assertEquals("LoadBalancer", clusterIPSvc.getSpec().getType()); | ||
assertEquals(9380, clusterIPSvc.getSpec().getPorts().get(0).getTargetPort().getIntVal().intValue()); | ||
} | ||
|
||
@Test | ||
public void testExternalNameCreateOrReplace() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. name |
||
// Given | ||
Service service = new ServiceBuilder() | ||
.withNewMetadata().withName("serviceit-externalname-createorreplace").endMetadata() | ||
.withNewSpec() | ||
.withType("ExternalName") | ||
.withExternalName("my.database.example.com") | ||
.endSpec() | ||
.build(); | ||
|
||
// When | ||
client.services().inNamespace(session.getNamespace()).createOrReplace(service); | ||
service.getSpec().setExternalName("his.database.example.com"); | ||
service = client.services().inNamespace(session.getNamespace()).createOrReplace(service); | ||
|
||
// Then | ||
assertNotNull(service); | ||
assertEquals("serviceit-externalname-createorreplace", service.getMetadata().getName()); | ||
assertEquals("ExternalName", service.getSpec().getType()); | ||
assertEquals("his.database.example.com", service.getSpec().getExternalName()); | ||
} | ||
|
||
@AfterClass | ||
public static void cleanup() { | ||
ClusterEntity.remove(ServiceIT.class.getResourceAsStream("/service-it.yml")); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the
patch
also work withExternalName
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right. Could you please create an issue for this?