Search in sources :

Example 31 with V1ObjectMeta

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();
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1beta1CustomResourceDefinitionNames(io.kubernetes.client.models.V1beta1CustomResourceDefinitionNames) V1beta1CustomResourceDefinitionSpec(io.kubernetes.client.models.V1beta1CustomResourceDefinitionSpec) V1beta1CustomResourceDefinition(io.kubernetes.client.models.V1beta1CustomResourceDefinition) ApiException(io.kubernetes.client.ApiException)

Example 32 with V1ObjectMeta

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");
}
Also used : V1ServicePort(io.kubernetes.client.models.V1ServicePort) WlsServerConfig(oracle.kubernetes.operator.wlsconfig.WlsServerConfig) DomainSpec(oracle.kubernetes.weblogic.domain.v1.DomainSpec) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) WlsClusterConfig(oracle.kubernetes.operator.wlsconfig.WlsClusterConfig) V1ServiceSpec(io.kubernetes.client.models.V1ServiceSpec) V1Service(io.kubernetes.client.models.V1Service) Domain(oracle.kubernetes.weblogic.domain.v1.Domain) WlsDomainConfig(oracle.kubernetes.operator.wlsconfig.WlsDomainConfig) Engine(oracle.kubernetes.operator.work.Engine) Before(org.junit.Before)

Example 33 with V1ObjectMeta

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);
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) V1Secret(io.kubernetes.client.models.V1Secret) ApiException(io.kubernetes.client.ApiException)

Example 34 with V1ObjectMeta

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);
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) V1ServiceList(io.kubernetes.client.models.V1ServiceList) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) Fiber(oracle.kubernetes.operator.work.Fiber) V1Service(io.kubernetes.client.models.V1Service) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) Step(oracle.kubernetes.operator.work.Step) DomainPresenceInfo(oracle.kubernetes.operator.helpers.DomainPresenceInfo) DomainSpec(oracle.kubernetes.weblogic.domain.v1.DomainSpec) Domain(oracle.kubernetes.weblogic.domain.v1.Domain) Engine(oracle.kubernetes.operator.work.Engine) Test(org.junit.Test)

Example 35 with V1ObjectMeta

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());
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1Service(io.kubernetes.client.models.V1Service) Test(org.junit.Test)

Aggregations

V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)36 Test (org.junit.Test)12 V1Service (io.kubernetes.client.models.V1Service)10 ApiException (io.kubernetes.client.ApiException)7 CallBuilderFactory (oracle.kubernetes.operator.helpers.CallBuilderFactory)6 V1beta1Ingress (io.kubernetes.client.models.V1beta1Ingress)5 DomainPresenceInfo (oracle.kubernetes.operator.helpers.DomainPresenceInfo)4 IntOrString (io.kubernetes.client.custom.IntOrString)3 V1PodTemplateSpec (io.kubernetes.client.models.V1PodTemplateSpec)3 HashMap (java.util.HashMap)3 Domain (oracle.kubernetes.weblogic.domain.v1.Domain)3 DomainSpec (oracle.kubernetes.weblogic.domain.v1.DomainSpec)3 V1LabelSelector (io.kubernetes.client.models.V1LabelSelector)2 V1Namespace (io.kubernetes.client.models.V1Namespace)2 V1Secret (io.kubernetes.client.models.V1Secret)2 V1ServicePort (io.kubernetes.client.models.V1ServicePort)2 V1ServiceSpec (io.kubernetes.client.models.V1ServiceSpec)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 ServerKubernetesObjects (oracle.kubernetes.operator.helpers.ServerKubernetesObjects)2