ansible / ansible-kubernetes-modules

DEPRECATED Ansible role containing pre-release K8s modules
Apache License 2.0
73 stars 39 forks source link

Why there is different notation between k8s api and Ansible playbooks #7

Open slaskawi opened 7 years ago

slaskawi commented 7 years ago

I'm currently migrating our templates into Ansible Service Broker. The API seems very similar but in some cases it's a bit different.

Here are just a few examples:

oc export dc/...
...
        livenessProbe:
          exec:
            command:
            - /opt/datagrid/bin/livenessProbe.sh
          failureThreshold: 5
          initialDelaySeconds: 5
          periodSeconds: 30
          successThreshold: 1
          timeoutSeconds: 25
...

Migrated part into Ansible:

...
     liveness_probe:
        _exec:
          command: /opt/datagrid/bin/livenessProbe.sh
        failure_threshold: 5
        initial_delay_seconds: 5
        period_seconds: 30
        success_threshold: 1
        timeout_seconds: 25
...

Note that exec was changed to _exec, livenessProbe to liveness_probe etc. This actually makes copy/pasting pretty hard and error prone. Are there any plans to unify Ansible parser with k8s api?

awiddersheim commented 7 years ago

Most modules have a resource_defintion parameter that you can use to basically copy and paste your templates too instead of figuring out the parameters for each module.

https://github.com/ansible/ansible-kubernetes-modules/blob/master/library/openshift_v1_deployment_config.py#L74

slaskawi commented 6 years ago

It seems to work but only partially...

Here's an example - it's a copy/paste from running DeploymentConfig:

- name: Create Deployment Config
  openshift_v1_deployment_config:
    name: infinispan-app
    namespace: '{{ namespace }}'
    labels:
      application: infinispan-app
    resource_definition:
      replicas: 1
      selector:
       deploymentConfig: infinispan-app
      strategy:
       rollingParams:
         intervalSeconds: 20
         maxSurge: 1
         maxUnavailable: 1
         timeoutSeconds: 1200
         updatePeriodSeconds: 20
       type: Rolling
      template:
       metadata:
         labels:
           application: infinispan-app
           deploymentConfig: infinispan-app
         name: infinispan-app
       spec:
         containers:
         - env:
           - name: OPENSHIFT_KUBE_PING_LABELS
             value: application=infinispan-app
           - name: OPENSHIFT_KUBE_PING_NAMESPACE
             valueFrom:
               fieldRef:
                 apiVersion: v1
                 fieldPath: metadata.namespace
           - name: KUBERNETES_LABELS
             value: application=infinispan-app
           - name: KUBERNETES_NAMESPACE
             valueFrom:
               fieldRef:
                 apiVersion: v1
                 fieldPath: metadata.namespace
           image: docker-registry.engineering.redhat.com/jboss-dataservices/dataservices72-caching-service
           imagePullPolicy: Always
           livenessProbe:
             exec:
               command:
               - /opt/datagrid/bin/livenessProbe.sh
             failureThreshold: 5
             initialDelaySeconds: 5
             periodSeconds: 30
             successThreshold: 1
             timeoutSeconds: 25
           name: infinispan-app
           ports:
           - containerPort: 8080
             name: http
             protocol: TCP
           - containerPort: 8888
             name: ping
             protocol: TCP
           - containerPort: 11222
             name: hotrod
             protocol: TCP
           - containerPort: 11211
             name: memcached
             protocol: TCP
           readinessProbe:
             exec:
               command:
               - /opt/datagrid/bin/readinessProbe.sh
             failureThreshold: 5
             initialDelaySeconds: 5
             periodSeconds: 30
             successThreshold: 2
             timeoutSeconds: 25
           resources:
             requests:
               cpu: 500m
               memory: 512Mi
         serviceAccount: infinispan-app
         serviceAccountName: infinispan-app
         terminationGracePeriodSeconds: 60

This resulted in the following error:

TASK [provision-datagrid-online-services-apb : Create Deployment Config] *******
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Error parsing resource definition. Encountered selector_deployment_config, which does not map to a module parameter. If this looks like a problem with the module, please open an issue at github.com/openshift/openshift-restclient-python/issues"}
    to retry, use: --limit @/opt/apb/actions/provision.retry

After commenting selector part, I got another error:

TASK [provision-datagrid-online-services-apb : Create Deployment Config] *******
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Error parsing resource definition. Encountered template_spec_termination_grace_period_seconds, which does not map to a module parameter. If this looks like a problem with the module, please open an issue at github.com/openshift/openshift-restclient-python/issues"}
    to retry, use: --limit @/opt/apb/actions/provision.retry

So it seems not all sections are interpreted correctly...

awiddersheim commented 6 years ago

Well the error message tells you some good next steps.

If this looks like a problem with the module, please open an issue at github.com/openshift/openshift-restclient-python/issues