uselagoon / remote-controller

A group of controllers for handling Lagoon builds and tasks in Kubernetes or Openshift
5 stars 1 forks source link

`pullrequest.number` dissapears causing issues to deploy #21

Closed Schnitzel closed 3 years ago

Schnitzel commented 3 years ago

I'm currently testing lagoon-master with lagoon-kbd against a kubernetes cluster and found the following issue:

Lagoon-master creates a rabbitmq message like this:

{
  "metadata": {
    "name": "lagoon-build-qzzyhp",
    "namespace": "lagoon"
  },
  "spec": {
    "build": {
      "type": "pullrequest",
      "image": {},
      "ci": "false"
    },
    "branch": {
      "name": "pr-78"
    },
    "pullrequest": {
      "headBranch": "pr-testing",
      "headSha": "14627d2b6061ed1a1a1b8a692963145271a9a5d8",
      "baseBranch": "master",
      "baseSha": "229ec3e57e220114e1c6ab60dde07a8ea12b873b",
      "title": "Update system.site.yml - update",
      "number": "78"
    },
    "project": {
      "name": "drupal-example-test1-controller",
      "gitUrl": "git@github.com:amazeeio/drupal-example.git",
      "uiLink": "https://ui-lagoon-master.ch.amazee.io/projects/drupal-example-test1-controller/drupal-example-test1-controller-pr-78/deployments/lagoon-build-qzzyhp",
      "environment": "pr-78",
      "environmentType": "development",
      "productionEnvironment": "master2",
      "standbyEnvironment": "master",
      "subfolder": "",
      "routerPattern": "pr-78.drupal-example-test1-controller.test1.amazee.io",
      "deployTarget": "test1.amazee.io",
      "projectSecret": "7d6c71a7f475e53b96142e1ce7b141e80f8de59365e17b964a6085fd4bd96f73",
      "registry": "registry.lagoon.svc:5000",
      "monitoring": {
        "contact": "",
        "statuspageID": "null"
      },
      "variables": {
        "project": "W3sibmFtZSI6IklOVEVSTkFMX1JFR0lTVFJZX1VSTCIsInZhbHVlIjoiaHR0cHM6Ly9oYXJib3ItbmdpbngtbGFnb29uLW1hc3Rlci5jaC5hbWF6ZWUuaW8iLCJzY29wZSI6ImludGVybmFsX2NvbnRhaW5lcl9yZWdpc3RyeSJ9LHsibmFtZSI6IklOVEVSTkFMX1JFR0lTVFJZX1VTRVJOQU1FIiwidmFsdWUiOiJyb2J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TZFejhGdVh6SW9UVHhmSUxjTlNHWGljM00yN1hGX2RON2d0OWpQaTVfWEJMekNWYVRQNHZ6TDN4eVByVHV5dWNseWFVR0JkNl9GelRIeWRwNXlJczVRS2czREhCSm9ielB4ZzNCZEJqbTNXNmd5blh2bmNadWU5UmVqMmdHb3lNa0xPT21QS2VWcnhXNm1uWmptd2l4blR1cE5vVzA2Vktqek9ZRWRHenkwVmJKQnBjVk03Y2xCQ1BYb2x0TElGQ3hsRWVib3lzV1NYVGk4dk0zeXR4WEFfenlkeG5uNDVET3RVQkxBdENtUlFWSXJuYUpMNDFpSGtwZ0NtVU9yWW1zNFlkSWRhMVAzbXRhR3hSc0pEckI4RzVkZkFnelUiLCJzY29wZSI6ImludGVybmFsX2NvbnRhaW5lcl9yZWdpc3RyeSJ9XQ==",
        "environment": "W10="
      }
    }
  }
}

see the spec.pullrequest.number in there

but then the LagoonBuild object is created by lagoon-build-deploy and it disapears:

kind: LagoonBuild
apiVersion: lagoon.amazee.io/v1alpha1
metadata:
  creationTimestamp: '2020-12-24T15:11:26Z'
  finalizers:
    - finalizer.lagoonbuild.lagoon.amazee.io/v1alpha1
  generation: 2
  labels:
    lagoon.sh/buildStatus: Failed
    lagoon.sh/controller: lagoon
  managedFields:
    - apiVersion: lagoon.amazee.io/v1alpha1
      fieldsType: FieldsV1
      fieldsV1:
        'f:metadata':
          'f:finalizers':
            .: {}
            'v:"finalizer.lagoonbuild.lagoon.amazee.io/v1alpha1"': {}
          'f:labels':
            .: {}
            'f:lagoon.sh/buildStatus': {}
            'f:lagoon.sh/controller': {}
        'f:spec':
          .: {}
          'f:branch':
            .: {}
            'f:name': {}
          'f:build':
            .: {}
            'f:ci': {}
            'f:type': {}
          'f:gitReference': {}
          'f:project':
            .: {}
            'f:deployTarget': {}
            'f:environment': {}
            'f:environmentType': {}
            'f:gitUrl': {}
            'f:key': {}
            'f:monitoring':
              .: {}
              'f:statuspageID': {}
            'f:name': {}
            'f:productionEnvironment': {}
            'f:projectSecret': {}
            'f:registry': {}
            'f:routerPattern': {}
            'f:standbyEnvironment': {}
            'f:uiLink': {}
            'f:variables':
              .: {}
              'f:environment': {}
              'f:project': {}
          'f:promote': {}
          'f:pullrequest':
            .: {}
            'f:baseBranch': {}
            'f:baseSha': {}
            'f:headBranch': {}
            'f:headSha': {}
            'f:title': {}
        'f:status':
          .: {}
          'f:conditions': {}
      manager: manager
      operation: Update
      time: '2020-12-24T15:11:44Z'
  name: lagoon-build-qzzyhp
  namespace: drupal-example-test1-controller-pr-78
  resourceVersion: '132895455'
  selfLink: >-
    /apis/lagoon.amazee.io/v1alpha1/namespaces/drupal-example-test1-controller-pr-78/lagoonbuilds/lagoon-build-qzzyhp
  uid: f969b554-bed7-4fa2-9c9f-70881db54e80
spec:
  branch:
    name: pr-78
  build:
    ci: 'false'
    type: pullrequest
  gitReference: ''
  project:
    deployTarget: test1.amazee.io
    environment: pr-78
    environmentType: development
    gitUrl: 'git@github.com:amazeeio/drupal-example.git'
    monitoring:
      statuspageID: 'null'
    name: drupal-example-test1-controller
    productionEnvironment: master2
    projectSecret: 7d6c71a7f475e53b96142e1ce7b141e80f8de59365e17b964a6085fd4bd96f73
    registry: 'registry.lagoon.svc:5000'
    routerPattern: pr-78.drupal-example-test1-controller.test1.amazee.io
    standbyEnvironment: master
    uiLink: >-
      https://ui-lagoon-master.ch.amazee.io/projects/drupal-example-test1-controller/drupal-example-test1-controller-pr-78/deployments/lagoon-build-qzzyhp
    variables:
      environment: W10=
      project: >-
        W3sibmFtZSI6IklOVEVSTkFMX1JFR0lTVFJZX1VSTCIsInZhbHVlIjoiaHR0cHM6Ly9oYXJib3ItbmdpbngtbGFnb29uLW1hc3Rlci5jaC5hbWF6ZWUuaW8iLCJzY29wZSI6ImludGVybmFsX2NvbnRhaW5lcl9yZWdpc3RyeSJ9LHsibmFtZSI6IklOVEVSTkFMX1JFR0lTVFJZX1VTRVJOQU1FIiwidmFsdWUiOiJyb2JvdCRkcnVwYWwtZXhhbXBsZS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lNHWGljM00yN1hGX2RON2d0OWpQaTVfWEJMekNWYVRQNHZ6TDN4eVByVHV5dWNseWFVR0JkNl9GelRIeWRwNXlJczVRS2czREhCSm9ielB4ZzNCZEJqbTNXNmd5blh2bmNadWU5UmVqMmdHb3lNa0xPT21QS2VWcnhXNm1uWmptd2l4blR1cE5vVzA2Vktqek9ZRWRHenkwVmJKQnBjVk03Y2xCQ1BYb2x0TElGQ3hsRWVib3lzV1NYVGk4dk0zeXR4WEFfenlkeG5uNDVET3RVQkxBdENtUlFWSXJuYUpMNDFpSGtwZ0NtVU9yWW1zNFlkSWRhMVAzbXRhR3hSc0pEckI4RzVkZkFnelUiLCJzY29wZSI6ImludGVybmFsX2NvbnRhaW5lcl9yZWdpc3RyeSJ9XQ==
  promote: {}
  pullrequest:
    baseBranch: master
    baseSha: 229ec3e57e220114e1c6ab60dde07a8ea12b873b
    headBranch: pr-testing
    headSha: 14627d2b6061ed1a1a1b8a692963145271a9a5d8
    title: Update system.site.yml - update

see that now spec.pullrequest.number is missing

the pod that is created to deploy PRs then looks like this:

kind: Pod
apiVersion: v1
metadata:
  name: lagoon-build-qzzyhp
  namespace: drupal-example-test1-controller-pr-78
  selfLink: >-
    /api/v1/namespaces/drupal-example-test1-controller-pr-78/pods/lagoon-build-qzzyhp
  uid: 09b491ed-f686-4f37-b87a-52c9983527e6
  resourceVersion: '132895453'
  creationTimestamp: '2020-12-24T15:11:27Z'
  labels:
    lagoon.sh/buildName: lagoon-build-qzzyhp
    lagoon.sh/controller: lagoon
    lagoon.sh/jobType: build
  annotations:
    kubernetes.io/psp: eks.privileged
  ownerReferences:
    - apiVersion: lagoon.amazee.io/v1alpha1
      kind: LagoonBuild
      name: lagoon-build-qzzyhp
      uid: f969b554-bed7-4fa2-9c9f-70881db54e80
spec:
  volumes:
    - name: lagoon-deployer-token-r5b7f
      secret:
        secretName: lagoon-deployer-token-r5b7f
        defaultMode: 420
    - name: lagoon-sshkey
      secret:
        secretName: lagoon-sshkey
        defaultMode: 420
    - name: default-token-mgnb7
      secret:
        secretName: default-token-mgnb7
        defaultMode: 420
  containers:
    - name: lagoon-build
      image: 'imagecache.amazeeio.cloud/amazeeio/kubectl-build-deploy-dind:v1.13.1'
      env:
        - name: SOURCE_REPOSITORY
          value: 'git@github.com:amazeeio/drupal-example.git'
        - name: GIT_REF
        - name: SUBFOLDER
        - name: BRANCH
          value: pr-78
        - name: PROJECT
          value: drupal-example-test1-controller
        - name: ENVIRONMENT_TYPE
          value: development
        - name: ACTIVE_ENVIRONMENT
          value: master2
        - name: STANDBY_ENVIRONMENT
          value: master
        - name: PROJECT_SECRET
          value: 7d6c71a7f475e53b96142e1ce7b141e80f8de59365e17b964a6085fd4bd96f73
        - name: MONITORING_ALERTCONTACT
        - name: BUILD_TYPE
          value: pullrequest
        - name: ENVIRONMENT
          value: pr-78
        - name: KUBERNETES
          value: test1.amazee.io
        - name: REGISTRY
          value: 'registry.lagoon.svc:5000'
        - name: ROUTER_URL
          value: pr-78.drupal-example-test1-controller.test1.amazee.io
        - name: CI
          value: 'false'
        - name: PR_HEAD_BRANCH
          value: pr-testing
        - name: PR_HEAD_SHA
          value: 14627d2b6061ed1a1a1b8a692963145271a9a5d8
        - name: PR_BASE_BRANCH
          value: master
        - name: PR_BASE_SHA
          value: 229ec3e57e220114e1c6ab60dde07a8ea12b873b
        - name: PR_TITLE
          value: Update system.site.yml - update
        - name: PR_NUMBER
          value: "\0"
        - name: LAGOON_PROJECT_VARIABLES
          value: >-
            [{"name":"INTERNAL_REGISTRY_URL","value":"https://harbor-nginx-lagoon-master.ch.amazee.io","scope":"internal_container_registry"},{"name":"INTERNAL_REGISTRY_USERNAME","value":"robot$drupal-example-test1-controller-1607911253","scope":"internal_container_registry"},{"name":"INTERNAL_REGISTRY_PASSWORD","value":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NTExMTEyNTMsImlhdCI6MTYwNzkxMTI1MywiaXNzIjoiaGFyYm9yLXRva2VuLWRlZmF1bHRJc3N1ZXIiLCJpZCI6MzIxNTc5LCJwaWQiOjExNDMsImFjY2VzcyI6W3siUmVzb3VyY2UiOiIvcHJvamVjdC8xMTQzL3JlcG9zaXRvcnkiLCJBY3Rpb24iOiJwdXNoIiwiRWZmZWN0IjoiIn1dfQ.pn7suCNPTa9wnhncRuqZ3dAHCOdktSYzPvj9LYslxEZmawnn1apIOUdgFTvtaY5p4plfSBS4ZVgvo5SKGXBH9jkIQiZ1YVLyvvO9N7adNV-ljCSisZH3FhifdtPII2JLmQ5zBWN9HRR03rfJ2GBx5gvGtS-ZRElHYEEJZygSUto0i731OZhfHeeE15Qo7pHvChqZHaMrl9-0jfF7MQM9m4cw0ciZYTkCa2LEBKzieoOXg7r0yYRwfExiFMbvn0Ie5waqfdE9PFSGaXY4fpRH_D7vVE-wA7qf0f2ZKHKk4pf9vZPwRW-dPSKuDitnXrp-jgusGTzPHSs1Dt9Kd8qoWYa3YluUFuBrwTx2gtWUoh56tbn9G0ihLnrmL2eCTS4AG3VmmdQdaPczY6Ez8FuXzIoTTxfILcNSGXic3M27XF_dN7gt9jPi5_XBLzCVaTP4vzL3xyPrTuyuclyaUGBd6_FzTHydp5yIs5QKg3DHBJobzPxg3BdBjm3W6gynXvncZue9Rej2gGoyMkLOOmPKeVrxW6mnZjmwixnTupNoW06VKjzOYEdGzy0VbJBpcVM7clBCPXoltLIFCxlEeboysWSXTi8vM3ytxXA_zydxnn45DOtUBLAtCmRQVIrnaJL41iHkpgCmUOrYms4YdIda1P3mtaGxRsJDrB8G5dfAgzU","scope":"internal_container_registry"}]
        - name: MONITORING_STATUSPAGEID
          value: 'null'
      resources: {}
      volumeMounts:
        - name: lagoon-deployer-token-r5b7f
          readOnly: true
          mountPath: /var/run/secrets/lagoon/deployer
        - name: lagoon-sshkey
          readOnly: true
          mountPath: /var/run/secrets/lagoon/ssh
        - name: default-token-mgnb7
          readOnly: true
          mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      imagePullPolicy: Always
  restartPolicy: Never
  terminationGracePeriodSeconds: 30
  dnsPolicy: ClusterFirst
  serviceAccountName: default
  serviceAccount: default
  nodeName: ip-10-200-123-50.eu-central-1.compute.internal
  securityContext: {}
  schedulerName: default-scheduler
  tolerations:
    - key: lagoon/build
      operator: Exists
      effect: NoSchedule
    - key: lagoon/build
      operator: Exists
      effect: PreferNoSchedule
    - key: node.kubernetes.io/not-ready
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
    - key: node.kubernetes.io/unreachable
      operator: Exists
      effect: NoExecute
      tolerationSeconds: 300
  priorityClassName: lagoon-priority-production
  priority: 1000000
  enableServiceLinks: true
status:
  phase: Failed
  conditions:
    - type: Initialized
      status: 'True'
      lastProbeTime: null
      lastTransitionTime: '2020-12-24T15:11:27Z'
    - type: Ready
      status: 'False'
      lastProbeTime: null
      lastTransitionTime: '2020-12-24T15:11:27Z'
      reason: ContainersNotReady
      message: 'containers with unready status: [lagoon-build]'
    - type: ContainersReady
      status: 'False'
      lastProbeTime: null
      lastTransitionTime: '2020-12-24T15:11:27Z'
      reason: ContainersNotReady
      message: 'containers with unready status: [lagoon-build]'
    - type: PodScheduled
      status: 'True'
      lastProbeTime: null
      lastTransitionTime: '2020-12-24T15:11:27Z'
  hostIP: 10.200.123.50
  podIP: 10.200.87.81
  podIPs:
    - ip: 10.200.87.81
  startTime: '2020-12-24T15:11:27Z'
  containerStatuses:
    - name: lagoon-build
      state:
        terminated:
          exitCode: 128
          reason: ContainerCannotRun
          message: >-
            OCI runtime create failed: container_linux.go:370: starting
            container process caused: process_linux.go:459: container init
            caused: setenv: invalid argument: unknown
          startedAt: '2020-12-24T15:11:40Z'
          finishedAt: '2020-12-24T15:11:40Z'
          containerID: >-
            docker://6b760f4c4ac254f15a031bbc94a420a953e503ea1e391ec5338494127b13c2de
      lastState: {}
      ready: false
      restartCount: 0
      image: 'imagecache.amazeeio.cloud/amazeeio/kubectl-build-deploy-dind:v1.13.1'
      imageID: >-
        docker-pullable://imagecache.amazeeio.cloud/amazeeio/kubectl-build-deploy-dind@sha256:3fdb6515cb513971adebbb2a1fb87cae860cdd47b34a0fd0f58f9d34f2e5cd86
      containerID: >-
        docker://6b760f4c4ac254f15a031bbc94a420a953e503ea1e391ec5338494127b13c2de
      started: false
  qosClass: BestEffort

with

        - name: PR_NUMBER
          value: "\0"

which then causes kubernetes to fail:

Error: failed to start container "lagoon-build": Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: setenv: invalid argument: unknown

while I think this is actually a kubernetes bug that you should be able to create a pod with \0 as env variable, it's also a bug that the pull request number gets somehow swallowed by the controller.

I found the code that takes the message and creaetes the LagoonBuilds object: https://github.com/amazeeio/lagoon-kbd/blob/main/handlers/message_queue.go#L95-L106 and I don't see anything wrong with it.

The only piece that I could imagine is that somehow the fact the value in the rabbitmq message is a string, but the lagoon types for LagoonBuilds is defined as a number: https://github.com/amazeeio/lagoon-kbd/blob/86935f85c0516ee50deff1839000f7567f6b1b53/api/v1alpha1/lagoonbuild_types.go#L142 could cause some issues?

Schnitzel commented 3 years ago

regarding kubernetes bug, looks like that it's actually a linux thing: https://github.com/kubernetes/kubernetes/issues/89906

its not possible to store a NUL-byte inside a linux environment variable

so I think that's ok therefore and we need to solve the issue on our side

Schnitzel commented 3 years ago

I was able to get it running with: https://github.com/amazeeio/lagoon-kbd/pull/22 - pushed as amazeeio/lagoon-builddeploy:v0.1.6rc1

but honestly I'm not sure if that's the right way, the LagoonBuilds object now looks like this:

  pullrequest:
    baseBranch: master
    baseSha: 229ec3e57e220114e1c6ab60dde07a8ea12b873b
    headBranch: pr-testing
    headSha: 14627d2b6061ed1a1a1b8a692963145271a9a5d8
    number: "78"
    title: test2

which then creates a pod with

        - name: PR_TITLE
          value: test2
        - name: PR_NUMBER
          value: '78'

I tried to create a pod with

        - name: PR_NUMBER
          value: 78

and this actually doesn't work as kubectl errors:

Error from server (BadRequest): error when creating "/private/var/folders/xx/8zf5sz1d24n0cxtgsk956cvr0000gn/T/5c917a3e651ad4ef254f46d6784d17f2/resource.yaml": Pod in version "v1" cannot be handled as a Pod: v1.Pod.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.Value: ReadString: expects " or n, but found 7, error found in #10 byte of ...|,"value":78},{"name"|..., bigger context ...|LE","value":"test2"},{"name":"PR_NUMBER","value":78},{"name":"LAGOON_PROJECT_VARIABLES","value":"[{\|...

So I think this solution actually should be a solution

I'm more confused why the testing infra works though?

Schnitzel commented 3 years ago

figured out why the testing does not fail, we actually never test pullrequests currently in amazeeio/lagoon or in amazeeio/lagoon-kbd:

https://github.com/amazeeio/lagoon/blob/2823f93897b034b7292c5d08f59ca761fb06897d/Makefile#L929

therefore this never was caught.

So I think we should merge this in.

shreddedbacon commented 3 years ago

Nice! I think we can go with this for now. I am concerned that Lagoon is sending the int as a string though.

When creating the EnvVar, the controller converts the int to string so that it gets created properly. For reference, the types for corev1.EnvVar are Name:string, Value:string.

podEnvs = append(podEnvs, corev1.EnvVar{
    Name:  "PR_NUMBER",
    Value: string(lagoonBuild.Spec.Pullrequest.Number),
})

The step that performs an unmarshalling of the JSON payload into a LagoonBuild won't know how to turn the string to an int, so gets confused. I think this is the reason that it was breaking is because the PR number in the spec wasn't being created properly as an int cause Lagoon was sending it as a string.

If Lagoon sent the PR number as an actual JSON int, it would have been fine.

I think Lagoon should try and do types properly where possible, if a value is an int, make sure the JSON representation being passed around is an int too.