openshift / jenkins-client-plugin

Apache License 2.0
218 stars 145 forks source link

openshift.newApp not create the deploymentConfig in OpenShift #342

Closed brunourb closed 3 years ago

brunourb commented 4 years ago

Hi,

The command openshift.newApp in Jenkins pipeline not create deploymentconfig (DC). I have 2 jenkins (test and staging) with the same image in quay.io and same plugin version.

Quay.io repo: https://quay.io/repository/openshift/origin-jenkins/, tag is 4.6 Jenkins version is: 2.222.1-1.1

I tested the OpenShift Jenkins Pipeline version 1.0.32 at 1.0.34. https://updates.jenkins.io/download/plugins/openshift-client/

In TEST, the version of oc client and k8s is:

TEST

sh-4.2$ oc whoami
system:serviceaccount:ci-cd:jenkins
sh-4.2$ oc version
Client Version: v4.2.0-alpha.0-505-g89c0b73
Kubernetes Version: v1.11.0+d4cacc0

In stage, the version of oc client and k8s is:

STAGING

sh-4.2$ oc whoami
system:serviceaccount:ci-cd:jenkins
sh-4.2$ oc version
Client Version: v4.2.0-alpha.0-659-gad8b00f
Kubernetes Version: v1.11.0+d4cacc0

When i run the pipeline with this stage, the DC is not create in STAGING environment. In DEV environment the dc is created.

        stage('Create Image Builder') {
            steps {
                script {
                    openshift.withCluster() {
                        openshift.withProject(PROJECT) {
                            if (openshift.selector("bc", IMAGE).exists()) {

                                def bc = openshift.startBuild(IMAGE)
                                openshift.set("env dc/${IMAGE} BUILD_NUMBER=${BUILD_NUMBER}")
                                openshift.set("env dc/${IMAGE} JAVA_OPTIONS='-Dglobal.url_pandora=http://pandora:8080'")
                                // output build logs to the Jenkins console
                                echo "Logs from build"
                                def result = bc.logs('-f')
                                // actions that took place
                                echo "The logs operation require ${result.actions.size()} 'oc' interactions"
                                // see exactly what oc command was executed.
                                echo "Logs executed: ${result.actions[0].cmd}"
                            } else {
                                echo "No proevious BuildConfig. Creating new BuildConfig."
                                def myNewApp = openshift.newApp(
                                        "${GIT_REPO}#${BRANCH}",
                                        "--name=${IMAGE}",
                                        "--context-dir=.",
                                        "--source-secret=gitlab",
                                        "-e BUILD_NUMBER=${BUILD_NUMBER}",
                                        "-e BUILD_ENV=${openshift.project()}",
                                        "-e PROFILE=stage",
                                        "-e SPRING_PROFILES_ACTIVE=stage",
                                        "-e BUILD_ENV=${openshift.project()}"
                                )
                                echo "new-app myNewApp ${myNewApp.count()} objects named: ${myNewApp.names()}"

                                myNewApp.describe()
                                // selects the build config
                                def bc = myNewApp.narrow('bc')
                                // output build logs to the Jenkins console
                                echo "Logs from build"
                                def result = bc.logs('-f')
                                // actions that took place
                                echo "The logs operation require ${result.actions.size()} 'oc' interactions"
                                // see exactly what oc command was executed.
                                echo "Logs executed: ${result.actions[0].cmd}"
                            }
                            echo "Tag Container image with 'build number' as version"
                            openshift.tag("${IMAGE}:latest", "${IMAGE}:v${BUILD_NUMBER}")
                            echo "Validating Route for Service exist, if Not create Route"
                            if (!openshift.selector("route", IMAGE).exists()) {
                                openshift.selector("svc", IMAGE).expose()
                            }
                        }
                    }
                }
            }
        }

Console the TEST environment

[Pipeline] stage
[Pipeline] { (Create Image Builder)
[Pipeline] script
[Pipeline] { (hide)
[Pipeline] _OcContextInit
[Pipeline] _OcContextInit
[Pipeline] readFile
[Pipeline] _OcAction
[Pipeline] readFile
[Pipeline] _OcAction
[Pipeline] echo
No proevious BuildConfig. Creating new BuildConfig.
[Pipeline] readFile
[Pipeline] _OcAction
[Pipeline] readFile (hide)
[Pipeline] _OcAction
[Pipeline] readFile
[Pipeline] _OcAction
[Pipeline] echo
new-app myNewApp 4 objects named: [imagestream/portal-server, buildconfig/portal-server, deploymentconfig/portal-server, service/portal-server]

Console in the STAGING environment

[Pipeline] stage
[Pipeline] { (Create Image Builder)
[Pipeline] script
[Pipeline] { (hide)
[Pipeline] _OcContextInit
[Pipeline] _OcContextInit
[Pipeline] readFile
[Pipeline] _OcAction
[Pipeline] readFile
[Pipeline] _OcAction
[Pipeline] echo
No proevious BuildConfig. Creating new BuildConfig.
[Pipeline] readFile
[Pipeline] _OcAction
[Pipeline] readFile
[Pipeline] _OcAction
[Pipeline] readFile
[Pipeline] _OcAction
[Pipeline] echo
new-app myNewApp 4 objects named: [imagestream/portal-server, buildconfig/portal-server, deployment/portal-server, service/portal-server]

When i type command oc get all in the DEV project, console returns:

➜  ~ oc get all -l app=portal-server
NAME                                    DESIRED   CURRENT   READY     AGE
replicationcontroller/portal-server-1   1         1         1         14h

NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/portal-server   ClusterIP   172.33.120.216   <none>        8080/TCP   14h

NAME                                               REVISION   DESIRED   CURRENT   TRIGGERED BY
deploymentconfig.apps.openshift.io/portal-server   1          1         1         config,image(portal-server:latest)

NAME                                           TYPE      FROM         LATEST
buildconfig.build.openshift.io/portal-server   Source    Git@master   1

NAME                                       TYPE      FROM          STATUS     STARTED        DURATION
build.build.openshift.io/portal-server-1   Source    Git@30a1fc8   Complete   14 hours ago   1m13s

NAME                                           DOCKER REPO                                               TAGS        UPDATED
imagestream.image.openshift.io/portal-server   docker-registry.default.svc:5000/xxx-dev/portal-server   v8,latest   14 hours ago

NAME                                     HOST/PORT                                        PATH      SERVICES        PORT       TERMINATION   WILDCARD
route.route.openshift.io/portal-server   portal-server-xxx-dev.paas-dev.xxx.xx.xxx.br             portal-server   8080-tcp                 None

oc get all in the STAGING environment

➜  ~ oc get all -l app=portal-server
NAME                                    DESIRED   CURRENT   READY     AGE
replicationcontroller/portal-server-1   1         1         1         14h

NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/portal-server   ClusterIP   172.33.120.216   <none>        8080/TCP   14h

NAME                                               REVISION   DESIRED   CURRENT   TRIGGERED BY
deploymentconfig.apps.openshift.io/portal-server   1          1         1         config,image(portal-server:latest)

NAME                                           TYPE      FROM         LATEST
buildconfig.build.openshift.io/portal-server   Source    Git@master   1

NAME                                       TYPE      FROM          STATUS     STARTED        DURATION
build.build.openshift.io/portal-server-1   Source    Git@30a1fc8   Complete   14 hours ago   1m13s

NAME                                           DOCKER REPO                                               TAGS        UPDATED
imagestream.image.openshift.io/portal-server   docker-registry.default.svc:5000/xxx-dev/portal-server   v8,latest   14 hours ago

NAME                                     HOST/PORT                                        PATH      SERVICES        PORT       TERMINATION   WILDCARD
route.route.openshift.io/portal-server   portal-server-xxx-xxx.xxx-xx.xxx.xxx.xx.br             portal-server   8080-tcp                 None

DEBUG openshift.verbose() in TEST

Verbose sub-step output:
    Command> oc --server=https://172.33.0.1:443 --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt --namespace=cliente-dev --loglevel=8 --token=XXXXX new-app https://github.com/williamcaban/podcicd.git#master --name=portal-server --context-dir=myapp -e BUILD_NUMBER=10 -e BUILD_ENV=cliente-dev -e PROFILE=cliente-homolog -e SPRING_PROFILES_ACTIVE=cliente-homolog -e BUILD_ENV=cliente-dev -o=json 
    Status> 0
    StdOut>{
    "kind": "List",
    "apiVersion": "v1",
    "metadata": {},
    "items": [
        {
            "kind": "ImageStream",
            "apiVersion": "image.openshift.io/v1",
            "metadata": {
                "name": "portal-server",
                "creationTimestamp": null,
                "labels": {
                    "app": "portal-server",
                    "app.kubernetes.io/component": "portal-server",
                    "app.kubernetes.io/instance": "portal-server"
                },
                "annotations": {
                    "openshift.io/generated-by": "OpenShiftNewApp"
                }
            },
            "spec": {
                "lookupPolicy": {
                    "local": false
                }
            },
            "status": {
                "dockerImageRepository": ""
            }
        },
        {
            "kind": "BuildConfig",
            "apiVersion": "build.openshift.io/v1",
            "metadata": {
                "name": "portal-server",
                "creationTimestamp": null,
                "labels": {
                    "app": "portal-server",
                    "app.kubernetes.io/component": "portal-server",
                    "app.kubernetes.io/instance": "portal-server"
                },
                "annotations": {
                    "openshift.io/generated-by": "OpenShiftNewApp"
                }
            },
            "spec": {
                "triggers": [
                    {
                        "type": "GitHub",
                        "github": {
                            "secret": "ZAq2r-NZG18AWKafzlvA"
                        }
                    },
                    {
                        "type": "Generic",
                        "generic": {
                            "secret": "OFnLdPbJ_9FCET-sd0XM"
                        }
                    },
                    {
                        "type": "ConfigChange"
                    },
                    {
                        "type": "ImageChange",
                        "imageChange": {}
                    }
                ],
                "source": {
                    "type": "Git",
                    "git": {
                        "uri": "https://github.com/williamcaban/podcicd.git",
                        "ref": "master"
                    },
                    "contextDir": "myapp"
                },
                "strategy": {
                    "type": "Source",
                    "sourceStrategy": {
                        "from": {
                            "kind": "ImageStreamTag",
                            "namespace": "openshift",
                            "name": "python:3.6"
                        }
                    }
                },
                "output": {
                    "to": {
                        "kind": "ImageStreamTag",
                        "name": "portal-server:latest"
                    }
                },
                "resources": {},
                "postCommit": {},
                "nodeSelector": null
            },
            "status": {
                "lastVersion": 0
            }
        },
        {
            "kind": "DeploymentConfig",
            "apiVersion": "apps.openshift.io/v1",
            "metadata": {
                "name": "portal-server",
                "creationTimestamp": null,
                "labels": {
                    "app": "portal-server",
                    "app.kubernetes.io/component": "portal-server",
                    "app.kubernetes.io/instance": "portal-server"
                },
                "annotations": {
                    "openshift.io/generated-by": "OpenShiftNewApp"
                }
            },
            "spec": {
                "strategy": {
                    "resources": {}
                },
                "triggers": [
                    {
                        "type": "ConfigChange"
                    },
                    {
                        "type": "ImageChange",
                        "imageChangeParams": {
                            "automatic": true,
                            "containerNames": [
                                "portal-server"
                            ],
                            "from": {
                                "kind": "ImageStreamTag",
                                "name": "portal-server:latest"
                            }
                        }
                    }
                ],
                "replicas": 1,
                "test": false,
                "selector": {
                    "deploymentconfig": "portal-server"
                },
                "template": {
                    "metadata": {
                        "creationTimestamp": null,
                        "labels": {
                            "deploymentconfig": "portal-server"
                        },
                        "annotations": {
                            "openshift.io/generated-by": "OpenShiftNewApp"
                        }
                    },
                    "spec": {
                        "containers": [
                            {
                                "name": "portal-server",
                                "image": "portal-server:latest",
                                "ports": [
                                    {
                                        "containerPort": 8080,
                                        "protocol": "TCP"
                                    }
                                ],
                                "env": [
                                    {
                                        "name": "BUILD_ENV",
                                        "value": "cliente-dev"
                                    },
                                    {
                                        "name": "BUILD_NUMBER",
                                        "value": "10"
                                    },
                                    {
                                        "name": "PROFILE",
                                        "value": "cliente-homolog"
                                    },
                                    {
                                        "name": "SPRING_PROFILES_ACTIVE",
                                        "value": "cliente-homolog"
                                    }
                                ],
                                "resources": {}
                            }
                        ]
                    }
                }
            },
            "status": {
                "latestVersion": 0,
                "observedGeneration": 0,
                "replicas": 0,
                "updatedReplicas": 0,
                "availableReplicas": 0,
                "unavailableReplicas": 0
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "metadata": {
                "name": "portal-server",
                "creationTimestamp": null,
                "labels": {
                    "app": "portal-server",
                    "app.kubernetes.io/component": "portal-server",
                    "app.kubernetes.io/instance": "portal-server"
                },
                "annotations": {
                    "openshift.io/generated-by": "OpenShiftNewApp"
                }
            },
            "spec": {
                "ports": [
                    {
                        "name": "8080-tcp",
                        "protocol": "TCP",
                        "port": 8080,
                        "targetPort": 8080
                    }
                ],
                "selector": {
                    "deploymentconfig": "portal-server"
                }
            },
            "status": {
                "loadBalancer": {}
            }
        }
    ]
}

DEBUG openshift.verbose() in STAGING

found the following oc executables on the target computer of OS type UNIX: [/usr/bin/oc, /bin/oc]
Verbose sub-step output:
Command> oc --server=https://172.30.0.1:443 --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt --namespace=cliente-staging-teste-deploy --loglevel=8 --token=XXXXX new-app https://github.com/williamcaban/podcicd.git#master --name=portal-server --context-dir=myapp -e BUILD_NUMBER=74 -e BUILD_ENV=cliente-staging-teste-deploy -e PROFILE=cliente-staging-homolog -e SPRING_PROFILES_ACTIVE=cliente-staging-homolog -e BUILD_ENV=cliente-staging-teste-deploy -o=json 
Status> 0
StdOut>
{
  "kind": "List",
  "apiVersion": "v1",
  "metadata": {},
  "items": [
    {
      "kind": "ImageStream",
      "apiVersion": "image.openshift.io/v1",
      "metadata": {
        "name": "portal-server",
        "creationTimestamp": null,
        "labels": {
          "app": "portal-server",
          "app.kubernetes.io/component": "portal-server",
          "app.kubernetes.io/instance": "portal-server"
        },
        "annotations": {
          "openshift.io/generated-by": "OpenShiftNewApp"
        }
      },
      "spec": {
        "lookupPolicy": {
          "local": false
        }
      },
      "status": {
        "dockerImageRepository": ""
      }
    },
    {
      "kind": "BuildConfig",
      "apiVersion": "build.openshift.io/v1",
      "metadata": {
        "name": "portal-server",
        "creationTimestamp": null,
        "labels": {
          "app": "portal-server",
          "app.kubernetes.io/component": "portal-server",
          "app.kubernetes.io/instance": "portal-server"
        },
        "annotations": {
          "openshift.io/generated-by": "OpenShiftNewApp"
        }
      },
      "spec": {
        "triggers": [
          {
            "type": "GitHub",
            "github": {
              "secret": "tbBy8iXl3E2umFulVp2O"
            }
          },
          {
            "type": "Generic",
            "generic": {
              "secret": "3GdqYXEXAcJDPoyHlBjH"
            }
          },
          {
            "type": "ConfigChange"
          },
          {
            "type": "ImageChange",
            "imageChange": {}
          }
        ],
        "source": {
          "type": "Git",
          "git": {
            "uri": "https://github.com/williamcaban/podcicd.git",
            "ref": "master"
          },
          "contextDir": "myapp"
        },
        "strategy": {
          "type": "Source",
          "sourceStrategy": {
            "from": {
              "kind": "ImageStreamTag",
              "namespace": "openshift",
              "name": "python:3.6"
            }
          }
        },
        "output": {
          "to": {
            "kind": "ImageStreamTag",
            "name": "portal-server:latest"
          }
        },
        "resources": {},
        "postCommit": {},
        "nodeSelector": null
      },
      "status": {
        "lastVersion": 0
      }
    },
    {
      "kind": "Deployment",
      "apiVersion": "apps/v1",
      "metadata": {
        "name": "portal-server",
        "creationTimestamp": null,
        "labels": {
          "app": "portal-server",
          "app.kubernetes.io/component": "portal-server",
          "app.kubernetes.io/instance": "portal-server"
        },
        "annotations": {
          "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"portal-server:latest\"},\"fieldPath\":\"spec.template.spec.containers[?(@.name==\\\"portal-server\\\")].image\"}]",
          "openshift.io/generated-by": "OpenShiftNewApp"
        }
      },
      "spec": {
        "replicas": 1,
        "selector": {
          "matchLabels": {
            "deployment": "portal-server"
          }
        },
        "template": {
          "metadata": {
            "creationTimestamp": null,
            "labels": {
              "deployment": "portal-server"
            },
            "annotations": {
              "openshift.io/generated-by": "OpenShiftNewApp"
            }
          },
          "spec": {
            "containers": [
              {
                "name": "portal-server",
                "image": " ",
                "ports": [
                  {
                    "containerPort": 8080,
                    "protocol": "TCP"
                  }
                ],
                "env": [
                  {
                    "name": "BUILD_ENV",
                    "value": "cliente-staging-teste-deploy"
                  },
                  {
                    "name": "BUILD_NUMBER",
                    "value": "74"
                  },
                  {
                    "name": "PROFILE",
                    "value": "cliente-staging-homolog"
                  },
                  {
                    "name": "SPRING_PROFILES_ACTIVE",
                    "value": "cliente-staging-homolog"
                  }
                ],
                "resources": {}
              }
            ]
          }
        },
        "strategy": {}
      },
      "status": {}
    },
    {
      "kind": "Service",
      "apiVersion": "v1",
      "metadata": {
        "name": "portal-server",
        "creationTimestamp": null,
        "labels": {
          "app": "portal-server",
          "app.kubernetes.io/component": "portal-server",
          "app.kubernetes.io/instance": "portal-server"
        },
        "annotations": {
          "openshift.io/generated-by": "OpenShiftNewApp"
        }
      },
      "spec": {
        "ports": [
          {
            "name": "8080-tcp",
            "protocol": "TCP",
            "port": 8080,
            "targetPort": 8080
          }
        ],
        "selector": {
          "deployment": "portal-server"
        }
      },
      "status": {
        "loadBalancer": {}
      }
    }
  ]
}

who can create deploymentconfig in STAGING

➜  ~ oc adm policy who-can create deploymentconfig
Namespace: cliente-staging-teste-deploy
Verb:      create
Resource:  deploymentconfigs.apps.openshift.io

Users:  admin
        system:admin
        system:serviceaccount:ci-cd:jenkins
        system:serviceaccount:kube-service-catalog:default
        system:serviceaccount:kube-system:clusterrole-aggregation-controller
        system:serviceaccount:openshift-ansible-service-broker:asb
        system:serviceaccount:openshift-infra:template-instance-controller
        system:serviceaccount:openshift-infra:template-instance-finalizer-controller

Groups: system:cluster-admins
        system:masters
        system:serviceaccounts:ci-cd:jenkins

I don't understand why newApp not create the deploymentconfig. Anybody can help me? Regards

openshift-bot commented 4 years ago

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

openshift-bot commented 3 years ago

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity. Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten /remove-lifecycle stale

openshift-bot commented 3 years ago

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen. Mark the issue as fresh by commenting /remove-lifecycle rotten. Exclude this issue from closing again by commenting /lifecycle frozen.

/close

openshift-ci-robot commented 3 years ago

@openshift-bot: Closing this issue.

In response to [this](https://github.com/openshift/jenkins-client-plugin/issues/342#issuecomment-751344843): >Rotten issues close after 30d of inactivity. > >Reopen the issue by commenting `/reopen`. >Mark the issue as fresh by commenting `/remove-lifecycle rotten`. >Exclude this issue from closing again by commenting `/lifecycle frozen`. > >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.