Search in sources :

Example 1 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.

the class IngressWatcher method getIngressClusterName.

static String getIngressClusterName(V1beta1Ingress ingress) {
    V1ObjectMeta meta = ingress.getMetadata();
    Map<String, String> labels = meta.getLabels();
    if (labels != null) {
        return labels.get(LabelConstants.CLUSTERNAME_LABEL);
    }
    return null;
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta)

Example 2 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.

the class IngressWatcher method getIngressDomainUID.

static String getIngressDomainUID(V1beta1Ingress ingress) {
    V1ObjectMeta meta = ingress.getMetadata();
    Map<String, String> labels = meta.getLabels();
    if (labels != null) {
        return labels.get(LabelConstants.DOMAINUID_LABEL);
    }
    return null;
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta)

Example 3 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.

the class Main method dispatchServiceWatch.

private static void dispatchServiceWatch(Watch.Response<V1Service> item) {
    V1Service s = item.object;
    if (s != null) {
        V1ObjectMeta metadata = s.getMetadata();
        String domainUID = metadata.getLabels().get(LabelConstants.DOMAINUID_LABEL);
        String serverName = metadata.getLabels().get(LabelConstants.SERVERNAME_LABEL);
        String channelName = metadata.getLabels().get(LabelConstants.CHANNELNAME_LABEL);
        String clusterName = metadata.getLabels().get(LabelConstants.CLUSTERNAME_LABEL);
        if (domainUID != null) {
            DomainPresenceInfo info = domains.get(domainUID);
            ServerKubernetesObjects sko = null;
            if (info != null) {
                if (serverName != null) {
                    ServerKubernetesObjects created = new ServerKubernetesObjects();
                    ServerKubernetesObjects current = info.getServers().putIfAbsent(serverName, created);
                    sko = current != null ? current : created;
                }
                switch(item.type) {
                    case "ADDED":
                        if (sko != null) {
                            if (channelName != null) {
                                sko.getChannels().put(channelName, s);
                            } else {
                                sko.getService().set(s);
                            }
                        } else if (clusterName != null) {
                            info.getClusters().put(clusterName, s);
                        }
                        break;
                    case "MODIFIED":
                        if (sko != null) {
                            if (channelName != null) {
                                V1Service skoService = sko.getChannels().get(channelName);
                                if (skoService != null) {
                                    sko.getChannels().replace(channelName, skoService, s);
                                }
                            } else {
                                V1Service skoService = sko.getService().get();
                                if (skoService != null) {
                                    sko.getService().compareAndSet(skoService, s);
                                }
                            }
                        } else if (clusterName != null) {
                            V1Service clusterService = info.getClusters().get(clusterName);
                            if (clusterService != null) {
                                info.getClusters().replace(clusterName, clusterService, s);
                            }
                        }
                        break;
                    case "DELETED":
                        if (sko != null) {
                            if (channelName != null) {
                                V1Service oldService = sko.getChannels().put(channelName, null);
                                if (oldService != null) {
                                    // Service was deleted, but sko still contained a non-null entry
                                    LOGGER.info(MessageKeys.SERVER_SERVICE_DELETED, domainUID, metadata.getNamespace(), serverName);
                                    doCheckAndCreateDomainPresence(info.getDomain(), true);
                                }
                            } else {
                                V1Service oldService = sko.getService().getAndSet(null);
                                if (oldService != null) {
                                    // Service was deleted, but sko still contained a non-null entry
                                    LOGGER.info(MessageKeys.SERVER_SERVICE_DELETED, domainUID, metadata.getNamespace(), serverName);
                                    doCheckAndCreateDomainPresence(info.getDomain(), true);
                                }
                            }
                        } else if (clusterName != null) {
                            V1Service oldService = info.getClusters().put(clusterName, null);
                            if (oldService != null) {
                                // Service was deleted, but clusters still contained a non-null entry
                                LOGGER.info(MessageKeys.CLUSTER_SERVICE_DELETED, domainUID, metadata.getNamespace(), clusterName);
                                doCheckAndCreateDomainPresence(info.getDomain(), true);
                            }
                        }
                        break;
                    case "ERROR":
                    default:
                }
            }
        }
    }
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) ServerKubernetesObjects(oracle.kubernetes.operator.helpers.ServerKubernetesObjects) V1Service(io.kubernetes.client.models.V1Service) DomainPresenceInfo(oracle.kubernetes.operator.helpers.DomainPresenceInfo)

Example 4 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.

the class Main method dispatchPodWatch.

private static void dispatchPodWatch(Watch.Response<V1Pod> item) {
    V1Pod p = item.object;
    if (p != null) {
        V1ObjectMeta metadata = p.getMetadata();
        String domainUID = metadata.getLabels().get(LabelConstants.DOMAINUID_LABEL);
        String serverName = metadata.getLabels().get(LabelConstants.SERVERNAME_LABEL);
        if (domainUID != null) {
            DomainPresenceInfo info = domains.get(domainUID);
            if (info != null && serverName != null) {
                ServerKubernetesObjects created = new ServerKubernetesObjects();
                ServerKubernetesObjects current = info.getServers().putIfAbsent(serverName, created);
                ServerKubernetesObjects sko = current != null ? current : created;
                if (sko != null) {
                    switch(item.type) {
                        case "ADDED":
                            sko.getPod().set(p);
                            break;
                        case "MODIFIED":
                            V1Pod skoPod = sko.getPod().get();
                            if (skoPod != null) {
                                // If the skoPod is null then the operator deleted this pod
                                // and modifications are to the terminating pod
                                sko.getPod().compareAndSet(skoPod, p);
                            }
                            break;
                        case "DELETED":
                            V1Pod oldPod = sko.getPod().getAndSet(null);
                            if (oldPod != null) {
                                // Pod was deleted, but sko still contained a non-null entry
                                LOGGER.info(MessageKeys.POD_DELETED, domainUID, metadata.getNamespace(), serverName);
                                doCheckAndCreateDomainPresence(info.getDomain(), true);
                            }
                            break;
                        case "ERROR":
                        default:
                    }
                }
            }
        }
    }
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) ServerKubernetesObjects(oracle.kubernetes.operator.helpers.ServerKubernetesObjects) V1Pod(io.kubernetes.client.models.V1Pod) DomainPresenceInfo(oracle.kubernetes.operator.helpers.DomainPresenceInfo)

Example 5 with V1ObjectMeta

use of io.kubernetes.client.models.V1ObjectMeta in project weblogic-kubernetes-operator by oracle.

the class AuthorizationProxy method prepareSubjectAccessReview.

/**
 * Prepares an instance of SubjectAccessReview and returns same.
 *
 * @param principal     The user, group or service account.
 * @param groups        The groups that principal is a member of.
 * @param operation     The operation to be authorized.
 * @param resource      The kind of resource on which the operation is to be authorized.
 * @param resourceName  The name of the resource instance on which the operation is to be authorized.
 * @param scope         The scope of the operation (cluster or namespace).
 * @param namespaceName name of the namespace if scope is namespace else null.
 * @return an instance of SubjectAccessReview.
 */
private V1SubjectAccessReview prepareSubjectAccessReview(String principal, final List<String> groups, Operation operation, Resource resource, String resourceName, Scope scope, String namespaceName) {
    LOGGER.entering();
    V1SubjectAccessReviewSpec subjectAccessReviewSpec = new V1SubjectAccessReviewSpec();
    subjectAccessReviewSpec.setUser(principal);
    subjectAccessReviewSpec.setGroups(groups);
    subjectAccessReviewSpec.setResourceAttributes(prepareResourceAttributes(operation, resource, resourceName, scope, namespaceName));
    V1SubjectAccessReview subjectAccessReview = new V1SubjectAccessReview();
    subjectAccessReview.setApiVersion("authorization.k8s.io/v1");
    subjectAccessReview.setKind("SubjectAccessReview");
    subjectAccessReview.setMetadata(new V1ObjectMeta());
    subjectAccessReview.setSpec(subjectAccessReviewSpec);
    LOGGER.exiting(subjectAccessReview);
    return subjectAccessReview;
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1SubjectAccessReviewSpec(io.kubernetes.client.models.V1SubjectAccessReviewSpec) V1SubjectAccessReview(io.kubernetes.client.models.V1SubjectAccessReview)

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