gitlab autodeploy to kubernetes/openshift: error: no match for ":master"

4/5/2017

I'm trying to handle kubernetes (openshift origin) autodeploy. ci-config is below.

As far as I understand CI should get the code, check for a dockerfile, if it is not present (and it is not) — build herokuish container and push it to kubernetes. But I get an error:

$ command deploy
Generating kubeconfig...
Cluster "gitlab-deploy" set.
User "gitlab-deploy" set.
Context "gitlab-deploy" set.
Switched to context "gitlab-deploy".

Running on OpenShift.
Deleting old application...
No resources found

Creating application...
error: no match for ":master"

CI:

# Explanation on the scripts:
# https://gitlab.com/gitlab-examples/openshift-deploy/blob/master/README.md
image: registry.gitlab.com/gitlab-examples/openshift-deploy
services:
  - mysql:5.7
variables:
  # Application deployment domain
  KUBE_DOMAIN: kub.kub.myopenshift.com
  MYSQL_DATABASE: database
  MYSQL_ROOT_PASSWORD: secret
cache:
  key: "$CI_BUILD_REF_NAME"
  untracked: true
  paths:
    - vendor/
    - .env
stages:
  #- build
  #- test
  - review
  - staging
  - production
  - cleanup
#build:
#  stage: build
#  script:
#    - composer install --ignore-platform-reqs
#    - cp .env.testing .env
#  only:
#    - branches
#test:
#  stage: test
#  script:
#    - php vendor/bin/phpunit --colors
#  only:
#    - branches
production:
  stage: production
  variables:
    CI_ENVIRONMENT_URL: http://$CI_PROJECT_NAME.$KUBE_DOMAIN
  script:
    - command deploy
  environment:
    name: production
    url: http://$CI_PROJECT_NAME.$KUBE_DOMAIN
  when: manual
  only:
    - master
staging:
  stage: staging
  variables:
    CI_ENVIRONMENT_URL: http://$CI_PROJECT_NAME-staging.$KUBE_DOMAIN
  script:
    - command deploy
  environment:
    name: staging
    url: http://$CI_PROJECT_NAME-staging.$KUBE_DOMAIN
  only:
    - master
review:
  stage: review
  variables:
    CI_ENVIRONMENT_URL: http://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$KUBE_DOMAIN
  script:
    - command deploy
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: http://$CI_PROJECT_NAME-$CI_ENVIRONMENT_SLUG.$KUBE_DOMAIN
    on_stop: stop_review
  only:
    - branches
  except:
    - master
stop_review:
  stage: cleanup
  variables:
    GIT_STRATEGY: none
  script:
    - command destroy
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop
  when: manual
  only:
    - branches
  except:
    - master

What am I doing wrong? Does something should be additionally set up in openshift?

-- Terion
deployment
gitlab
gitlab-ci
kubernetes
openshift-origin

1 Answer

4/12/2017

Without doing all the steps here, I just tried the command from the step where it fails for you, in the deploy script.

oc new-app "--name=${CI_ENVIRONMENT_SLUG}" "$CI_REGISTRY_IMAGE:$CI_REGISTRY_TAG"

I ran similar command in my OpenShift environment, I am guessing your environment variable CI_REGISTRY_IMAGE is not set, so the script is taking it's empty value.

I ran

$ oc new-app :master
error: no match for ":master"

The 'oc new-app' command will match arguments to the following types:

  1. Images tagged into image streams in the current project or the 'openshift' project
     - if you don't specify a tag, we'll add ':latest'
  2. Images in the Docker Hub, on remote registries, or on the local Docker engine
  3. Templates in the current project or the 'openshift' project
  4. Git repository URLs or local paths that point to Git repositories

--allow-missing-images can be used to point to an image that does not exist yet.

See 'oc new-app -h' for examples.

Checkout the error which is similar to the one you got:

error: no match for ":master"

So try exporting that environment variable.

-- surajd
Source: StackOverflow