/tektoncd-pipeline-operator

tektoncd-pipeline operator for Kubernetes to manage installation, updation and uninstallation of tekton-cd pipelines.

Primary LanguageGoApache License 2.0Apache-2.0

Tektoncd-operator

Dev env

Checkout your fork

The Go tools require that you clone the repository to the src/github.com/openshift/tektoncd-pipeline-operator directory in your GOPATH.

To check out this repository:

  1. Create your own fork of this repo
  2. Clone it to your machine:
mkdir -p ${GOPATH}/src/github.com/openshift
cd ${GOPATH}/src/github.com/openshift
git clone git@github.com:${YOUR_GITHUB_USERNAME}/tektoncd-pipeline-operator.git
cd tektoncd-pipeline-operator
git remote add upstream git@github.com:tektoncd/tektoncd-pipeline-operator.git
git remote set-url --push upstream no_push

Prerequisites

You must install these tools:

  1. go: The language Tektoncd-pipeline-operator is built in
  2. git: For source control
  3. dep: For managing external Go dependencies. - Please Install dep v0.5.0 or greater.
  4. kubectl: For interacting with your kube cluster
  5. operator-sdk: https://github.com/operator-framework/operator-sdk
  6. minikube: https://kubernetes.io/docs/tasks/tools/install-minikube/

Install Minikube

Create minikube instance

minikube start -p mk-tekton \
 --cpus=4 --memory=8192 --kubernetes-version=v1.12.0 \
 --extra-config=apiserver.enable-admission-plugins="LimitRanger,NamespaceExists,NamespaceLifecycle,ResourceQuota,ServiceAccount,DefaultStorageClass,MutatingAdmissionWebhook"  \
 --extra-config=apiserver.service-node-port-range=80-32767

Set docker env

eval $(minikube docker-env -p mk-tekton)

Development build

  1. Change directory to '${GOPATH}/src/github.com/openshift/tektoncd-pipeline-operator'
cd ${GOPATH}/src/github.com/openshift/tektoncd-pipeline-operator
  1. Build go and docker image
operator-sdk build ${YOUR_REGISTORY}/openshift-pipelines-operator:${IMAGE_TAG}
  1. Push docker image
docker push ${YOUR-REGISTORY}/openshift-pipelines-operator:${IMAGE-TAG}
  1. Edit the 'image' value in deploy/operator.yaml to match to your image

Install OLM

Clone OLM repository (into go path)

git clone git@github.com:operator-framework/operator-lifecycle-manager.git \
          $GOPATH/src/github.com/operator-framework/

Install OLM

Ensure minikube is installed and docker env is set see above

cd $GOPATH/src/github.com/operator-framework/operator-lifecycle-manager
GO111MODULE=on NO_MINIKUBE=true make run-local

NOTE: NO_MINIKUBE=true: we don't want to start a new minikube instance while installing OLM

Launch web console

Open a new terminal

cd $GOPATH/src/github.com/operator-framework/operator-lifecycle-manager
./scripts/run_console_local.sh

Deploy openshift-pipelines-operator on minikube for testing

  1. Change directory to ${GOPATH}/src/github.com/openshift/tektoncd-pipeline-operator

  2. Create openshift-pipelines-operator namespace

    kubectl create namespace openshift-pipelines-operator

  3. Apply operator crd

    kubectl apply -f deploy/crds/*_crd.yaml

  4. Deploy the operator

    kubectl apply -f deploy/ -n openshift-pipelines-operator

  5. Install pipeline by creating an Install CR

    kubectl apply -f deploy/crds/*_cr.yaml

Deploy openshift-pipelines-operator using CatalogSource on OLM

  1. Install minikube see above

  2. Install olm see above

  3. Add local catalog source

    kubectl apply -f olm/openshift-pipelines-operator.resources.yaml

    Once the CatalogSource has been applied, you should find it under Catalog > Operator Management of the web console

  4. Subscribe to Openshift Pipelines Operator

    1. Open web console

    2. Select openshift-pipelines-operator namespace

    3. Select Catalog > Operator Management

    4. Select Catalog > Operator Management > Operator Catalogs

    5. Scroll down to Openshift Pipelines Operator under Openshift Pipelines Operator Registry

      NOTE: it will take a few minutes to appear after applying the catalogsource

    6. Click Create Subscription button

      1. ensure namespace in yaml is openshift-pipelines-operator e.g.

        sample subscription
          apiVersion: operators.coreos.com/v1alpha1
          kind: Subscription
          metadata:
            generateName: openshift-pipelines-operator-
            namespace: openshift-pipelines-operator
          spec:
            source: openshift-pipelines-operator-registry
            sourceNamespace: openshift-pipelines-operator
            name: openshift-pipelines-operator
            startingCSV: openshift-pipelines-operator.v0.3.1
            channel: alpha
      2. Click Create button at the bottom

  5. Verify operator is installed successfully

    1. Select Catalog > Installed operators
    2. Look for Status InstallSucceeded
  6. Install Tektoncd-Pipeline by creating an install CR

    1. Select Catalog > Developer Catalog, you should find Openshift Pipelines Install

    2. Click on it and it should show the Operator Details Panel

    3. Click on Create which show an example as below

      example
          apiVersion: tekton.dev/v1alpha1
          kind: Install
          metadata:
          name: pipelines-install
          namespace: openshift-pipelines-operator
          spec: {}

      NOTE: This will install Openshift Pipeline resources in Tekton-Pipelines Namespace

    4. Verify that the pipeline is installed

      1. Ensure pipeline pods are running

        kubectl get all -n tekton-pipelines

      2. Ensure pipeline crds exist

        kubectl get crds | grep tekton

        should show

        clustertasks.tekton.dev
        installs.tekton.dev
        pipelineresources.tekton.dev
        pipelineruns.tekton.dev
        pipelines.tekton.dev
        taskruns.tekton.dev
        tasks.tekton.dev

    NOTE: Now TektonCD Pipelines can be created and run

End to End workflow

This section explains how to test changes to the operator by executing the entire end-to-end workflow of edit, test, build, package, etc...

It asssumes you have already followed install minikube and OLM.

Generate new image, CSV

  1. Make changes to the operator
  2. Test operator locally with operator-sdk up local
  3. Build operator image operator-sdk build <imagename:tag>
  4. Update image reference in deploy/operator.yaml
  5. Update image reference in CSV deploy/olm-catalog/openshift-pipelines-operator/0.3.1/openshift-pipelines-operator.v0.3.1.clusterserviceversion.yaml

Update Local CatalogSource

    1. Build local catalog source localOperators

    ./scripts/olm_catalog.sh > olm/openshift-pipelines-operator.resources.yaml