github.com/zhyoulun/cilium@v1.6.12/Documentation/contributing/contributing.rst (about)

     1  .. only:: not (epub or latex or html)
     2  
     3      WARNING: You are looking at unreleased Cilium documentation.
     4      Please use the official rendered version released here:
     5      http://docs.cilium.io
     6  
     7  .. _dev_guide:
     8  
     9  Developer / Contributor Guide
    10  =============================
    11  
    12  We're happy you're interested in contributing to the Cilium project.
    13  
    14  This guide will help you make sure you have an environment capable of testing
    15  changes to the Cilium source code, and that you understand the workflow of getting
    16  these changes reviewed and merged upstream.
    17  
    18  .. _dev_env:
    19  
    20  Setting up the development environment
    21  --------------------------------------
    22  
    23  Requirements
    24  ~~~~~~~~~~~~
    25  
    26  You need to have the following tools available in order to effectively
    27  contribute to Cilium:
    28  
    29  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    30  | Dependency                                                                       | Version / Commit ID      | Download Command                                                              |
    31  +==================================================================================+==========================+===============================================================================+
    32  | git                                                                              | latest                   | N/A (OS-specific)                                                             |
    33  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    34  |  glibc-devel (32-bit)                                                            | latest                   | N/A (OS-specific)                                                             |
    35  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    36  | `go <https://golang.org/dl/>`_                                                   | 1.12.17                  | N/A (OS-specific)                                                             |
    37  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    38  | `dep <https://github.com/golang/dep/>`_                                          | >= v0.4.1                | ``curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh``  |
    39  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    40  | `go-bindata <https://github.com/cilium/go-bindata>`_                             | ``a0ff2567cfb``          | ``go get -u github.com/cilium/go-bindata/...``                                |
    41  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    42  + `ginkgo <https://github.com/onsi/ginkgo>`__                                      | >= 1.4.0                 | ``go get -u github.com/onsi/ginkgo/ginkgo``                                   |
    43  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    44  + `gomega <https://github.com/onsi/gomega>`_                                       | >= 1.2.0                 | ``go get -u github.com/onsi/gomega``                                          |
    45  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    46  + `ineffassign <https://github.com/gordonklaus/ineffassign>`_                      | >= ``1003c8b``           | ``go get -u github.com/gordonklaus/ineffassign``                              |
    47  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    48  + `Docker <https://docs.docker.com/engine/installation/>`_                         | OS-Dependent             | N/A (OS-specific)                                                             |
    49  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    50  + `Docker-Compose <https://docs.docker.com/compose/install/>`_                     | OS-Dependent             | N/A (OS-specific)                                                             |
    51  +----------------------------------------------------------------------------------+--------------------------+-------------------------------------------------------------------------------+
    52  
    53  
    54  To run Cilium locally on VMs, you need:
    55  
    56  +----------------------------------------------------------------------------------+-----------------------+--------------------------------------------------------------------------------+
    57  | Dependency                                                                       | Version / Commit ID   | Download Command                                                               |
    58  +==================================================================================+=======================+================================================================================+
    59  | `Vagrant <https://www.vagrantup.com/downloads.html>`_                            | >= 2.0                | `Vagrant Install Instructions <https://www.vagrantup.com/docs/installation/>`_ |
    60  +----------------------------------------------------------------------------------+-----------------------+--------------------------------------------------------------------------------+
    61  | `VirtualBox <https://www.virtualbox.org/wiki/Downloads>`_ (if not using libvirt) | >= 5.2                | N/A (OS-specific)                                                              |
    62  +----------------------------------------------------------------------------------+-----------------------+--------------------------------------------------------------------------------+
    63  
    64  Finally, in order to build the documentation, you should have Sphinx installed:
    65  
    66  ::
    67  
    68      $ sudo pip install sphinx
    69  
    70  You should start with the `gs_guide`, which walks you through the set-up, such
    71  as installing Vagrant, getting the Cilium sources, and going through some
    72  Cilium basics.
    73  
    74  
    75  Vagrant Setup
    76  ~~~~~~~~~~~~~
    77  
    78  While the `gs_guide` uses a Vagrantfile tuned for the basic walk through, the
    79  setup for the Vagrantfile in the root of the Cilium tree depends on a number of
    80  environment variables and network setup that are managed via
    81  ``contrib/vagrant/start.sh``.
    82  
    83  Using the provided Vagrantfile
    84  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    85  
    86  To bring up a Vagrant VM  with Cilium
    87  plus dependencies installed, run:
    88  
    89  ::
    90  
    91      $ contrib/vagrant/start.sh
    92  
    93  This will create and run a vagrant VM based on the base box
    94  ``cilium/ubuntu``. The box is currently available for the
    95  following providers:
    96  
    97  * virtualbox
    98  
    99  Options
   100  ^^^^^^^
   101  
   102  The following environment variables can be set to customize the VMs
   103  brought up by vagrant:
   104  
   105  * ``NWORKERS=n``: Number of child nodes you want to start with the master,
   106    default 0.
   107  * ``RELOAD=1``: Issue a ``vagrant reload`` instead of ``vagrant up``, useful
   108    to resume halted VMs.
   109  * ``NFS=1``: Use NFS for vagrant shared directories instead of rsync.
   110  * ``K8S=1``: Build & install kubernetes on the nodes. ``k8s1`` is the master
   111    node, which contains both master components: etcd, kube-controller-manager,
   112    kube-scheduler, kube-apiserver, and node components: kubelet,
   113    kube-proxy, kubectl and Cilium. When used in combination with ``NWORKERS=1`` a
   114    second node is created, where ``k8s2`` will be a kubernetes node, which
   115    contains: kubelet, kube-proxy, kubectl and cilium.
   116  * ``IPV4=1``: Run Cilium with IPv4 enabled.
   117  * ``RUNTIME=x``: Sets up the container runtime to be used inside a kubernetes
   118    cluster. Valid options are: ``docker``, ``containerd`` and ``crio``. If not
   119    set, it defaults to ``docker``.
   120  * ``VAGRANT_DEFAULT_PROVIDER={virtualbox \| libvirt \| ...}``
   121  * ``VM_SET_PROXY=https://127.0.0.1:80/`` Sets up VM's ``https_proxy``.
   122  
   123  If you want to start the VM with cilium enabled with ``containerd``, with
   124  kubernetes installed and plus a worker, run:
   125  
   126  ::
   127  
   128  	$ RUNTIME=containerd K8S=1 NWORKERS=1 contrib/vagrant/start.sh
   129  
   130  If you want to get VM status, run:
   131  ::
   132  
   133    $ RUNTIME=containerd K8S=1 NWORKERS=1 vagrant status
   134  
   135  If you want to connect to the Kubernetes cluster running inside the developer VM via ``kubectl`` from your host machine, set ``KUBECONFIG`` environment variable to include new kubeconfig file:
   136  
   137  ::
   138  
   139  $ export KUBECONFIG=$KUBECONFIG:$GOPATH/src/github.com/cilium/cilium/vagrant.kubeconfig
   140  
   141  and add ``127.0.0.1 k8s1`` to your hosts file.
   142  
   143  If you have any issue with the provided vagrant box
   144  ``cilium/ubuntu`` or need a different box format, you may
   145  build the box yourself using the `packer scripts <https://github.com/cilium/packer-ci-build>`_
   146  
   147  Manual Installation
   148  ^^^^^^^^^^^^^^^^^^^
   149  
   150  Alternatively you can import the vagrant box ``cilium/ubuntu``
   151  directly and manually install Cilium:
   152  
   153  ::
   154  
   155          $ vagrant init cilium/ubuntu
   156          $ vagrant up
   157          $ vagrant ssh [...]
   158          $ cd go/src/github.com/cilium/cilium/
   159          $ make
   160          $ sudo make install
   161          $ sudo mkdir -p /etc/sysconfig/
   162          $ sudo cp contrib/systemd/cilium.service /etc/systemd/system/
   163          $ sudo cp contrib/systemd/cilium  /etc/sysconfig/cilium
   164          $ sudo usermod -a -G cilium vagrant
   165          $ sudo systemctl enable cilium
   166          $ sudo systemctl restart cilium
   167  
   168  Notes
   169  ^^^^^
   170  
   171  Your Cilium tree is mapped to the VM so that you do not need to keep manually
   172  copying files between your host and the VM. Folders are by default synced
   173  automatically using `VirtualBox Shared Folders <https://www.virtualbox.org/manual/ch04.html#sharedfolders>`_ .
   174  You can also use NFS to access your Cilium tree from the VM by
   175  setting the environment variable ``NFS`` (mentioned above) before running the
   176  startup script (``export NFS=1``). Note that your host firewall must have a variety
   177  of ports open. The Vagrantfile will inform you of the configuration of these addresses
   178  and ports to enable NFS.
   179  
   180  .. note::
   181  
   182     OSX file system is by default case insensitive, which can confuse
   183     git.  At the writing of this Cilium repo has no file names that
   184     would be considered referring to the same file on a case
   185     insensitive file system.  Regardless, it may be useful to create a
   186     disk image with a case sensitive file system for holding your git
   187     repos.
   188  
   189  .. note::
   190  
   191     VirtualBox for OSX currently (version 5.1.22) always reports
   192     host-only networks' prefix length as 64.  Cilium needs this prefix
   193     to be 16, and the startup script will check for this.  This check
   194     always fails when using VirtualBox on OSX, but it is safe to let
   195     the startup script to reset the prefix length to 16.
   196  
   197  If for some reason, running of the provisioning script fails, you should bring the VM down before trying again:
   198  
   199  ::
   200  
   201      $ vagrant halt
   202  
   203  .. _packer_ci:
   204  
   205  Packer-CI-Build
   206  ^^^^^^^^^^^^^^^
   207  
   208  As part of Cilium development, we use a custom base box with a bunch of
   209  pre-installed libraries and tools that we need to enhance our daily workflow.
   210  That base box is built with `Packer <https://www.packer.io/>`_ and it is hosted
   211  in the `packer-ci-build
   212  <https://jenkins.cilium.io/job/Vagrant-Master-Boxes-Packer-Build/>`_ GitHub
   213  repository.
   214  
   215  New versions of this box can be created via `Jenkins Packer Build
   216  <https://jenkins.cilium.io/job/Vagrant-Master-Boxes-Packer-Build/>`_, where
   217  new builds of the image will be pushed to  `Vagrant Cloud
   218  <https://app.vagrantup.com/cilium>`_ . The version of the image corresponds to
   219  the `BUILD_ID <https://qa.nuxeo.org/jenkins/pipeline-syntax/globals#env>`_
   220  environment variable in the Jenkins job. That version ID will be used in Cilium
   221  `Vagrantfiles
   222  <https://github.com/cilium/cilium/blob/master/test/Vagrantfile#L10>`_.
   223  
   224  Changes to this image are made via contributions to the packer-ci-build
   225  repository. Authorized GitHub users can trigger builds with a GitHub comment on
   226  the PR containing the trigger phrase ``build-me-please``. In case that a new box
   227  needs to be rebased with a different branch than master, authorized developers
   228  can run the build with custom parameters. To use a different Cilium branch in
   229  the `job <https://jenkins.cilium.io/job/Vagrant-Master-Boxes-Packer-Build/>`_ go
   230  to *Build with parameters* and a base branch can be set as the user needs.
   231  
   232  This box will need to be updated when a new developer needs a new dependency
   233  that is not installed in the current version of the box, or if a dependency that
   234  is cached within the box becomes stale.
   235  
   236  Make sure that you update vagrant box versions in `test Vagrantfile <https://github.com/cilium/cilium/blob/master/test/Vagrantfile>`__
   237  and `root Vagrantfile <https://github.com/cilium/cilium/blob/master/Vagrantfile>`__ after new box is built and tested.
   238  
   239  Development process
   240  -------------------
   241  
   242  Local Development in Vagrant Box
   243  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   244  
   245  See :ref:`dev_env` for information on how to setup the development environment.
   246  
   247  When the development VM is provisioned, it builds and installs Cilium.  After
   248  the initial build and install you can do further building and testing
   249  incrementally inside the VM. ``vagrant ssh`` takes you to the Cilium source
   250  tree directory (``/home/vagrant/go/src/github.com/cilium/cilium``) by default,
   251  and the following commands assume that you are working within that directory.
   252  
   253  Build Cilium
   254  ^^^^^^^^^^^^
   255  
   256  Assuming you have synced (rsync) the source tree after you have made changes,
   257  or the tree is automatically in sync via NFS or guest additions folder sharing,
   258  you can issue a build as follows:
   259  
   260  ::
   261  
   262      $ make
   263  
   264  Install to dev environment
   265  ^^^^^^^^^^^^^^^^^^^^^^^^^^
   266  
   267  After a successful build and test you can re-install Cilium by:
   268  
   269  ::
   270  
   271      $ sudo -E make install
   272  
   273  Restart Cilium service
   274  ^^^^^^^^^^^^^^^^^^^^^^
   275  
   276  To run the newly installed version of Cilium, restart the service:
   277  
   278  ::
   279  
   280      $ sudo systemctl restart cilium
   281  
   282  You can verify the service and cilium-agent status by the following
   283  commands, respectively:
   284  
   285  ::
   286  
   287      $ sudo systemctl status cilium
   288      $ cilium status
   289  
   290  Making Changes
   291  ~~~~~~~~~~~~~~
   292  
   293  #. Create a topic branch: ``git checkout -b myBranch master``
   294  #. Make the changes you want
   295  #. Separate the changes into logical commits.
   296  
   297     #. Describe the changes in the commit messages. Focus on answering the
   298        question why the change is required and document anything that might be
   299        unexpected.
   300     #. If any description is required to understand your code changes, then
   301        those instructions should be code comments instead of statements in the
   302        commit description.
   303  #. Make sure your changes meet the following criteria:
   304  
   305     #. New code is covered by :ref:`unit_testing`.
   306     #. End to end integration / runtime tests have been extended or added. If
   307        not required, mention in the commit message what existing test covers the
   308        new code.
   309     #. Follow-up commits are squashed together nicely. Commits should separate
   310        logical chunks of code and not represent a chronological list of changes.
   311  #. Run ``git diff --check`` to catch obvious white space violations
   312  #. Run ``make`` to build your changes. This will also run ``go fmt`` and error out
   313     on any golang formatting errors.
   314  #. See :ref:`unit_testing` on how to run unit tests.
   315  #. See :ref:`testsuite` for information how to run the end to end integration
   316     tests
   317  
   318  .. _unit_testing:
   319  
   320  Unit Testing
   321  ~~~~~~~~~~~~
   322  
   323  Cilium uses the standard `go test <https://golang.org/pkg/testing/>`__ framework
   324  in combination with `gocheck <http://labix.org/gocheck>`__ for richer testing
   325  functionality.
   326  
   327  .. _unit_testing_prerequisites:
   328  
   329  Prerequisites
   330  ^^^^^^^^^^^^^
   331  
   332  Some tests interact with the kvstore and depend on a local kvstore instances of
   333  both etcd and consul. To start the local instances, run:
   334  
   335  ::
   336  
   337       $ make start-kvstores
   338  
   339  Running all tests
   340  ^^^^^^^^^^^^^^^^^
   341  
   342  To run unit tests over the entire repository, run the following command in the
   343  project root directory:
   344  
   345  ::
   346  
   347      $ make unit-tests
   348  
   349  Testing individual packages
   350  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   351  
   352  It is possible to test individual packages by invoking ``go test`` directly.
   353  You can then ``cd`` into the package subject to testing and invoke go test:
   354  
   355  ::
   356  
   357      $ cd pkg/kvstore
   358      $ go test
   359  
   360  
   361  If you need more verbose output, you can pass in the ``-check.v`` and
   362  ``-check.vv`` arguments:
   363  
   364  ::
   365  
   366      $ cd pkg/kvstore
   367      $ go test -check.v -check.vv
   368  
   369  If the unit tests have some prerequisites like :ref:`unit_testing_prerequisites`,
   370  you can use the following command to automatically set up the prerequisites,
   371  run the unit tests and tear down the prerequisites:
   372  
   373  ::
   374  
   375      $ make unit-tests TESTPKGS=github.com/cilium/cilium/pkg/kvstore
   376  
   377  Running individual tests
   378  ^^^^^^^^^^^^^^^^^^^^^^^^
   379  
   380  Due to the use of gocheck, the standard ``go test -run`` will not work,
   381  instead, the ``-check.f`` argument has to be specified:
   382  
   383  ::
   384  
   385      $ go test -check.f TestParallelAllocation
   386  
   387  Automatically run unit tests on code changes
   388  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   389  
   390  The script ``contrib/shell/test.sh`` contains some helpful bash functions to
   391  improve the feedback cycle between writing tests and seeing their results. If
   392  you're writing unit tests in a particular package, the ``watchtest`` function
   393  will watch for changes in a directory and run the unit tests for that package
   394  any time the files change. For example, if writing unit tests in ``pkg/policy``,
   395  run this in a terminal next to your editor:
   396  
   397  .. code:: bash
   398  
   399      $ . contrib/shell/test.sh
   400      $ watchtest pkg/policy
   401  
   402  This shell script depends on the ``inotify-tools`` package on Linux.
   403  
   404  Add/update a golang dependency
   405  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   406  
   407  Once you have downloaded dep make sure you have version >= 0.4.1
   408  
   409  .. code:: bash
   410  
   411      $ dep version
   412      dep:
   413       version     : v0.4.1
   414       build date  : 2018-01-24
   415       git hash    : 37d9ea0a
   416       go version  : go1.9.1
   417       go compiler : gc
   418       platform    : linux/amd64
   419  
   420  After that, you can edit the ``Gopkg.toml`` file, add the library that you want
   421  to add. Lets assume we want to add ``github.com/containernetworking/cni``
   422  version ``v0.5.2``:
   423  
   424  .. code:: bash
   425  
   426      [[constraint]]
   427        name = "github.com/containernetworking/cni"
   428        revision = "v0.5.2"
   429  
   430  Once you add the libraries that you need you can save the file and run
   431  
   432  .. code:: bash
   433  
   434      $ dep ensure -v
   435  
   436  For a first run, it can take a while as it will download all dependencies to
   437  your local cache but the remaining runs will be faster.
   438  
   439  Debugging
   440  ~~~~~~~~~
   441  
   442  Datapath code
   443  ^^^^^^^^^^^^^
   444  
   445  The tool ``cilium monitor`` can also be used to retrieve debugging information
   446  from the BPF based datapath. Debugging messages are sent if either the
   447  ``cilium-agent`` itself or the respective endpoint is in debug mode. The debug
   448  mode of the agent can be enabled by starting ``cilium-agent`` with the option
   449  ``--debug`` enabled or by running ``cilium config debug=true`` for an already
   450  running agent. Debugging of an individual endpoint can be enabled by running
   451  ``cilium endpoint config ID debug=true``
   452  
   453  
   454  .. code:: bash
   455  
   456      $ cilium endpoint config 3978 debug=true
   457      Endpoint 3978 configuration updated successfully
   458      $ cilium monitor -v --hex
   459      Listening for events on 2 CPUs with 64x4096 of shared memory
   460      Press Ctrl-C to quit
   461      ------------------------------------------------------------------------------
   462      CPU 00: MARK 0x1c56d86c FROM 3978 DEBUG: 70 bytes Incoming packet from container ifindex 85
   463      00000000  33 33 00 00 00 02 ae 45  75 73 11 04 86 dd 60 00  |33.....Eus....`.|
   464      00000010  00 00 00 10 3a ff fe 80  00 00 00 00 00 00 ac 45  |....:..........E|
   465      00000020  75 ff fe 73 11 04 ff 02  00 00 00 00 00 00 00 00  |u..s............|
   466      00000030  00 00 00 00 00 02 85 00  15 b4 00 00 00 00 01 01  |................|
   467      00000040  ae 45 75 73 11 04 00 00  00 00 00 00              |.Eus........|
   468      CPU 00: MARK 0x1c56d86c FROM 3978 DEBUG: Handling ICMPv6 type=133
   469      ------------------------------------------------------------------------------
   470      CPU 00: MARK 0x1c56d86c FROM 3978 Packet dropped 131 (Invalid destination mac) 70 bytes ifindex=0 284->0
   471      00000000  33 33 00 00 00 02 ae 45  75 73 11 04 86 dd 60 00  |33.....Eus....`.|
   472      00000010  00 00 00 10 3a ff fe 80  00 00 00 00 00 00 ac 45  |....:..........E|
   473      00000020  75 ff fe 73 11 04 ff 02  00 00 00 00 00 00 00 00  |u..s............|
   474      00000030  00 00 00 00 00 02 85 00  15 b4 00 00 00 00 01 01  |................|
   475      00000040  00 00 00 00                                       |....|
   476      ------------------------------------------------------------------------------
   477      CPU 00: MARK 0x7dc2b704 FROM 3978 DEBUG: 86 bytes Incoming packet from container ifindex 85
   478      00000000  33 33 ff 00 8a d6 ae 45  75 73 11 04 86 dd 60 00  |33.....Eus....`.|
   479      00000010  00 00 00 20 3a ff fe 80  00 00 00 00 00 00 ac 45  |... :..........E|
   480      00000020  75 ff fe 73 11 04 ff 02  00 00 00 00 00 00 00 00  |u..s............|
   481      00000030  00 01 ff 00 8a d6 87 00  20 40 00 00 00 00 fd 02  |........ @......|
   482      00000040  00 00 00 00 00 00 c0 a8  21 0b 00 00 8a d6 01 01  |........!.......|
   483      00000050  ae 45 75 73 11 04 00 00  00 00 00 00              |.Eus........|
   484      CPU 00: MARK 0x7dc2b704 FROM 3978 DEBUG: Handling ICMPv6 type=135
   485      CPU 00: MARK 0x7dc2b704 FROM 3978 DEBUG: ICMPv6 neighbour soliciation for address b21a8c0:d68a0000
   486  
   487  
   488  One of the most common issues when developing datapath code is that the BPF
   489  code cannot be loaded into the kernel. This frequently manifests as the
   490  endpoints appearing in the "not-ready" state and never switching out of it:
   491  
   492  .. code:: bash
   493  
   494      $ cilium endpoint list
   495      ENDPOINT   POLICY        IDENTITY   LABELS (source:key[=value])   IPv6                     IPv4            STATUS
   496                 ENFORCEMENT
   497      48896      Disabled      266        container:id.server           fd02::c0a8:210b:0:bf00   10.11.13.37     not-ready
   498      60670      Disabled      267        container:id.client           fd02::c0a8:210b:0:ecfe   10.11.167.158   not-ready
   499  
   500  Running ``cilium endpoint get`` for one of the endpoints will provide a
   501  description of known state about it, which includes BPF verification logs.
   502  
   503  The files under ``/var/run/cilium/state`` provide context about how the BPF
   504  datapath is managed and set up. The .log files will describe the BPF
   505  requirements and features that Cilium detected and used to generate the BPF
   506  programs. The .h files describe specific configurations used for BPF program
   507  compilation. The numbered directories describe endpoint-specific state,
   508  including header configuration files and BPF binaries.
   509  
   510  .. code:: bash
   511  
   512      # for log in /var/run/cilium/state/*.log; do echo "cat $log"; cat $log; done
   513      cat /var/run/cilium/state/bpf_features.log
   514      BPF/probes: CONFIG_CGROUP_BPF=y is not in kernel configuration
   515      BPF/probes: CONFIG_LWTUNNEL_BPF=y is not in kernel configuration
   516      HAVE_LPM_MAP_TYPE: Your kernel doesn't support LPM trie maps for BPF, thus disabling CIDR policies. Recommendation is to run 4.11+ kernels.
   517      HAVE_LRU_MAP_TYPE: Your kernel doesn't support LRU maps for BPF, thus switching back to using hash table for the cilium connection tracker. Recommendation is to run 4.10+ kernels.
   518  
   519  Current BPF map state for particular programs is held under ``/sys/fs/bpf/``,
   520  and the `bpf-map <https://github.com/cilium/bpf-map>`_ utility can be useful
   521  for debugging what is going on inside them, for example:
   522  
   523  .. code:: bash
   524  
   525      # ls /sys/fs/bpf/tc/globals/
   526      cilium_calls_15124  cilium_calls_48896        cilium_ct4_global       cilium_lb4_rr_seq       cilium_lb6_services  cilium_policy_25729  cilium_policy_60670       cilium_proxy6
   527      cilium_calls_25729  cilium_calls_60670        cilium_ct6_global       cilium_lb4_services     cilium_lxc           cilium_policy_3978   cilium_policy_reserved_1  cilium_reserved_policy
   528      cilium_calls_3978   cilium_calls_netdev_ns_1  cilium_events           cilium_lb6_reverse_nat  cilium_policy        cilium_policy_4314   cilium_policy_reserved_2  cilium_tunnel_map
   529      cilium_calls_4314   cilium_calls_overlay_2    cilium_lb4_reverse_nat  cilium_lb6_rr_seq       cilium_policy_15124  cilium_policy_48896  cilium_proxy4
   530      # bpf-map info /sys/fs/bpf/tc/globals/cilium_policy_15124
   531      Type:           Hash
   532      Key size:       8
   533      Value size:     24
   534      Max entries:    1024
   535      Flags:          0x0
   536      # bpf-map dump /sys/fs/bpf/tc/globals/cilium_policy_15124
   537      Key:
   538      00000000  6a 01 00 00 82 23 06 00                           |j....#..|
   539      Value:
   540      00000000  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
   541      00000010  00 00 00 00 00 00 00 00                           |........|
   542  
   543  
   544  .. _testsuite:
   545  
   546  End-To-End Testing Framework
   547  ----------------------------
   548  
   549  Introduction
   550  ~~~~~~~~~~~~
   551  
   552  Cilium uses `Ginkgo <https://onsi.github.io/ginkgo>`_ as a testing framework for
   553  writing end-to-end tests which test Cilium all the way from the API level (e.g.
   554  importing policies, CLI) to the datapath (i.e, whether policy that is imported
   555  is enforced accordingly in the datapath).  The tests in the ``test`` directory
   556  are built on top of Ginkgo. Ginkgo provides a rich framework for developing
   557  tests alongside the benefits of Golang (compilation-time checks, types, etc.).
   558  To get accustomed to the basics of Ginkgo, we recommend reading the `Ginkgo
   559  Getting-Started Guide
   560  <https://onsi.github.io/ginkgo/#getting-started-writing-your-first-test>`_ , as
   561  well as running `example tests
   562  <https://github.com/onsi/composition-ginkgo-example>`_ to get a feel for the
   563  Ginkgo workflow.
   564  
   565  These test scripts will invoke ``vagrant`` to create virtual machine(s) to
   566  run the tests. The tests make heavy use of the Ginkgo `focus <https://onsi.github.io/ginkgo/#focused-specs>`_ concept to
   567  determine which VMs are necessary to run particular tests. All test names
   568  *must* begin with one of the following prefixes:
   569  
   570  * ``Runtime``: Test cilium in a runtime environment running on a single node.
   571  * ``K8s``: Create a small multi-node kubernetes environment for testing
   572    features beyond a single host, and for testing kubernetes-specific features.
   573  * ``Nightly``: sets up a multinode Kubernetes cluster to run scale, performance, and chaos testing for Cilium.
   574  
   575  Running End-To-End Tests
   576  ~~~~~~~~~~~~~~~~~~~~~~~~
   577  
   578  Running All Tests
   579  ^^^^^^^^^^^^^^^^^
   580  
   581  Running all of the Ginkgo tests may take an hour or longer. To run all the
   582  ginkgo tests, invoke the make command as follows from the root of the cilium
   583  repository:
   584  
   585  ::
   586  
   587      $ sudo make -C test/
   588  
   589  The first time that this is invoked, the testsuite will pull the
   590  `testing VMs <https://app.vagrantup.com/cilium/boxes/ginkgo>`_ and provision
   591  Cilium into them. This may take several minutes, depending on your internet
   592  connection speed. Subsequent runs of the test will reuse the image.
   593  
   594  Running Runtime Tests
   595  ^^^^^^^^^^^^^^^^^^^^^
   596  
   597  To run all of the runtime tests, execute the following command from the ``test`` directory:
   598  
   599  ::
   600  
   601      ginkgo --focus="Runtime*" -noColor
   602  
   603  Ginkgo searches for all tests in all subdirectories that are "named" beginning
   604  with the string "Runtime" and contain any characters after it. For instance,
   605  here is an example showing what tests will be ran using Ginkgo's dryRun option:
   606  
   607  ::
   608  
   609      $ ginkgo --focus="Runtime*" -noColor -v -dryRun
   610      Running Suite: runtime
   611      ======================
   612      Random Seed: 1516125117
   613      Will run 42 of 164 specs
   614      ................
   615      RuntimePolicyEnforcement Policy Enforcement Always
   616        Always to Never with policy
   617        /Users/ianvernon/go/src/github.com/cilium/cilium/test/runtime/Policies.go:258
   618      •
   619      ------------------------------
   620      RuntimePolicyEnforcement Policy Enforcement Always
   621        Always to Never without policy
   622        /Users/ianvernon/go/src/github.com/cilium/cilium/test/runtime/Policies.go:293
   623      •
   624      ------------------------------
   625      RuntimePolicyEnforcement Policy Enforcement Never
   626        Container creation
   627        /Users/ianvernon/go/src/github.com/cilium/cilium/test/runtime/Policies.go:332
   628      •
   629      ------------------------------
   630      RuntimePolicyEnforcement Policy Enforcement Never
   631        Never to default with policy
   632        /Users/ianvernon/go/src/github.com/cilium/cilium/test/runtime/Policies.go:349
   633      .................
   634      Ran 42 of 164 Specs in 0.002 seconds
   635      SUCCESS! -- 0 Passed | 0 Failed | 0 Pending | 122 Skipped PASS
   636  
   637      Ginkgo ran 1 suite in 1.830262168s
   638      Test Suite Passed
   639  
   640  The output has been truncated. For more information about this functionality,
   641  consult the aforementioned Ginkgo documentation.
   642  
   643  Running Kubernetes Tests
   644  ^^^^^^^^^^^^^^^^^^^^^^^^
   645  
   646  To run all of the Kubernetes tests, run the following command from the ``test`` directory:
   647  
   648  ::
   649  
   650      ginkgo --focus="K8s*" -noColor
   651  
   652  
   653  Similar to the Runtime test suite, Ginkgo searches for all tests in all
   654  subdirectories that are "named" beginning with the string "K8s" and
   655  contain any characters after it.
   656  
   657  The Kubernetes tests support the following Kubernetes versions:
   658  
   659  * 1.8
   660  * 1.9
   661  * 1.10
   662  * 1.11
   663  * 1.12
   664  * 1.13
   665  * 1.14
   666  * 1.15
   667  * 1.16
   668  
   669  By default, the Vagrant VMs are provisioned with Kubernetes 1.13. To run with any other
   670  supported version of Kubernetes, run the test suite with the following format:
   671  
   672  ::
   673  
   674      K8S_VERSION=<version> ginkgo --focus="K8s*" -noColor
   675  
   676  .. note::
   677  
   678     When provisioning VMs with the net-next kernel (``NETNEXT=true``) on
   679     VirtualBox which version does not match a version of the VM image
   680     VirtualBox Guest Additions, Vagrant will install a new version of
   681     the Additions with ``mount.vboxsf``. The latter is not compatible with
   682     ``vboxsf.ko`` shipped within the VM image, and thus syncing of shared
   683     folders will not work.
   684  
   685     To avoid this, one can prevent Vagrant from installing the Additions by
   686     putting the following into ``$HOME/.vagrant.d/Vagrantfile``:
   687  
   688     .. code:: ruby
   689  
   690        Vagrant.configure('2') do |config|
   691  	if Vagrant.has_plugin?("vagrant-vbguest") then
   692  	  config.vbguest.auto_update = false
   693  	end
   694  
   695  	config.vm.provider :virtualbox do |vbox|
   696  	  vbox.check_guest_additions = false
   697  	end
   698        end
   699  
   700  Running Nightly Tests
   701  ^^^^^^^^^^^^^^^^^^^^^
   702  
   703  To run all of the Nightly tests, run the following command from the ``test`` directory:
   704  
   705  ::
   706  
   707      ginkgo --focus="Nightly*"  -noColor
   708  
   709  Similar to the other test suites, Ginkgo searches for all tests in all
   710  subdirectories that are "named" beginning with the string "Nightly" and contain
   711  any characters after it. The default version of running Nightly test are 1.8,
   712  but can be changed using the environment variable ``K8S_VERSION``.
   713  
   714  Available CLI Options
   715  ^^^^^^^^^^^^^^^^^^^^^
   716  
   717  For more advanced workflows, check the list of available custom options for the Cilium
   718  framework in the ``test/`` directory and interact with ginkgo directly:
   719  
   720  ::
   721  
   722      $ cd test/
   723      $ ginkgo . -- --help | grep -A 1 cilium
   724        -cilium.SSHConfig string
   725              Specify a custom command to fetch SSH configuration (eg: 'vagrant ssh-config')
   726        -cilium.holdEnvironment
   727              On failure, hold the environment in its current state
   728        -cilium.provision
   729              Provision Vagrant boxes and Cilium before running test (default true)
   730        -cilium.showCommands
   731              Output which commands are ran to stdout
   732        -cilium.testScope string
   733              Specifies scope of test to be ran (k8s, Nightly, runtime)
   734      $ ginkgo --focus "Policies*" -- --cilium.provision=false
   735  
   736  For more information about other built-in options to Ginkgo, consult the
   737  `Ginkgo documentation <https://onsi.github.io/ginkgo/>`_.
   738  
   739  Running Specific Tests Within a Test Suite
   740  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   741  
   742  If you want to run one specified test, there are a few options:
   743  
   744  * By modifying code: add the prefix "FIt" on the test you want to run; this marks the test as focused. Ginkgo will skip other tests and will only run the "focused" test. For more information, consult the `Focused Specs <https://onsi.github.io/ginkgo/#focused-specs>`_ documentation from Ginkgo.
   745  
   746  ::
   747  
   748      It("Example test", func(){
   749          Expect(true).Should(BeTrue())
   750      })
   751  
   752      FIt("Example focused test", func(){
   753          Expect(true).Should(BeTrue())
   754      })
   755  
   756  
   757  * From the command line: specify a more granular focus if you want to focus on, say, L7 tests:
   758  
   759  ::
   760  
   761      ginkgo --focus "Run*" --focus "L7 "
   762  
   763  
   764  This will focus on tests prefixed with "Run*", and within that focus, run any
   765  test that starts with "L7".
   766  
   767  Test Reports
   768  ~~~~~~~~~~~~
   769  
   770  The Cilium Ginkgo framework formulates JUnit reports for each test. The
   771  following files currently are generated depending upon the test suite that is ran:
   772  
   773  * runtime.xml
   774  * K8s.xml
   775  
   776  Best Practices for Writing Tests
   777  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   778  
   779  * Provide informative output to console during a test using the `By construct <https://onsi.github.io/ginkgo/#documenting-complex-its-by>`_. This helps with debugging and gives those who did not write the test a good idea of what is going on. The lower the barrier of entry is for understanding tests, the better our tests will be!
   780  * Leave the testing environment in the same state that it was in when the test started by deleting resources, resetting configuration, etc.
   781  * Gather logs in the case that a test fails. If a test fails while running on Jenkins, a postmortem needs to be done to analyze why. So, dumping logs to a location where Jenkins can pick them up is of the highest imperative. Use the following code in an ``AfterFailed`` method:
   782  
   783  ::
   784  
   785  	AfterFailed(func() {
   786  		vm.ReportFailed()
   787  	})
   788  
   789  
   790  Ginkgo Extensions
   791  ~~~~~~~~~~~~~~~~~
   792  
   793  In Cilium, some Ginkgo features are extended to cover some uses cases that are
   794  useful for testing Cilium.
   795  
   796  BeforeAll
   797  ^^^^^^^^^
   798  
   799  This function will run before all `BeforeEach
   800  <https://onsi.github.io/ginkgo/#extracting-common-setup-beforeeach>`_ within a
   801  `Describe or Context
   802  <https://onsi.github.io/ginkgo/#organizing-specs-with-containers-describe-and-context>`_.
   803  This method is an equivalent to ``SetUp`` or initialize functions in common
   804  unit test frameworks.
   805  
   806  AfterAll
   807  ^^^^^^^^
   808  
   809  This method will run after all `AfterEach
   810  <https://onsi.github.io/ginkgo/#extracting-common-setup-beforeeach>`_ functions
   811  defined in a `Describe or Context
   812  <https://onsi.github.io/ginkgo/#organizing-specs-with-containers-describe-and-context>`_.
   813  This method is used for tearing down objects created which are used by all
   814  ``Its`` within the given ``Context`` or ``Describe``. It is ran after all Its
   815  have ran, this method is a equivalent to ``tearDown`` or ``finalize`` methods in
   816  common unit test frameworks.
   817  
   818  A good use case for using ``AfterAll`` method is to remove containers or pods
   819  that are needed for multiple ``Its`` in the given ``Context`` or ``Describe``.
   820  
   821  JustAfterEach
   822  ^^^^^^^^^^^^^
   823  
   824  This method will run just after each test and before ``AfterFailed`` and
   825  ``AfterEach``. The main reason of this method is to to perform some assertions
   826  for a group of tests.  A good example of using a global ``JustAfterEach``
   827  function is for deadlock detection, which checks the Cilium logs for deadlocks
   828  that may have occurred in the duration of the tests.
   829  
   830  AfterFailed
   831  ^^^^^^^^^^^
   832  
   833  This method will run before all ``AfterEach`` and after ``JustAfterEach``. This
   834  function is only called when the test failed.This construct is used to gather
   835  logs, the status of Cilium, etc, which provide data for analysis when tests
   836  fail.
   837  
   838  Example Test Layout
   839  ^^^^^^^^^^^^^^^^^^^
   840  
   841  Here is an example layout of how a test may be written with the aforementioned
   842  constructs:
   843  
   844  Test description diagram:
   845  ::
   846  
   847      Describe
   848          BeforeAll(A)
   849          AfterAll(A)
   850          AfterFailed(A)
   851          AfterEach(A)
   852          JustAfterEach(A)
   853          TESTA1
   854          TESTA2
   855          TESTA3
   856          Context
   857              BeforeAll(B)
   858              AfterAll(B)
   859              AfterFailed(B)
   860              AfterEach(B)
   861              JustAfterEach(B)
   862              TESTB1
   863              TESTB2
   864              TESTB3
   865  
   866  
   867  Test execution flow:
   868  ::
   869  
   870      Describe
   871          BeforeAll
   872          TESTA1; JustAfterEach(A), AfterFailed(A), AfterEach(A)
   873          TESTA2; JustAfterEach(A), AfterFailed(A), AfterEach(A)
   874          TESTA3; JustAfterEach(A), AfterFailed(A), AfterEach(A)
   875          Context
   876              BeforeAll(B)
   877              TESTB1:
   878                 JustAfterEach(B); JustAfterEach(A)
   879                 AfterFailed(B); AfterFailed(A);
   880                 AfterEach(B) ; AfterEach(A);
   881              TESTB2:
   882                 JustAfterEach(B); JustAfterEach(A)
   883                 AfterFailed(B); AfterFailed(A);
   884                 AfterEach(B) ; AfterEach(A);
   885              TESTB3:
   886                 JustAfterEach(B); JustAfterEach(A)
   887                 AfterFailed(B); AfterFailed(A);
   888                 AfterEach(B) ; AfterEach(A);
   889              AfterAll(B)
   890          AfterAll(A)
   891  
   892  Debugging:
   893  ~~~~~~~~~~
   894  
   895  Ginkgo provides to us different ways of debugging. In case that you want to see
   896  all the logs messages in the console you can run the test in verbose mode using
   897  the option ``-v``:
   898  
   899  ::
   900  
   901  	ginkgo --focus "Runtime*" -v
   902  
   903  In case that the verbose mode is not enough, you can retrieve all run commands
   904  and their output in the report directory (``./test/test_results``). Each test
   905  creates a new folder, which contains a file called log where all information is
   906  saved, in case of a failing test an exhaustive data will be added.
   907  
   908  ::
   909  
   910  	$ head test/test_results/RuntimeKafkaKafkaPolicyIngress/logs
   911  	level=info msg=Starting testName=RuntimeKafka
   912  	level=info msg="Vagrant: running command \"vagrant ssh-config runtime\""
   913  	cmd: "sudo cilium status" exitCode: 0
   914  	 KVStore:            Ok         Consul: 172.17.0.3:8300
   915  	ContainerRuntime:   Ok
   916  	Kubernetes:         Disabled
   917  	Kubernetes APIs:    [""]
   918  	Cilium:             Ok   OK
   919  	NodeMonitor:        Disabled
   920  	Allocated IPv4 addresses:
   921  
   922  
   923  Running with delve
   924  ^^^^^^^^^^^^^^^^^^
   925  
   926  `Delve <https://github.com/derekparker/delve>`_ is a debugging tool for Go
   927  applications. If you want to run your test with delve,  you should add a new
   928  breakpoint using
   929  `runtime.BreakPoint() <https://golang.org/pkg/runtime/#Breakpoint>`_ in the
   930  code, and run ginkgo using ``dlv``.
   931  
   932  Example how to run ginkgo using ``dlv``:
   933  
   934  ::
   935  
   936  	dlv test . -- --ginkgo.focus="Runtime" -ginkgo.v=true --cilium.provision=false
   937  
   938  
   939  Running End-To-End Tests In Other Environments
   940  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   941  
   942  If you want to run tests in a different VM, you can use ``--cilium.SSHConfig`` to
   943  provide the SSH configuration of the endpoint on which tests will be ran. The
   944  tests presume the following on the remote instance:
   945  
   946  - Cilium source code is located in the directory ``/home/vagrant/go/src/github.com/cilium/cilium/``.
   947  - Cilium is installed and running.
   948  
   949  The ssh connection needs to be defined as a ``ssh-config`` file and need to have
   950  the following targets:
   951  
   952  - runtime: To run runtime tests
   953  - k8s{1..2}-${K8S_VERSION}: to run Kubernetes tests. These instances must have
   954    Kubernetes installed and running as a prerequisite for running tests.
   955  
   956  An example ``ssh-config`` can be the following:
   957  
   958  ::
   959  
   960  	Host runtime
   961  	  HostName 127.0.0.1
   962  	  User vagrant
   963  	  Port 2222
   964  	  UserKnownHostsFile /dev/null
   965  	  StrictHostKeyChecking no
   966  	  PasswordAuthentication no
   967  	  IdentityFile /home/eloy/.go/src/github.com/cilium/cilium/test/.vagrant/machines/runtime/virtualbox/private_key
   968  	  IdentitiesOnly yes
   969  	  LogLevel FATAL
   970  
   971  To run this you can use the following command:
   972  
   973  ::
   974  
   975      ginkgo  -v -- --cilium.provision=false --cilium.SSHConfig="cat ssh-config"
   976  
   977  
   978  VMs for Testing
   979  ~~~~~~~~~~~~~~~~
   980  
   981  The VMs used for testing are defined in ``test/Vagrantfile``. There are a variety of
   982  configuration options that can be passed as environment variables:
   983  
   984  +----------------------+-------------------+--------------+------------------------------------------------------------------+
   985  | ENV variable         | Default Value     | Options      | Description                                                      |
   986  +======================+===================+==============+==================================================================+
   987  | K8S\_NODES           | 2                 | 0..100       | Number of Kubernetes nodes in the cluster                        |
   988  +----------------------+-------------------+--------------+------------------------------------------------------------------+
   989  | NFS                  | 0                 | 1            | If Cilium folder needs to be shared using NFS                    |
   990  +----------------------+-------------------+--------------+------------------------------------------------------------------+
   991  | IPv6                 | 0                 | 0-1          | If 1 the Kubernetes cluster will use IPv6                        |
   992  +----------------------+-------------------+--------------+------------------------------------------------------------------+
   993  | CONTAINER\_RUNTIME   | docker            | containerd   | To set the default container runtime in the Kubernetes cluster   |
   994  +----------------------+-------------------+--------------+------------------------------------------------------------------+
   995  | K8S\_VERSION         | 1.13              | 1.\*\*       | Kubernetes version to install                                    |
   996  +----------------------+-------------------+--------------+------------------------------------------------------------------+
   997  | SERVER\_BOX          | cilium/ubuntu-dev | *            | Vagrantcloud base image                                          |
   998  +----------------------+-------------------+--------------+------------------------------------------------------------------+
   999  | CPU                  | 2                 | 0..100       | Number of CPUs that need to have the VM                          |
  1000  +----------------------+-------------------+--------------+------------------------------------------------------------------+
  1001  | MEMORY               | 4096              | \d+          | RAM size in Megabytes                                            |
  1002  +----------------------+-------------------+--------------+------------------------------------------------------------------+
  1003  
  1004  Further Assistance
  1005  ~~~~~~~~~~~~~~~~~~
  1006  
  1007  Have a question about how the tests work or want to chat more about improving the
  1008  testing infrastructure for Cilium? Hop on over to the
  1009  `testing <https://cilium.slack.com/messages/C7PE7V806>`_ channel on Slack.
  1010  
  1011  .. _howto_contribute:
  1012  
  1013  How to contribute
  1014  -----------------
  1015  
  1016  Getting Started
  1017  ~~~~~~~~~~~~~~~
  1018  
  1019  #. Make sure you have a `GitHub account <https://github.com/signup/free>`_
  1020  #. Clone the cilium repository
  1021  
  1022     ::
  1023  
  1024        go get -d github.com/cilium/cilium
  1025        cd $GOPATH/src/github.com/cilium/cilium
  1026  
  1027  #. Set up your :ref:`dev_env`
  1028  #. Check the GitHub issues for `good tasks to get started
  1029     <https://github.com/cilium/cilium/issues?q=is%3Aopen+is%3Aissue+label%3Agood-first-issue>`_.
  1030  
  1031  .. _submit_pr:
  1032  
  1033  Submitting a pull request
  1034  ~~~~~~~~~~~~~~~~~~~~~~~~~
  1035  
  1036  Contributions must be submitted in the form of pull requests against the github
  1037  repository at: `<https://github.com/cilium/cilium>`_
  1038  
  1039  #. Fork the Cilium repository to your own personal GitHub space or request
  1040     access to a Cilium developer account on Slack
  1041  #. Push your changes to the topic branch in your fork of the repository.
  1042  #. Submit a pull request on https://github.com/cilium/cilium.
  1043  
  1044  Before hitting the submit button, please make sure that the following
  1045  requirements have been met:
  1046  
  1047  #. Each commit compiles and is functional on its own to allow for bisecting of
  1048     commits.
  1049  #. All code is covered by unit and/or runtime tests where feasible.
  1050  #. All changes have been tested and checked for regressions by running the
  1051     existing testsuite against your changes. See the :ref:`testsuite` section
  1052     for additional details.
  1053  #. All commits contain a well written commit description including a title,
  1054     description and a ``Fixes: #XXX`` line if the commit addresses a particular
  1055     GitHub issue. Note that the GitHub issue will be automatically closed when
  1056     the commit is merged.
  1057  
  1058     ::
  1059  
  1060          apipanic: Log stack at debug level
  1061  
  1062          Previously, it was difficult to debug issues when the API panicked
  1063          because only a single line like the following was printed:
  1064  
  1065          level=warning msg="Cilium API handler panicked" client=@ method=GET
  1066          panic_message="write unix /var/run/cilium/cilium.sock->@: write: broken
  1067          pipe"
  1068  
  1069          This patch logs the stack at this point at debug level so that it can at
  1070          least be determined in developer environments.
  1071  
  1072          Fixes: #4191
  1073  
  1074          Signed-off-by: Joe Stringer <joe@covalent.io>
  1075  
  1076     .. note:
  1077  
  1078         Make sure to include a blank line in between commit title and commit
  1079         description.
  1080  
  1081  #. If any of the commits fixes a particular commit already in the tree, that
  1082     commit is referenced in the commit message of the bugfix. This ensures that
  1083     whoever performs a backport will pull in all required fixes:
  1084  
  1085     ::
  1086  
  1087        daemon: use endpoint RLock in HandleEndpoint
  1088  
  1089        Fixes: a804c7c7dd9a ("daemon: wait for endpoint to be in ready state if specified via EndpointChangeRequest")
  1090  
  1091        Signed-off-by: André Martins <andre@cilium.io>
  1092  
  1093     .. note:
  1094  
  1095        The proper format for the ``Fixes:`` tag referring to commits is to use
  1096        the first 12 characters of the git SHA followed by the full commit title
  1097        as seen above without breaking the line.
  1098  
  1099  #. All commits are signed off. See the section :ref:`dev_coo`.
  1100  
  1101  #. Pick the appropriate milestone for which this PR is being targeted to, e.g.
  1102     ``1.1``, ``1.2``. This is in particular important in the time frame between
  1103     the feature freeze and final release date.
  1104  
  1105  #. Pick the right release-note label
  1106  
  1107     +--------------------------+---------------------------------------------------------------------------+
  1108     | Labels                   | When to set                                                               |
  1109     +==========================+===========================================================================+
  1110     | ``release-note/bug``     | This is a non-trivial bugfix                                              |
  1111     +--------------------------+---------------------------------------------------------------------------+
  1112     | ``release-note/major``   | This is a major feature addition, e.g. Add MongoDB support                |
  1113     +--------------------------+---------------------------------------------------------------------------+
  1114     | ``release-note/minor``   | This is a minor feature addition, e.g. Refactor endpoint package          |
  1115     +--------------------------+---------------------------------------------------------------------------+
  1116  
  1117  #. Verify the release note text. If not explicitly changed, the title of the PR
  1118     will be used for the release notes. If you want to change this, you can add
  1119     a special section to the description of the PR.
  1120  
  1121     ::
  1122  
  1123        ```release-note
  1124        This is a release note text
  1125        ```
  1126  
  1127     .. note::
  1128  
  1129        If multiple lines are provided, then the first line serves as the high
  1130        level bullet point item and any additional line will be added as a sub
  1131        item to the first line.
  1132  
  1133  #. Pick the right labels for your PR:
  1134  
  1135     +------------------------------+---------------------------------------------------------------------------+
  1136     | Labels                       | When to set                                                               |
  1137     +==============================+===========================================================================+
  1138     | ``kind/bug``                 | This is a bugfix worth mentioning in the release notes                    |
  1139     +------------------------------+---------------------------------------------------------------------------+
  1140     | ``kind/enhancement``         | This is an enhancement/feature                                            |
  1141     +------------------------------+---------------------------------------------------------------------------+
  1142     | ``priority/release-blocker`` | This PR should block the current release                                  |
  1143     +------------------------------+---------------------------------------------------------------------------+
  1144     | ``area/*``                   | Code area this PR covers                                                  |
  1145     +------------------------------+---------------------------------------------------------------------------+
  1146     | ``needs-backport/X.Y``       | PR needs to be backported to these stable releases                        |
  1147     +------------------------------+---------------------------------------------------------------------------+
  1148     | ``pending-review``           | PR is immediately ready for review                                        |
  1149     +------------------------------+---------------------------------------------------------------------------+
  1150     | ``wip``                      | PR is still work in progress, signals reviewers to hold.                  |
  1151     +------------------------------+---------------------------------------------------------------------------+
  1152     | ``backport/X.Y``             | This is backport PR, may only be set as part of :ref:`backport_process`   |
  1153     +------------------------------+---------------------------------------------------------------------------+
  1154     | ``upgrade-impact``           | The code changes have a potential upgrade impact                          |
  1155     +------------------------------+---------------------------------------------------------------------------+
  1156  
  1157     .. note:
  1158  
  1159        If you do not have permissions to set labels on your pull request. Leave
  1160        a comment and a core team member will add the labels for you. Most
  1161        reviewers will do this automatically without prior request.
  1162  
  1163  Getting a pull request merged
  1164  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1165  
  1166  #. As you submit the pull request as described in the section :ref:`submit_pr`.
  1167     One of the reviewers will start a CI run by replying with a comment
  1168     ``test-me-please`` as described in :ref:`trigger_phrases`. If you are a
  1169     core team member, you may trigger the CI run yourself.
  1170  
  1171     #. Hound: basic ``golang/lint`` static code analyzer. You need to make the
  1172        puppy happy.
  1173     #. :ref:`ci_jenkins`: Will run a series of tests:
  1174  
  1175        #. Unit tests
  1176        #. Single node runtime tests
  1177        #. Multi node Kubernetes tests
  1178  
  1179  #. As part of the submission, GitHub will have requested a review from the
  1180     respective code owners according to the ``CODEOWNERS`` file in the
  1181     repository.
  1182  
  1183     #. Address any feedback received from the reviewers
  1184     #. You can push individual commits to address feedback and then rebase your
  1185        branch at the end before merging.
  1186  
  1187  #. Owners of the repository will automatically adjust the labels on the pull
  1188     request to track its state and progress towards merging.
  1189  #. Once the PR has been reviewed and the CI tests have passed, the PR will be
  1190     merged by one of the repository owners. In case this does not happen, ping
  1191     us on Slack.
  1192  
  1193  
  1194  Pull request review process
  1195  ---------------------------
  1196  
  1197  .. note::
  1198  
  1199     These instructions assume that whoever is reviewing is a member of the
  1200     Cilium GitHub organization or has the status of a contributor. This is
  1201     required to obtain the privileges to modify GitHub labels on the pull
  1202     request.
  1203  
  1204  #. Review overall correctness of the PR according to the rules specified in the
  1205     section :ref:`submit_pr`.
  1206  
  1207     Set the label accordingly.
  1208  
  1209  
  1210     +--------------------------------+---------------------------------------------------------------------------+
  1211     | Labels                         | When to set                                                               |
  1212     +================================+===========================================================================+
  1213     | ``dont-merge/needs-sign-off``  | Some commits are not signed off                                           |
  1214     +--------------------------------+---------------------------------------------------------------------------+
  1215     | ``needs-rebase``               | PR is outdated and needs to be rebased                                    |
  1216     +--------------------------------+---------------------------------------------------------------------------+
  1217  
  1218  #. As soon as a PR has the label ``pending-review``, review the code and
  1219     request changes as needed by using the GitHub ``Request Changes`` feature or
  1220     by using Reviewable.
  1221  
  1222  #. Validate that bugfixes are marked with ``kind/bug`` and validate whether the
  1223     assessment of backport requirements as requested by the submitter conforms
  1224     to the :ref:`stable_releases` process.
  1225  
  1226  
  1227     +--------------------------+---------------------------------------------------------------------------+
  1228     | Labels                   | When to set                                                               |
  1229     +==========================+===========================================================================+
  1230     | ``needs-backport/X.Y``   | PR needs to be backported to these stable releases                        |
  1231     +--------------------------+---------------------------------------------------------------------------+
  1232  
  1233  #. If the PR is subject to backport, validate that the PR does not mix bugfix
  1234     and refactoring of code as it will heavily complicate the backport process.
  1235     Demand for the PR to be split.
  1236  
  1237  #. Validate the ``release-note/*`` label and check the PR title for release
  1238     note suitability. Put yourself into the perspective of a future release
  1239     notes reader with lack of context and ensure the title is precise but brief.
  1240  
  1241     +-----------------------------------+---------------------------------------------------------------------------+
  1242     | Labels                            | When to set                                                               |
  1243     +===================================+===========================================================================+
  1244     | ``dont-merge/needs-release-note`` | Do NOT merge PR, needs a release note                                     |
  1245     +-----------------------------------+---------------------------------------------------------------------------+
  1246     | ``release-note/bug``              | This is a non-trivial bugfix                                              |
  1247     +-----------------------------------+---------------------------------------------------------------------------+
  1248     | ``release-note/major``            | This is a major feature addition                                          |
  1249     +-----------------------------------+---------------------------------------------------------------------------+
  1250     | ``release-note/minor``            | This is a minor feature addition                                          |
  1251     +-----------------------------------+---------------------------------------------------------------------------+
  1252  
  1253  #. Check for upgrade compatibility impact and if in doubt, set the label
  1254     ``upgrade-impact`` and discuss in the Slack channel.
  1255  
  1256     +--------------------------+---------------------------------------------------------------------------+
  1257     | Labels                   | When to set                                                               |
  1258     +==========================+===========================================================================+
  1259     | ``upgrade-impact``       | The code changes have a potential upgrade impact                          |
  1260     +--------------------------+---------------------------------------------------------------------------+
  1261  
  1262  #. When everything looks OK, approve the changes.
  1263  
  1264  #. When all review objectives for all ``CODEOWNERS`` are met and all CI tests
  1265     have passed, you may set the ``ready-to-merge`` label to indicate that all
  1266     criteria have been met.
  1267  
  1268     +--------------------------+---------------------------------------------------------------------------+
  1269     | Labels                   | When to set                                                               |
  1270     +==========================+===========================================================================+
  1271     | ``ready-to-merge``       | PR is ready to be merged                                                  |
  1272     +--------------------------+---------------------------------------------------------------------------+
  1273  
  1274  
  1275  Building Container Images
  1276  -------------------------
  1277  
  1278  Two make targets exists to build container images automatically based on the
  1279  locally checked out branch:
  1280  
  1281  Developer images
  1282  ~~~~~~~~~~~~~~~~
  1283  
  1284  ::
  1285  
  1286      DOCKER_IMAGE_TAG=jane-developer-my-fix make dev-docker-image
  1287  
  1288  You can then push the image tag to the registry for development builds:
  1289  
  1290  ::
  1291  
  1292      docker push cilium/cilium-dev:jane-developer-my-fix
  1293  
  1294  Access to the developer builds registry is restricted but access is granted
  1295  liberally. Join the #development channel in Slack and ask for permission to
  1296  push builds.
  1297  
  1298  Official release images
  1299  ~~~~~~~~~~~~~~~~~~~~~~~
  1300  
  1301  Anyone can build official release images using the make target below but
  1302  pushing to the official registries is restricted to Cilium maintainers. Ask in
  1303  the #launchpad Slack channels for the exact details.
  1304  
  1305  ::
  1306  
  1307      DOCKER_IMAGE_TAG=v1.4.0 make docker-image
  1308  
  1309  You can then push the image tag to the registry:
  1310  
  1311  ::
  1312  
  1313      docker push cilium/cilium:v1.4.0
  1314  
  1315  Documentation
  1316  -------------
  1317  
  1318  Building
  1319  ~~~~~~~~
  1320  
  1321  The documentation has several dependencies which can be installed using pip:
  1322  
  1323  ::
  1324  
  1325      $ pip install -r Documentation/requirements.txt
  1326  
  1327  .. note:
  1328  
  1329     If you are using the vagrant development environment, these requirements are
  1330     usually already installed.
  1331  
  1332  Whenever making changes to Cilium documentation you should check that you did not introduce any new warnings or errors, and also check that your changes look as you intended.  To do this you can build the docs:
  1333  
  1334  ::
  1335  
  1336      $ make -C Documentation html
  1337  
  1338  After this you can browse the updated docs as HTML starting at
  1339  ``Documentation\_build\html\index.html``.
  1340  
  1341  Alternatively you can use a Docker container to build the pages:
  1342  
  1343  ::
  1344  
  1345      $ make render-docs
  1346  
  1347  This builds the docs in a container and builds and starts a web server with
  1348  your document changes.
  1349  
  1350  Now the documentation page should be browsable on http://localhost:9080.
  1351  
  1352  Update cilium-builder and cilium-runtime images
  1353  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1354  
  1355  Login to quay.io with your credentials to the repository that you want to
  1356  update:
  1357  
  1358  `cilium-builder <https://quay.io/repository/cilium/cilium-builder?tab=builds>`__ - contains Cilium build-time dependencies
  1359  `cilium-runtime <https://quay.io/repository/cilium/cilium-runtime?tab=builds>`__ - contains Cilium run-time dependencies
  1360  
  1361  0. After login, select the tab "builds" on the left menu.
  1362  
  1363  .. image:: ../images/cilium-quayio-tag-0.png
  1364      :align: center
  1365  
  1366  1. Click on the wheel.
  1367  2. Enable the trigger for that build trigger.
  1368  
  1369  .. image:: ../images/cilium-quayio-tag-1.png
  1370      :align: center
  1371  
  1372  3. Confirm that you want to enable the trigger.
  1373  
  1374  .. image:: ../images/cilium-quayio-tag-2.png
  1375      :align: center
  1376  
  1377  4. After enabling the trigger, click again on the wheel.
  1378  5. And click on "Run Trigger Now".
  1379  
  1380  .. image:: ../images/cilium-quayio-tag-3.png
  1381      :align: center
  1382  
  1383  6. A new pop-up will appear and you can select the branch that contains your
  1384     changes.
  1385  7. Select the branch that contains the new changes.
  1386  
  1387  .. image:: ../images/cilium-quayio-tag-4.png
  1388      :align: center
  1389  
  1390  8. After selecting your branch click on "Start Build".
  1391  
  1392  .. image:: ../images/cilium-quayio-tag-5.png
  1393      :align: center
  1394  
  1395  9. Once the build has started you can disable the Build trigger by clicking on
  1396     the wheel.
  1397  10. And click on "Disable Trigger".
  1398  
  1399  .. image:: ../images/cilium-quayio-tag-6.png
  1400      :align: center
  1401  
  1402  11. Confirm that you want to disable the build trigger.
  1403  
  1404  .. image:: ../images/cilium-quayio-tag-7.png
  1405      :align: center
  1406  
  1407  12. Once the build is finished click under Tags (on the left menu).
  1408  13. Click on the wheel and;
  1409  14. Add a new tag to the image that was built.
  1410  
  1411  .. image:: ../images/cilium-quayio-tag-8.png
  1412      :align: center
  1413  
  1414  15. Write the name of the tag that you want to give for the newly built image.
  1415  16. Confirm the name is correct and click on "Create Tag".
  1416  
  1417  .. image:: ../images/cilium-quayio-tag-9.png
  1418      :align: center
  1419  
  1420  17. After the new tag was created you can delete the other tag, which is the
  1421      name of your branch. Select the tag name.
  1422  18. Click in Actions.
  1423  19. Click in "Delete Tags".
  1424  
  1425  .. image:: ../images/cilium-quayio-tag-10.png
  1426      :align: center
  1427  
  1428  20. Confirm that you want to delete tag with your branch name.
  1429  
  1430  .. image:: ../images/cilium-quayio-tag-11.png
  1431      :align: center
  1432  
  1433  You have created a new image build with a new tag. The next steps should be to
  1434  update the repository root's Dockerfile so that it points to the new
  1435  ``cilium-builder`` or ``cilium-runtime`` image recently created.
  1436  
  1437  21. Update the versions of the images that are pulled into the CI VMs.
  1438  
  1439  * Open a PR against the :ref:`packer_ci` with an update to said image versions. Once your PR is merged, a new version of the VM will be ready for consumption in the CI.
  1440  * Update the ``SERVER_VERSION``  field in ``test/Vagrantfile`` to contain the new version, which is the build number from the `Jenkins Job for the VMs <https://jenkins.cilium.io/job/Vagrant-Master-Boxes-Packer-Build/>`_. For example, build 119 from the pipeline would be the value to set for ``SERVER_VERSION``.
  1441  * Open a pull request with this version change in the cilium repository.
  1442  
  1443  
  1444  Nightly Docker image
  1445  ~~~~~~~~~~~~~~~~~~~~
  1446  
  1447  After each successful Nightly build, a `cilium/nightly`_ image is pushed to dockerhub.
  1448  
  1449  To use latest nightly build, please use ``cilium/nightly:latest`` tag.
  1450  Nightly images are stored on dockerhub tagged with following format: ``YYYYMMDD-<job number>``.
  1451  Job number is added to tag for the unlikely event of two consecutive nightly builds being built on the same date.
  1452  
  1453  
  1454  .. _dev_coo:
  1455  
  1456  Developer's Certificate of Origin
  1457  ---------------------------------
  1458  
  1459  To improve tracking of who did what, we've introduced a "sign-off"
  1460  procedure.
  1461  
  1462  The sign-off is a simple line at the end of the explanation for the
  1463  commit, which certifies that you wrote it or otherwise have the right to
  1464  pass it on as open-source work. The rules are pretty simple: if you can
  1465  certify the below:
  1466  
  1467  ::
  1468  
  1469      Developer Certificate of Origin
  1470      Version 1.1
  1471  
  1472      Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
  1473      1 Letterman Drive
  1474      Suite D4700
  1475      San Francisco, CA, 94129
  1476  
  1477      Everyone is permitted to copy and distribute verbatim copies of this
  1478      license document, but changing it is not allowed.
  1479  
  1480  
  1481      Developer's Certificate of Origin 1.1
  1482  
  1483      By making a contribution to this project, I certify that:
  1484  
  1485      (a) The contribution was created in whole or in part by me and I
  1486          have the right to submit it under the open source license
  1487          indicated in the file; or
  1488  
  1489      (b) The contribution is based upon previous work that, to the best
  1490          of my knowledge, is covered under an appropriate open source
  1491          license and I have the right under that license to submit that
  1492          work with modifications, whether created in whole or in part
  1493          by me, under the same open source license (unless I am
  1494          permitted to submit under a different license), as indicated
  1495          in the file; or
  1496  
  1497      (c) The contribution was provided directly to me by some other
  1498          person who certified (a), (b) or (c) and I have not modified
  1499          it.
  1500  
  1501      (d) I understand and agree that this project and the contribution
  1502          are public and that a record of the contribution (including all
  1503          personal information I submit with it, including my sign-off) is
  1504          maintained indefinitely and may be redistributed consistent with
  1505          this project or the open source license(s) involved.
  1506  
  1507  then you just add a line saying:
  1508  
  1509  ::
  1510  
  1511     Signed-off-by: Random J Developer <random@developer.example.org>
  1512  
  1513  Use your real name (sorry, no pseudonyms or anonymous contributions.)
  1514  
  1515  .. toctree::
  1516  
  1517     ../commit-access
  1518  
  1519  .. _cilium/nightly: https://hub.docker.com/r/cilium/nightly/
  1520  .. _Cilium-Nightly-Tests Job: https://jenkins.cilium.io/job/Cilium-Master-Nightly-Tests-All/