StackStorm-Exchange / stackstorm-kubernetes

st2 content pack containing Kubernetes sensors
https://exchange.stackstorm.org/
Apache License 2.0
19 stars 17 forks source link

Trying to trigger on 3rd party resource creation. #11

Open jeremyjjbrown opened 7 years ago

jeremyjjbrown commented 7 years ago

I created a Kubernetes 3rd party resource api and I'd like to trigger a rule. However I am not getting any trigger instances in my ST2 and it appears most K8s events are failing validation.

st2 trigger-instance list --trigger="kubernetes.pods"+----+---------+-----------------+--------+
| id | trigger | occurrence_time | status |
+----+---------+-----------------+--------+
+----+---------+-----------------+--------+
ubuntu@st2vagrant2:~ $ st2 trigger-instance list --trigger="kubernetes.deployments"
+----+---------+-----------------+--------+
| id | trigger | occurrence_time | status |
+----+---------+-----------------+--------+
+----+---------+-----------------+--------+

/var/log/st2/st2sensorcontainer.log is full of log info from the K8s API server with many instances of

WARNING sensor_wrapper [-] Trigger payload validation failed and validation is enabled, not dispatching a trigger "kubernetes.thirdpartyresources" ({'resource': 'ADDED', 'uid': '53e7d4a9-2f6a-11e7-88e8-0ebd2ffaca5c', 'labels': 'None', 'namespace': 'None', 'object_kind': 'ThirdPartyResource', 'name': 'buckets.stable.here.com'})
WARNING sensor_wrapper [-] Failed to validate payload ({'resource': 'MODIFIED', 'uid': 'b60476a4-2a0c-11e7-bc9d-0a0ac53f9d60', 'labels': 'None', 'namespace': 'kafka', 'object_kind': 'Event', 'name': 'zoo-0.14b8c6e1bb4a477d'}) for trigger "kubernetes.events": [u'obj', 'null'] is not valid under any of the given schemas

Failed validating 'anyOf' in schema['properties']['properties']['additionalProperties']['properties']['type']:
    {'anyOf': [{'$ref': '#/definitions/simpleTypes'},
               {'items': {'$ref': '#/definitions/simpleTypes'},
                'minItems': 1,
                'type': 'array',
                'uniqueItems': True}]}

On instance['properties'][u'resource']['type']:
    [u'obj', 'null']

Not sure what the issue is here.

Kami commented 7 years ago

Thanks for reporting this.

This is related to the issue https://github.com/StackStorm/st2/issues/3385.

LindsayHill commented 7 years ago

@Kami is right that part of the problem is st2/#3385, where validation is also enabled.

The problem also seems to be related to this template https://github.com/StackStorm-Exchange/stackstorm-kubernetes/blob/master/etc/st2packgen/templates/sensor_template.yaml.jinja#L13

      payload_schema:
        type: "object"
        properties:
          resource:
            type: "obj"
          name:
            type: "obj"
          labels:
            type: "obj"
          object_kind:
            type: "obj"
          namespace:
            type: "obj"

Rather than type: "obj", it probably needs to be type: "object". May need a uid object in there too.

Mierdin commented 7 years ago

Just FYI - this behavior is addressed in https://github.com/StackStorm/st2/pull/3390 and will be included in the next release. Still, the schema should be adjusted to match the trigger payload anyways in the meantime.

AndyMoore111 commented 7 years ago

I've created branch 1.5 from the latest 1.5.x kubernetes swagger.json

We're currently testing this on our dev cluster - if it looks good I'll merge tonight/tomorrow