Environment Custom Resource

2 minute read
On this page

When you request a preview environment, the CloudBees Previews webhook creates an Environment Custom Resource (CR) that provides all the information needed for the Environment operator component to create the environment.

Environment

The Environment describes the state of the environment that is created.

Example Environment Custom Resource
kind: Environment
apiVersion: environment.cloudbees.com/v1alpha1
metadata:
  name: acme-web-pr-1-default
  namespace: preview
  annotations:                                                      (1)
    git-clone-url: 'https://github.com/acme/acme-web.git'
    git-kind: github
    git-server: 'https://github.com'
    pr-clone-url: 'https://github.com/acme/acme-web.git'
    pr-number: '1'
    pr-ref: issue-1
    pr-sha: 67f379b3be900712a543a2dea4eadda9e4aa86e6
    preview-context: default
    repo-name: acme-web
    repo-namespace: acme
spec:
  context: default                                                  (2)
  source:
    name: acme-web                                                  (3)
    owner: acme                                                     (4)
    server: 'https://github.com'                                    (5)
    sha: 67f379b3be900712a543a2dea4eadda9e4aa86e6                   (6)
    secretRef:
      name: acme-github-token                                       (7)
  detector:
    image: 'eu.gcr.io/wombat-dev-283614/environment-detector:0.0.4' (8)
1Kubernetes annotations providing all required information about base and pull request repositories.
2Name of the preview context for which the environment is created.
3Repository name containing the sources and preview configuration.
4Namespace/owner of the repository.
5Base URL of the SCM provider.
6Git SHA to check out and use to create the environment.
7Reference to the secret containing the OAuth token for the source repository.
8Image to run in order to detect, parse, and configure the environment creation pipeline.

During the provisioning of the environment, CloudBees Previews makes several updates to the Environment CR, recording the state of the deployment. The two most important status updates are the detection and deployment results.

Detection result

CloudBees Previews adds the detection result to the Environment CR after it has parsed the .preview.yaml configuration. The detection result lists the configured preview contexts specified in .preview.yaml and which context was selected. It also shows the pipeline it executes to create the environment.

Example DetectionResult
status:
  detectionResult:
    availableContexts:
      - default
      - debug-context
    context: default
    deployer:
      args:
        - deploy
      env:
        - name: ENV_RESOURCE_DIR
          value: /workspace/target/k8s/manifest.yaml
      image: 'eu.gcr.io/wombat-dev-283614/environment-deployer:0.0.12'              (1)
    observedGeneration: 1
    pipeline:
        image: 'eu.gcr.io/wombat-dev-283614/environment-manifest-generator:0.0.3'   (2)
        name: manifest-generator
    undeployer:
      args:
        - undeploy
      image: 'eu.gcr.io/wombat-dev-283614/environment-deployer:0.0.12'              (3)
1The default CloudBees Preview deployer is used to deploy the Kubernetes resources.
2The manifest generator image is used to generate Kubernetes resources. This indicates that the selected default context used generated manifests.
3The name of the repository that contains the sources and preview configuration.

Deployment result

The last status to get recorded in the Environment CR is the deployment result. In a successful deployment, it contains the URL to the preview environment that was created.

Example DeploymentResult
status:
  deploymentResult:
    observedGeneration: 1
    urls:
      - url: 'http://104.198.25.48:31677'