diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5601d3bbb232b817dddb815531d4697e507721ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target/ +.project +.classpath +/.settings diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..bb7d754baa751630b25598e182a30f062e9b6ebd --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,40 @@ +include: + - project: osl/code/org.etsi.osl.main + ref: main + file: + - ci-templates/default.yml + - ci-templates/build.yml + rules: + - if: '$CI_COMMIT_REF_NAME == "main"' + + - project: osl/code/org.etsi.osl.main + ref: develop + file: + - ci-templates/default.yml + - ci-templates/build.yml + rules: + - if: '$CI_COMMIT_REF_NAME == "develop"' + + - project: osl/code/org.etsi.osl.main + ref: $CI_COMMIT_REF_NAME + file: + - ci-templates/default.yml + - ci-templates/build.yml + rules: + - if: '$CI_COMMIT_REF_PROTECTED && $CI_COMMIT_REF_NAME != "main" && $CI_COMMIT_REF_NAME != "develop"' + + - project: osl/code/org.etsi.osl.main + ref: develop + file: + - ci-templates/default.yml + - ci-templates/build_unprotected.yml + rules: + - if: '$CI_COMMIT_REF_NAME != "main" && $CI_COMMIT_REF_NAME != "develop" && !$CI_COMMIT_REF_PROTECTED' + +maven_build: + extends: .maven_build + +docker_build: + extends: .docker_build + needs: + - maven_build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..f44060eb99868f55b3768468447451422e6a00dc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM ibm-semeru-runtimes:open-17.0.7_7-jdk +MAINTAINER openslice.io +RUN mkdir /opt/shareclasses +RUN mkdir -p /opt/openslice/lib/ +COPY target/org.etsi.osl.cridge-1.0.0-exec.jar /opt/openslice/lib/ +CMD ["java", "-Xshareclasses:cacheDir=/opt/shareclasses", "-jar", "/opt/openslice/lib/org.etsi.osl.cridge-1.0.0-exec.jar"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 7069b5fa928c0ae11e03819f25e4a9da10bf7e1d..2f649ae9a9fec4df01edbefcd6eb91bd8123bd1d 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,4 @@ # org.etsi.osl.cridge +Openslice CRD 2 TMF bridge services. It is used to translate K8S resource models to TMF models. - - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://labs.etsi.org/rep/osl/code/org.etsi.osl.cridge.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://labs.etsi.org/rep/osl/code/org.etsi.osl.cridge/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +It also can receive resource LCM from OSOM and manage the local K8S defined resources. diff --git a/ci_settings.xml b/ci_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..69ad06ed6c63795d191555afde6ea2d1da4e133d --- /dev/null +++ b/ci_settings.xml @@ -0,0 +1,16 @@ + + + + gitlab-maven + + + + Job-Token + ${CI_JOB_TOKEN} + + + + + + diff --git a/docs/CRIDGEforDevelopers.md b/docs/CRIDGEforDevelopers.md new file mode 100644 index 0000000000000000000000000000000000000000..defea971cbe0b2b0153389327981784457c57869 --- /dev/null +++ b/docs/CRIDGEforDevelopers.md @@ -0,0 +1,221 @@ + +# CRIDGE: A Service to manage Custom Resources in a Kubernetes Cluster + +## Intended Audience: OSL developers + + > Kubernetes is an orchestration system for automating software deployment, scaling, and management. One can interact though the Kubernetes API and it has a set of objects ready for use out of the box. Custom Resource Definitions (CRDs) is a way that allows to manage things other than Kubernetes itself and allows to create our own objects The use of CRDs makes the possibilities of Kubernetes management almost limitless. You can extend the base Kubernetes API with any object you like using CRDs. + + +CRIDGE is a service designed to create and manage Custom Resources (CRs) based on Custom Resource Definitions (CRDs) installed on a Kubernetes cluster. By leveraging the OpenSlice (OSL), CRIDGE enables seamless integration and orchestration within Kubernetes environments, utilizing Kubernetes APIs via the TMF APIs and models. Thus, more or less, OSL exposes Kubernetes APIs as TMF APIs and models. + + >By allowing the design and lifecycle management of services/resources that expose CRDs/CRs in a Kubernetes cluster via the TMF APIs, OSL can be used in many complex scenarios now involing resources from multiple domains. + + + +1. CRIDGE service allows OSL to: + - Create and manage Custom Resources (CRs) using installed CRDs on a target Kubernetes cluster. + - Facilitate complex orchestration scenarios by wrapping Kubernetes APIs as TMF APIs and models. + - Handles connectivity to a Kubernetes cluster and manages the lifecycle of CRDs + - Wraps the Kubernetes API, Receives and provides resources towards other OSL services via the service bus + +2. Enabling Loose Coupling and Orchestration + - Language Flexibility: Developers can write CRDs in any language and expose them via the Kubernetes APIs. OSL will reuse these CRDs, enhancing flexibility and integration capabilities. + - Familiar Deployment: Developers can create and deploy applications using familiar tools such as Helm charts, simplifying the process and reducing the learning curve. + +3. Ecosystem Reusability + - CRIDGE capitalizes on the extensive Kubernetes ecosystem, particularly focusing on operators (CRDs). + - Key repositories and hubs such as artifacthub.io and Operatorhub.io can be utilized for finding and deploying operators. + +4. Service Catalog Exposure and Deployment + + OSL can expose CRs in service catalogs, facilitating their deployment in complex scenarios. + These scenarios may include service bundles that involve multiple systems, such as RAN controllers or other Kubernetes clusters, providing a robust and versatile deployment framework. + + + + > Why the CRIDGE name? we wanted to build a service that maps TMF models to CRDs; a kind of a **CR**D to TMF br**idge**. Therefore CRIDGE was born + +# Approach + + > OSL in general is responible for exposing service specifications which are ready to be ordered and orchestrated, through tmforum Open APIs as defined in the OSL Service Spec Catalog. Usually for a service specification a corresponding (one or more) resource specification (resourceSpecificationReference) is registered in the OSL Resource Spec Catalog. + +The following image illustrates the approach. + + + +1. A CRD in a cluster will be mapped in TMF model as a Resource specification and therefore can be exposed as a service specification in a catalog +2. Service Orders can be created for this service specification. The OSL Orchestrator (OSOM) will manage the lifecycle of the Service Order. +3. OSOM creates a Resource in OSL Resource inventory and requests (via CRIDGE) a new Custom Resource (CR) in the target cluster + - The resource is created in a specific namespace (for example the UUID of the Service Order) + - A CR in a cluster will be mapped in TMF model as a Resource in the resource Inventory + - Other related resources created by the CRD Controller within the namespace are automatically created in OSL Resource Inventory under the same Service Order + + + + +The provided image illustrates the architecture and workflow of the CRIDGE service, showing how it interacts with other components within a Kubernetes (K8s) cluster. Here is an explanation of the key components and flow in the diagram: + + - Other OSL Services: This box represents various OSL services such as Service Spec Catalogue, Resource Spec Catalogue, Service Inventory, Resource Inventory, and OSOM (OpenSlice Service Orchestration and Management). + - Service Bus: This is the communication layer that facilitates interaction between the CRIDGE service and other OSL services. + - CRIDGE: CRIDGE acts as a bridge that converts CRDs (Custom Resource Definitions) to TMF (TM Forum) APIs and models. It enables the creation and management of Custom Resources (CRs) in the Kubernetes cluster. + - K8s API: The Kubernetes API server, which is the central control point for managing the Kubernetes cluster. CRIDGE interacts with the K8s API to manage CRDs and CRs. + + > CRD (Custom Resource Definition): A CRD is a way to define custom resources in Kubernetes cluster-wise. It allows the extension of Kubernetes API to create and manage user-defined resources. Example : +``` + apiVersion: apiextensions.k8s.io/v1 + kind: CustomResourceDefinition + metadata: + name: myresource.example.com +``` + + - Namespaces: Kubernetes namespaces provide a way to partition resources within a cluster. The diagram shows that multiple namespaces (nsxx, nsyy, nsz) can be managed by CRIDGE. + + > CR (Custom Resource): A CR is an instance of a CRD. It represents the actual custom resource that is managed within the Kubernetes cluster. Example shown in different namespaces: +``` + apiVersion: example.com/v1 + kind: Myresource + metadata: + name: example_resource_1 +``` + +In a nutchell: + + - Various OSL services use the Service Bus to communicate with CRIDGE. + - CRIDGE converts requests towards Kubernetes API and vice-versa, facilitating the integration of custom resources with other OSL services. + - CRDs are defined and managed through the K8s API. The example CRD is named myresource.example.com. + - Deploying CRs in Namespaces: Custom resources defined by the CRD are created and managed within different namespaces in the Kubernetes cluster. Each namespace can have its own instances of the custom resources. + + > The example CRD myresource.example.com allows the creation of custom resources of type Myresource. + > Instances of Myresource are created in various namespaces, each with unique names like example_resource_1. + + +# Handling more than one clusters + +A CRIDGE service is usually responsible for managing one cluster. In the following diagram we show how it can be used for managing multiple clusters: + + + +We assume that there is an OSL Management cluster that OSL is installed. CRIDGE is also installed there if we would like to manage resources in the same management cluster. + - Each CRIDGE service has for example its own configuration to connect to target cluster + - Each CRIDGE can be installed either in the managed cluster or at the remote clusters. Connectivity is handled via the service bus + - Important: Each CRIDGE has a different context and API endpoints. This is used to request CRDs on a different cluster + + + > A CRD has a globally unique name for example mycrd.example.com. So we need to somehow identify also the different cluster + + +# Awareness for CRDs and CRs in cluster + +> CRDs and CRs can appear (disappear) or change status at any time in a cluster. OSL Resource Inventory need to be aware of these events. + +The sync process is found in the code and explained by the following picture: + + + + + WatcherService is executed when the cridge service application starts (see onApplicationEvent). First things: + +- KubernetesClientResource is a class that wraps fabric8’s KubernetesClient + - This fabric8 KubernetesClient is initialized from the kubeconf and default context of the machine that runs CRIDGE +- On CRIDGE Start up we try to register this cluster and context to OSL catalogs. + - See registerKubernetesClientInOSLResource method which registers the KubernetesContextDefinition in Resource Inventory as a LogicalResource via createOrUpdateResourceByNameCategoryVersion method +- After the creation(or update) of this cluster as a Resource in OSL we proceed to create SharedIndexInformers for CustomResourceDefinition objects +- In this way CRIDGE is always aware of all CRDs and their CRs in the cluster, even if a CRD or CR is added/updated/deleted in the K8S cluster outside of OSL(CRIDGE) +- The SharedIndexInformer events notify CRIDGE, which is always aware of all CRDs and their CRs in the cluster, even if a CRD or CR is added/updated/deleted in the K8S cluster outside of OSL(CRIDGE) + - NOTE: The ADD event is raised every time also we run CRIDGE. Therefore, on ADD we do the method to createORupdate resource specifications and resources +- On ADD event: + - The CRD is transformed to OSL Kubernetes domain model: method kubernetesClientResource.KubernetesCRD2OpensliceCRD + - Then the OSL Kubernetes domain model is: + - transformed to Resource Specification and is stored to catalog (see createOrUpdateResourceSpecByNameCategoryVersion) + - Transformed to Resource and is stored to catalog (see createOrUpdateResourceByNameCategoryVersion) + - Conceptually while a CRD is a new resource located in the Kubernetes cluster resource, it is transformed also as a Resource Specification (a high-level entity) which is ready to be reused as an entity to other scenarios. The same concept as in Kubernetes where a CRD is a definition ready to be used for instantiating resources of this CRD + - Then for this CRD a Watcher is added for all Resources of this Kind (fabric8’s GenericKubernetesResource entity) + - When we have a newly added/updated/deleted resource of a certain CRD the method updateGenericKubernetesResourceInOSLCatalog is called for this object (fabric8’s GenericKubernetesResource entity) + - We examine if the resource has label org.etsi.osl.resourceId + - This label is added by OSOM during service orders to correlate K8S requested resources with resources in inventory + - If the label exists, we update the resource by ID updateResourceById + - Else a resource is created in catalog + + +# Deployment of a new CR based on a CRD + + + + +- A message arrives to deploy a CR + - The call examines if this CRIDGE service can handle the request (based on context and masterURL) +- There are headers received and a crspec in json +- The crspec is unmarshaled as GenericKubernetesResource +- Headers are in format org.etsi.osl.* +- These headers are injected as labels + - (see later in orchestration) +- A namespace is created for this resource +- Watchers are created for this namespace for e.g. new secrets, config maps etc , so that they can be available back as resources to the Inventory of OSL (Note only Secrets for now are watched) + + +# Expose CRDs as Service Specifications in OpenSlice catalogs + +See [ExposingKubernetesResources](ExposingKubernetesResources.md) + + + + +# Service Orchestration and CRDs/CRs + +OSOM checks the presence of attribute _CR_SPEC at the RFS to make a request for a CR deployment + +- _CR_SPEC is a JSON or YAML string that is used for the request + - It is similar to what one will do with e.g. a kubectl apply + - There are tools to translate a yaml file to a json + +> LCM rules can be used to change attributes of this yaml/json file, before sending this for orchestration + +However, the following issue needs to be solved: ** How to map the CR lifecycle that is defined in the CRD with the TMF resource Lifecycle? ** + - For this We introduced the following characteristics: _CR_CHECK_FIELD, _CR_CHECKVAL_STANDBY, _CR_CHECKVAL_ALARM, _CR_CHECKVAL_AVAILABLE, _CR_CHECKVAL_RESERVED, _CR_CHECKVAL_UNKNOWN, _CR_CHECKVAL_SUSPENDED + +OSOM sends to CRIDGE a message with the following information: + +- currentContextCluster: current context of cluster +- clusterMasterURL: current master url of the cluster +- org.etsi.osl.serviceId: This is the related service id that the created resource has a reference +- org.etsi.osl.resourceId: This is the related resource id that the created CR will wrap and reference. +- org.etsi.osl.prefixName: we need to add a short prefix (default is cr) to various places. For example in K8s cannot start with a number +- org.etsi.osl.serviceOrderId: the related service order id of this deployment request +- org.etsi.osl.namespace: requested namespace name +- org.etsi.osl.statusCheckFieldName: The name of the field that is needed to be monitored in order to monitor the status of the service and translate it to TMF resource statys (RESERVED AVAILABLE, etc) +- org.etsi.osl.statusCheckValueStandby: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state STANDBY (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- org.etsi.osl.statusCheckValueAlarm: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state ALARMS (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- org.etsi.osl.statusCheckValueAvailable: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state AVAILABLE (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- org.etsi.osl.statusCheckValueReserved: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state RESERVED (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- org.etsi.osl.statusCheckValueUnknown: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state UNKNOWN (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- org.etsi.osl.statusCheckValueSuspended: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state SUSPENDED (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) + +- Parameters: + - aService reference to the service that the resource and the CR belongs to + - resourceCR reference the equivalent resource in TMF repo of the target CR. One to one mapping + - orderId related service order ID + - startDate start date of the deployment (not used currently) + - endDate end date of the deployment (not used currently) + - _CR_SPEC the spec that is sent to cridge (in json) +- Returns: + - a string response from cridge. It might return "OK" if everything is ok. "SEE OTHER" if there are multiple CRIDGEs then some other cridge will handle the request for the equivalent cluster. Any other response is handled as error + + +- CRIDGE receives the message and creates according to the labels the necessary CR +- It monitors the created resource(s) in namespace (see the Sequence Diagram in previous images) +- It monitors and tries to figure out and map the Status of the CR to the TMF Status according to the provided org.etsi.osl.statusCheck* labels +- It sends to the message bus the current resource for creation or update to the TMF service inventory + + +--- + +## What's next? + + - See examples of exposing operators via OpenSlice: + - [Exposing Kubernetes Operators as a Service : Offering "Calculator as a Service" through OpenSlice](ExposingCRDs_aaS_Example_Calculator.md) + + + + + + diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/ExposingCRDs_aaS_Example_Calculator.md b/docs/ExposingCRDs_aaS_Example_Calculator/ExposingCRDs_aaS_Example_Calculator.md new file mode 100644 index 0000000000000000000000000000000000000000..e50c05c53e03a0fc0e24ddbe117b6397dfa6bdab --- /dev/null +++ b/docs/ExposingCRDs_aaS_Example_Calculator/ExposingCRDs_aaS_Example_Calculator.md @@ -0,0 +1,262 @@ + +# Exposing Kubernetes Operators as a Service : Offering "Calculator as a Service" through OpenSlice + +## Intended Audience: Service Designers + + +> To illustrate the powerful concept of Kubernetes operators and how they can be utilized to offer a service through OpenSlice, let's provide an example of a "Calculator as a Service." + +> This example will demonstrate the flexibility and capabilities of Kubernetes operators in managing custom resources and automating operational tasks. + +--- +## Offering "Calculator as a Service" through OpenSlice + +- We have a service that can accept two integers and an action (SUM, SUB, etc) and returns a result +- We would like to offer it as a Service through OpenSlice +- So when a user orders it with some initial parameters, OpenSlice will create it and return the result +- Also while the service is active, we can do further calculations, until we destroy it. + + +Assume the following simple CRD of a calculator model accepting two params (spec section) and an action and returning a result (status section) + +The controller (the calculator code) is implemented in any language and is installed in a Kubernetes cluster + +``` + +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: mycalculators.examples.osl.etsi.org +spec: + group: examples.osl.etsi.org + names: + kind: MyCalculator + plural: mycalculators + singular: mycalculator + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + properties: + spec: + properties: + parama: + type: integer + paramb: + type: integer + action: + type: string + type: object + status: + properties: + result: + type: integer + status: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +``` + + +Request to the cluster (through e.g. kubectl apply) + +``` +apiVersion: examples.osl.etsi.org/v1alpha1 +kind: MyCalculator +metadata: + name: mycalculator.examples.osl.etsi.org +spec: + parama: 170 + paramb: 180 + action: 'SUM' + +``` + +Response + +``` +apiVersion: examples.osl.etsi.org/v1alpha1 +kind: MyCalculator +metadata: +  creationTimestamp: '2023-12-05T12:26:07Z’ + + + +status: +  result: 350 +  status: CALCULATED +spec: +  action: SUM +  parama: 170 +  paramb: 180 + +``` + +To perform this through OpenSlice as a Service Specification ready to be ordered we need to do the following: + +--- +### CRD is saved automatically as Resource Specification + +As soon as the CRD is deployed in the cluster (e.g. by your admin via kubctl or via any installation through the internet) it is automatically transformed and is available in OpenSlice catalogs as a Resource Specification. + +- See also the fully qualified name of the resource specification. + - MyCalculator@examples.osl.etsi.org/v1alpha1@docker-desktop@https://kubernetes.docker.internal:6443/ + - The resource specification name is quite unique, so you can install the CRD in many clusters around the internet. Each CRD on each cluster will appear here, for example: + - MyCalculator@examples.osl.etsi.org/v1alpha1@default_cluster@https://10.10.10.8:6443/ + - MyCalculator@examples.osl.etsi.org/v1alpha1@edge1_cluster@https://172.16.10.10:6443/ + - Having this OpenSlice can manage resources in multiple clusters + + + + +> See also the detailed characteristics. See how OpenSlice makes all characteristics automatically flat and expanded with key-value style + + + +--- +# Expose to Users + +## Start by Creating a ResourceFacingServiceSpecification + +From the UI menu create a new Service Specification + + + + + + + + + +### Creation of CRD-related characteristics + +- We need now to adjust some characteristics of this CRD as Resource Specification. +- OpenSlice transalted automatically the CRD spec in a flat list of characteristics.So the "spec" section from the original yaml for example, is now unfold into: spec, spec.parama, spec.paramb, etc. the same for "status" object +- We need to make OpenSlice aware of when the service will be active. + - So we go to characteristic _CR_CHECK_FIELD and we define that the field that shows the status of the service is the characteristic "status.status" (is a text field) + - Then we go to _CR_CHECKVAL_AVAILABLE and we define the value CALCULATED, which signals the following: When the characteristic "status.status" has the value "CALCULATED" then OpenSlice will mark the underlying service as "ACTIVE" + - We need also to define the yaml file that OpenSLice will use to create the new resource in the kubernetes cluster + - We insert the YAML in the characteristic _CR_SPEC + + the _CR_SPEC is: + +``` +apiVersion: examples.osl.etsi.org/v1alpha1 +kind: MyCalculator +metadata: + name: mycalculator.examples.osl.etsi.org +spec: + parama: 170 + paramb: 180 + action: 'SUM' + +``` + + + + +> However the values are fixed. How do we allow a user to pass parameters through OpenSlice + +## Expose in Catalog + +Create a new CustomerFacingServiceSpecification + + - Go to the menu Service Specification>New Service Specification + - Create a service My Calulator and mark it as a Bundle + - Go to Service Specification Relationships and add MyCalculatorRFS + - The service will be automatically transformed to a "CustomerFacingServiceSpecification" + - Add the following characteristics as the image shows: + + + + + + + + +### Allow users to pass new values through OpenSlice + + + +We need to Create LCM rules in CustomerFacingServiceSpecification: + + - The goal of the rules is to allow the user to pass parameters to the actual resource towards the cluster. + - we will create one rule that will pass the parameters just before creating the service (PRE_PROVISION phase) + - we will create one rule that will pass the parameters while the service is active (SUPERVISION phase) + - The rules will be the same + + + +If we see one rule it will look like the following: + + +- We need to change the _CR_SPEC characteristic of the referenced ResourceFacingServiceSpecification +- First bring a block from Service>Relationships>Service Refs and drop the "Service MyCalculatorRFS" block +- Then add a list block from Lists +- Then add the block that modifies a referenced characteristic from Service>Relationships>Service Refs the block "Set value to characteristic of a Referenced Service" +- Add a block for text _CR_SPEC +- We use a block that changes a String according to variables Text>"A formatted text replacing variables from List" +- See that we have as Input string the YAML string lines + - see that parama, paramb has a %d (they accept integers), action is %s (accepts a string) + - See that the variables tha will replace the %d, %d and %s are an list + - the first %d will be replaced with the value from characteristic spec.parama + - the second %d will be replaced with the value from characteristic spec.paramb + - the %s will be replaced with the value from characteristic spec.action + + + +If we see the SUPERVISION rule it will look like the following: + +- It contains also the Result field, which takes the value from the referenced service +- Add a block for the Result field from Service>Number blocks +- Add a str to int block from Number blocks +- Add Service>Relationships>Service Refs and drop the input block [Service MyCalculatorRFS] "Get Service details from current context running service" and select from the drop down the "serviceCharacteristicValue" +- Add as name the "status.result" + + + + + + + +Expose it then to a catalogue for orders through the Service Categories and Service Catalogs + + + + + +### Order the Service + +When a user orders the service, it will look like this: + + + + + +- After the Service Order we have 2 services in service inventory on CFS and on RFS. Both have references to values +- OpenSlice (via CRIDGE service) updates the Resource in Resource Inventory and OSOM updates the Services in Service Inventory +- The Actual resources are running in the Kubernetes cluster managed by OpenSlice +- The result is in the characteristic status.result of the running service + + + + + +### Modify the running service + + The user can modify the service + + + +- After a while the update is applied to the cluster, the controller will pick up the resource update and patch the resource +- OpenSlice (via CRIDGE service) updates the Resource in Resource Inventory and OSOM updates the Services in Service Inventory +- The result will be available to the respective characteristic "Result" after a few seconds, as need to go through various steps (OpenSlice orchestrator, down to kubernetes, to Calculator controller and back) + + + + \ No newline at end of file diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/cfs_img12.png b/docs/ExposingCRDs_aaS_Example_Calculator/cfs_img12.png new file mode 100644 index 0000000000000000000000000000000000000000..d3f55dad53fef145b49e720afd5a13140a097917 Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/cfs_img12.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img07.png b/docs/ExposingCRDs_aaS_Example_Calculator/img07.png new file mode 100644 index 0000000000000000000000000000000000000000..6990bf18122d41d5c3eee345270c4c18b5b0a1dc Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img07.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img08.png b/docs/ExposingCRDs_aaS_Example_Calculator/img08.png new file mode 100644 index 0000000000000000000000000000000000000000..fdb27bf11096f00458a89586ae5efc2cb8e162b8 Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img08.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img09.png b/docs/ExposingCRDs_aaS_Example_Calculator/img09.png new file mode 100644 index 0000000000000000000000000000000000000000..a6b963879355580e242b02b10e007e1434fdceb3 Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img09.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img10.png b/docs/ExposingCRDs_aaS_Example_Calculator/img10.png new file mode 100644 index 0000000000000000000000000000000000000000..73d0ef7c9aaa5e56098c5fca4420fd6c50b8cd2a Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img10.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img11.png b/docs/ExposingCRDs_aaS_Example_Calculator/img11.png new file mode 100644 index 0000000000000000000000000000000000000000..af0be10ddb844714a802343c3cef7d1231049355 Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img11.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img12.png b/docs/ExposingCRDs_aaS_Example_Calculator/img12.png new file mode 100644 index 0000000000000000000000000000000000000000..47b924e5c384702fec7c911f194b45be001fe814 Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img12.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img13.png b/docs/ExposingCRDs_aaS_Example_Calculator/img13.png new file mode 100644 index 0000000000000000000000000000000000000000..f97136493d1c2b6bca4c52a99a2d237a4109b090 Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img13.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img13_1.png b/docs/ExposingCRDs_aaS_Example_Calculator/img13_1.png new file mode 100644 index 0000000000000000000000000000000000000000..f3d019ce3704a7397b9b5049022362dd1b8bc32a Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img13_1.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img14.png b/docs/ExposingCRDs_aaS_Example_Calculator/img14.png new file mode 100644 index 0000000000000000000000000000000000000000..570933dcd05ec67463254237a008515e098699eb Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img14.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img15.png b/docs/ExposingCRDs_aaS_Example_Calculator/img15.png new file mode 100644 index 0000000000000000000000000000000000000000..4e35c0818e4daae0f500ccb0bab4181a5310c4d6 Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img15.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img16.png b/docs/ExposingCRDs_aaS_Example_Calculator/img16.png new file mode 100644 index 0000000000000000000000000000000000000000..11cd78e7cb200ee0506f09a681b01b41331de5bb Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img16.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img17.png b/docs/ExposingCRDs_aaS_Example_Calculator/img17.png new file mode 100644 index 0000000000000000000000000000000000000000..d11c3c47217474cc72f95a746bbb71c5f913b840 Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img17.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img18.png b/docs/ExposingCRDs_aaS_Example_Calculator/img18.png new file mode 100644 index 0000000000000000000000000000000000000000..5dfc8b9a5f7afdfcc63df9ac3c62e2d5f367d28f Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img18.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img19.png b/docs/ExposingCRDs_aaS_Example_Calculator/img19.png new file mode 100644 index 0000000000000000000000000000000000000000..ad9d34b5396d69f7654447e4ee74331386adb2a5 Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img19.png differ diff --git a/docs/ExposingCRDs_aaS_Example_Calculator/img20.png b/docs/ExposingCRDs_aaS_Example_Calculator/img20.png new file mode 100644 index 0000000000000000000000000000000000000000..be0c6f94c46cfb6d0a5024115ebbe9200ae8812a Binary files /dev/null and b/docs/ExposingCRDs_aaS_Example_Calculator/img20.png differ diff --git a/docs/ExposingKubernetesResources.md b/docs/ExposingKubernetesResources.md new file mode 100644 index 0000000000000000000000000000000000000000..0a64cdd9d89ed6f246166081133c290a06780d30 --- /dev/null +++ b/docs/ExposingKubernetesResources.md @@ -0,0 +1,169 @@ + +# Expose and manage Kubernetes Custom Resource Definitions (Operators) in a Kubernetes Cluster + +OpenSlice is capable of exposing Kubernetes Resources and Definitions as Service Specifications + +## Intended Audience: Service Designers + + > Kubernetes is an orchestration system for automating software deployment, scaling, and management. One can interact though the Kubernetes API and it has a set of objects ready for use out of the box. Custom Resource Definitions (CRDs) is a way that allows to manage things other than Kubernetes itself and allows to create our own objects The use of CRDs makes the possibilities of Kubernetes management almost limitless. You can extend the base Kubernetes API with any object you like using CRDs. + + > By allowing the design and lifecycle management of services/resources that expose CRDs/CRs in a Kubernetes cluster via the TMF APIs, OSL can be used in many complex scenarios now involing resources from multiple domains. + + +1. OpenSlice is capable to: + - Create and manage Custom Resources (CRs) using installed CRDs on a target Kubernetes cluster. + - Facilitate complex orchestration scenarios by wrapping Kubernetes APIs as TMF APIs and models. + - Handles connectivity to a Kubernetes cluster and manages the lifecycle of CRDs + - Wraps the Kubernetes API, Receives and provides resources towards other OpenSlice services via the service bus + +2. Enabling Loose Coupling and Orchestration + - Language Flexibility: Developers can write CRDs in any language and expose them via the Kubernetes APIs. OSL will reuse these CRDs, enhancing flexibility and integration capabilities. + - Familiar Deployment: Developers can create and deploy applications using familiar tools such as Helm charts, simplifying the process and reducing the learning curve. + +3. Ecosystem Reusability + - OpenSlice capitalizes on the extensive Kubernetes ecosystem, particularly focusing on operators (CRDs). + - Key repositories and hubs such as artifacthub.io and Operatorhub.io can be utilized for finding and deploying operators. + +4. Service Catalog Exposure and Deployment + - OpenSlice can expose CRs in service catalogs, facilitating their deployment in complex scenarios. + - These scenarios may include service bundles that involve multiple systems, such as RAN controllers or other Kubernetes clusters, providing a robust and versatile deployment framework. + +# Approach + + > OpenSlice in general is responible for exposing service specifications which are ready to be ordered and orchestrated, through tmforum Open APIs as defined in the OSL Service Spec Catalog. Usually for a service specification a corresponding (one or more) resource specification (resourceSpecificationReference) is registered in the OSL Resource Spec Catalog. + +The following image illustrates the approach. + + + +1. A CRD in a cluster will be mapped in TMF model as a Resource specification and therefore can be exposed as a service specification in a catalog +2. Service Orders can be created for this service specification. +3. OSOM creates a Resource in OSL Resource inventory and requests new Custom Resource (CR) in the target cluster + - The resource is created in a specific namespace (for example the UUID of the Service Order) + - A CR in a cluster will be mapped in TMF model as a Resource in the resource Inventory + - Other related resources created by the CRD Controller within the namespace are automatically created in OSL Resource Inventory under the same Service Order + + +# Awareness for CRDs and CRs in cluster + +> CRDs and CRs can appear (disappear) or change status at any time in a cluster. OpenSlice Resource Inventory need to be aware of these events. + + When installing OpenSlice you can configure at least one management cluster. OpenSlice connects via a provided kubeconf + +- On Start up OSL tries to register this cluster and context to OSL catalogs. +- After the registration of this cluster as a Resource in OSL OSL is always aware of all CRDs and their CRs in the cluster, even if a CRD or CR is added/updated/deleted in the K8S cluster outside of OSL +- Resources created by OpenSlice have labels, e.g. (org.etsi.osl.*) + +# Expose CRDs as Service Specifications in OpenSlice catalogs + +**A CRD by default is exposed as a Resource Specification** + +To ensure unique names across the clusters that OpenSlice can manage, the name of a CRD is constructed as follows: + +```Kind @ ApiGroup/version @ ContextCluster @ masterURL``` + +For example you might see resource Specifications like: + + - ```Application@argoproj.io/v1alpha1@kubernetes@https://10.10.10.144:6443/``` + - ```IPAddressPool@metallb.io/v1beta1@kubernetes@https://10.10.10.144:6443/``` + - ```Provider@pkg.crossplane.io/v1@kubernetes@https://10.10.10.144:6443/``` + +All attributes of the CRD are translated into characteristics + +The following specific characteristics are **added**: + + - _CR_SPEC: Used for providing the json Custom Resource description to apply + - _CR_CHECK_FIELD: Used for providing the field that need to be checked for the resource status + - _CR_CHECKVAL_STANDBY: Used for providing the equivalent value from resource to signal the standby status + - _CR_CHECKVAL_ALARM: Used for providing the equivalent value from resource to signal the alarm status + - _CR_CHECKVAL_AVAILABLE: Used for providing the equivalent value from resource to signal the available status + - _CR_CHECKVAL_RESERVED: Used for providing the equivalent value from resource to signal the reserved status + - _CR_CHECKVAL_UNKNOWN: Used for providing the equivalent value from resource to signal the unknown status + - _CR_CHECKVAL_SUSPENDED: Used for providing the equivalent value from resource to signal the suspended status + + +1. Create a new Service Specification and use this Resource Specification in Resource Specification Relationships + - Then the Service Specification is saved as ResourceFacingServiceSpecification + + 1.1. You can give at this stage values to the characteristics: + + - _CR_SPEC, + - _CR_CHECK_FIELD + - _CR_CHECKVAL_STANDBY + - _CR_CHECKVAL_ALARM + - _CR_CHECKVAL_AVAILABLE + - _CR_CHECKVAL_RESERVED + - _CR_CHECKVAL_UNKNOWN + - _CR_CHECKVAL_SUSPENDED + + 1.2. You can now create LCM rules if you wish + +2. Create a new Service Specification and use the Resource Facing Service Specification in Service Specification Relationships + - Then the Service Specification is saved as CustomerFacingServiceSpecification + + 2.1. You can give at this stage values to the characteristics: + + - _CR_SPEC, + - _CR_CHECK_FIELD + - _CR_CHECKVAL_STANDBY + - _CR_CHECKVAL_ALARM + - _CR_CHECKVAL_AVAILABLE + - _CR_CHECKVAL_RESERVED + - _CR_CHECKVAL_UNKNOWN + - _CR_CHECKVAL_SUSPENDED + + 2.2. You We can create LCM rules for this new Service Specification + + 2.3. You Expose configurable values for users to configure during service order + + + + +# Service Orchestration and CRDs/CRs + +OSOM - OpenSlice Service Orchestrator, checks the presence of attribute _CR_SPEC at the RFS to make a request for a CR deployment + +- _CR_SPEC is a JSON or YAML string that is used for the request + - It is similar to what one will do with e.g. a kubectl apply + - There are tools to translate a yaml file to a json + +> LCM rules can be used to change attributes of this yaml/json file, before sending this for orchestration + + +## Mapping the CR lifecycle that is defined in the CRD with the OpenSLice (TMF-based) resource Lifecycle + +OpenSlice adds automatically as we see the following characteristics: + + - _CR_CHECK_FIELD + - _CR_CHECKVAL_STANDBY + - _CR_CHECKVAL_ALARM + - _CR_CHECKVAL_AVAILABLE + - _CR_CHECKVAL_RESERVED + - _CR_CHECKVAL_UNKNOWN + - _CR_CHECKVAL_SUSPENDED + +**These characteristics instrument OpenSlice services to manage and reflect the lifecycle of a kubernetes resource to OpenSlice's (TMF based) lifecycle** + + +- _CR_CHECK_FIELD: The name of the field that is needed to be monitored in order to monitor the status of the service and translate it to TMF resource statys (RESERVED AVAILABLE, etc) +- _CR_CHECKVAL_STANDBY: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state STANDBY (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- _CR_CHECKVAL_ALARM: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state ALARMS (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- _CR_CHECKVAL_AVAILABLE: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state AVAILABLE (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- _CR_CHECKVAL_RESERVED: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state RESERVED (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- _CR_CHECKVAL_UNKNOWN: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state UNKNOWN (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) +- _CR_CHECKVAL_SUSPENDED: The CR specific value (of the CheckFieldName) that needs to me mapped to the TMF resource state SUSPENDED (see org.etsi.osl.tmf.ri639.model.ResourceStatusType) + + +--- + +## What's next? + + + - See examples of exposing operators via OpenSlice: + - [Exposing Kubernetes Operators as a Service : Offering "Calculator as a Service" through OpenSlice](ExposingCRDs_aaS_Example_Calculator.md) + - [Learn more about CRIDGE, the service in OSL that manages CRDs/CRs](CRIDGEforDevelopers_Jenkins_Example.md) + + + + + diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/HELM_Installation_aaS_Jenkins_Example.md b/docs/HELM_Installation_aaS_Jenkins_Example/HELM_Installation_aaS_Jenkins_Example.md new file mode 100644 index 0000000000000000000000000000000000000000..ca1995192974c6b7bd2f14da7d954b6f9ab9de7d --- /dev/null +++ b/docs/HELM_Installation_aaS_Jenkins_Example/HELM_Installation_aaS_Jenkins_Example.md @@ -0,0 +1,199 @@ +# Expose HELM charts as Service Specifications +Manage Helm charts installations via OpenSlice Service Specifications and Service Orders. +## Intended Audience: Service Designers + + +> Kubernetes is an orchestration system for automating software deployment, scaling, and management. One can interact though the Kubernetes API and it has a set of objects ready for use out of the box. + +> Helm is a tool that automates the creation, packaging, configuration, and deployment of Kubernetes applications by combining your configuration files into a single reusable package + +> At the heart of Helm is the packaging format called charts. Each chart comprises one or more Kubernetes manifests -- and a given chart can have child charts and dependent charts, as well. Using Helm charts: + +> - Reduces the complexity of deploying Microservices +> - Enhances deployment speed +> - Developers already know the technology + +> There are many Helm charts and Helm repositories there that are ready to be used + +> Enable loose coupling and more orchestration scenarios + +> Developers create and deploy applications in things they already know (e.g. Helm charts) + +> Use the TMF models as wrapper entities around Helm charts + + +Use OpenSlice to expose them in service catalogs and deploy them in complex scenarios (service bundles) involving also other systems: + + - Include e.g. RAN controllers, + - Pass values through life cycle rules from one service to another, + - Manage multiple Helms in multiple clusters + + +## The installation of HELM charts is based on OpenSlice CRD support + +Please read more [here](../ExposingKubernetesResources.md) + + +For installing HELM charts we will use ArgoCD a well known Kubernetes-native continuous deployment (CD) tool + +> ArgoCD is a Kubernetes-native continuous deployment (CD) tool + +> While just deploying Heml charts is just a scenario for ArgoCD , in future one can exploit it for many things + +> Despite some other tools like FluxCD, it provides also a UI which is useful for management and troubleshooting + + +We will mainly use the CRD of ```Kind: Application``` that ArgoCD can manage + + + +Before proceeding, install ArgoCD in your management cluster, by following ArgoCD instructions + +As soon as you install ArgoCD, OpenSlice is automatically aware for specific new Kinds. The one we will use is is the ```Kind: Application``` that ArgoCD can manage under the apiGroup argoproj.io + +Browse to Resource Specifications. You will see an entry like the following: + +```Application@argoproj.io/v1alpha1@kubernetes@https://10.10.10.144:6443/``` + +see image: + + + +# Example: Offer Jenkins as a Service via Openslice + +We will use the ```Kind: Application``` of ArgoCD and create a ResourceFacingServiceSpecification for Jenkins + + 1. Go to Service Specifications + 2. Create New Specification + 3. Give a Name, eg. jenkinsrfs + 4. Go to Resource Specification Relationships + 5. Assign ```Application@argoproj.io/v1alpha1@kubernetes@https://10.10.10.144:6443/``` + + + + +Focus now on the characteristics configuration. + +First we need to map the lifecycle of ArgoCD Application to TMF Resource State + + + + +In ArgoCD the field **health.status** has the value that we need to check (Healty, Progressing, etc) + + +The _CR_SPEC can be designed first in a YAML or json editor. Let's see a YAML definition: + + + ``` + +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + finalizers: + - resources-finalizer.argocd.argoproj.io + name: openslice-jenkins + namespace: argocd +spec: + project: default + destination: + namespace: opencrdtest + name: in-cluster + source: + repoURL: https://charts.jenkins.io + targetRevision: 4.6.1 + chart: jenkins + helm: + values: | + controller: + service: + type: ClusterIP + syncPolicy: + automated: + prune: true + selfHeal: true + allowEmpty: false + syncOptions: + - Validate=false + - CreateNamespace=true + - PrunePropagationPolicy=foreground + - PruneLast=true + - RespectIgnoreDifferences=true +``` + +**NOTICE** + +On each installation OSOM will change the name of the resource in order to be unique (will have a UUID) + + ```name: openslice-jenkins``` + + destination namespace that ArgoCD will use is the name ```opencrdtest``` + + ```destination: + namespace: opencrdtest + ``` + +**This implies that ArgoCD installs the Jenkins always in the same namespace** + +**To avoid this we will create a simple pre-provision rule to change the namespace properly** + +See the following image: + + +1. Drag-Drop the _CR_SPEC characteristic of jenkinsrfs from the Service>Text blocks +2. Drag-Drop Text>Formatted text block +3. Drag-Drop Text>Multi-line text input block +4. Copy paste the YAML text +5. Change the spec: destination:namespace to the value %s +6. Drag-Drop Lists>Create list with block delete 2 items (click the gear icon). Connect it to formatted text block +7. Drag-Drop Context>Current Service Order block and select the id. Connect it to the List +8. Save the PRE_PROVISION Rule + +# Expose the service to your users + +Expose then as CustomerFacingServiceSpecification by using the previous RFSS as Service Specification Relationship +1. Create a Jenkins service and mark as Bundle and save it +2. Go to Service Specification Relationships and assign Jenkinsrfs +3. Add also a Logo if you wish + + + + +Expose it now to a Category and a Catalog to be available for ordering. + + + +# Order the service + +Order the service from the catalog. + + +Soon the order will be completed and the Services will be active + + + + +# How to access the Jenkins installation: + +From the Supporting services of the Service Order, select the ResourceFacingService (jenkinsrfs) + +The ResourceFacingService has also supporting resources in resource inventory. + + + +One is the resource reference to the application (e.g. _cr_tmpname_...), the other is a secret (e.g. cr87893...). + +Click to go to the secret resource (This is in the Resource inventory of OpenSlice) + + + +Use them to login in your Jenkins. + + +> Exposing Jenkins to you external is a matter of cluster configuration and request (nodeport, load balancing, etc)! This is not a topic for this example + + + + + + diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img01.png b/docs/HELM_Installation_aaS_Jenkins_Example/img01.png new file mode 100644 index 0000000000000000000000000000000000000000..bbe29df97934dd4438f39f2f3e0e0e443ba0e4d3 Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img01.png differ diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img02.png b/docs/HELM_Installation_aaS_Jenkins_Example/img02.png new file mode 100644 index 0000000000000000000000000000000000000000..c3719c6c04d5e04fc126d5d8388e8862a524ba2b Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img02.png differ diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img03.png b/docs/HELM_Installation_aaS_Jenkins_Example/img03.png new file mode 100644 index 0000000000000000000000000000000000000000..fa3d7327fa68743d247aef9842ace2262cdeb84e Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img03.png differ diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img04.png b/docs/HELM_Installation_aaS_Jenkins_Example/img04.png new file mode 100644 index 0000000000000000000000000000000000000000..8a6c0bf1deb000fc1fd494317bbe0a318eb1d3e5 Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img04.png differ diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img05.png b/docs/HELM_Installation_aaS_Jenkins_Example/img05.png new file mode 100644 index 0000000000000000000000000000000000000000..a505d800a71024148fe04533d15d7c26d0f1a75f Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img05.png differ diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img06.png b/docs/HELM_Installation_aaS_Jenkins_Example/img06.png new file mode 100644 index 0000000000000000000000000000000000000000..2089e793a2c668e24dab0597c7c2965700b57f5f Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img06.png differ diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img061.png b/docs/HELM_Installation_aaS_Jenkins_Example/img061.png new file mode 100644 index 0000000000000000000000000000000000000000..f2dcdf951f264b1164804fba435449ad176e8da7 Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img061.png differ diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img07.png b/docs/HELM_Installation_aaS_Jenkins_Example/img07.png new file mode 100644 index 0000000000000000000000000000000000000000..d3bced145f17fc2804b6f36ab1a4919ff3ec656a Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img07.png differ diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img08.png b/docs/HELM_Installation_aaS_Jenkins_Example/img08.png new file mode 100644 index 0000000000000000000000000000000000000000..979adc4d20afd24eb0aabf78f72171b26e8ef25e Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img08.png differ diff --git a/docs/HELM_Installation_aaS_Jenkins_Example/img09.png b/docs/HELM_Installation_aaS_Jenkins_Example/img09.png new file mode 100644 index 0000000000000000000000000000000000000000..06b8306a2416fc3a15110672b2971ddada0b4d69 Binary files /dev/null and b/docs/HELM_Installation_aaS_Jenkins_Example/img09.png differ diff --git a/docs/K8aas_example.md b/docs/K8aas_example.md new file mode 100644 index 0000000000000000000000000000000000000000..3bda09f3d2c97bc372fade5e96c49cebc3ed6b18 --- /dev/null +++ b/docs/K8aas_example.md @@ -0,0 +1,92 @@ +@startuml +actor Participant as caller +boundary OSLAPI as oslapirest +control OSLC as oslapi +control OSOM as osom +control CRIDGE as cridge +control MGMK8S as mgtk8s +control ARGOCD as argo +control K8SaaSCRD as k88ascrd + +caller -> oslapirest : Create Service Order for K8SaaS spec\n (With ACKNOWLEDGED state) +oslapirest -> oslapi: Create\nService\nOrder +osom -> oslapi: Fetch ACK\norders +activate osom +osom -> osom: Process orders +osom -> cridge: Deploy CR App +note right + This CR is matched with equivalent + Resource in RI (ref resourceId) +end note +cridge -// mgtk8s: Create CR +note right + here we label this CR with resourceId +end note +cridge -> cridge: Start watching\nSO namespace +cridge -> osom: response OK +osom -> oslapi: Order is INPROGRESS \n (services are created\nin RESERVED) + +mgtk8s -> argo: Create CR +argo -> k88ascrd: Create CR +argo -// mgtk8s: CR status +mgtk8s -// cridge: CRs watch +group sync and reconciliation + cridge -// oslapi: Update equivalent resource in RI of this CR\n(ref resourceId) + oslapi -> oslapi: EVENT_RESOURCE_STATE_CHANGED + mgtk8s -// cridge: Secrets watch + cridge -// oslapi: Add/Update equivalent secret resource in RI of this CR\n(ref resourceId) + note right + org.etsi.osl.* labels are added + so this resource can be managed by OSL + end note + oslapi -> oslapi: EVENT_RESOURCE_STATE_CHANGED + note left + SIM638 needs to take this event in case + this Resource is related + to a specific supporting resource + (see resourceStateChangedEvent() and + updateResourceFromKubernetesLabel() ) + Any resources that has characteristic org.etsi.osl.serviceId equals to a service + are automatically added as supportingResources of this Service + end note +end + +osom -> osom: Wait all Active or Failures +note left +Wait for all services and +underlying resources +to be Active or Failed +end note +osom -> osom: Order is COMPLETED +osom -> oslapi: Order is COMPLETED +deactivate osom + +group sync and reconciliation (continuous process) + mgtk8s -// cridge: CRs watch + cridge -// oslapi: Update equivalent resource in RI of this CR\n(ref resourceId) + oslapi -> oslapi: EVENT_RESOURCE_STATE_CHANGED + mgtk8s -// cridge: Secrets watch + cridge -// oslapi: Add/Update equivalent secret resource in RI of this CR\n(ref resourceId) + oslapi -> oslapi: EVENT_RESOURCE_STATE_CHANGED +end + + + +caller -> oslapirest : request Service Order (by id) +activate caller +caller <- oslapirest : Service Order +caller -> caller : examine supportingService list +caller -> oslapirest : request Service (by id) +activate caller #FFDDDD +group focus only on the Resource Facing Service +caller -> caller : examine supportingResource list of this RFS +caller -> oslapirest : request Resource (by id) (tf-output@...) +caller <- oslapirest : Resource from Inventory +caller -> caller :get characteristics kubeconf +caller -> oslapirest : request Resource (by id) (tfstate-...) +caller <- oslapirest : Resource from Inventory +caller -> caller :get characteristic tfstate +end +deactivate caller +deactivate caller +@enduml diff --git a/docs/WatcherService_diagrams.md b/docs/WatcherService_diagrams.md new file mode 100644 index 0000000000000000000000000000000000000000..df50156b7804b81cd3652156f712eaf956c3fbb6 --- /dev/null +++ b/docs/WatcherService_diagrams.md @@ -0,0 +1,43 @@ +@startuml +participant "WatcherService" as Watcher +participant "SharedInformerFactory" as InformerFactory +participant "SharedIndexInformer" as IndexInformer +participant "CustomResourceDefinition" as CRD +participant "ResourceEventHandler" as EventHandler +database "CatalogClient" as Catalog + +Watcher -> InformerFactory : getKubernetesClient().informers() +activate InformerFactory +InformerFactory --> Watcher : sharedInformerFactory +deactivate InformerFactory + +Watcher -> IndexInformer : sharedInformerFactory.sharedIndexInformerFor(CRD, 30 * 1000L) +activate IndexInformer +IndexInformer --> Watcher : shixInformer +deactivate IndexInformer + +Watcher -> IndexInformer : addEventHandler(new ResourceEventHandler()) +activate IndexInformer +IndexInformer -> EventHandler : onAdd(CRD) +activate EventHandler +EventHandler -> Catalog : createOrUpdateResourceSpecByNameCategoryVersion() +EventHandler -> Catalog : createOrUpdateResourceByNameCategoryVersion() +activate Catalog +Catalog --> EventHandler : Response +deactivate Catalog +EventHandler --> IndexInformer : onAdd Completed +EventHandler -> Watcher : createCRDSharedIndexInformer +deactivate EventHandler + +IndexInformer -> EventHandler : onUpdate(oldCRD, newCRD) +activate EventHandler +EventHandler --> IndexInformer : onUpdate Completed +deactivate EventHandler + +IndexInformer -> EventHandler : onDelete(CRD, deletedFinalStateUnknown) +activate EventHandler +EventHandler --> IndexInformer : onDelete Completed +deactivate EventHandler + +deactivate IndexInformer +@enduml \ No newline at end of file diff --git a/docs/img01.png b/docs/img01.png new file mode 100644 index 0000000000000000000000000000000000000000..d9f6f73dd21ff94572fd411c68e31a2915426f70 Binary files /dev/null and b/docs/img01.png differ diff --git a/docs/img02.png b/docs/img02.png new file mode 100644 index 0000000000000000000000000000000000000000..fb546ad61cce1ce5c9cc593507f816ef64c7bcc5 Binary files /dev/null and b/docs/img02.png differ diff --git a/docs/img03.png b/docs/img03.png new file mode 100644 index 0000000000000000000000000000000000000000..79d0d2a208ca3c63489264a87d4a155d44d12cc4 Binary files /dev/null and b/docs/img03.png differ diff --git a/docs/img04.png b/docs/img04.png new file mode 100644 index 0000000000000000000000000000000000000000..233831d1bb986c92432fdaff602db44fc2c0df48 Binary files /dev/null and b/docs/img04.png differ diff --git a/docs/img05.png b/docs/img05.png new file mode 100644 index 0000000000000000000000000000000000000000..3b05561502893694d3d72d12cbbfc154786da853 Binary files /dev/null and b/docs/img05.png differ diff --git a/docs/img06.png b/docs/img06.png new file mode 100644 index 0000000000000000000000000000000000000000..ef8d3879cbb887e5ce686a246b981da14cb6e64c Binary files /dev/null and b/docs/img06.png differ diff --git a/docs/img07.png b/docs/img07.png new file mode 100644 index 0000000000000000000000000000000000000000..6990bf18122d41d5c3eee345270c4c18b5b0a1dc Binary files /dev/null and b/docs/img07.png differ diff --git a/docs/img08.png b/docs/img08.png new file mode 100644 index 0000000000000000000000000000000000000000..fdb27bf11096f00458a89586ae5efc2cb8e162b8 Binary files /dev/null and b/docs/img08.png differ diff --git a/docs/img09.png b/docs/img09.png new file mode 100644 index 0000000000000000000000000000000000000000..a6b963879355580e242b02b10e007e1434fdceb3 Binary files /dev/null and b/docs/img09.png differ diff --git a/docs/img10.png b/docs/img10.png new file mode 100644 index 0000000000000000000000000000000000000000..73d0ef7c9aaa5e56098c5fca4420fd6c50b8cd2a Binary files /dev/null and b/docs/img10.png differ diff --git a/docs/kubernetesClientResource_diagrams.md b/docs/kubernetesClientResource_diagrams.md new file mode 100644 index 0000000000000000000000000000000000000000..22dbf6ac9c6233e2eb5820eba500e0818aeb549b --- /dev/null +++ b/docs/kubernetesClientResource_diagrams.md @@ -0,0 +1,53 @@ +@startuml +queue MQ +control "KubernetesClientResource" as KubeClientResource +participant "KubernetesClient" as KubeClient +entity "GenericKubernetesResource" as ResourceObj +participant "Namespace" as NamespaceDB + +MQ -> KubeClientResource : deployCR(headers, crspec) + +alt check if this cridge can handle the CRSPEC\ncurrentContextCluster, clusterMasterURL + + KubeClientResource --> MQ : Response (SEE OTHER) +end + +activate KubeClientResource + +KubeClientResource -> KubeClient : new KubernetesClientBuilder() +activate KubeClient +KubeClient --> KubeClientResource : k8s +deactivate KubeClient + + +KubeClientResource -> NamespaceDB : Try creating Namespace +activate NamespaceDB +NamespaceDB --> KubeClientResource : Namespace Created / Exists +deactivate NamespaceDB + +KubeClientResource -> KubeClientResource : createWatchersFornamespace() + + +activate KubeClientResource + + +KubeClientResource -> SharedInformer : KubernetesClient.secrets().inNamespace(nameSpacename).inform(new ResourceEventHandler<>()) + +loop For each Secret Event + SharedInformer -> EventHandler : onAdd()/onUpdate()/onDelete() + activate EventHandler + EventHandler -> KubeClientResource : updateKubernetesSecretResourceInOSLCatalog + deactivate EventHandler +end + +deactivate KubeClientResource + + +KubeClientResource -> ResourceObj : k8s.resource(gkr) +activate ResourceObj +ResourceObj --> KubeClientResource : Creation Response +deactivate ResourceObj + +KubeClientResource --> MQ : Response (OK / FAIL) +deactivate KubeClientResource +@enduml diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..76e6d7e936603df3a077bf7b37d4e722307488c7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,325 @@ + + 4.0.0 + + org.etsi.osl + org.etsi.osl.main + 1.0.0 + ../org.etsi.osl.main + + + + org.etsi.osl.cridge + org.etsi.osl.cridge + https://osl.etsi.org + + + + + UTF-8 + UTF-8 + 3.2.2 + 3.1.0 + 6.10.0 + + + + 4.0.0-RC1 + 1.7.5 + 1.7.28 + + + + + gitlab-maven + https://labs.etsi.org/rep/api/v4/groups/260/-/packages/maven + + + + + gitlab-maven + ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven + + + gitlab-maven + ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot-version} + pom + import + + + org.springframework.cloud + spring-cloud-starter-kubernetes-fabric8-all + ${spring.boot.fabric8-version} + + + + + org.apache.camel.springboot + camel-spring-boot-dependencies + ${camel.version} + pom + import + + + + + + + + + + org.projectlombok + lombok + provided + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + + org.springframework.cloud + spring-cloud-starter-kubernetes-fabric8-all + + + + + org.etsi.osl + org.etsi.osl.model.tmf + ${org.etsi.osl.model.tmf.version} + + + org.etsi.osl + org.etsi.osl.model.k8s + ${org.etsi.osl.model.k8s.version} + + + + + + + org.springframework.boot + spring-boot-starter-activemq + + + org.apache.activemq + activemq-amqp + test + + + org.apache.qpid + proton-j + + + + + org.messaginghub + pooled-jms + + + + + org.apache.camel.springboot + camel-spring-boot-starter + + + org.apache.activemq + activemq-pool + + + org.apache.camel + camel-activemq + + + org.apache.activemq + activemq-broker + + + + + org.apache.camel.springboot + camel-service-starter + + + + org.apache.camel.springboot + camel-http-starter + + + org.apache.camel + camel-jackson + + + org.apache.camel + camel-stream + + + + com.h2database + h2 + + + + org.slf4j + slf4j-simple + + + + org.slf4j + slf4j-api + + + + io.fabric8 + kubernetes-httpclient-okhttp + ${fabric8.version} + + + + + + + org.springframework.boot + spring-boot-starter-test + + + org.junit.jupiter + junit-jupiter-engine + + + org.apache.activemq + activemq-broker + test + + + javax.jms + javax.jms-api + 2.0.1 + test + + + commons-io + commons-io + 2.15.1 + test + + + io.fabric8 + kubernetes-server-mock + ${fabric8.version} + test + + + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + 17 + 17 + + + org.projectlombok + lombok + 1.18.28 + + + + + + + org.codehaus.mojo + license-maven-plugin + ${maven-license-plugin.version} + + false + ========================LICENSE_START================================= + =========================LICENSE_END================================== + *.json + + + + generate-license-headers + + update-file-header + + process-sources + + ${license.licenseName} + + + + + download-licenses + + download-licenses + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-version} + + + + repackage + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-version} + + exec + + + + + + + + + diff --git a/src/main/java/org/etsi/osl/cridge/ActiveMQComponentConfig.java b/src/main/java/org/etsi/osl/cridge/ActiveMQComponentConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..e58a3ec0a46e9e6e82cb3aa795c21f594f9fbd9e --- /dev/null +++ b/src/main/java/org/etsi/osl/cridge/ActiveMQComponentConfig.java @@ -0,0 +1,41 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.bugzilla + * %% + * Copyright (C) 2019 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.cridge; + + +import org.apache.camel.component.activemq.ActiveMQComponent; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import jakarta.jms.ConnectionFactory; + +/** + * @author ctranoris + * + */ +@Configuration +public class ActiveMQComponentConfig { + + @Bean(name = "activemq") + public ActiveMQComponent createComponent(ConnectionFactory factory) { + ActiveMQComponent activeMQComponent = new ActiveMQComponent(); + activeMQComponent.setConnectionFactory( factory ); + return activeMQComponent; + } +} diff --git a/src/main/java/org/etsi/osl/cridge/CRRouteBuilder.java b/src/main/java/org/etsi/osl/cridge/CRRouteBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..78ec06a93467a1a3af0ca0f050b753d36b043056 --- /dev/null +++ b/src/main/java/org/etsi/osl/cridge/CRRouteBuilder.java @@ -0,0 +1,96 @@ +package org.etsi.osl.cridge; + +import java.util.Date; +import java.util.concurrent.TimeUnit; +import org.apache.camel.LoggingLevel; +import org.apache.camel.builder.RouteBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import io.fabric8.kubernetes.api.model.Namespace; +import io.fabric8.kubernetes.api.model.NamespaceBuilder; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import lombok.Getter; + +@Service +@Getter +public class CRRouteBuilder extends RouteBuilder{ + + @Value("${CRD_DEPLOY_CR_REQ}") + private String CRD_DEPLOY_CR_REQ = ""; + + + @Value("${CRD_PATCH_CR_REQ}") + private String CRD_PATCH_CR_REQ = ""; + + @Value("${CRD_DELETE_CR_REQ}") + private String CRD_DELETE_CR_REQ = ""; + + + @Autowired + private KubernetesClientResource kubernetesClientResource; + + + private static final Logger logger = LoggerFactory.getLogger( CRRouteBuilder.class.getSimpleName()); + + @Override + public void configure() throws Exception { + + from( CRD_DEPLOY_CR_REQ ) + .log(LoggingLevel.INFO, log, CRD_DEPLOY_CR_REQ + " message received!") + .to("log:DEBUG?showBody=true&showHeaders=true") + .bean( kubernetesClientResource, "deployCR(${headers}, ${body})") + .convertBodyTo( String.class ); + + from( CRD_DELETE_CR_REQ ) + .log(LoggingLevel.INFO, log, CRD_DELETE_CR_REQ + " message received!") + .to("log:DEBUG?showBody=true&showHeaders=true") + .bean( kubernetesClientResource, "deleteCR(${headers}, ${body})") + .convertBodyTo( String.class ); + + from( CRD_PATCH_CR_REQ ) + .log(LoggingLevel.INFO, log, CRD_PATCH_CR_REQ + " message received!") + .to("log:DEBUG?showBody=true&showHeaders=true") + .bean( kubernetesClientResource, "patchCR(${headers}, ${body})") + .convertBodyTo( String.class ); + + // every 3600000 ms (60 minutes) + from( "timer://processUpdateResources?period=3600000" ) + .log(LoggingLevel.INFO, log, " process nameSpacesTobeDeleted!") + .to("log:DEBUG?showBody=true&showHeaders=true") + .bean( CRRouteBuilder.class , "processNameSpacesTobeDeleted()"); + + } + + public void processNameSpacesTobeDeleted() { + + kubernetesClientResource.getNameSpacesTobeDeleted().forEach( (nameSpaceName, datetime) -> { + + Date currentTime = new Date(); //get current time + long diffInMillies = Math.abs(currentTime .getTime() - datetime.getTime()); + + long diff = TimeUnit.HOURS.convert(diffInMillies, TimeUnit.MILLISECONDS); + if (diff<=2) { //after 2 hours this namespace will be deleted + return; + } + + try (final KubernetesClient k8s = new KubernetesClientBuilder().build()) { + logger.info("Trying to delete namespace {}", nameSpaceName); + Namespace ns = new NamespaceBuilder() + .withNewMetadata() + .withName( nameSpaceName ) + .endMetadata().build(); + k8s.namespaces().resource(ns).delete(); + + kubernetesClientResource.getNameSpacesTobeDeleted().remove(nameSpaceName); + }catch (Exception e) { + e.printStackTrace(); + } + }); + + } + +} diff --git a/src/main/java/org/etsi/osl/cridge/CatalogClient.java b/src/main/java/org/etsi/osl/cridge/CatalogClient.java new file mode 100644 index 0000000000000000000000000000000000000000..0527c112490fd42faf3432af76c9d13e867c2124 --- /dev/null +++ b/src/main/java/org/etsi/osl/cridge/CatalogClient.java @@ -0,0 +1,284 @@ +package org.etsi.osl.cridge; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.etsi.osl.tmf.rcm634.model.LogicalResourceSpecification; +import org.etsi.osl.tmf.rcm634.model.ResourceSpecification; +import org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCreate; +import org.etsi.osl.tmf.ri639.model.LogicalResource; +import org.etsi.osl.tmf.ri639.model.Resource; +import org.etsi.osl.tmf.ri639.model.ResourceCreate; +import org.etsi.osl.tmf.ri639.model.ResourceUpdate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +/** + * @author ctranoris + */ +@Service +public class CatalogClient extends RouteBuilder{ + + + private static final Logger logger = LoggerFactory.getLogger( CatalogClient.class.getSimpleName()); + + @Autowired + private ProducerTemplate template; + + + @Value("${CATALOG_GET_RESOURCESPEC_BY_ID}") + private String CATALOG_GET_RESOURCESPEC_BY_ID = ""; + + @Value("${CATALOG_GET_RESOURCESPEC_BY_ΝAME_CATEGORY}") + private String CATALOG_GET_RESOURCESPEC_BY_ΝAME_CATEGORY = ""; + + + @Value("${CATALOG_UPDADD_RESOURCESPEC}") + private String CATALOG_UPDADD_RESOURCESPEC = ""; + + + @Value("${CATALOG_UPDADD_RESOURCE}") + private String CATALOG_UPDADD_RESOURCE = ""; + + + @Value("${CATALOG_UPD_RESOURCE}") + private String CATALOG_UPD_RESOURCE = ""; + + @Value("${CATALOG_GET_RESOURCE_BY_ID}") + private String CATALOG_GET_RESOURCE_BY_ID = ""; + + + //private ConcurrentHashMap resourcesToBeUpdated = new ConcurrentHashMap<>(); + + + @Override + public void configure() throws Exception { + + + +// from( "timer://processUpdateResources?period=5000" ) +// .log(LoggingLevel.INFO, log, " process processUpdateResources!") +// .to("log:DEBUG?showBody=true&showHeaders=true") +// .bean( "catalogClient", "processUpdateResources()"); + + + } + + + /** + * get service spec by id from model via bus + * @param id + * @return + * @throws IOException + */ + public ResourceSpecification retrieveResourceSpecByNameCategoryVersion(String aName, String aCategory, String aVersion) { + logger.info("will retrieve Resource Specification aName=" + aName ); + + try { + Map map = new HashMap<>(); + map.put( "aname", aName); + map.put( "acategory", aCategory); + map.put( "aversion", aVersion); + Object response = + template.requestBodyAndHeaders( CATALOG_GET_RESOURCESPEC_BY_ΝAME_CATEGORY, null, map); + + if ( !(response instanceof String)) { + logger.error("Resource Specification object is wrong."); + return null; + } + LogicalResourceSpecification sor = toJsonObj( (String)response, LogicalResourceSpecification.class); + //logger.debug("retrieveSpec response is: " + response); + return sor; + + }catch (Exception e) { + logger.error("Cannot retrieve Resource Specification details from catalog. " + e.toString()); + } + return null; + } + + /** + * get service spec by id from model via bus + * @param id + * @return + * @throws IOException + */ + public ResourceSpecification retrieveResourceSpec(String specid) { + logger.info("will retrieve Resource Specification id=" + specid ); + + try { + Object response = template. + requestBody( CATALOG_GET_RESOURCESPEC_BY_ID, specid); + + if ( !(response instanceof String)) { + logger.error("Resource Specification object is wrong."); + return null; + } + LogicalResourceSpecification sor = toJsonObj( (String)response, LogicalResourceSpecification.class); + //logger.debug("retrieveSpec response is: " + response); + return sor; + + }catch (Exception e) { + logger.error("Cannot retrieve Resource Specification details from catalog. " + e.toString()); + } + return null; + } + + + public LogicalResourceSpecification createOrUpdateResourceSpecByNameCategoryVersion( ResourceSpecificationCreate s) { + logger.info("will createOrUpdateResourceSpecByNameCategoryVersion " ); + try { + Map map = new HashMap<>(); + map.put("aname", s.getName()); + map.put("aversion", s.getVersion()); + map.put("acategory", s.getCategory()); + + Object response = template.requestBodyAndHeaders( CATALOG_UPDADD_RESOURCESPEC, toJsonString(s), map); + + if ( !(response instanceof String)) { + logger.error("ResourceSpecification object is wrong."); + } + + LogicalResourceSpecification rs = toJsonObj( (String)response, LogicalResourceSpecification.class); + return rs; + + + }catch (Exception e) { + logger.error("Cannot create ResourceSpecification"); + e.printStackTrace(); + } + return null; + + } + + public Resource createOrUpdateResourceByNameCategoryVersion( ResourceCreate s) { + logger.info("will createOrUpdateResourceByNameVersion a Resource " ); + try { + Map map = new HashMap<>(); + map.put("aname", s.getName()); + map.put("aversion", s.getResourceVersion()); + map.put("acategory", s.getCategory()); + + Object response = template.requestBodyAndHeaders( CATALOG_UPDADD_RESOURCE, toJsonString(s), map); + + if ( !(response instanceof String)) { + logger.error("Resource object is wrong."); + } + + logger.debug( response.toString() ); + try { + LogicalResource rs = toJsonObj( (String)response, LogicalResource.class); + return rs; + }catch (Exception e) { + logger.error("Cannot create LogicalResource"); + e.printStackTrace(); + } + + try { + Resource rs = toJsonObj( (String)response, Resource.class); + return rs; + }catch (Exception e) { + logger.error("Cannot create as Resource"); + e.printStackTrace(); + } + + + }catch (Exception e) { + logger.error("Cannot create Resource"); + e.printStackTrace(); + } + return null; + + } + + + + private T toJsonObj(String content, Class valueType) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + return mapper.readValue( content, valueType); + } + + private String toJsonString(Object object) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + return mapper.writeValueAsString(object); + } + + + + public Resource updateResourceById(String oslResourceId, ResourceUpdate rs) { + + + logger.info("will update Resource : " + oslResourceId ); + try { + Map map = new HashMap<>(); + map.put("resourceId", oslResourceId ); + map.put("triggerServiceActionQueue", false ); + + Object response = template.requestBodyAndHeaders( CATALOG_UPD_RESOURCE, toJsonString(rs), map); + + if ( !(response instanceof String)) { + logger.error("Service Instance object is wrong."); + } + + LogicalResource resourceInstance = toJsonObj( (String)response, LogicalResource.class); + //logger.debug("createService response is: " + response); + return resourceInstance; + + + }catch (Exception e) { + e.printStackTrace(); + logger.error("Cannot update Service: " + oslResourceId + ": " + e.toString()); + } + return null; + } + +// public void updateResourceById(String oslResourceId, ResourceUpdate rs) { +// +// resourcesToBeUpdated.put(oslResourceId, rs); +// +// +// } + +// public void processUpdateResources() { +// +// resourcesToBeUpdated.forEach( (oslResourceId, rs) -> { +// +// logger.info("will update Resource : " + oslResourceId ); +// try { +// Map map = new HashMap<>(); +// map.put("resourceId", oslResourceId ); +// map.put("triggerServiceActionQueue", false ); +// String json = toJsonString(rs); +// Object response = template.requestBodyAndHeaders( CATALOG_UPD_RESOURCE, json, map); +// +// if ( !(response instanceof String)) { +// logger.error("Service Instance object is wrong."); +// } +// +// //LogicalResource resourceInstance = toJsonObj( (String)response, LogicalResource.class); +// //logger.debug("createService response is: " + response); +// //return resourceInstance; +// +// resourcesToBeUpdated.remove(oslResourceId); +// +// +// logger.info("Updated successfully Resource : " + oslResourceId ); +// }catch (Exception e) { +// e.printStackTrace(); +// logger.error("Cannot update Resource: " + oslResourceId + ": " + e.toString()); +// } +// +// +// +// }); +// } + +} diff --git a/src/main/java/org/etsi/osl/cridge/CridgeSpringBoot.java b/src/main/java/org/etsi/osl/cridge/CridgeSpringBoot.java new file mode 100644 index 0000000000000000000000000000000000000000..2f29316dff699fb5c2073b4bb76df59b339fe360 --- /dev/null +++ b/src/main/java/org/etsi/osl/cridge/CridgeSpringBoot.java @@ -0,0 +1,82 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.cridge + * %% + * Copyright (C) 2019 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.cridge; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.ExitCodeGenerator; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.annotation.EnableScheduling; +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; + +/** + * @author ctranoris + * + */ +@EnableScheduling +@SpringBootApplication +public class CridgeSpringBoot implements CommandLineRunner { + + private static ApplicationContext applicationContext; + + private static final Logger logger = + LoggerFactory.getLogger(CridgeSpringBoot.class.getSimpleName()); + + + @Bean + KubernetesClient kubernetesClient() { +// System.setProperty(Config.KUBERNETES_KUBECONFIG_FILE , "C:\\Users\\ctranoris\\.kube\\10.10.10.144.config"); +// Config config = Config.autoConfigure(null); +// return new KubernetesClientBuilder().withConfig(config).build(); + return new KubernetesClientBuilder().build(); + } + + + @Override + public void run(String... arg0) throws Exception { + if (arg0.length > 0 && arg0[0].equals("exitcode")) { + throw new ExitException(); + } + + } + + public static void main(String[] args) throws Exception { + + logger.info("=========== STARTING CRIDGE =============================="); + applicationContext = new SpringApplication(CridgeSpringBoot.class).run(args); + } + + class ExitException extends RuntimeException implements ExitCodeGenerator { + private static final long serialVersionUID = 1L; + + @Override + public int getExitCode() { + return 10; + } + } + + +} diff --git a/src/main/java/org/etsi/osl/cridge/KubernetesClientResource.java b/src/main/java/org/etsi/osl/cridge/KubernetesClientResource.java new file mode 100644 index 0000000000000000000000000000000000000000..088cd982fdfd3af871c23c519db39fcd9824ace2 --- /dev/null +++ b/src/main/java/org/etsi/osl/cridge/KubernetesClientResource.java @@ -0,0 +1,699 @@ +package org.etsi.osl.cridge; + + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.etsi.osl.domain.model.kubernetes.KubernetesCRDProperty; +import org.etsi.osl.domain.model.kubernetes.KubernetesCRDV1; +import org.etsi.osl.domain.model.kubernetes.KubernetesCRV1; +import org.etsi.osl.domain.model.kubernetes.KubernetesContextDefinition; +import org.etsi.osl.domain.model.kubernetes.KubernetesSecret; +import org.etsi.osl.tmf.common.model.EValueType; +import org.etsi.osl.tmf.rcm634.model.ResourceSpecification; +import org.etsi.osl.tmf.ri639.model.ResourceCreate; +import org.etsi.osl.tmf.ri639.model.ResourceStatusType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import io.fabric8.kubernetes.api.model.GenericKubernetesResource; +import io.fabric8.kubernetes.api.model.Namespace; +import io.fabric8.kubernetes.api.model.NamespaceBuilder; +import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.api.model.Secret; +import io.fabric8.kubernetes.api.model.StatusDetails; +import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; +import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.informers.ResourceEventHandler; +import io.fabric8.kubernetes.client.informers.SharedIndexInformer; +import io.fabric8.kubernetes.client.utils.Serialization; +import lombok.Getter; + +/** + * @author ctranoris + */ +@Component +@Getter +public class KubernetesClientResource { + + private static final Logger logger = LoggerFactory.getLogger( "org.etsi.osl.cridge" ); + + @Autowired + private KubernetesClient kubernetesClient; + + @Autowired + CatalogClient catalogClient; + + private KubernetesContextDefinition kubernetesContextDefinition = null; + + private ResourceSpecification kubernetesCRDV1ResourceSpec = null; + + private ResourceSpecification kubernetesCRV1ResourceSpec = null; + + private ResourceSpecification kubernetesSecretResourceSpec = null; + + + /** + * Garbage collect namespaces to be deleted + * Key is the name of the namespace and value the datetime requested. We need this to properly expire this + */ + private ConcurrentHashMap nameSpacesTobeDeleted = new ConcurrentHashMap<>(); + + private Map watchersForNamespaces = new HashMap<>(); + + + + /** + * @return the opensliceResourceSpecification + * @throws Exception + */ + public KubernetesContextDefinition getKubernetesContextDefinition() throws Exception { + if (kubernetesContextDefinition == null) { + ResourceSpecification rspec = catalogClient.retrieveResourceSpecByNameCategoryVersion( + KubernetesContextDefinition.OSL_KUBD_RSPEC_NAME, + KubernetesContextDefinition.OSL_KUBD_RSPEC_CATEGORY, + KubernetesContextDefinition.OSL_KUBD_RSPEC_VERSION); + if (rspec == null) { + throw new Exception("Cannot retrieve KubernetesContextDefinition ResourceSpecification"); + } + + + kubernetesContextDefinition = KubernetesContextDefinition.builder() + .osl_KUBD_SPEC_UUID(rspec.getUuid()) + .name(this.getKubernetesClient().getConfiguration().getCurrentContext().getContext().getCluster() + + "@" + kubernetesClient.getMasterUrl().toExternalForm()) + .clusterVersion(kubernetesClient.getKubernetesVersion().getMajor() + "." + + kubernetesClient.getKubernetesVersion().getMinor()) + .masterURL(kubernetesClient.getMasterUrl().toExternalForm()) + .currentContextCluster( + kubernetesClient.getConfiguration().getCurrentContext().getContext().getCluster()) + .currentContextName(kubernetesClient.getConfiguration().getCurrentContext().getName()) + .currentContextUser(kubernetesClient.getConfiguration().getCurrentContext().getContext().getUser()) + .build(); + + // initialize also KubernetesCRDV1 + kubernetesCRDV1ResourceSpec = catalogClient.retrieveResourceSpecByNameCategoryVersion( + KubernetesCRDV1.OSL_KUBCRD_RSPEC_NAME, KubernetesCRDV1.OSL_KUBCRD_RSPEC_CATEGORY, + KubernetesCRDV1.OSL_KUBCRD_RSPEC_VERSION); + + kubernetesCRV1ResourceSpec = catalogClient.retrieveResourceSpecByNameCategoryVersion( + KubernetesCRV1.OSL_KUBCRV1_RSPEC_NAME, + KubernetesCRV1.OSL_KUBCRV1_RSPEC_CATEGORY, + KubernetesCRV1.OSL_KUBCRV1_RSPEC_VERSION); + + kubernetesSecretResourceSpec = catalogClient.retrieveResourceSpecByNameCategoryVersion( + KubernetesSecret.OSL_KUBSECRET_RSPEC_NAME, + KubernetesSecret.OSL_KUBSECRET_RSPEC_CATEGORY, + KubernetesSecret.OSL_KUBSECRET_RSPEC_VERSION); + + } + return kubernetesContextDefinition; + } + + + List KubernetesCRD2OpensliceCRD(CustomResourceDefinition crd) { + + ArrayList result = new ArrayList<>(); + crd.getSpec().getVersions().stream().forEach(version -> { + KubernetesCRDV1 kcrd = KubernetesCRDV1.builder() + .osl_KUBCRD_RSPEC_UUID( kubernetesCRDV1ResourceSpec.getUuid() ) + .name( crd.getSpec().getNames().getKind() + + "@" + + crd.getSpec().getGroup()+"/"+version.getName() + + "@" + + kubernetesClient.getConfiguration().getCurrentContext().getContext().getCluster() + + "@" + + kubernetesClient.getMasterUrl().toExternalForm() ) + .version( version.getName() ) + .currentContextCluster( kubernetesClient.getConfiguration().getCurrentContext().getContext().getCluster() ) + .clusterMasterURL( kubernetesClient.getMasterUrl().toString() ) + .fullResourceName( crd.getFullResourceName() ) + .kind( crd.getSpec().getNames().getKind() ) + .apiGroup( crd.getSpec().getGroup() ) + .uID( crd.getMetadata().getUid() ) + .description( version.getSchema().getOpenAPIV3Schema().getDescription() ) + .metadata( "" ) + .build(); + + if (version.getSchema().getOpenAPIV3Schema().getProperties() != null) + version.getSchema().getOpenAPIV3Schema().getProperties().forEach((kPropName, vProVal) -> { + if (kPropName.equals("spec") || kPropName.equals("status")) { + logger.debug("propName={} propValue={} ", kPropName, vProVal.getType()); + addCRDProperties(kcrd, kPropName, vProVal, ""); + } + + + }); + + if (version.getSchema().getOpenAPIV3Schema().getAdditionalProperties() != null) { + version.getSchema().getOpenAPIV3Schema().getAdditionalProperties().getAdditionalProperties() + .forEach((kPropName, vProVal) -> { + logger.debug("propName={} propValue={} ", kPropName, vProVal); + KubernetesCRDProperty kpcrdProperty = KubernetesCRDProperty + .builder() + .name(kPropName) + .build(); + kcrd.getAdditionalProperties().put("additionalProperty." + kPropName, kpcrdProperty); + + }); + } + + kcrd.setYaml( Serialization.asYaml( version.getSchema().getOpenAPIV3Schema().getProperties() ) ); + kcrd.setJson( Serialization.asJson( version.getSchema().getOpenAPIV3Schema().getProperties() ) ); + + result.add( kcrd ); + }); + + return result; + + } + + private void addCRDProperties(KubernetesCRDV1 kcrd, String kPropName, JSONSchemaProps vProVal, String prefix ) { + + + String propertyToAdd = prefix + kPropName; + + EValueType etype; + if (vProVal.getType() == null) { + etype = EValueType.TEXT; + } else if (vProVal.getType().equalsIgnoreCase("boolean")) { + etype = EValueType.BOOLEAN; + } else if (vProVal.getType().equalsIgnoreCase("integer")) { + etype = EValueType.INTEGER; + } else if (vProVal.getType().equalsIgnoreCase("object")) { + etype = EValueType.OBJECT; + vProVal.getProperties().forEach((pk, pv) -> { + addCRDProperties(kcrd, pk, pv, propertyToAdd + "."); + }); + } else if (vProVal.getType().equalsIgnoreCase("array")) { + etype = EValueType.ARRAY; + vProVal.getProperties().forEach((pk, pv) -> { + addCRDProperties(kcrd, pk, pv, propertyToAdd + "[]."); + }); + } else + etype = EValueType.TEXT; + + + KubernetesCRDProperty kpcrdProperty = KubernetesCRDProperty + .builder() + .name(kPropName) + .description( vProVal.getDescription() ) + .defaultValue( vProVal.getDefault()!=null? vProVal.getDefault().asText() : "" ) + .valueType( etype.getValue() ) + .build(); + + + kcrd.getProperties().put( propertyToAdd, kpcrdProperty ); + + } + + + KubernetesCRV1 KubernetesCR2OpensliceCR(GenericKubernetesResource gkr) { + + String baseCRD = String.format( "%s@%s@%s@%s", + gkr.getKind(), + gkr.getApiVersion(), + kubernetesClient.getConfiguration().getCurrentContext().getContext().getCluster(), + kubernetesClient.getMasterUrl().toExternalForm()); + + KubernetesCRV1 kcrv = KubernetesCRV1.builder() + .osl_KUBCRV1_RSPEC_UUID( kubernetesCRV1ResourceSpec.getUuid() ) + .name( gkr.getMetadata().getName() + + "@" + + gkr.getMetadata().getNamespace() + + "@" + + kubernetesClient.getConfiguration().getCurrentContext().getContext().getCluster() + + "@" + + kubernetesClient.getMasterUrl().toExternalForm() ) + .version( gkr.getApiVersion() ) + .currentContextCluster( kubernetesClient.getConfiguration().getCurrentContext().getContext().getCluster() ) + .clusterMasterURL( kubernetesClient.getMasterUrl().toString() ) + .fullResourceName( "" ) + .namespace( Serialization.asJson( gkr.getMetadata().getNamespace()) ) + .kind( gkr.getKind() ) + .apiGroup( gkr.getPlural() ) + .uID( gkr.getMetadata().getUid() ) + .metadata( gkr.getMetadata().toString() ) //.metadata( gkr.getMetadata().toString() ) + .category( baseCRD ) + .description( + String.format( "A CR in namespace %s based on CRD %s", gkr.getMetadata().getNamespace(), baseCRD )) + .build(); + + + gkr.getMetadata().getLabels().forEach((pk, pv) -> { + logger.debug("\t label: {} {} ", pk, pv); + kcrv.getProperties().put( pk , pv); + + }); + + kcrv.setStatusCheckFieldName( gkr.getMetadata().getLabels().get("org.etsi.osl.statusCheckFieldName")); + kcrv.setStatusCheckValueStandby( gkr.getMetadata().getLabels().get("org.etsi.osl.statusCheckValueStandby")); + kcrv.setStatusCheckValueAlarm( gkr.getMetadata().getLabels().get("org.etsi.osl.statusCheckValueAlarm")); + kcrv.setStatusCheckValueAvailable( gkr.getMetadata().getLabels().get("org.etsi.osl.statusCheckValueAvailable")); + kcrv.setStatusCheckValueReserved( gkr.getMetadata().getLabels().get("org.etsi.osl.statusCheckValueReserved")); + kcrv.setStatusCheckValueUnknown( gkr.getMetadata().getLabels().get("org.etsi.osl.statusCheckValueUnknown")); + kcrv.setStatusCheckValueSuspended( gkr.getMetadata().getLabels().get("org.etsi.osl.statusCheckValueSuspended")); + kcrv.setStatusValue( ResourceStatusType.UNKNOWN ); + + gkr.getAdditionalProperties().forEach((pk, pv) -> { + logger.debug("\t {} {} ", pk, pv); + if (pv instanceof Map) { + addCRVProperties( kcrv, pk, (Map) pv, ""); + }else { + Map values = (Map) pv; + values.forEach((speck, specv) ->{ + logger.debug("\t {}={} ", speck, specv); + String propertyName = pk +"." +speck; + String propertyValue = specv.toString(); + kcrv.getProperties().put( propertyName , propertyValue); + + //check resource status + if ( kcrv.getStatusCheckFieldName().equals(propertyName) ){ + kcrv.setStatusValue( checKCRVResourceStatus(kcrv, propertyValue) ); + } + }); + } + + }); + + kcrv.getProperties().put( "AdditionPropertiesAsJson" , Serialization.asJson( gkr.getAdditionalProperties() )); + + kcrv.setYaml( Serialization.asYaml( gkr ) ); + kcrv.setJson( Serialization.asJson( gkr ) ); + kcrv.setCr_spec_applied( Serialization.asJson( gkr ) ); + + return kcrv; + + } + + + private ResourceStatusType checKCRVResourceStatus(KubernetesCRV1 kcrv, String propertyValue) { + + if (propertyValue.equals(kcrv.getStatusCheckValueAlarm())) { + return ResourceStatusType.ALARM; + } else if (propertyValue.equals(kcrv.getStatusCheckValueAvailable())) { + return ResourceStatusType.AVAILABLE; + } else if (propertyValue.equals(kcrv.getStatusCheckValueReserved())) { + return ResourceStatusType.RESERVED; + } else if (propertyValue.equals(kcrv.getStatusCheckValueStandby())) { + return ResourceStatusType.STANDBY; + } else if (propertyValue.equals(kcrv.getStatusCheckValueSuspended())) { + return ResourceStatusType.SUSPENDED; + } else if (propertyValue.equals(kcrv.getStatusCheckValueUnknown())) { + return ResourceStatusType.UNKNOWN; + } else { + return ResourceStatusType.UNKNOWN; + } + + } + + + private void addCRVProperties(KubernetesCRV1 kcrv,String kPropName, Map vProVal, String prefix) { + + + + vProVal.forEach((speck, specv) ->{ + if (specv instanceof Map) { + String propertyToAdd = prefix + kPropName; + addCRVProperties( kcrv, speck, (Map) specv, propertyToAdd + "."); + }else { + String propertyToAdd = prefix + kPropName+ "."+speck; + logger.debug("\t {} {}={} ", propertyToAdd, speck, specv); + kcrv.getProperties().put( propertyToAdd , specv.toString()); + String propertyName = propertyToAdd; + String propertyValue = specv.toString(); + if ( kcrv.getStatusCheckFieldName()!=null && kcrv.getStatusCheckFieldName().equals(propertyName) ){ + kcrv.setStatusValue( checKCRVResourceStatus(kcrv, propertyValue) ); + } + } + + }); + + + + } + + + KubernetesSecret KubernetesSecret2OpensliceResource(Secret secret) { + + + String baseCRD = String.format( "%s@%s@%s@%s", + secret.getKind(), + secret.getApiVersion(), + kubernetesClient.getConfiguration().getCurrentContext().getContext().getCluster(), + kubernetesClient.getMasterUrl().toExternalForm()); + + KubernetesSecret kcrv = KubernetesSecret.builder() + .osl_KUBCRD_RSPEC_UUID( kubernetesSecretResourceSpec.getUuid() ) + .name( secret.getMetadata().getName() + + "@" + + secret.getMetadata().getNamespace() + + "@" + + kubernetesClient.getConfiguration().getCurrentContext().getContext().getCluster() + + "@" + + kubernetesClient.getMasterUrl().toExternalForm() ) + .version( secret.getApiVersion() ) + .currentContextCluster( kubernetesClient.getConfiguration().getCurrentContext().getContext().getCluster() ) + .clusterMasterURL( kubernetesClient.getMasterUrl().toString() ) + .fullResourceName( "" ) + .namespace( Serialization.asJson( secret.getMetadata().getNamespace()) ) + .kind( secret.getKind() ) + .apiGroup( secret.getPlural() ) + .uID( secret.getMetadata().getUid() ) + .metadata(Serialization.asJson( secret.getMetadata()) ) //.metadata( gkr.getMetadata().toString() ) + .description( + String.format( "A secret in namespace %s on %s", secret.getMetadata().getNamespace(), baseCRD )) + .build(); + + + secret.getMetadata().getLabels().forEach((pk, pv) -> { + logger.debug("\t label: {} {} ", pk, pv); + kcrv.getProperties().put( pk , pv); + + }); + + + if (secret.getData() != null) + secret.getData().forEach((kPropName, vProVal) -> { + logger.debug("propName={} propValue={} ", kPropName, vProVal ); + kcrv.getData().put(kPropName, vProVal); + }); + if (secret.getStringData() != null) + secret.getStringData().forEach((kPropName, vProVal) -> { + logger.debug("propName={} propValue={} ", kPropName, vProVal ); + kcrv.getProperties().put(kPropName, vProVal); + }); + + kcrv.setDataObj( Serialization.asYaml( secret.getData() ) ); + kcrv.setYaml( Serialization.asYaml( secret ) ); + kcrv.setJson( Serialization.asJson( secret ) ); + + return kcrv; + } + + + + public String deployCR(Map headers, String crspec) { + + logger.debug("============ Deploy crspec =============" ); + + logger.debug("Check if this CRIDGE instance is related to this kubernets cluster context"); + if (!checkCRIDGEClusterContext(headers)) { + return "SEE OTHER"; + } + + logger.debug("Deploy the following CR:" ); + logger.debug("{}", crspec ); + +// crspec = """ +// %s +// """.formatted( crspec ); +// +// logger.debug("Deploy the following CR NORMALIZED:" ); +// logger.debug("{}", crspec ); + + try { + + GenericKubernetesResource gkr = Serialization.unmarshal( crspec ); + headers.forEach(((hname, hval) ->{ + if (hval instanceof String s) { + if ( hname.contains("org.etsi.osl")) { + logger.debug("Header: {} = {} ", hname, s ); + if ( gkr.getMetadata() == null ) { + gkr.setMetadata( new ObjectMeta()); + gkr.getMetadata().setLabels( new HashMap()); + } + gkr.getMetadata().getLabels().put(hname, s); + } + } + })); + + //we must change and assign a name to the resource + if ( headers.get("org.etsi.osl.prefixId") !=null ) { + gkr.getMetadata().setName( (String) headers.get("org.etsi.osl.prefixName") ) ; + }else { + //it must start with an alpha character + gkr.getMetadata().setName( "cr" + ((String) headers.get("org.etsi.osl.resourceId")).substring(0, 8) ) ; + } + + + if ( gkr.getMetadata().getNamespace() == null || gkr.getMetadata().getNamespace().equals("") ) { + gkr.getMetadata().setNamespace( (String) headers.get("org.etsi.osl.serviceOrderId") ); //set default namespace the service Order ID if a namespace is not there + } + + String nameSpacename = (String) headers.get("org.etsi.osl.namespace"); + + try { + + //first try create namespace for the service order + Namespace ns = new NamespaceBuilder() + .withNewMetadata() + .withName( nameSpacename ) + .addToLabels("org.etsi.osl", "org.etsi.osl") + .endMetadata().build(); + kubernetesClient.namespaces().resource(ns).create(); + + + }catch (Exception e) { + //e.printStackTrace(); + //if it exists already just continue! + logger.info("Cannot create namespace, already exists!" + e.getMessage() ); + } + + + /* if the equivalent namespace for the service order is successfully created the create + * related watchers for secrets, services, configmaps, pods, etc + * 1) we need to create domainmodels for these + * 2) we add them as support resources to our initial resource + */ + + if ( this.watchersForNamespaces.get(nameSpacename) == null ) { + SharedIndexInformer result = createWatchersFornamespace( nameSpacename, headers ); + this.watchersForNamespaces.put(nameSpacename, result); + } + + + logger.debug("Object to deploy:{}", gkr.toString() ); + + Resource dummyObject = kubernetesClient.resource( gkr ); + + GenericKubernetesResource result = dummyObject.create(); + + logger.debug("============ Create crspec: result {} =============", result.toString() ); + + + }catch (Exception e) { + e.printStackTrace(); + return "FAIL " + e.getMessage(); + } + + return "OK"; + + } + + /** + * if the equivalent namespace for the service order is successfully created the create + * related wathcers for secrets, services, configmaps, pods, etc + * 1) we need to create domainmodels for these + * 2) we add them as support resources to our initial resource + * @param nameSpacename + * @param headers + * @return + */ + private SharedIndexInformer createWatchersFornamespace(String nameSpacename, Map headers) { + //watcher for secrets + + SharedIndexInformer shixInformer = + this.getKubernetesClient() + .secrets().inNamespace(nameSpacename).inform(new ResourceEventHandler() { + + @Override + public void onAdd(Secret obj) { + logger.debug("Added Namespace watcher Resource Kind:{} Name:{} UID:{} Namespace:{}", + obj.getKind(), + obj.getMetadata().getName(), + obj.getMetadata().getUid(), + obj.getMetadata().getNamespace()); + + headers.forEach(((hname, hval) ->{ + if (hval instanceof String s) { + if ( hname.contains("org.etsi.osl")) { + logger.debug("Header: {} = {} ", hname, s ); + if ( obj.getMetadata() == null ) { + obj.setMetadata( new ObjectMeta()); + obj.getMetadata().setLabels( new HashMap()); + } + obj.getMetadata().getLabels().put(hname, s); + } + } + })); + + updateKubernetesSecretResourceInOSLCatalog( obj ); + + + } + + @Override + public void onUpdate(Secret oldObj, Secret newObj) { + logger.debug("onUpdate Namespace watcher Resource Kind:{} Name:{} UID:{} Namespace:{}", + newObj.getKind(), + newObj.getMetadata().getName(), + newObj.getMetadata().getUid(), + newObj.getMetadata().getNamespace()); + updateKubernetesSecretResourceInOSLCatalog( newObj ); + + } + + @Override + public void onDelete(Secret obj, boolean deletedFinalStateUnknown) { + logger.debug("onDelete Namespace watcher Resource Kind:{} Name:{} UID:{} Namespace:{}", + obj.getKind(), + obj.getMetadata().getName(), + obj.getMetadata().getUid(), + obj.getMetadata().getNamespace()); + updateKubernetesSecretResourceInOSLCatalog( obj ); + + } + + + }, 30 * 1000L); // resync period (set 0 for no resync); + + shixInformer.start(); + + return shixInformer; + + } + + private void updateKubernetesSecretResourceInOSLCatalog(Secret resource) { + ResourceCreate rs = this + .KubernetesSecret2OpensliceResource( resource ) + .toResourceCreate(); + + catalogClient.createOrUpdateResourceByNameCategoryVersion( rs ); + + } + + + + + + + public String deleteCR(Map headers, String crspec) { + + logger.debug("============ DELETE crspec =============" ); + if (!checkCRIDGEClusterContext(headers)) { + return "SEE OTHER"; + } + + try { + + GenericKubernetesResource gkr = Serialization.unmarshal( crspec ); + headers.forEach(((hname, hval) ->{ + if (hval instanceof String s) { + if ( hname.contains("org.etsi.osl")) { + logger.debug("Header: {} = {} ", hname, s ); + gkr.getMetadata().getLabels().put(hname, s); + } + } + })); + + gkr.getMetadata().setName( (String) headers.get("org.etsi.osl.prefixName")) ; + String nameSpacename = (String) headers.get("org.etsi.osl.namespace"); + if ( gkr.getMetadata().getNamespace() == null ) { + gkr.getMetadata().setNamespace(nameSpacename); + } + + logger.debug("Object to delete:{}", Serialization.asYaml( gkr ) ); + Resource dummyObject = kubernetesClient.resource( gkr ); + + List result = dummyObject.delete(); + logger.debug("============ DELETE crspec: result {} =============", result.toString() ); + + + this.nameSpacesTobeDeleted.put(nameSpacename, new Date() ); + this.watchersForNamespaces.remove(nameSpacename); + + }catch (Exception e) { + e.printStackTrace(); + return "ERROR " + e.getMessage(); + } + + return "OK"; + + } + + public String patchCR(Map headers, String crspec) { + logger.debug("============ patchCR crspec ============="); + + logger.debug("Check if this CRIDGE instance is related to this kubernets cluster context"); + if (!checkCRIDGEClusterContext(headers)) { + return "SEE OTHER"; + } + + + + logger.debug("Patch the following CR:"); + logger.debug("{}", crspec); + try { + + GenericKubernetesResource gkr = Serialization.unmarshal( crspec ); + headers.forEach(((hname, hval) ->{ + if (hval instanceof String s) { + if ( hname.contains("org.etsi.osl")) { + logger.debug("Header: {} = {} ", hname, s ); + if ( gkr.getMetadata() == null ) { + gkr.setMetadata( new ObjectMeta()); + gkr.getMetadata().setLabels( new HashMap()); + } + gkr.getMetadata().getLabels().put(hname, s); + } + } + })); + gkr.getMetadata().setNamespace( (String) headers.get("org.etsi.osl.namespace") ); //set default namespace the service Order ID if a namespace is not there + gkr.getMetadata().setName( (String) headers.get("org.etsi.osl.prefixName") ) ; + + + logger.debug("{}", gkr.toString() ); + + Resource dummyObject = kubernetesClient.resource( gkr ); + dummyObject.patch(); + }catch (Exception e) { + e.printStackTrace(); + return "FAIL " + e.getMessage(); + } + return "OK"; + + + } + + private Boolean checkCRIDGEClusterContext( Map headers) { + if ( (headers.get("currentContextCluster") ==null) || + (headers.get("clusterMasterURL") ==null) || + ( ! headers.get("currentContextCluster").equals( kubernetesContextDefinition.getCurrentContextCluster() )) || + ( ! headers.get("clusterMasterURL").equals( kubernetesContextDefinition.getMasterURL() ))) { + + logger.debug("Will return SEE OTHER header.currentContextCluster={}, this.context= {} header.clusterMasterURLclusterMasterURL={}, this.context= {}", + headers.get("currentContextCluster"), + kubernetesContextDefinition.getCurrentContextCluster(), + headers.get("clusterMasterURL"), + kubernetesContextDefinition.getMasterURL() ); + return false; + } + + return true; + } + + + public void setKubernetesClient(KubernetesClient kubernetesClient2) { + this.kubernetesClient = kubernetesClient2; + + } + +} diff --git a/src/main/java/org/etsi/osl/cridge/WatcherService.java b/src/main/java/org/etsi/osl/cridge/WatcherService.java new file mode 100644 index 0000000000000000000000000000000000000000..4dc6d2daf9d13bbc380d246f094aae72b5e74180 --- /dev/null +++ b/src/main/java/org/etsi/osl/cridge/WatcherService.java @@ -0,0 +1,330 @@ +package org.etsi.osl.cridge; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.etsi.osl.domain.model.kubernetes.KubernetesCRDV1; +import org.etsi.osl.tmf.ri639.model.Resource; +import org.etsi.osl.tmf.ri639.model.ResourceCreate; +import org.etsi.osl.tmf.ri639.model.ResourceUpdate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.event.ContextStoppedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Service; +import io.fabric8.kubernetes.api.model.GenericKubernetesResource; +import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; +import io.fabric8.kubernetes.client.Watch; +import io.fabric8.kubernetes.client.Watcher; +import io.fabric8.kubernetes.client.WatcherException; +import io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext; +import io.fabric8.kubernetes.client.informers.ResourceEventHandler; +import io.fabric8.kubernetes.client.informers.SharedIndexInformer; +import io.fabric8.kubernetes.client.informers.SharedInformerFactory; +import jakarta.annotation.PreDestroy; + +/** + * @author ctranoris + */ +@Service +public class WatcherService { + + private static final Logger logger = LoggerFactory.getLogger("org.etsi.osl.cridge"); + + private Watch watch; + + @Autowired + CatalogClient catalogClient; + + @Autowired + private KubernetesClientResource kubernetesClientResource; + + + /** + * This one is executed when the cridge service application starts + * @param event + */ + @EventListener(ApplicationStartedEvent.class) + public void onApplicationEvent() { + + //logger.info("Starting WatcherS.getervice event {} ", event.toString()); + logger.info("Starting WatcherService for cluster getContexts {} ", + kubernetesClientResource.getKubernetesClient().getConfiguration().getContexts().toString()); + + Resource result = registerKubernetesClientInOSLResource(); + while ( result == null ) { + try { + logger.info("Cannot get resource for registerKubernetesClient. Retrying in 10 seconds" ); + Thread.sleep( 10000 ); + } catch (InterruptedException e) { + e.printStackTrace(); + } + result = registerKubernetesClientInOSLResource(); + } + + SharedInformerFactory sharedInformerFactory = kubernetesClientResource.getKubernetesClient().informers(); + + SharedIndexInformer shixInformer = sharedInformerFactory + .sharedIndexInformerFor(CustomResourceDefinition.class, 30 * 1000L); + + shixInformer.addEventHandler(new ResourceEventHandler() { + @Override + public void onAdd(CustomResourceDefinition crd) { + logger.debug("ADDED {} CRD:{} Group:{} Kind:{} UID:{} ", crd.getKind(), + crd.getMetadata().getName(), + crd.getSpec().getGroup(), + crd.getSpec().getNames().getKind(), + crd.getMetadata().getUid()); + + + + List rspec = kubernetesClientResource.KubernetesCRD2OpensliceCRD(crd); + for (KubernetesCRDV1 rs : rspec) { + catalogClient.createOrUpdateResourceSpecByNameCategoryVersion(rs.toRSpecCreate()); + catalogClient.createOrUpdateResourceByNameCategoryVersion( rs.toResourceCreate() ); + } + + + + createCRDSharedIndexInformer(crd); + + } + + @Override + public void onUpdate(CustomResourceDefinition oldcrd, CustomResourceDefinition newcrd) { + logger.debug("CRD_UPDATED {} {} for kind {}", newcrd.getKind(), newcrd.getSpec().getGroup(), newcrd.getSpec().getNames().getKind()); + + String oldLAC = oldcrd.getMetadata().getAnnotations() + .get("kubectl.kubernetes.io/last-applied-configuration"); + String newLAC = newcrd.getMetadata().getAnnotations() + .get("kubectl.kubernetes.io/last-applied-configuration"); + if ( (newLAC == null) || !newLAC.equals(oldLAC)) { + logger.debug("\t NEWCRD:{} Group:{} Kind:{} UID:{} ", newcrd.getMetadata().getName(), + newcrd.getSpec().getGroup(), newcrd.getSpec().getNames().getKind(), + newcrd.getMetadata().getUid()); + + logger.debug("UPDATED Resource Definition of {} ", newcrd.getKind()); + logger.debug("\t Annotations:{} ", newcrd.getMetadata().getAnnotations().toString()); + } + + } + + @Override + public void onDelete(CustomResourceDefinition crd, boolean deletedFinalStateUnknown) { + logger.debug("CRD_DELETED {}", crd.getKind()); + logger.debug("\t DELETEDCRD:{} Group:{} Kind:{} UID:{} ", crd.getMetadata().getName(), + crd.getSpec().getGroup(), crd.getSpec().getNames().getKind(), crd.getMetadata().getUid()); + } + }); + + sharedInformerFactory.startAllRegisteredInformers(); + +// watch = kubernetesClient.apiextensions().v1().customResourceDefinitions().watch(new Watcher<>() { +// +// @Override +// public void eventReceived(Action action, CustomResourceDefinition crd) { +// +// +// //kubernetesClient.namespaces(). +// +// logger.debug("{} CRD:{} Group:{} Kind:{} UID:{} ", +// action.name(), +// crd.getMetadata().getName(), +// crd.getSpec().getGroup(), +// crd.getSpec().getNames().getKind(), +// crd.getMetadata().getUid()); +// +// crd.getSpec().getVersions().stream().forEach( +// version -> { +// +// if (version.getSchema().getOpenAPIV3Schema().getProperties()!=null ) +// version.getSchema().getOpenAPIV3Schema().getProperties().forEach( +// (k,v1) -> { +// logger.debug("propName={} propValue={} ",k,v1.getType() ); +// if (k.equals("spec") || k.equals("status")) { +// v1.getProperties().forEach( (pk, pv) -> logger.debug("\t{} {} ", pk, pv.getType() )); +// } +// }); +// if (version.getSchema().getOpenAPIV3Schema().getAdditionalProperties()!=null ) +// version.getSchema().getOpenAPIV3Schema().getAdditionalProperties().getAdditionalProperties().forEach( +// (kPropName,vProVal) -> { +// logger.debug("AdditionalProperty propName={} propValue={} ", kPropName ,vProVal ); +// +// }); +// } +// ); +// if ( action.name().equals( Action.ADDED.name() ) ) { +// createCRDWatcher( crd ); +// ResourceSpecificationCreate rspec = (ResourceSpecificationCreate) modelTransformer.CRD2TMFResourceSpecification(crd); +// catalogClient.createResourceSpec( rspec ); +// } +// +// } +// +// @Override +// public void onClose(WatcherException e) { +// logger.debug("Closing due to {} ", e.getMessage()); +// +// } +// +// }); + + } + + /** + * register the Kubernetes Context of this Cridge instance + * @return + */ + private Resource registerKubernetesClientInOSLResource() { + + try { + ResourceCreate rsc; + rsc = kubernetesClientResource.getKubernetesContextDefinition().toResourceCreate(); + Resource result = catalogClient.createOrUpdateResourceByNameCategoryVersion(rsc ); + return result; + } catch (Exception e1) { + + e1.printStackTrace(); + } + + return null; + + + } + + protected void createCRDSharedIndexInformer(CustomResourceDefinition crd) { + + ResourceDefinitionContext context = new ResourceDefinitionContext.Builder() + .withGroup(crd.getSpec().getGroup()) + .withVersion(crd.getSpec().getVersions().get(0).getName()) + .withKind(crd.getSpec().getNames().getKind()) + .withPlural(crd.getSpec().getNames().getPlural()).build(); + try { + int a = kubernetesClientResource.getKubernetesClient().genericKubernetesResources(context).list().getItems().size(); + } catch (Exception e) { + // e.printStackTrace(); + logger.error("Cannot create createCRDSharedIndexInformer. Seems there are no resources for kind: " + + crd.getSpec().getNames().getKind()); + return; + } + + logger.debug("Creating new Watcher for kind: {}", crd.getSpec().getNames().getKind()); + Watch watch = kubernetesClientResource.getKubernetesClient().genericKubernetesResources(context).inAnyNamespace().watch(new Watcher<>() { + + private String watcherResourcesName; + + + @Override + public void eventReceived(Action action, GenericKubernetesResource genericKubernetesResource) { + watcherResourcesName = genericKubernetesResource.getKind(); + + /** + * Ignore the following kinds! + */ + if ( genericKubernetesResource.getKind() .startsWith("IPAM") ) { + return; + } + + + logger.debug("{} Resource Kind:{} Name:{} UID:{} Namespace:{} ", action.name(), + genericKubernetesResource.getKind(), genericKubernetesResource.getMetadata().getName(), + genericKubernetesResource.getMetadata().getUid(), + genericKubernetesResource.getMetadata().getNamespace() ); + + + genericKubernetesResource.getAdditionalProperties().forEach((pk, pv) -> { + logger.debug("\t {} {} ", pk, pv); + if (pv instanceof Map) { + Map values = (Map) pv; + values.forEach((speck, specv) -> logger.debug("\t {}={} ", speck, specv)); + } else if (pv instanceof ArrayList) { + ArrayList values = (ArrayList) pv; + values.forEach((speck) -> logger.debug("\t {}={} ", speck)); + } + }); + + + //ADDED, DELETED, MODIFIED, BOOKMARK, ERROR + if ( action.name().equals( "ADDED" ) ) { + updateGenericKubernetesResourceInOSLCatalog( genericKubernetesResource ); + + } else if ( action.name().equals( "MODIFIED" ) ) { + updateGenericKubernetesResourceInOSLCatalog( genericKubernetesResource ); + } else if ( action.name().equals( "DELETED" ) ) { + genericKubernetesResource.getMetadata().getLabels().put("org.etsi.osl.deleted", "DELETED"); + updateGenericKubernetesResourceInOSLCatalog( genericKubernetesResource ); + } else { + + } + + } + + @Override + public void onClose(WatcherException e) { + logger.info("Closing resources Watcher of {} due to {} ", watcherResourcesName, e.getMessage()); + createCRDSharedIndexInformer(crd); //schedule a new one + return; + } + + }); + + + + } + + protected void updateGenericKubernetesResourceInOSLCatalog(GenericKubernetesResource genericKubernetesResource) { + String oslResourceId = genericKubernetesResource.getMetadata().getLabels().get("org.etsi.osl.resourceId"); + + if ( oslResourceId != null ) { + ResourceUpdate rs = kubernetesClientResource + .KubernetesCR2OpensliceCR( genericKubernetesResource ) + .toResourceUpdate(); + catalogClient.updateResourceById(oslResourceId, rs); + }else { + ResourceCreate rs = kubernetesClientResource + .KubernetesCR2OpensliceCR( genericKubernetesResource ) + .toResourceCreate(); + + catalogClient.createOrUpdateResourceByNameCategoryVersion( rs ); + } + + } + +// protected void createCRDWatcher(CustomResourceDefinition crd) { +// ResourceDefinitionContext context = new ResourceDefinitionContext.Builder().withGroup(crd.getSpec().getGroup()) +// .withVersion(crd.getSpec().getVersions().get(0).getName()).withKind(crd.getSpec().getNames().getKind()) +// .withPlural(crd.getSpec().getNames().getPlural()).build(); +// +// Watch watch = kubernetesClientResource.getKubernetesClient().genericKubernetesResources(context).inAnyNamespace().watch(new Watcher<>() { +// @Override +// public void eventReceived(Action action, GenericKubernetesResource genericKubernetesResource) { +// logger.debug("{} Kind:{} Name:{} UID:{} Namespace:{}", action.name(), +// genericKubernetesResource.getKind(), genericKubernetesResource.getMetadata().getName(), +// genericKubernetesResource.getMetadata().getUid(), +// genericKubernetesResource.getMetadata().getNamespace()); +// genericKubernetesResource.getAdditionalProperties().forEach((pk, pv) -> { +// logger.debug("\t {} {} ", pk, pv); +// Map values = (Map) pv; +// values.forEach((speck, specv) -> logger.debug("\t {}={} ", speck, specv)); +// }); +// } +// +// @Override +// public void onClose(WatcherException e) { +// logger.info("Closing due to {} ", e.getMessage()); +// } +// }); +// +// } + + @PreDestroy + ApplicationListener stop() { + // return event -> sharedInformerFactory.stopAllRegisteredInformers(); + logger.info("Closing due to ContextStoppedEvent "); + return event -> watch.close(); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..3dcfe7f5d3f21f9643a3f64f6c353611194ceb19 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,47 @@ +spring: + application: + name: cridge + main: + web-application-type: none + activemq: + brokerUrl: tcp://localhost:61616?jms.watchTopicAdvisories=false + user: artemis + password: artemis + pool: + enabled: true + max-connections: 100 + packages: + trust-all: true + +server: + port: 0 + + +logging: + level: + org.etsi.osl.cridge: DEBUG + root: INFO + org.springframework: INFO + org.apache.camel: INFO + reactor.netty.tcp.TcpClient: INFO + reactor.netty.http.client.HttpClient: INFO + pattern: + console: "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" + file: "%d %p %c{1.} [%t] %m%n" + + +CATALOG_ADD_RESOURCE: "jms:queue:CATALOG.ADD.RESOURCE" +CATALOG_UPD_RESOURCE: "jms:queue:CATALOG.UPD.RESOURCE" +CATALOG_UPDADD_RESOURCE: "jms:queue:CATALOG.UPDADD.RESOURCE" +CATALOG_GET_RESOURCE_BY_ID: "jms:queue:CATALOG.GET.RESOURCE" +CATALOG_ADD_RESOURCESPEC: "jms:queue:CATALOG.ADD.RESOURCESPEC" +CATALOG_UPD_RESOURCESPEC: "jms:queue:CATALOG.UPD.RESOURCESPEC" +CATALOG_UPDADD_RESOURCESPEC: "jms:queue:CATALOG.UPDADD.RESOURCESPEC" +CATALOG_GET_RESOURCESPEC_BY_ID: "jms:queue:CATALOG.GET.RESOURCESPEC_BY_ID" +CATALOG_GET_RESOURCESPEC_BY_ΝAME_CATEGORY: "jms:queue:CATALOG.GET.RESOURCESPEC_BY_ΝAME_CATEGORY" + + +#CRD ACTIONS +CRD_DEPLOY_CR_REQ: "jms:queue:CRD.DEPLOY.CR_REQ" +CRD_DELETE_CR_REQ: "jms:queue:CRD.DELETE.CR_REQ" +CRD_PATCH_CR_REQ: "jms:queue:CRD.PATCH.CR_REQ" \ No newline at end of file diff --git a/src/main/resources/banner.txt b/src/main/resources/banner.txt new file mode 100644 index 0000000000000000000000000000000000000000..74229cd400fb31f76673214d76c0256f438e4ccc --- /dev/null +++ b/src/main/resources/banner.txt @@ -0,0 +1,11 @@ + ___ ____ _ _ + / _ \ _ __ ___ _ __ / ___|| (_) ___ ___ + | | | | '_ \ / _ \ '_ \\___ \| | |/ __/ _ \ + | |_| | |_) | __/ | | |___) | | | (_| __/ + \___/| .__/ \___|_| |_|____/|_|_|\___\___| + |_| + __ __________________ + / / __ __ / __/_ __/ __/ _/ + / _ \/ // / / _/ / / _\ \_/ / + /_.__/\_, / /___/ /_/ /___/___/ + /___/ \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/cridge/CridgeIntegrationTest.java b/src/test/java/org/etsi/osl/cridge/CridgeIntegrationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..3ebb8aec06da6a8d761b1e158cbe040d0d2b8524 --- /dev/null +++ b/src/test/java/org/etsi/osl/cridge/CridgeIntegrationTest.java @@ -0,0 +1,589 @@ +package org.etsi.osl.cridge; + +import static io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext.v1CRDFromCustomResourceType; +import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.net.HttpURLConnection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import org.apache.camel.CamelContext; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.dataformat.JsonLibrary; +import org.etsi.osl.domain.model.kubernetes.KubernetesCRDV1; +import org.etsi.osl.domain.model.kubernetes.KubernetesCRV1; +import org.etsi.osl.domain.model.kubernetes.KubernetesSecret; +import org.etsi.osl.tmf.ri639.model.ResourceCreate; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.event.EventListener; +import org.springframework.test.context.event.RecordApplicationEvents; +import io.fabric8.kubernetes.api.model.Condition; +import io.fabric8.kubernetes.api.model.GenericKubernetesResource; +import io.fabric8.kubernetes.api.model.KubernetesResource; +import io.fabric8.kubernetes.api.model.KubernetesResourceList; +import io.fabric8.kubernetes.api.model.ListMeta; +import io.fabric8.kubernetes.api.model.ListMetaBuilder; +import io.fabric8.kubernetes.api.model.NamedContext; +import io.fabric8.kubernetes.api.model.NamedContextBuilder; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.api.model.Secret; +import io.fabric8.kubernetes.api.model.SecretBuilder; +import io.fabric8.kubernetes.api.model.WatchEvent; +import io.fabric8.kubernetes.api.model.WatchEventBuilder; +import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition; +import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionList; +import io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionListBuilder; +import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; +import io.fabric8.kubernetes.client.Watch; +import io.fabric8.kubernetes.client.Watcher; +import io.fabric8.kubernetes.client.WatcherException; +import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext; +import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient; +import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; +import io.fabric8.kubernetes.client.utils.Serialization; + +@RecordApplicationEvents +//@RunWith(SpringRunner.class) +@SpringBootTest(properties = { + + "kubernetes.master = test_kube", + "spring.activemq.brokerUrl = vm://embedded?broker.persistent=false,useShutdownHook=false", + "CATALOG_GET_RESOURCESPEC_BY_ID = direct:get_rspec_byid", + "CATALOG_GET_RESOURCESPEC_BY_ΝAME_CATEGORY = direct:get_rspec_byNameCategory", + "CATALOG_UPDADD_RESOURCE = direct:updadd_resource",}) + + +@EnableKubernetesMockClient +public class CridgeIntegrationTest { + private static final Logger logger = LoggerFactory.getLogger("org.etsi.osl.cridge"); + + private static KubernetesMockServer server; + + @Autowired + KubernetesClientResource kubernetesClientResource; + + @Autowired + CatalogClient catalogClient; + + + /** + * it is used to override beans and setup the environment before application context starts + */ + @TestConfiguration + static class routesPreparation { + + @Autowired + private CamelContext camelContext; + + private SCMocked scmocked = new SCMocked(); + + private static KubernetesClient kubernetesClient; + + @Autowired + KubernetesClientResource kubernetesClientResource; + + RoutesBuilder builder = new RouteBuilder() { + @Override + public void configure() { + from("direct:get_rspec_byid").bean(scmocked, "getRspecID"); + from("direct:get_rspec_byNameCategory").bean(scmocked, + "get_rspec_byNameCategory(${header.aname}, ${header.acategory}, ${header.aversion})"); + from("direct:updadd_resource").unmarshal() + .json(JsonLibrary.Jackson, ResourceCreate.class, true).bean(scmocked, + "updadd_resource(${header.aname},${header.acategory}, ${header.aversion}, ${body})"); + + }; + }; + + + @EventListener(ApplicationStartedEvent.class) + public void preparedForTheTest() { + logger.info("=============== Created routes for the test and initialise =============== "); + + NamedContext nctx = new NamedContextBuilder().withNewContext().withCluster("testCluster") + .and().withName("tstContext").build(); + + // KubernetesClientBuilderCustomizer zzz = new KubernetesClientBuilderCustomizer(); + Config config = Config.autoConfigure(null); + config.setNamespace("testNamespace"); + KubernetesClientBuilder xxx = new KubernetesClientBuilder().withConfig(config); + // zzz.accept(xxx); + kubernetesClient = server.createClient(); + kubernetesClient.getConfiguration().setCurrentContext(nctx); + + + kubernetesClientResource.setKubernetesClient(kubernetesClient); + logger.info("Starting preparedForTheTest kubernetesClient.toString() {} ", + kubernetesClient.toString()); + logger.info("Starting preparedForTheTest for cluster getContexts {} ", + kubernetesClient.getConfiguration().getContexts().toString()); + + + ListMeta metada = new ListMetaBuilder().build(); + // Given + CustomResourceDefinitionList list = + new CustomResourceDefinitionListBuilder().withMetadata(metada).build(); + + + // the following expects are for the sharedIndexInformers in the beginning + server.expect().get() + .withPath("/apis/apiextensions.k8s.io/v1/customresourcedefinitions?resourceVersion=0") + .andReturn(HttpURLConnection.HTTP_OK, list).once(); + + server.expect().get().withPath( + "/apis/apiextensions.k8s.io/v1/customresourcedefinitions?allowWatchBookmarks=true&timeoutSeconds=600&watch=true") + .andReturn(HttpURLConnection.HTTP_OK, list).once(); + + try { + camelContext.addRoutes(builder); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + + @Test + public void testCRDRegister() throws Exception { + + logger.info("===============TEST testCRDRegister ============================="); + CustomResourceDefinition crdMyCalc = v1CRDFromCustomResourceType(MyCalculator.class).build(); + server.expect().post().withPath("/apis/apiextensions.k8s.io/v1/customresourcedefinitions") + .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); + // When + CustomResourceDefinition createdCronTabCrd = routesPreparation.kubernetesClient.apiextensions() + .v1().customResourceDefinitions().resource(crdMyCalc).create(); + + // Then + assertNotNull(createdCronTabCrd); + } + + + @Test + public void testCRDEPLOY() throws Exception { + logger.info("===============TEST testCRDEPLOY ============================="); + + + // CustomResourceDefinition cronTabCrd = routesPreparation.kubernetesClient.apiextensions().v1() + // .customResourceDefinitions() + // .load(new BufferedInputStream(new FileInputStream("src/test/resources/crontab-crd.yaml"))) + // .item(); + + + // prepare CR_SPEC request + CustomResourceDefinition crdMyCalc = v1CRDFromCustomResourceType(MyCalculator.class).build(); + + + + Map map = new HashMap<>(); + map.put("currentContextCluster", "testCluster"); + map.put("clusterMasterURL", server.getHostName()); + map.put("org.etsi.osl.serviceId", "sid-xxx-xxx-xxx"); + map.put("org.etsi.osl.resourceId", "rid-xxx-xxx-xxx"); + map.put("org.etsi.osl.prefixName", "crrid12345"); + map.put("org.etsi.osl.serviceOrderId", "orderid-xxx-xxx-xxx"); + map.put("org.etsi.osl.namespace", "orderid-xxx-xxx-xxx"); + map.put("org.etsi.osl.statusCheckFieldName", "_CR_CHECK_FIELD"); + map.put("org.etsi.osl.statusCheckValueStandby", "_CR_CHECKVAL_STANDBY"); + map.put("org.etsi.osl.statusCheckValueAlarm", "_CR_CHECKVAL_ALARM"); + map.put("org.etsi.osl.statusCheckValueAvailable", "_CR_CHECKVAL_AVAILABLE"); + map.put("org.etsi.osl.statusCheckValueReserved", "_CR_CHECKVAL_RESERVED"); + map.put("org.etsi.osl.statusCheckValueUnknown", "_CR_CHECKVAL_UNKNOWN"); + map.put("org.etsi.osl.statusCheckValueSuspended", "_CR_CHECKVAL_SUSPENDED"); + + + String _CR_SPEC = Serialization.asYaml(getMyCalculator("test-resource")); + + // First check for an invalid context cluster + String response = kubernetesClientResource.deployCR(map, _CR_SPEC); + assertEquals("SEE OTHER", response); + + + // Now try for the correct context cluster + map.put("currentContextCluster", + kubernetesClientResource.getKubernetesContextDefinition().getCurrentContextCluster()); + map.put("clusterMasterURL", + kubernetesClientResource.getKubernetesContextDefinition().getMasterURL()); + + + // server api expectations + server.expect().get() + .withPath("/api/v1/namespaces/orderid-xxx-xxx-xxx/secrets?resourceVersion=0") + .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); + + server.expect().get().withPath( + "/api/v1/namespaces/orderid-xxx-xxx-xxx/secrets?allowWatchBookmarks=true&timeoutSeconds=600&watch=true") + .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); + + server.expect().get() + .withPath("/apis/stable.example.com/v1/namespaces/orderid-xxx-xxx-xxx/mycalculators") + .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); + + server.expect().get().withPath( + "/apis/stable.example.com/v1/namespaces/orderid-xxx-xxx-xxx/mycalculators/amycalculator") + .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); + + server.expect().post().withPath("/api/v1/namespaces/orderid-xxx-xxx-xxx/mycalculators") + .andReturn(HttpURLConnection.HTTP_CREATED, crdMyCalc).once(); + + server.expect().post() + .withPath( + "/apis/examples.osl.etsi.org/v1alpha1/namespaces/orderid-xxx-xxx-xxx/mycalculators") + .andReturn(HttpURLConnection.HTTP_CREATED, crdMyCalc).once(); + + // register the resource handler + KubernetesClient client = routesPreparation.kubernetesClient; + + client.getKubernetesSerialization().registerKubernetesResource("examples.osl.etsi.org/v1alpha1", + "MyCalculator", MyCalculator.class); + + // make the deployment test! + response = kubernetesClientResource.deployCR(map, _CR_SPEC); + + assertEquals("OK", response); + + } + + @Test + public void testCRWithWatch() throws Exception { + // useful blog + // https://itnext.io/mock-kubernetes-api-server-in-java-using-fabric8-kubernetes-mock-server-81a75cf6c47c + + // Given + KubernetesClient client = routesPreparation.kubernetesClient; + + server.expect().withPath( + "/apis/examples.osl.etsi.org/v1alpha1/namespaces/orderid-xxx-xxx-xxx/mycalculators?allowWatchBookmarks=true&watch=true") + .andUpgradeToWebSocket().open().waitFor(10L) + .andEmit(new WatchEvent(getMyCalculator("amycalculator"), "ADDED")).waitFor(20L) + .andEmit(new WatchEventBuilder().withNewStatusObject() + .withMessage("410 - the event requested is outdated") + .withCode(HttpURLConnection.HTTP_GONE).endStatusObject().build()) + .done().always(); + + MixedOperation, Resource> userAclClient = + client.resources(MyCalculator.class); + + + // When + CountDownLatch eventRecieved = new CountDownLatch(1); + client.getKubernetesSerialization().registerKubernetesResource("examples.osl.etsi.org/v1alpha1", + "MyCalculator", MyCalculator.class); + + Watch watch = + userAclClient.inNamespace("orderid-xxx-xxx-xxx").watch(new Watcher() { + @Override + public void eventReceived(Action action, MyCalculator calc) { + if (action.name().contains("ADDED")) { + eventRecieved.countDown(); + logger.info( + "===============CountDownLatch eventRecieved.countDown ADDED {}=============================", + Serialization.asYaml(calc)); + } + } + + @Override + public void onClose(WatcherException e) {} + }); + + // Then + eventRecieved.await(30, TimeUnit.SECONDS); + Assertions.assertEquals(0, eventRecieved.getCount()); + watch.close(); + + } + + + private KubernetesResource getMyCalculator(String resourceName) { + MyCalculatorSpec spec = new MyCalculatorSpec(); + spec.setAction("amycalculator"); + + MyCalculator createdMyCalcL = new MyCalculator(); + createdMyCalcL.setMetadata(new ObjectMetaBuilder().withName(resourceName).build()); + createdMyCalcL.setSpec(spec); + + Condition condition = new Condition(); + condition.setMessage("Last reconciliation succeeded"); + condition.setReason("Successful"); + condition.setStatus("True"); + condition.setType("Successful"); + MyCalculatorStatus status = new MyCalculatorStatus(); + status.setCondition(new Condition[] {condition}); + createdMyCalcL.setStatus(status); + + return createdMyCalcL; + } + + + @Test + public void testKubernetesCRD2OpensliceCRD() throws FileNotFoundException { + + logger.info("===============TEST testCRDRegister ============================="); + // CustomResourceDefinition crdMyCalc = v1CRDFromCustomResourceType(MyCalculator.class).build(); + CustomResourceDefinition cronTabCrd = + routesPreparation.kubernetesClient.apiextensions().v1().customResourceDefinitions() + .load( + new BufferedInputStream(new FileInputStream("src/test/resources/crontab-crd.yaml"))) + .item(); + + List value = kubernetesClientResource.KubernetesCRD2OpensliceCRD(cronTabCrd); + + assertEquals(1, value.size()); + assertEquals("CronTab", value.get(0).getKind()); + assertEquals("v1", value.get(0).getVersion()); + assertEquals("stable.example.com", value.get(0).getApiGroup()); + + + } + + @Test + public void testKubernetesCRDOpensliceCR() throws FileNotFoundException { + + + logger.info("===============TEST testCRRegister ============================="); + + ResourceDefinitionContext resourceDefinitionContext = new ResourceDefinitionContext.Builder() + .withGroup("stable.example.com").withVersion("v1").withPlural("crontabs").build(); + + GenericKubernetesResource cronTabCr = + routesPreparation.kubernetesClient.genericKubernetesResources(resourceDefinitionContext) + .load(new FileInputStream("src/test/resources/crontab-cr.yaml")).item(); + + + KubernetesCRV1 value = kubernetesClientResource.KubernetesCR2OpensliceCR(cronTabCr); + + assertEquals("CronTab", value.getKind()); + + + } + + @Test + public void testKubernetesSecret2OpensliceResource() throws FileNotFoundException { + + + logger.info( + "===============TEST KubernetesSecret2OpensliceResource ============================="); + + + Secret secret1 = new SecretBuilder().withNewMetadata().withName("secret1").endMetadata() + .addToData("username", "guccifer").addToData("password", "shadowgovernment").build(); + + + server.expect().post().withPath("/api/v1/namespaces/default/secrets") + .andReturn(HttpURLConnection.HTTP_OK, secret1).once(); + + Secret secretCreated = routesPreparation.kubernetesClient.secrets().inNamespace("default") + .resource(secret1).create(); + + + KubernetesSecret value = + kubernetesClientResource.KubernetesSecret2OpensliceResource(secretCreated); + + assertEquals("Secret", value.getKind()); + assertEquals("v1", value.getVersion()); + + + } + + +// @Test +// public void testCRDelete() throws Exception { +// logger.info("===============TEST testCRDelete ============================="); +// +// +// // CustomResourceDefinition cronTabCrd = routesPreparation.kubernetesClient.apiextensions().v1() +// // .customResourceDefinitions() +// // .load(new BufferedInputStream(new FileInputStream("src/test/resources/crontab-crd.yaml"))) +// // .item(); +// +// +// // prepare CR_SPEC request +// CustomResourceDefinition crdMyCalc = v1CRDFromCustomResourceType(MyCalculator.class).build(); +// +// +// +// Map map = new HashMap<>(); +// map.put("currentContextCluster", "testCluster"); +// map.put("clusterMasterURL", server.getHostName()); +// map.put("org.etsi.osl.serviceId", "sid-xxx-xxx-xxx"); +// map.put("org.etsi.osl.resourceId", "rid-xxx-xxx-xxx"); +// map.put("org.etsi.osl.prefixName", "crrid12345"); +// map.put("org.etsi.osl.serviceOrderId", "orderid-xxx-xxx-xxx"); +// map.put("org.etsi.osl.namespace", "orderid-xxx-xxx-xxx"); +// map.put("org.etsi.osl.statusCheckFieldName", "_CR_CHECK_FIELD"); +// map.put("org.etsi.osl.statusCheckValueStandby", "_CR_CHECKVAL_STANDBY"); +// map.put("org.etsi.osl.statusCheckValueAlarm", "_CR_CHECKVAL_ALARM"); +// map.put("org.etsi.osl.statusCheckValueAvailable", "_CR_CHECKVAL_AVAILABLE"); +// map.put("org.etsi.osl.statusCheckValueReserved", "_CR_CHECKVAL_RESERVED"); +// map.put("org.etsi.osl.statusCheckValueUnknown", "_CR_CHECKVAL_UNKNOWN"); +// map.put("org.etsi.osl.statusCheckValueSuspended", "_CR_CHECKVAL_SUSPENDED"); +// +// +// String _CR_SPEC = Serialization.asYaml(getMyCalculator("test-resource")); +// +// // First check for an invalid context cluster +// String response = kubernetesClientResource.deployCR(map, _CR_SPEC); +// assertEquals("SEE OTHER", response); +// +// +// // Now try for the correct context cluster +// map.put("currentContextCluster", +// kubernetesClientResource.getKubernetesContextDefinition().getCurrentContextCluster()); +// map.put("clusterMasterURL", +// kubernetesClientResource.getKubernetesContextDefinition().getMasterURL()); +// +// +// // server api expectations +// server.expect().get() +// .withPath("/api/v1/namespaces/orderid-xxx-xxx-xxx/secrets?resourceVersion=0") +// .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); +// +// server.expect().get().withPath( +// "/api/v1/namespaces/orderid-xxx-xxx-xxx/secrets?allowWatchBookmarks=true&timeoutSeconds=600&watch=true") +// .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); +// +// server.expect().get() +// .withPath("/apis/stable.example.com/v1/namespaces/orderid-xxx-xxx-xxx/mycalculators") +// .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); +// +// server.expect().get().withPath( +// "/apis/stable.example.com/v1/namespaces/orderid-xxx-xxx-xxx/mycalculators/amycalculator") +// .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); +// +// server.expect().post().withPath("/api/v1/namespaces/orderid-xxx-xxx-xxx/mycalculators") +// .andReturn(HttpURLConnection.HTTP_CREATED, crdMyCalc).once(); +// +// server.expect().post() +// .withPath( +// "/apis/examples.osl.etsi.org/v1alpha1/namespaces/orderid-xxx-xxx-xxx/mycalculators") +// .andReturn(HttpURLConnection.HTTP_CREATED, crdMyCalc).once(); +// +// // register the resource handler +// KubernetesClient client = routesPreparation.kubernetesClient; +// +// client.getKubernetesSerialization().registerKubernetesResource("examples.osl.etsi.org/v1alpha1", +// "MyCalculator", MyCalculator.class); +// +// // make the deployment test! +// response = kubernetesClientResource.deleteCR(map, _CR_SPEC); +// +// assertEquals("OK", response); +// +// } + + + +// @Test +// public void testCPatch() throws Exception { +// logger.info("===============TEST testCRDEPLOY ============================="); +// +// +// // CustomResourceDefinition cronTabCrd = routesPreparation.kubernetesClient.apiextensions().v1() +// // .customResourceDefinitions() +// // .load(new BufferedInputStream(new FileInputStream("src/test/resources/crontab-crd.yaml"))) +// // .item(); +// +// +// // prepare CR_SPEC request +// CustomResourceDefinition crdMyCalc = v1CRDFromCustomResourceType(MyCalculator.class).build(); +// +// +// +// Map map = new HashMap<>(); +// map.put("currentContextCluster", "testCluster"); +// map.put("clusterMasterURL", server.getHostName()); +// map.put("org.etsi.osl.serviceId", "sid-xxx-xxx-xxx"); +// map.put("org.etsi.osl.resourceId", "rid-xxx-xxx-xxx"); +// map.put("org.etsi.osl.prefixName", "crrid12345"); +// map.put("org.etsi.osl.serviceOrderId", "orderid-xxx-xxx-xxx"); +// map.put("org.etsi.osl.namespace", "orderid-xxx-xxx-xxx"); +// map.put("org.etsi.osl.statusCheckFieldName", "_CR_CHECK_FIELD"); +// map.put("org.etsi.osl.statusCheckValueStandby", "_CR_CHECKVAL_STANDBY"); +// map.put("org.etsi.osl.statusCheckValueAlarm", "_CR_CHECKVAL_ALARM"); +// map.put("org.etsi.osl.statusCheckValueAvailable", "_CR_CHECKVAL_AVAILABLE"); +// map.put("org.etsi.osl.statusCheckValueReserved", "_CR_CHECKVAL_RESERVED"); +// map.put("org.etsi.osl.statusCheckValueUnknown", "_CR_CHECKVAL_UNKNOWN"); +// map.put("org.etsi.osl.statusCheckValueSuspended", "_CR_CHECKVAL_SUSPENDED"); +// +// +// String _CR_SPEC = Serialization.asYaml(getMyCalculator("test-resource")); +// +// // First check for an invalid context cluster +// String response = kubernetesClientResource.deployCR(map, _CR_SPEC); +// assertEquals("SEE OTHER", response); +// +// +// // Now try for the correct context cluster +// map.put("currentContextCluster", +// kubernetesClientResource.getKubernetesContextDefinition().getCurrentContextCluster()); +// map.put("clusterMasterURL", +// kubernetesClientResource.getKubernetesContextDefinition().getMasterURL()); +// +// +// // server api expectations +// server.expect().get() +// .withPath("/api/v1/namespaces/orderid-xxx-xxx-xxx/secrets?resourceVersion=0") +// .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); +// +// server.expect().get().withPath( +// "/api/v1/namespaces/orderid-xxx-xxx-xxx/secrets?allowWatchBookmarks=true&timeoutSeconds=600&watch=true") +// .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); +// +// server.expect().get() +// .withPath("/apis/stable.example.com/v1/namespaces/orderid-xxx-xxx-xxx/mycalculators") +// .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); +// +// server.expect().get().withPath( +// "/apis/stable.example.com/v1/namespaces/orderid-xxx-xxx-xxx/mycalculators/amycalculator") +// .andReturn(HttpURLConnection.HTTP_OK, crdMyCalc).once(); +// +// server.expect().post().withPath("/api/v1/namespaces/orderid-xxx-xxx-xxx/mycalculators") +// .andReturn(HttpURLConnection.HTTP_CREATED, crdMyCalc).once(); +// +// server.expect().post() +// .withPath( +// "/apis/examples.osl.etsi.org/v1alpha1/namespaces/orderid-xxx-xxx-xxx/mycalculators") +// .andReturn(HttpURLConnection.HTTP_CREATED, crdMyCalc).once(); +// +// // register the resource handler +// KubernetesClient client = routesPreparation.kubernetesClient; +// +// client.getKubernetesSerialization().registerKubernetesResource("examples.osl.etsi.org/v1alpha1", +// "MyCalculator", MyCalculator.class); +// +// server.expect().get() +// .withPath( +// "/apis/examples.osl.etsi.org/v1alpha1/namespaces/orderid-xxx-xxx-xxx/mycalculators/crrid12345") +// .andReturn(HttpURLConnection.HTTP_OK, null).once(); +// server.expect().patch() +// .withPath( +// "/apis/examples.osl.etsi.org/v1alpha1/namespaces/orderid-xxx-xxx-xxx/mycalculators/crrid12345") +// .andReturn(HttpURLConnection.HTTP_OK, null).once(); +// +// +// // make the deployment test! +// response = kubernetesClientResource.patchCR(map, _CR_SPEC); +// +// assertEquals("OK", response); +// +// } + + +} diff --git a/src/test/java/org/etsi/osl/cridge/MyCalculator.java b/src/test/java/org/etsi/osl/cridge/MyCalculator.java new file mode 100644 index 0000000000000000000000000000000000000000..cbadd3e9bb37482bc93a1382e3c0f8a1e9fb82a1 --- /dev/null +++ b/src/test/java/org/etsi/osl/cridge/MyCalculator.java @@ -0,0 +1,13 @@ +package org.etsi.osl.cridge; + +import io.fabric8.kubernetes.api.model.Namespaced; +import io.fabric8.kubernetes.client.CustomResource; +import io.fabric8.kubernetes.model.annotation.Group; +import io.fabric8.kubernetes.model.annotation.Version; + +@Version("v1alpha1") // -> CRD Version +@Group("examples.osl.etsi.org") // -> CRD Group +public class MyCalculator // -> CRD Kind (if not provided in @Kind annotation) + extends CustomResource + implements Namespaced { +} // -> CRD scope Namespaced \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/cridge/MyCalculatorSpec.java b/src/test/java/org/etsi/osl/cridge/MyCalculatorSpec.java new file mode 100644 index 0000000000000000000000000000000000000000..e1be74eb2bddc75f567fb464034638122a19a4d2 --- /dev/null +++ b/src/test/java/org/etsi/osl/cridge/MyCalculatorSpec.java @@ -0,0 +1,47 @@ +package org.etsi.osl.cridge; + + +public class MyCalculatorSpec { + private int parama; + private int paramb; + private String action; + /** + * @return the parama + */ + public int getParama() { + return parama; + } + /** + * @param parama the parama to set + */ + public void setParama(int parama) { + this.parama = parama; + } + /** + * @return the paramb + */ + public int getParamb() { + return paramb; + } + /** + * @param paramb the paramb to set + */ + public void setParamb(int paramb) { + this.paramb = paramb; + } + /** + * @return the action + */ + public String getAction() { + return action; + } + /** + * @param action the action to set + */ + public void setAction(String action) { + this.action = action; + } + + + +} \ No newline at end of file diff --git a/src/test/java/org/etsi/osl/cridge/MyCalculatorStatus.java b/src/test/java/org/etsi/osl/cridge/MyCalculatorStatus.java new file mode 100644 index 0000000000000000000000000000000000000000..30905fa89cd189e5c926d9eec7f465751e0b91c0 --- /dev/null +++ b/src/test/java/org/etsi/osl/cridge/MyCalculatorStatus.java @@ -0,0 +1,54 @@ +package org.etsi.osl.cridge; + +import io.fabric8.kubernetes.api.model.Condition; + +public class MyCalculatorStatus { + private int result; + private String status; + Condition[] condition; + + /** + * @return the result + */ + public int getResult() { + return result; + } + + /** + * @param result the result to set + */ + public void setResult(int result) { + this.result = result; + } + + /** + * @return the status + */ + public String getStatus() { + return status; + } + + /** + * @param status the status to set + */ + public void setStatus(String status) { + this.status = status; + } + + /** + * @return the condition + */ + public Condition[] getCondition() { + return condition; + } + + /** + * @param condition the condition to set + */ + public void setCondition(Condition[] condition) { + this.condition = condition; + } + + + +} diff --git a/src/test/java/org/etsi/osl/cridge/SCMocked.java b/src/test/java/org/etsi/osl/cridge/SCMocked.java new file mode 100644 index 0000000000000000000000000000000000000000..197c05100749227731b2d094b867865898241f16 --- /dev/null +++ b/src/test/java/org/etsi/osl/cridge/SCMocked.java @@ -0,0 +1,132 @@ +/*- + * ========================LICENSE_START================================= + * org.etsi.osl.osom + * %% + * Copyright (C) 2019 openslice.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ +package org.etsi.osl.cridge; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.etsi.osl.tmf.ri639.model.Resource; +import org.etsi.osl.tmf.ri639.model.ResourceCreate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class SCMocked { + + + private static final Logger logger = LoggerFactory.getLogger("org.etsi.osl.cridge"); + + + private static Map runningServices = + new HashMap<>(); + + + + public String getRspecID(String id) throws IOException { + logger.info("getRspecID id= " + id); + File sspec = new File("src/test/resources/TestExServiceOrder.json"); + InputStream in = new FileInputStream(sspec); + String sspectext = IOUtils.toString(in, "UTF-8"); + + return sspectext; + } + + + public String get_rspec_byNameCategory(String aname, String aCategory, String aVersion) throws IOException { + logger.info("get_rspec_byNameCategory {} {} {} ", aname, aCategory, aVersion); + + File sspec = null; + if (aname.equals("kubernetes-context-definition.openslice.io")) { + sspec = new File("src/test/resources/kubernetes-context-definition.openslice.io.json"); + + } else if (aname.equals("kubernetes-crd.openslice.io")) { + sspec = new File("src/test/resources/kubernetes-crd.openslice.io.json"); + } else if (aname.equals("kubernetes-cr-v1.openslice.io")) { + sspec = new File("src/test/resources/kubernetes-cr-v1.openslice.io.json"); + } else if (aname.equals("kubernetes-secret.openslice.io")) { + sspec = new File("src/test/resources/kubernetes-secret.openslice.io.json"); + } + + + + + InputStream in = new FileInputStream(sspec); + String sspectext = IOUtils.toString(in, "UTF-8"); + + return sspectext; + } + + public String updadd_resource(String aName, String aCategory, + String aVersion, ResourceCreate aResourceCreate) throws IOException { + logger.info("updadd_resource {} {} {} {}", aName, aCategory, aVersion, aResourceCreate); + + Resource r = new Resource().name( aResourceCreate.getName() ); + + return toJsonString(r); + } + + + public String getServiceById(String id) throws IOException { + + logger.info("getServiceById id = " + id); + + String sspectext = null; + + if (runningServices.get(id) != null) { + org.etsi.osl.tmf.sim638.model.Service serviceInstance = runningServices.get(id); + sspectext = toJsonString(serviceInstance); + return sspectext; + } + + + File sspec = new File("src/test/resources/TestService.json"); + InputStream in = new FileInputStream(sspec); + sspectext = IOUtils.toString(in, "UTF-8"); + return sspectext; + } + + + + static String toJsonString(Object object) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + return mapper.writeValueAsString(object); + } + + static T toJsonObj(String content, Class valueType) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + return mapper.readValue(content, valueType); + } + + + +} diff --git a/src/test/resources/asecret.yaml b/src/test/resources/asecret.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5c7900ad974799bb39329de9cfa39008a79ab4aa --- /dev/null +++ b/src/test/resources/asecret.yaml @@ -0,0 +1,27 @@ +apiVersion: v1 +kind: Secret +metadata: + name: dotfile-secret +data: + .secret-file: dmFsdWUtMg0KDQo= +--- +apiVersion: v1 +kind: Pod +metadata: + name: secret-dotfiles-pod +spec: + volumes: + - name: secret-volume + secret: + secretName: dotfile-secret + containers: + - name: dotfile-test-container + image: registry.k8s.io/busybox + command: + - ls + - "-l" + - "/etc/secret-volume" + volumeMounts: + - name: secret-volume + readOnly: true + mountPath: "/etc/secret-volume" \ No newline at end of file diff --git a/src/test/resources/crontab-cr.yaml b/src/test/resources/crontab-cr.yaml new file mode 100644 index 0000000000000000000000000000000000000000..88fb77d745dd17d878279b88326fed71f8d5c656 --- /dev/null +++ b/src/test/resources/crontab-cr.yaml @@ -0,0 +1,9 @@ +# Taken from https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#create-custom-objects + +apiVersion: "stable.example.com/v1" +kind: CronTab +metadata: + name: my-new-cron-object +spec: + cronSpec: "* * * * */5" + image: my-awesome-cron-image \ No newline at end of file diff --git a/src/test/resources/crontab-crd.yaml b/src/test/resources/crontab-crd.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3ff7481af8ba1d8c166adb1f04681e4313cc2346 --- /dev/null +++ b/src/test/resources/crontab-crd.yaml @@ -0,0 +1,40 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + # name must match the spec fields below, and be in the form: . + name: crontabs.stable.example.com +spec: + # group name to use for REST API: /apis// + group: stable.example.com + # list of versions supported by this CustomResourceDefinition + versions: + - name: v1 + # Each version can be enabled/disabled by Served flag. + served: true + # One and only one version must be marked as the storage version. + storage: true + schema: + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + cronSpec: + type: string + image: + type: string + replicas: + type: integer + # either Namespaced or Cluster + scope: Namespaced + names: + # plural name to be used in the URL: /apis/// + plural: crontabs + # singular name to be used as an alias on the CLI and for display + singular: crontab + # kind is normally the CamelCased singular type. Your resource manifests use this. + kind: CronTab + # shortNames allow shorter string to match your resource on the CLI + shortNames: + - ct \ No newline at end of file diff --git a/src/test/resources/kubernetes-context-definition.openslice.io.json b/src/test/resources/kubernetes-context-definition.openslice.io.json new file mode 100644 index 0000000000000000000000000000000000000000..4a71e2a67a8352b5369ec2957cc145454d33c6c1 --- /dev/null +++ b/src/test/resources/kubernetes-context-definition.openslice.io.json @@ -0,0 +1,303 @@ +{ + "uuid": "35671aef-dfdd-4cdd-a4b7-226877b1dc0a", + "lastUpdate": "2023-08-31T15:21:02.047461Z", + "atSchemaLocation": null, + "@baseType": "ResourceSpecification", + "@schemaLocation": null, + "@type": "LogicalResourceSpecification", + "href": null, + "name": "kubernetes-context-definition.openslice.io", + "description": "This Specification is used to describe a KubernetesClient", + "lifecycleStatus": "Active", + "version": "0.0.1", + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047862Z", + "startDateTime": "2023-08-31T15:21:02.047857Z" + }, + "id": "35671aef-dfdd-4cdd-a4b7-226877b1dc0a", + "isBundle": null, + "category": "KubernetesContextDefinition", + "targetResourceSchema": null, + "attachment": [], + "featureSpecification": [], + "relatedParty": [], + "resourceSpecCharacteristic": [ + { + "uuid": "050dac35-c056-4041-a64b-46fafae0cd52", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "resourceVersion", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047584Z", + "startDateTime": "2023-08-31T15:21:02.047580Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "61b854dd-2aba-4454-883f-5fa8e8ba9520", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047637Z", + "startDateTime": "2023-08-31T15:21:02.047634Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "a13fdf50-1a10-4921-a4e9-1a295e928485", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "masterURL", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047525Z", + "startDateTime": "2023-08-31T15:21:02.047521Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "b156faf3-0fd2-4047-980c-af8420e80159", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047550Z", + "startDateTime": "2023-08-31T15:21:02.047547Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "bf0c2090-fdec-4579-b6de-04b8f18a5960", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "currentContextCluster", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047715Z", + "startDateTime": "2023-08-31T15:21:02.047711Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "017b9bd4-7361-4ca0-8046-ab913d7f0c64", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047730Z", + "startDateTime": "2023-08-31T15:21:02.047727Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "c3c66ffa-6c27-4e3c-a8e1-828f9e31aa71", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "currentContextName", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047671Z", + "startDateTime": "2023-08-31T15:21:02.047668Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "e0ae87b1-f0c1-4c40-b0ca-54942d6059fe", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047685Z", + "startDateTime": "2023-08-31T15:21:02.047682Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "f09b696a-5342-4172-ba20-e3ffbbf9c756", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "clusterVersion", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047811Z", + "startDateTime": "2023-08-31T15:21:02.047808Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "9f201bed-e57c-4bc0-9f9c-9935c93357a8", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047826Z", + "startDateTime": "2023-08-31T15:21:02.047822Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "f472aad3-98ad-4d38-ae48-6413005b4314", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "currentContextUser", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047763Z", + "startDateTime": "2023-08-31T15:21:02.047760Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "227169fd-3bc1-43be-9783-881ba2eb0887", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.047778Z", + "startDateTime": "2023-08-31T15:21:02.047775Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + } + ], + "resourceSpecRelationship": [] +} \ No newline at end of file diff --git a/src/test/resources/kubernetes-cr-v1.openslice.io.json b/src/test/resources/kubernetes-cr-v1.openslice.io.json new file mode 100644 index 0000000000000000000000000000000000000000..9c0ad3a3b91e3f1d184aaa85310519ac534fbfb4 --- /dev/null +++ b/src/test/resources/kubernetes-cr-v1.openslice.io.json @@ -0,0 +1,487 @@ +{ + "uuid": "f52d52bf-8986-439d-8706-be99153f2171", + "lastUpdate": "2023-08-31T15:21:02.330931Z", + "atSchemaLocation": null, + "@baseType": "ResourceSpecification", + "@schemaLocation": null, + "@type": "LogicalResourceSpecification", + "href": null, + "name": "kubernetes-cr-v1.openslice.io", + "description": "This Specification is used to describe a generic KubernetesCRV1", + "lifecycleStatus": "Active", + "version": "0.0.4", + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331235Z", + "startDateTime": "2023-08-31T15:21:02.331234Z" + }, + "id": "f52d52bf-8986-439d-8706-be99153f2171", + "isBundle": null, + "category": "KubernetesCRV1-apiextensions.k8s.io/v1", + "targetResourceSchema": null, + "attachment": [], + "featureSpecification": [], + "relatedParty": [], + "resourceSpecCharacteristic": [ + { + "uuid": "8e2a6ea5-1eab-4024-960a-3886f2487a05", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "yaml", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331171Z", + "startDateTime": "2023-08-31T15:21:02.331171Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "9fc9d76d-0480-470f-ad50-0e1c97491af3", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331176Z", + "startDateTime": "2023-08-31T15:21:02.331176Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "33cb8b97-c856-4df5-baa4-81b0e148d886", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "fullResourceName", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331003Z", + "startDateTime": "2023-08-31T15:21:02.331003Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "279d5f17-0917-49a2-a227-87427addfb10", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331009Z", + "startDateTime": "2023-08-31T15:21:02.331009Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "6ec58bc1-3959-4024-b33b-0ae86090903f", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "clusterMasterURL", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.330955Z", + "startDateTime": "2023-08-31T15:21:02.330954Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "d0709cb6-1d53-4e9a-9809-324020674bf5", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.330967Z", + "startDateTime": "2023-08-31T15:21:02.330967Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "2eaa3573-2b82-451e-ba3e-9bb65ae03cdb", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "metadata", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331148Z", + "startDateTime": "2023-08-31T15:21:02.331146Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "b5760ec3-a1a2-4f8c-9b30-5eae5a5bbd1a", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331153Z", + "startDateTime": "2023-08-31T15:21:02.331152Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "fe91aeab-9607-40d3-b19e-873a3f624ce7", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "currentContextCluster", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.330985Z", + "startDateTime": "2023-08-31T15:21:02.330984Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "c4f1697a-f0ea-4268-a56d-bba246f03aaf", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.330991Z", + "startDateTime": "2023-08-31T15:21:02.330991Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "2a387477-e6c2-4bb7-b182-e8c99198b310", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "apiGroup", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331040Z", + "startDateTime": "2023-08-31T15:21:02.331039Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "987194d4-49f3-47d1-9bd6-88bc59243f3a", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331046Z", + "startDateTime": "2023-08-31T15:21:02.331045Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "02a63d48-232e-468d-b50d-90aa4d36b171", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "Kind", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331021Z", + "startDateTime": "2023-08-31T15:21:02.331021Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "91f25d94-0071-42e6-b993-fae4a37eff36", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331027Z", + "startDateTime": "2023-08-31T15:21:02.331027Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "6fbfb458-976d-4cb9-a0fe-5a45169ce97b", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "json", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331212Z", + "startDateTime": "2023-08-31T15:21:02.331211Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "f950d4b3-230f-4c66-acc5-338a404947b4", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331218Z", + "startDateTime": "2023-08-31T15:21:02.331218Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "a50151a2-4420-4a51-9274-3477fa6bd009", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "UID", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331103Z", + "startDateTime": "2023-08-31T15:21:02.331103Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "3317fa59-5a99-42a1-bcfa-aa0fda6d33eb", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331109Z", + "startDateTime": "2023-08-31T15:21:02.331108Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + }, + { + "uuid": "da587f43-2beb-47fd-941c-2ecc1e920c98", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "namespace", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331125Z", + "startDateTime": "2023-08-31T15:21:02.331125Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [ + { + "uuid": "d1ce339a-dbb5-4665-baf4-46112dbc2027", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "valueType": null, + "isDefault": true, + "value": { + "value": "", + "alias": null + }, + "unitOfMeasure": null, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.331130Z", + "startDateTime": "2023-08-31T15:21:02.331130Z" + }, + "valueFrom": null, + "valueTo": null, + "rangeInterval": null, + "regex": null + } + ] + } + ], + "resourceSpecRelationship": [] +} \ No newline at end of file diff --git a/src/test/resources/kubernetes-crd.openslice.io.json b/src/test/resources/kubernetes-crd.openslice.io.json new file mode 100644 index 0000000000000000000000000000000000000000..db7f2b607cbfe631df686b5b8632508d9247a6a6 --- /dev/null +++ b/src/test/resources/kubernetes-crd.openslice.io.json @@ -0,0 +1,234 @@ +{ + "uuid": "e643a6b8-3385-4033-ae8e-94270fee722a", + "lastUpdate": "2023-08-31T15:21:02.198335Z", + "atSchemaLocation": null, + "@baseType": "ResourceSpecification", + "@schemaLocation": null, + "@type": "LogicalResourceSpecification", + "href": null, + "name": "kubernetes-crd.openslice.io", + "description": "This Specification is used to describe a generic KubernetesCRD", + "lifecycleStatus": "Active", + "version": "0.0.3", + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198641Z", + "startDateTime": "2023-08-31T15:21:02.198638Z" + }, + "id": "e643a6b8-3385-4033-ae8e-94270fee722a", + "isBundle": null, + "category": "KubernetesCRD-apiextensions.k8s.io/v1", + "targetResourceSchema": null, + "attachment": [], + "featureSpecification": [], + "relatedParty": [], + "resourceSpecCharacteristic": [ + { + "uuid": "ccc02eec-2e98-4499-8d17-e37fdf7d2156", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "apiGroup", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198473Z", + "startDateTime": "2023-08-31T15:21:02.198471Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "12efb209-a998-4bb6-af4b-0cae3f1fd52e", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "yaml", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198588Z", + "startDateTime": "2023-08-31T15:21:02.198586Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "781ddf50-515f-468e-9bd4-591417ac129f", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "Kind", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198427Z", + "startDateTime": "2023-08-31T15:21:02.198425Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "8ae5e60b-7b09-483d-b1fe-11033225a585", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "UID", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198516Z", + "startDateTime": "2023-08-31T15:21:02.198514Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "915d6f12-2611-443f-bb89-0e9f0e97bf7d", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "currentContextCluster", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198393Z", + "startDateTime": "2023-08-31T15:21:02.198391Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "874c570e-390d-4976-a0e7-72743bccb406", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "json", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198620Z", + "startDateTime": "2023-08-31T15:21:02.198617Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "242fc539-7d20-44fe-b7ba-083699e4ffd4", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "fullResourceName", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198410Z", + "startDateTime": "2023-08-31T15:21:02.198408Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "f5fa11d5-b2e7-4fe8-a48f-b5ecd2949924", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "clusterMasterURL", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198367Z", + "startDateTime": "2023-08-31T15:21:02.198364Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "fc2779a1-9d25-42c7-8dca-c1b56563e767", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "io.openslice.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "metadata", + "description": null, + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-08-31T15:21:02.198558Z", + "startDateTime": "2023-08-31T15:21:02.198555Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + } + ], + "resourceSpecRelationship": [] +} \ No newline at end of file diff --git a/src/test/resources/kubernetes-secret.openslice.io.json b/src/test/resources/kubernetes-secret.openslice.io.json new file mode 100644 index 0000000000000000000000000000000000000000..8e38d2cce0b6b7360712e52c9b72b53609fd9920 --- /dev/null +++ b/src/test/resources/kubernetes-secret.openslice.io.json @@ -0,0 +1,257 @@ +{ + "uuid": "9c9995ea-458a-476c-8328-3e1942916ea5", + "lastUpdate": "2023-11-27T15:53:38.781582Z", + "atSchemaLocation": null, + "@baseType": "ResourceSpecification", + "@schemaLocation": null, + "@type": "LogicalResourceSpecification", + "href": null, + "name": "kubernetes-secret.openslice.io", + "description": "This Specification is used to describe a generic Kubernetes Secret", + "lifecycleStatus": "Active", + "version": "0.0.3", + "validFor": { + "endDateTime": "2043-11-27T15:53:38.782314Z", + "startDateTime": "2023-11-27T15:53:38.782295Z" + }, + "id": "9c9995ea-458a-476c-8328-3e1942916ea5", + "isBundle": null, + "category": "Secret/Kubernetes/v1", + "targetResourceSchema": null, + "attachment": [], + "featureSpecification": [], + "relatedParty": [], + "resourceSpecCharacteristic": [ + { + "uuid": "93a79b93-2467-438d-bd2c-e1a9e9a264eb", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "yaml", + "description": "", + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.782112Z", + "startDateTime": "2023-11-27T15:53:38.782100Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "bda7450a-e073-4548-8feb-9f0749555f18", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "json", + "description": "", + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.782174Z", + "startDateTime": "2023-11-27T15:53:38.782161Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "e4f59527-91e3-4d4c-94bf-e340d2ca0241", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "fullResourceName", + "description": "", + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.781728Z", + "startDateTime": "2023-11-27T15:53:38.781722Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "0d6081ab-9664-4948-a50a-347682c05430", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "Kind", + "description": "", + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.781844Z", + "startDateTime": "2023-11-27T15:53:38.781839Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "756481d7-83d1-477f-af00-3ab3c496d18e", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "UID", + "description": "", + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.781991Z", + "startDateTime": "2023-11-27T15:53:38.781987Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "a0516d6e-b7f8-4047-ba05-52a67f43027d", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "currentContextCluster", + "description": "", + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.781703Z", + "startDateTime": "2023-11-27T15:53:38.781698Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "43629eac-bfe8-4499-a67c-8e4413a7d8bd", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "metadata", + "description": "", + "valueType": "OBJECT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.782052Z", + "startDateTime": "2023-11-27T15:53:38.782039Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "caed942c-8845-46a7-858f-d135a9d09af9", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "apiGroup", + "description": "", + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.781937Z", + "startDateTime": "2023-11-27T15:53:38.781911Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "9eab7863-0f97-4d2d-b918-7e83e2b8b1b2", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "data", + "description": "", + "valueType": "OBJECT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.782235Z", + "startDateTime": "2023-11-27T15:53:38.782223Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + }, + { + "uuid": "b6f77315-276a-464f-bf9d-422e3bbe5529", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.rcm634.model.ResourceSpecificationCharacteristic", + "href": null, + "name": "clusterMasterURL", + "description": "URL of cluster", + "valueType": "TEXT", + "configurable": false, + "validFor": { + "endDateTime": "2043-11-27T15:53:38.781650Z", + "startDateTime": "2023-11-27T15:53:38.781644Z" + }, + "@valueSchemaLocation": null, + "minCardinality": null, + "maxCardinality": null, + "isUnique": null, + "regex": null, + "extensible": null, + "resourceSpecCharRelationship": [], + "resourceSpecCharacteristicValue": [] + } + ], + "resourceSpecRelationship": [] +} \ No newline at end of file diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 0000000000000000000000000000000000000000..e535939c74ad282638c06453b9938ac004463b39 --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,32 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + +