You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Documentation/README.md
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,12 @@ cd Documentation
16
16
pip install -r requirements.txt
17
17
```
18
18
19
+
### Edit it
20
+
21
+
Documentation is created in the ReSTructured text format.
22
+
A nice document listing important commands is the [Restructured Text (reST) and Sphinx CheatSheet](https://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html).
Copy file name to clipboardExpand all lines: Documentation/components/iptables/pcn-iptables.rst
+19-4Lines changed: 19 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -61,8 +61,8 @@ Prerequisites
61
61
pcn-iptables comes as a component of polycube framework.
62
62
Refer to :doc:`polycube install guide<../../../installation>` for dependencies, kernel requirements and basic checkout and install guide.
63
63
64
-
Install Steps
65
-
^^^^^^^^^^^^^
64
+
Install
65
+
^^^^^^^
66
66
67
67
To compile and install ``pcn-iptables``, you should enable the ``ENABLE_PCN_IPTABLES`` flag in the polycube CMakeFile, which is set to ``OFF`` by default;
68
68
this allows to compile the customized version of ``iptables`` used to translate commands, and install in the system pcn-iptables-init pcn-iptables and pcn-iptables-clean utils.
@@ -160,14 +160,29 @@ Limitations
160
160
pcn-iptables components
161
161
-----------------------
162
162
163
+
``pcn-iptables`` is composed by three main components:
164
+
165
+
1. ``pcn-iptables`` service (``src/services/pcn-iptables``): a Polycube service, a special one since performs some extra work, but basically expose its API and CLI, according to Polycube standard.
166
+
163
167
iptables submodule
164
168
^^^^^^^^^^^^^^^^^^
165
169
166
170
A customized fork of iptables is included as submodule under :scm_web:`src/components/iptables/iptables <src/components/iptables>`.
167
-
We customized this version of iptables in order not to inject iptables command into netfilter, but convert them, after a validation step, into polycube syntax.
171
+
This modified version of iptables is in charge of validate commands, translate them from iptables to polycube syntax, then forward them to pcn-iptables service instead of pushing them into the kernel via netfilter.
168
172
169
173
scripts folder
170
174
^^^^^^^^^^^^^^
171
175
172
176
Scripts are used as a glue logic to make pcn-iptables run. Main purpose is initialize, cleanup and run pcn-iptables, pass pcn-iptables parameters through iptables (in charge of converting them), then pass converted commands to pcn-iptables service.
173
-
Scripts are installed under ``/usr/local/bin``.
177
+
Scripts are installed under ``/usr/local/bin``.
178
+
179
+
pcn-iptables components
180
+
-----------------------
181
+
182
+
``pcn-iptables`` is composed by three main components:
183
+
184
+
1. ``pcn-iptables`` service (``src/services/pcn-iptables``): a Polycube service that is especially tailored to work with the ``pcn-iptables`` executable; as usual, it exposes its API and CLI according to Polycube standard.
185
+
186
+
2. ``iptables*`` (``src/components/iptables/iptables``): a modified version of iptables, in charge of validate commands, translate them from iptables to polycube syntax, then forward them to pcn-iptables service instead of push them into the kernel via netfilter.
187
+
188
+
3. ``scripts`` (``src/components/iptables/scripts``): this is a folder containing some glue logic and scripts to initialize, cleanup and use ``pcn-iptables``. ``pcn-iptables`` itself is a script that forwards commands to ``iptables*`` (2), then forwards the translated command to ``pcn-iptables`` (1). Scripts are installed under ``/usr/local/bin``.
Copy file name to clipboardExpand all lines: Documentation/components/k8s/developers.rst
+174-7Lines changed: 174 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,177 @@
1
-
pcn-k8s Developers
2
-
==================
1
+
Information for developers
2
+
==========================
3
+
4
+
Controllers
5
+
-----------
6
+
7
+
Controllers are entities that are in charge of providing you with the resource that you need, as well as watch for events and notify when one has occurred.
8
+
In Polycube, five controllers are implemented:
9
+
10
+
- ``Kubernetes Network Policies``
11
+
- ``Polycube Network Policies``
12
+
- ``Services``
13
+
- ``Namespaces``
14
+
- ``Pods``
15
+
16
+
Not all of them provide the same functionalities and filtering criteria, but all work based on the same principle.
17
+
18
+
19
+
Usage
20
+
^^^^^
21
+
22
+
The usage is inspired by Kubernetes' API style.
23
+
To use the controllers, you simply need to import the ``pcn_controllers`` package and call the controller you'd like to use.
// Build a query to get all resources, regardless of name and labels
98
+
allResources := utils.BuildQuery("", nil)
99
+
100
+
This function returns a **pointer** to the actual query structure because that's what controllers need. When wanting to get all resources, the function returns nil, so you may even just use a nil value without calling the BuildQuery function.
101
+
102
+
103
+
List resources
104
+
^^^^^^^^^^^^^^
105
+
106
+
To list resources, you need to first create the queries, and then call the **List** function of the controller.
107
+
Not all controllers support both name and label criteria: i.e. the Pod Controller only supports labels.
108
+
109
+
.. code-block:: go
110
+
111
+
// I want all services that apply to pods with labels "app: my-app" and "role: db"
112
+
// and are on a namespace called "production"
113
+
// So, first create the queries for both the service and namespace.
So, usually, the first argument is criteria about the resource, while the second is reserved for criteria about the namespace where you want to find such resources.
130
+
131
+
To give additional information:
132
+
133
+
- The ``Kubernetes Network Policies`` and ``Polycube Network Policies`` controllers only support querying the policy by name
134
+
- The ``Pod`` controller only supports querying by labels
135
+
- The ``Pod`` controller also supports a third argument for the node where you want this pod to be located.
136
+
- The ``Services`` controller supports both name and labels, but when using labels it searches for them in the **spec.selector** field, not those under its metadata.
137
+
- The ``Namespaces`` controller work with namespaces, which cannot belong to other resources and only want one argument.
138
+
139
+
Note that, according to the criteria, it may take you a long time to get the results. Whenever possible, or when you expect a query to return lots of resources, adopt an async pattern or use multiple goroutines.
140
+
141
+
142
+
Watch for events
143
+
^^^^^^^^^^^^^^^^
144
+
145
+
To watch for events, you need to use a controller's ``Subscribe`` function by passing to it the event type you want to monitor, the resource criteria, and the function to be executed when that event is detected.
146
+
147
+
.. code-block:: go
148
+
149
+
func firstfunc() {
150
+
// I want to "myfunc" to be notified whenever a new pod is born.
151
+
// Pod controller has the most complex subscribe function, as it also asks you for the phase of the pod.
As the above example shows, the ``Subscribe`` function returns a pointer to a function that you need to call when you're not interested in that event anymore.
165
+
166
+
The function to execute must always have two arguments: the current state of the object and its previous state. There are three event types: ``New``, ``Update``, ``Delete``.
167
+
168
+
Just some heads up:
169
+
170
+
- When monitoring ``New`` events, only the current state of the object is present, the previous is obviously always ``nil``.
171
+
- When monitoring ``Delete`` events, the object does not exist anymore, so the current state is always ``nil``.
172
+
173
+
All the ``Subscribe`` functions share a similar structure to the ``List`` function in the same controller, to make sure about their usage, check their definitions in the ``pcn_controllers`` package
174
+
3
175
4
176
Creating the Docker Images
5
177
--------------------------
@@ -12,8 +184,3 @@ Docker 18.06 is needed to build the images, and the daemon has to be started wit
12
184
export DOCKER_BUILDKIT=1 # flag needed to enable the --mount option
0 commit comments