From 48f2d2838bcf7596a96b9a98efaa68265d4a8f16 Mon Sep 17 00:00:00 2001 From: sarka_scavnicka Date: Wed, 25 Sep 2019 14:10:17 +0000 Subject: [PATCH] Add a loadbalancer CRD This commit adds CRD to Kuryr that contains informations about service's annotations and endpoints' annotations, also it is ensured that CRD is created on the cluster when using devstack. Partially-Implements: blueprint move-svc-annotations-to-crds Change-Id: I4088ad09efe96b2d395fb892750adcb39abee3a4 --- devstack/lib/kuryr_kubernetes | 1 + devstack/plugin.sh | 1 + kubernetes_crds/kuryrloadbalancer.yaml | 193 ++++++++++++++++++++++ kuryr_kubernetes/constants.py | 2 + kuryr_kubernetes/tests/unit/test_utils.py | 4 +- 5 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 kubernetes_crds/kuryrloadbalancer.yaml diff --git a/devstack/lib/kuryr_kubernetes b/devstack/lib/kuryr_kubernetes index 4a83428f1..7836e3e86 100644 --- a/devstack/lib/kuryr_kubernetes +++ b/devstack/lib/kuryr_kubernetes @@ -448,6 +448,7 @@ rules: resources: - kuryrnets - kuryrnetpolicies + - kuryrloadbalancers - apiGroups: ["networking.k8s.io"] resources: - networkpolicies diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 92cde69fc..7067fab1f 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -1165,6 +1165,7 @@ if [[ "$1" == "stack" && "$2" == "extra" ]]; then if is_service_enabled kuryr-kubernetes; then /usr/local/bin/kubectl apply -f ${KURYR_HOME}/kubernetes_crds/kuryrnet.yaml /usr/local/bin/kubectl apply -f ${KURYR_HOME}/kubernetes_crds/kuryrnetpolicy.yaml + /usr/local/bin/kubectl apply -f ${KURYR_HOME}/kubernetes_crds/kuryrloadbalancer.yaml if [ "$KURYR_K8S_CONTAINERIZED_DEPLOYMENT" == "True" ]; then generate_containerized_kuryr_resources fi diff --git a/kubernetes_crds/kuryrloadbalancer.yaml b/kubernetes_crds/kuryrloadbalancer.yaml new file mode 100644 index 000000000..acb73937f --- /dev/null +++ b/kubernetes_crds/kuryrloadbalancer.yaml @@ -0,0 +1,193 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: kuryrloadbalancers.openstack.org +spec: + group: openstack.org + version: v1 + scope: Namespaced + names: + plural: kuryrloadbalancers + singular: kuryrloadbalancer + kind: KuryrLoadBalancer + shortNames: + - klb + additionalPrinterColumns: + - name: PROJECT-ID + type: string + description: The ID of the PROJECT associated to the loadbalancer + JSONPath: .spec.project_id + - name: Age + type: date + JSONPath: .metadata.creationTimestamp + validation: + openAPIV3Schema: + properties: + spec: + type: object + required: + - ip + - ports + - project_id + - security_groups_ids + - subnet_id + - type + properties: + ip: + type: string + lb_ip: + type: string + ports: + type: array + items: + type: object + required: + - name + - port + - protocol + - targetPort + properties: + name: + type: string + port: + type: integer + protocol: + type: string + targetPort: + type: string + project_id: + type: string + security_groups_ids: + type: array + items: + type: string + subnet_id: + type: string + type: + type: string + status: + type: object + required: + - listeners + - loadbalancer + - members + - pools + properties: + listeners: + type: array + items: + type: object + required: + - id + - loadbalancer_id + - name + - port + - project_id + - protocol + properties: + id: + type: string + loadbalancer_id: + type: string + name: + type: string + port: + type: integer + project_id: + type: string + protocol: + type: string + loadbalancer: + type: object + required: + - id + - ip + - name + - port_id + - project_id + - provider + - security_groups + - subnet_id + properties: + id: + type: string + ip: + type: string + name: + type: string + port_id: + type: string + project_id: + type: string + provider: + type: string + security_groups: + type: array + items: + type: string + subnet_id: + type: string + members: + type: array + items: + type: object + required: + - id + - ip + - name + - pool_id + - port + - project_id + - subnet_id + properties: + id: + type: string + ip: + type: string + name: + type: string + pool_id: + type: string + port: + type: integer + project_id: + type: string + subnet_id: + type: string + pools: + type: array + items: + type: object + required: + - id + - listener_id + - loadbalancer_id + - name + - project_id + - protocol + properties: + id: + type: string + listener_id: + type: string + loadbalancer_id: + type: string + name: + type: string + project_id: + type: string + protocol: + type: string + service_pub_ip_info: + type: object + required: + - ip_id + - ip_addr + - alloc_method + properties: + ip_id: + type: string + ip_addr: + type: string + alloc_method: + type: string diff --git a/kuryr_kubernetes/constants.py b/kuryr_kubernetes/constants.py index 8643e18fc..ec22d1052 100644 --- a/kuryr_kubernetes/constants.py +++ b/kuryr_kubernetes/constants.py @@ -19,6 +19,7 @@ K8S_API_CRD = '/apis/openstack.org/v1' K8S_API_CRD_NAMESPACES = K8S_API_CRD + '/namespaces' K8S_API_CRD_KURYRNETS = K8S_API_CRD + '/kuryrnets' K8S_API_CRD_KURYRNETPOLICIES = K8S_API_CRD + '/kuryrnetpolicies' +K8S_API_CRD_KURYRLOADBALANCERS = K8S_API_CRD + '/kuryrloadbalancers' K8S_API_POLICIES = '/apis/networking.k8s.io/v1/networkpolicies' K8S_API_NPWG_CRD = '/apis/k8s.cni.cncf.io/v1' @@ -30,6 +31,7 @@ K8S_OBJ_ENDPOINTS = 'Endpoints' K8S_OBJ_POLICY = 'NetworkPolicy' K8S_OBJ_KURYRNET = 'KuryrNet' K8S_OBJ_KURYRNETPOLICY = 'KuryrNetPolicy' +K8S_OBJ_KURYRLOADBALANCER = 'KuryrLoadBalancer' K8S_POD_STATUS_PENDING = 'Pending' diff --git a/kuryr_kubernetes/tests/unit/test_utils.py b/kuryr_kubernetes/tests/unit/test_utils.py index f493f14b6..2653791ec 100644 --- a/kuryr_kubernetes/tests/unit/test_utils.py +++ b/kuryr_kubernetes/tests/unit/test_utils.py @@ -149,7 +149,9 @@ class TestUtils(test_base.TestCase): def test__has_kuryr_crd_error(self): crds = [k_const.K8S_API_CRD_KURYRNETS, - k_const.K8S_API_CRD_KURYRNETPOLICIES] + k_const.K8S_API_CRD_KURYRNETPOLICIES, + k_const.K8S_API_CRD_KURYRLOADBALANCERS] + for crd_url in crds: kubernetes = self.useFixture(k_fix.MockK8sClient()).client kubernetes.get.side_effect = k_exc.K8sClientException