Extension chaosistio

Version 0.1.2
Repository https://github.com/chaostoolkit-incubator/chaostoolkit-istio

Python versions

This project is a collection of actions and probes, gathered as an extension to the Chaos Toolkit.

Install

This package requires Python 3.5+

To be used from your experiment, this package must be installed in the Python environment where chaostoolkit already lives.

$ pip install -U chaostoolkit-istio

Usage

Below is an example of using this extension to inject a delay of 5 seconds to a specific user.

Note this example can be applied against the bookinfo Istio sample application.

To run it, simple set the KUBERNETES_CONTEXT environment variable to the target cluster and ensure your local kubeconfig is properly populated for that context. Set also the PRODUCT_PAGE_SERVICE_BASE_URL to the address of the Istio gateway.

For instance:

$ export PRODUCT_PAGE_SERVICE_BASE_URL=$(kubectl get po -l istio=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}'):$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
{
    "title": "Network latency does not impact our users",
    "description": "Using Istio fault injection capability, let's explore how latency impacts a single user",
    "configuration": {
        "product_page_url": {
            "type": "env",
            "key": "PRODUCT_PAGE_SERVICE_BASE_URL"
        }
    },
    "secrets": {
        "istio": {
            "KUBERNETES_CONTEXT": {
                "type": "env",
                "key": "KUBERNETES_CONTEXT"
            }
        }
    },
    "steady-state-hypothesis": {
        "title": "Our service should respond under 1 second",
        "probes": [
            {
                "type": "probe",
                "name": "sign-in-as-jason",
                "tolerance": 0,
                "provider": {
                    "type": "process",
                    "path": "curl",
                    "arguments": "-v -X POST -d 'username=jason&passwd=' -c /tmp/cookie.txt --silent ${product_page_url}/login"
                }
            },
            {
                "type": "probe",
                "name": "fetch-productpage-for-jason-in-due-time",
                "tolerance": 0,
                "provider": {
                    "type": "process",
                    "path": "curl",
                    "arguments": "-v --connect-timeout 1 --max-time 1 -b /tmp/cookie.txt --silent ${product_page_url}/productpage"
                }
            }
        ]
    },
    "method": [
        {
            "type": "action",
            "name": "inject-fault-for-jason-only",
            "provider": {
                "type": "python",
                "module": "chaosistio.fault.actions",
                "func": "add_delay_fault",
                "secrets": ["istio"],
                "arguments": {
                    "virtual_service_name": "reviews",
                    "fixed_delay": "5s",
                    "percent": 100,
                    "routes": [
                        {
                            "destination": {
                                "host": "reviews",
                                "subset": "v2"
                            }
                        }
                    ]
                }
            },
            "pauses": {
                "after": 2
            }
        }
    ],
    "rollbacks": [
        {
            "type": "action",
            "name": "remove-fault-for-jason-only",
            "provider": {
                "type": "python",
                "module": "chaosistio.fault.actions",
                "func": "remove_delay_fault",
                "secrets": ["istio"],
                "arguments": {
                    "virtual_service_name": "reviews",
                    "routes": [
                        {
                            "destination": {
                                "host": "reviews",
                                "subset": "v2"
                            }
                        }
                    ]
                }
            }
        }
    ]
}

That’s it!

Please explore the code to see existing probes and actions.

Configuration

This extension needs you specify how to connect to the Kubernetes cluster. This can be done by setting the KUBERNETES_CONTEXT in the secrets payload.

Contribute

If you wish to contribute more functions to this package, you are more than welcome to do so. Please, fork this project, make your changes following the usual PEP 8 code style, sprinkling with tests and submit a PR for review.

The Chaos Toolkit projects require all contributors must sign a Developer Certificate of Origin on each commit they would like to merge into the master branch of the repository. Please, make sure you can abide by the rules of the DCO before submitting a PR.

Develop

If you wish to develop on this project, make sure to install the development dependencies. But first, create a virtual environment and then install those dependencies.

$ pip install -r requirements-dev.txt -r requirements.txt

Then, point your environment to this directory:

$ python setup.py develop

Now, you can edit the files and they will be automatically be seen by your environment, even when running from the chaos command locally.

Test

To run the tests for the project execute the following:

$ pytest

Exported Activities

fault


add_abort_fault

Type action
Module chaosistio.fault.actions
Name add_abort_fault
Return mapping

Abort requests early by the virtual service identified by name

See https://istio.io/docs/reference/config/istio.networking.v1alpha3/#HTTPFaultInjection-Abort

Signature:

def add_abort_fault(
        virtual_service_name: str,
        http_status: int,
        routes: List[Dict[str, str]],
        percent: float = None,
        ns: str = 'default',
        version: str = 'networking.istio.io/v1alpha3',
        configuration: Dict[str, Dict[str, str]] = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
virtual_service_name string Yes
http_status integer Yes
routes list Yes
percent number null No
ns string “default” No
version string “networking.istio.io/v1alpha3” No

Usage:

{
  "name": "add-abort-fault",
  "type": "action",
  "provider": {
    "type": "python",
    "func": "add_abort_fault",
    "arguments": {
      "virtual_service_name": "",
      "routes": [],
      "http_status": 0
    },
    "module": "chaosistio.fault.actions"
  }
}
name: add-abort-fault
provider:
  arguments:
    http_status: 0
    routes: []
    virtual_service_name: ''
  func: add_abort_fault
  module: chaosistio.fault.actions
  type: python
type: action

add_delay_fault

Type action
Module chaosistio.fault.actions
Name add_delay_fault
Return mapping

Add delay to the virtual service identified by name

See https://istio.io/docs/reference/config/istio.networking.v1alpha3/#HTTPFaultInjection-Delay

Signature:

def add_delay_fault(
        virtual_service_name: str,
        fixed_delay: str,
        routes: List[Dict[str, str]],
        percent: float = None,
        ns: str = 'default',
        version: str = 'networking.istio.io/v1alpha3',
        configuration: Dict[str, Dict[str, str]] = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
virtual_service_name string Yes
fixed_delay string Yes
routes list Yes
percent number null No
ns string “default” No
version string “networking.istio.io/v1alpha3” No

Usage:

{
  "name": "add-delay-fault",
  "type": "action",
  "provider": {
    "type": "python",
    "func": "add_delay_fault",
    "arguments": {
      "virtual_service_name": "",
      "fixed_delay": "",
      "routes": []
    },
    "module": "chaosistio.fault.actions"
  }
}
name: add-delay-fault
provider:
  arguments:
    fixed_delay: ''
    routes: []
    virtual_service_name: ''
  func: add_delay_fault
  module: chaosistio.fault.actions
  type: python
type: action

get_virtual_service

Type probe
Module chaosistio.fault.probes
Name get_virtual_service
Return mapping

Get a virtual service identified by name

See https://istio.io/docs/reference/config/istio.networking.v1alpha3/#VirtualService

Signature:

def get_virtual_service(
        virtual_service_name: str,
        ns: str = 'default',
        version: str = 'networking.istio.io/v1alpha3',
        configuration: Dict[str, Dict[str, str]] = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
virtual_service_name string Yes
ns string “default” No
version string “networking.istio.io/v1alpha3” No

Usage:

{
  "name": "get-virtual-service",
  "type": "probe",
  "provider": {
    "type": "python",
    "func": "get_virtual_service",
    "arguments": {
      "virtual_service_name": ""
    },
    "module": "chaosistio.fault.probes"
  }
}
name: get-virtual-service
provider:
  arguments:
    virtual_service_name: ''
  func: get_virtual_service
  module: chaosistio.fault.probes
  type: python
type: probe

remove_abort_fault

Type action
Module chaosistio.fault.actions
Name remove_abort_fault
Return mapping

Remove abort request faults from the virtual service identified by name

See https://istio.io/docs/reference/config/istio.networking.v1alpha3/#HTTPFaultInjection-Abort

Signature:

def remove_abort_fault(
        virtual_service_name: str,
        routes: List[Dict[str, str]],
        ns: str = 'default',
        version: str = 'networking.istio.io/v1alpha3',
        configuration: Dict[str, Dict[str, str]] = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
virtual_service_name string Yes
routes list Yes
ns string “default” No
version string “networking.istio.io/v1alpha3” No

Usage:

{
  "name": "remove-abort-fault",
  "type": "action",
  "provider": {
    "type": "python",
    "func": "remove_abort_fault",
    "arguments": {
      "virtual_service_name": "",
      "routes": []
    },
    "module": "chaosistio.fault.actions"
  }
}
name: remove-abort-fault
provider:
  arguments:
    routes: []
    virtual_service_name: ''
  func: remove_abort_fault
  module: chaosistio.fault.actions
  type: python
type: action

remove_delay_fault

Type action
Module chaosistio.fault.actions
Name remove_delay_fault
Return mapping

Remove delay from the virtual service identified by name

See https://istio.io/docs/reference/config/istio.networking.v1alpha3/#HTTPFaultInjection-Delay

Signature:

def remove_delay_fault(
        virtual_service_name: str,
        routes: List[Dict[str, str]],
        ns: str = 'default',
        version: str = 'networking.istio.io/v1alpha3',
        configuration: Dict[str, Dict[str, str]] = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
virtual_service_name string Yes
routes list Yes
ns string “default” No
version string “networking.istio.io/v1alpha3” No

Usage:

{
  "name": "remove-delay-fault",
  "type": "action",
  "provider": {
    "type": "python",
    "func": "remove_delay_fault",
    "arguments": {
      "virtual_service_name": "",
      "routes": []
    },
    "module": "chaosistio.fault.actions"
  }
}
name: remove-delay-fault
provider:
  arguments:
    routes: []
    virtual_service_name: ''
  func: remove_delay_fault
  module: chaosistio.fault.actions
  type: python
type: action

set_fault

Type action
Module chaosistio.fault.actions
Name set_fault
Return mapping

Setfault injection on the virtual service identified by name

The fault argument must be the object passed as the spec property of a virtual service resource.

If a fault already exists, it is updated with the new specification.

See https://istio.io/docs/reference/config/istio.networking.v1alpha3/#HTTPFaultInjection

Signature:

def set_fault(virtual_service_name: str,
              routes: List[Dict[str, str]],
              fault: Dict[str, Any],
              ns: str = 'default',
              version: str = 'networking.istio.io/v1alpha3',
              configuration: Dict[str, Dict[str, str]] = None,
              secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
virtual_service_name string Yes
routes list Yes
fault mapping Yes
ns string “default” No
version string “networking.istio.io/v1alpha3” No

Usage:

{
  "name": "set-fault",
  "type": "action",
  "provider": {
    "type": "python",
    "func": "set_fault",
    "arguments": {
      "virtual_service_name": "",
      "fault": {},
      "routes": []
    },
    "module": "chaosistio.fault.actions"
  }
}
name: set-fault
provider:
  arguments:
    fault: {}
    routes: []
    virtual_service_name: ''
  func: set_fault
  module: chaosistio.fault.actions
  type: python
type: action

unset_fault

Type action
Module chaosistio.fault.actions
Name unset_fault
Return mapping

Unset fault injection from the virtual service identified by name

The fault argument must be the object passed as the spec property of a virtual service resource.

See https://istio.io/docs/reference/config/istio.networking.v1alpha3/#HTTPFaultInjection

Signature:

def unset_fault(virtual_service_name: str,
                routes: List[Dict[str, str]],
                ns: str = 'default',
                version: str = 'networking.istio.io/v1alpha3',
                configuration: Dict[str, Dict[str, str]] = None,
                secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
virtual_service_name string Yes
routes list Yes
ns string “default” No
version string “networking.istio.io/v1alpha3” No

Usage:

{
  "name": "unset-fault",
  "type": "action",
  "provider": {
    "type": "python",
    "func": "unset_fault",
    "arguments": {
      "virtual_service_name": "",
      "routes": []
    },
    "module": "chaosistio.fault.actions"
  }
}
name: unset-fault
provider:
  arguments:
    routes: []
    virtual_service_name: ''
  func: unset_fault
  module: chaosistio.fault.actions
  type: python
type: action