use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.
the class CRDHelper method checkAndCreateCustomResourceDefinition.
/**
* Validates and, if necessary, created domains.weblogic.oracle CRD. No need
* to be async as operator can not begin processing until CRD exists
*/
public static void checkAndCreateCustomResourceDefinition() {
LOGGER.entering();
V1beta1CustomResourceDefinition crd = new V1beta1CustomResourceDefinition();
crd.setApiVersion("apiextensions.k8s.io/v1beta1");
crd.setKind("CustomResourceDefinition");
V1ObjectMeta om = new V1ObjectMeta();
om.setName("domains.weblogic.oracle");
crd.setMetadata(om);
V1beta1CustomResourceDefinitionSpec crds = new V1beta1CustomResourceDefinitionSpec();
crds.setGroup(KubernetesConstants.DOMAIN_GROUP);
crds.setVersion(KubernetesConstants.DOMAIN_VERSION);
crds.setScope("Namespaced");
V1beta1CustomResourceDefinitionNames crdn = new V1beta1CustomResourceDefinitionNames();
crdn.setPlural(KubernetesConstants.DOMAIN_PLURAL);
crdn.setSingular(KubernetesConstants.DOMAIN_SINGULAR);
crdn.setKind("Domain");
crdn.setShortNames(Collections.singletonList(KubernetesConstants.DOMAIN_SHORT));
crds.setNames(crdn);
crd.setSpec(crds);
CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
V1beta1CustomResourceDefinition existingCRD = null;
try {
existingCRD = factory.create().readCustomResourceDefinition(crd.getMetadata().getName());
} catch (ApiException e) {
if (e.getCode() != CallBuilder.NOT_FOUND) {
LOGGER.warning(MessageKeys.EXCEPTION, e);
}
}
try {
if (existingCRD == null) {
LOGGER.info(MessageKeys.CREATING_CRD, crd.toString());
factory.create().createCustomResourceDefinition(crd);
}
} catch (ApiException e) {
LOGGER.warning(MessageKeys.EXCEPTION, e);
}
LOGGER.exiting();
}
use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.
the class IngressHelperTest method setUp.
@Before
public void setUp() throws ApiException {
// make sure test bed is clean
tearDown();
// Create domain
Domain domain = new Domain();
V1ObjectMeta metadata = new V1ObjectMeta();
metadata.setName("domianIngressHelperTest");
metadata.setNamespace(namespace);
domain.setMetadata(metadata);
DomainSpec spec = new DomainSpec();
spec.setDomainName("base_domain");
spec.setDomainUID(domainUID);
domain.setSpec(spec);
info = new DomainPresenceInfo(domain);
// Create scan
WlsDomainConfig scan = new WlsDomainConfig();
WlsServerConfig server1Scan = new WlsServerConfig(server1Name, server1Port, server1Name, null);
WlsServerConfig server2Scan = new WlsServerConfig(server2Name, server2Port, server2Name, null);
scan.getServerConfigs().put(server1Name, server1Scan);
scan.getServerConfigs().put(server2Name, server2Scan);
WlsClusterConfig cluster1Scan = new WlsClusterConfig(clusterName);
cluster1Scan.getServerConfigs().add(server1Scan);
cluster1Scan.getServerConfigs().add(server2Scan);
scan.getClusterConfigs().put(clusterName, cluster1Scan);
info.setScan(scan);
ServerKubernetesObjects sko = new ServerKubernetesObjects();
V1Service service = new V1Service();
V1ObjectMeta sm = new V1ObjectMeta();
sm.setName(service1Name);
sm.setNamespace(namespace);
service.setMetadata(sm);
V1ServiceSpec ss = new V1ServiceSpec();
V1ServicePort port = new V1ServicePort();
port.setPort(server1Port);
ss.addPortsItem(port);
service.setSpec(ss);
sko.getService().set(service);
info.getServers().put(server1Name, sko);
sko = new ServerKubernetesObjects();
service = new V1Service();
sm = new V1ObjectMeta();
sm.setName(service2Name);
sm.setNamespace(namespace);
service.setMetadata(sm);
ss = new V1ServiceSpec();
port = new V1ServicePort();
port.setPort(server2Port);
ss.addPortsItem(port);
service.setSpec(ss);
sko.getService().set(service);
info.getServers().put(server2Name, sko);
engine = new Engine("IngressHelperTest");
}
use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.
the class SecretHelperTest method createInvalidSecret.
// Create a named secret with no username / password in specified namespace
private V1Secret createInvalidSecret(String name, String namespace) throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
try {
V1Secret existing = factory.create().readSecret(name, namespace);
if (existing != null)
return existing;
} catch (ApiException ignore) {
// Just ignore and try to create it
}
if (isVersion18)
return null;
V1Secret body = new V1Secret();
// Set the required api version and kind of resource
body.setApiVersion("v1");
body.setKind("Secret");
// Setup the standard object metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(name);
meta.setNamespace(namespace);
body.setMetadata(meta);
return factory.create().createSecret(namespace, body);
}
use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.
the class ServiceHelperTest method createReadListUpdate.
@Test
public void createReadListUpdate() throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
// Domain
Domain dom = new Domain();
V1ObjectMeta metadata = new V1ObjectMeta();
metadata.setResourceVersion("12345");
metadata.setNamespace("tests");
dom.setMetadata(metadata);
DomainSpec spec = new DomainSpec();
spec.setDomainUID("domain-uid");
spec.setDomainName("base_domain");
dom.setSpec(spec);
// Create a new service.
System.out.println("Creating service");
Step s = ServiceHelper.createForServerStep(null);
Engine e = new Engine("ServiceHelperTest");
Packet p = new Packet();
DomainPresenceInfo info = new DomainPresenceInfo(dom);
p.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info));
p.put(ProcessingConstants.SERVER_NAME, "admin");
p.put(ProcessingConstants.PORT, Integer.valueOf(7001));
Fiber f = e.createFiber();
f.start(s, p, null);
f.get();
// Read the service we just created.
System.out.println("Reading service");
V1Service service = factory.create().readService("domain-uid-admin", "tests");
checkService(service, false);
// Get a list of services.
System.out.println("Listing services");
V1ServiceList serviceList = factory.create().listService("tests");
boolean serviceFound = false;
for (V1Service item : serviceList.getItems()) {
if (item.getMetadata().getName().equals("domain-uid-admin")) {
serviceFound = true;
break;
}
}
Assert.assertTrue("Expected service domain-uid-admin not found in list", serviceFound);
// Add a second selector to this service.
Map<String, String> selector = service.getSpec().getSelector();
selector.put("domain", "domain-uid");
service.getSpec().setSelector(selector);
// TODO: uncomment out when bug calling replace service is fixed.
// System.out.println("Replacing service");
// service = serviceHelper.replace("domain-uid-admin", service);
// checkService(service, true);
}
use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.
the class ServiceWatcherTest method whenServiceHasNoChannelName_returnNull.
@Test
public void whenServiceHasNoChannelName_returnNull() throws Exception {
V1Service service = new V1Service().metadata(new V1ObjectMeta());
assertThat(ServiceWatcher.getServiceChannelName(service), nullValue());
}
Aggregations