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: 'cloudbees/environment-detector:0.10.0'                  (8)
1 Kubernetes annotations providing all required information about base and pull request repositories.
2 Name of the preview context for which the environment is created.
3 Repository name containing the sources and preview configuration.
4 Namespace/owner of the repository.
5 Base URL of the SCM provider.
6 Git SHA to check out and use to create the environment.
7 Reference to the secret containing the OAuth token for the source repository.
8 Image 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: 'cloudbees/environment-deployer:0.5.3'                  (1)
    observedGeneration: 1
    pipeline:
        image: 'cloudbees/environment-manifest-generator:1.0.1'      (2)
        name: manifest-generator
    undeployer:
      args:
        - undeploy
      image: 'cloudbees/environment-deployer:0.5.3'                  (3)
1 The default CloudBees Preview deployer is used to deploy the Kubernetes resources.
2 The manifest generator image is used to generate Kubernetes resources. This indicates that the selected default context used generated manifests.
3 The 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'