migtools / pvc-migrate

Standalone PVC migration
Apache License 2.0
5 stars 13 forks source link

Stage 2 - Passing wrong parameters format #127

Closed lcordero closed 4 years ago

lcordero commented 4 years ago

== Error 1 ==

Description: Error creating NS on destination cluster. As the object _namespacedata is treated as JSON, at the time you are passing item.annotations on the loop, it'll fail because the template format is YAML and not JSON.

Error:

TASK [Ensure the namespaces are created for the pvcs] ****************************************************

failed: [localhost] (item={'namespace': 'lcordero', 'annotations': {'openshift.io/description': '', 'openshift.io/display-name': 'lcordero', 'openshift.io/requester': 'C14674A@ena.us.experian.local', 'openshift.io/sa.scc.mcs': 's0:c12,c4', 'openshift.io/sa.scc.supplemental-groups': '1000140000/10000', 'openshift.io/sa.scc.uid-range': '1000140000/10000'}}) => {"ansible_loop_var": "item", "changed": false, "error": 422, "item": {"annotations": {"openshift.io/description": "", "openshift.io/display-name": "lcordero", "openshift.io/requester": "C14674A@ena.us.experian.local", "openshift.io/sa.scc.mcs": "s0:c12,c4", "openshift.io/sa.scc.supplemental-groups": "1000140000/10000", "openshift.io/sa.scc.uid-range": "1000140000/10000"}, "namespace": "lcordero"}, "msg": "Failed to patch object: b'{\"kind\":\"Status\",\"apiVersion\":\"v1\",\"metadata\":{},\"status\":\"Failure\",\"message\":\" \\\\\"\\\\\" is invalid: patch: Invalid value: \\\\\"{\\\\\\\\\\\\\"apiVersion\\\\\\\\\\\\\":\\\\\\\\\\\\\"v1\\\\\\\\\\\\\",\\\\\\\\\\\\\"kind\\\\\\\\\\\\\":\\\\\\\\\\\\\"Namespace\\\\\\\\\\\\\",\\\\\\\\\\\\\"metadata\\\\\\\\\\\\\":{\\\\\\\\\\\\\"annotations\\\\\\\\\\\\\":\\\\\\\\\\\\\"{openshift.io/description: \\'\\', openshift.io/display-name: lcordero, openshift.io/requester: C14674A@ena.us.experian.local, openshift.io/sa.scc.mcs: \\'s0:c12,c4\\', openshift.io/sa.scc.supplemental-groups: 1000140000/10000, openshift.io/sa.scc.uid-range: 1000140000/10000} \\\\\\\\\\\\\",\\\\\\\\\\\\\"creationTimestamp\\\\\\\\\\\\\":\\\\\\\\\\\\\"2020-07-30T14:23:16Z\\\\\\\\\\\\\",\\\\\\\\\\\\\"labels\\\\\\\\\\\\\":{\\\\\\\\\\\\\"name\\\\\\\\\\\\\":\\\\\\\\\\\\\"lcordero\\\\\\\\\\\\\",\\\\\\\\\\\\\"with-pvc\\\\\\\\\\\\\":\\\\\\\\\\\\\"true\\\\\\\\\\\\\"},\\\\\\\\\\\\\"name\\\\\\\\\\\\\":\\\\\\\\\\\\\"lcordero\\\\\\\\\\\\\",\\\\\\\\\\\\\"resourceVersion\\\\\\\\\\\\\":\\\\\\\\\\\\\"3946930\\\\\\\\\\\\\",\\\\\\\\\\\\\"uid\\\\\\\\\\\\\":\\\\\\\\\\\\\"dffe71f5-0cde-4996-a97e-6570f43f15ea\\\\\\\\\\\\\"},\\\\\\\\\\\\\"spec\\\\\\\\\\\\\":{\\\\\\\\\\\\\"finalizers\\\\\\\\\\\\\":[\\\\\\\\\\\\\"kubernetes\\\\\\\\\\\\\"]},\\\\\\\\\\\\\"status\\\\\\\\\\\\\":{\\\\\\\\\\\\\"phase\\\\\\\\\\\\\":\\\\\\\\\\\\\"Active\\\\\\\\\\\\\"}}\\\\\": v1.Namespace.ObjectMeta: v1.ObjectMeta.Annotations: ReadMapCB: expect { or n, but found \\\\\", error found in #10 byte of ...|tations\\\\\":\\\\\"{openshift|..., bigger context ...|v1\\\\\",\\\\\"kind\\\\\":\\\\\"Namespace\\\\\",\\\\\"metadata\\\\\":{\\\\\"annotations\\\\\":\\\\\"{openshift.io/description: \\'\\', openshift.io/displa|...\",\"reason\":\"Invalid\",\"details\":{\"causes\":[{\"reason\":\"FieldValueInvalid\",\"message\":\"Invalid value: \\\\\"{\\\\\\\\\\\\\"apiVersion\\\\\\\\\\\\\":\\\\\\\\\\\\\"v1\\\\\\\\\\\\\",\\\\\\\\\\\\\"kind\\\\\\\\\\\\\":\\\\\\\\\\\\\"Namespace\\\\\\\\\\\\\",\\\\\\\\\\\\\"metadata\\\\\\\\\\\\\":{\\\\\\\\\\\\\"annotations\\\\\\\\\\\\\":\\\\\\\\\\\\\"{openshift.io/description: \\'\\', openshift.io/display-name: lcordero, openshift.io/requester: C14674A@ena.us.experian.local, openshift.io/sa.scc.mcs: \\'s0:c12,c4\\', openshift.io/sa.scc.supplemental-groups: 1000140000/10000, openshift.io/sa.scc.uid-range: 1000140000/10000} \\\\\\\\\\\\\",\\\\\\\\\\\\\"creationTimestamp\\\\\\\\\\\\\":\\\\\\\\\\\\\"2020-07-30T14:23:16Z\\\\\\\\\\\\\",\\\\\\\\\\\\\"labels\\\\\\\\\\\\\":{\\\\\\\\\\\\\"name\\\\\\\\\\\\\":\\\\\\\\\\\\\"lcordero\\\\\\\\\\\\\",\\\\\\\\\\\\\"with-pvc\\\\\\\\\\\\\":\\\\\\\\\\\\\"true\\\\\\\\\\\\\"},\\\\\\\\\\\\\"name\\\\\\\\\\\\\":\\\\\\\\\\\\\"lcordero\\\\\\\\\\\\\",\\\\\\\\\\\\\"resourceVersion\\\\\\\\\\\\\":\\\\\\\\\\\\\"3946930\\\\\\\\\\\\\",\\\\\\\\\\\\\"uid\\\\\\\\\\\\\":\\\\\\\\\\\\\"dffe71f5-0cde-4996-a97e-6570f43f15ea\\\\\\\\\\\\\"},\\\\\\\\\\\\\"spec\\\\\\\\\\\\\":{\\\\\\\\\\\\\"finalizers\\\\\\\\\\\\\":[\\\\\\\\\\\\\"kubernetes\\\\\\\\\\\\\"]},\\\\\\\\\\\\\"status\\\\\\\\\\\\\":{\\\\\\\\\\\\\"phase\\\\\\\\\\\\\":\\\\\\\\\\\\\"Active\\\\\\\\\\\\\"}}\\\\\": v1.Namespace.ObjectMeta: v1.ObjectMeta.Annotations: ReadMapCB: expect { or n, but found \\\\\", error found in #10 byte of ...|tations\\\\\":\\\\\"{openshift|..., bigger context ...|v1\\\\\",\\\\\"kind\\\\\":\\\\\"Namespace\\\\\",\\\\\"metadata\\\\\":{\\\\\"annotations\\\\\":\\\\\"{openshift.io/description: \\'\\', openshift.io/displa|...\",\"field\":\"patch\"}]},\"code\":422}\\n'", "reason": "Unprocessable Entity", "status": 422}

Possible solution: Change the format of the template _2_pvc_destinationgen/templates/namespace.yml.j2 to json; like this:

file: _2_pvc_destinationgen/templates/namespace.json.j2

{
  "apiVersion": "v1",
  "kind": "Namespace",
  "metadata": {
    "annotations": {{ item.annotations }},
    "name": "{{ item.namespace }}"
  },
  "spec": {
    "finalizers": [
      "kubernetes"
    ]
  }
}

== Error 2 ==

Description: Error creating PVC on destination cluster. As the object _ mig_dest_adjusted_pvcdata is treated as JSON, at the time you are passing _item.accessmodes (json Array) on the loop, it'll fail because the template format is YAML and not JSON.

Error:

TASK [Ensure pvc is created on destination] **************************************************************

fatal: [localhost]: FAILED! => {"changed": false, "error": 400, "msg": "Failed to create object: b'{\"kind\":\"Status\",\"apiVersion\":\"v1\",\"metadata\":{},\"status\":\"Failure\",\"message\":\"PersistentVolumeClaim in version \\\\\"v1\\\\\" cannot be handled as a PersistentVolumeClaim: v1.PersistentVolumeClaim.Spec: v1.PersistentVolumeClaimSpec.AccessModes: []v1.PersistentVolumeAccessMode: decode slice: expect [ or n, but found \\\\\", error found in #10 byte of ...|sModes\\\\\": \\\\\"[\\'ReadWrit|..., bigger context ...|namespace\\\\\": \\\\\"lcordero\\\\\"}, \\\\\"spec\\\\\": {\\\\\"accessModes\\\\\": \\\\\"[\\'ReadWriteOnce\\']\\\\\", \\\\\"resources\\\\\": {\\\\\"requests\\\\\": {\\\\\"st|...\",\"reason\":\"BadRequest\",\"code\":400}\\n'", "reason": "Bad Request", "status": 400}
...ignoring

Possible solution: Change the format of the template _2_pvc_destinationgen/templates/pvc.yml.j2 to json; like this:

file: _2_pvc_destinationgen/templates/pvc.json.j2

{
  "apiVersion": "v1",
  "kind": "PersistentVolumeClaim",
  "metadata": {
    "finalizers": [
      "kubernetes.io/pvc-protection"
    ],
    "name": "{{ item.pvc_name }}",
    "namespace": "{{ item.pvc_namespace }}"
  },
  "spec": {
    "accessModes": {{ item.access_modes }},
    "resources": {
      "requests": {
        "storage": "{{ item.capacity }}"
      }
    },
    "storageClassName": "{{ item.storage_class }}",
    "volumeMode": "Filesystem"
  }
}

I have tested both solutions and now the playbook is working, at least the tests I performed.

pranavgaikwad commented 4 years ago

@lcordero Primary investigation leads me to believe that this is related to latest changes we made in how templates were created. It's a side-effect of adding " to the templated names. Nested JSON objects seem to be not parsed correctly by Ansible. Will update here as I learn more.

Related to https://github.com/konveyor/pvc-migrate/pull/126 and https://github.com/konveyor/pvc-migrate/issues/125