# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: kf.dev/v1alpha1
kind: KfSystem
metadata:
  name: kfsystem
spec:
  kf:
    # This flag determines whether Kf should be installed in the cluster.
    enabled: false
    # Kf related settings goes here.
    config:
      _example: |
        ################################
        #                              #
        #    EXAMPLE CONFIGURATION     #
        #                              #
        ################################

        # This block is not actually functional configuration,
        # but serves to illustrate the available configuration
        # options and document them in a way that is accessible
        # to users that `kubectl edit` this config map.
        #
        # These sample configuration options may be copied out of
        # this example block and unindented to be in the data block
        # to actually change the configuration.
        secrets:
          # Enable Workload Identity (WI) by setting googleServiceAccount to a Google
          # Service Account. If left empty, then WI is disabled and a
          # 'build.imagePushSecrets' is required. More information about WI can be
          # found here:
          # https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identit
          workloadidentity:
            googleprojectid: "project-id"
            googleserviceaccount: "some-gsa"
          build:
            imagePushSecrets: "kf-build-key"

        # spaceContainerRegistry is the default container registry to assign to
        # spaces.
        spaceContainerRegistry: gcr.io/my-project

        # spaceClusterDomains contains an ordered list of default domains to be
        # injected into spaces. The value must be a valid JSON or YAML array.
        #
        # Each entry in the list must be an object with a `domain` property.
        # This property contains a string representation of the domain.
        #
        # It MAY contain the following two varaible substitutions:
        # - $(SPACE_NAME) - The name of the space
        # - $(CLUSTER_INGRESS_IP) - The ingress IP of the cluster
        #
        # It's recommended (but not required) that all domains contain the $(SPACE_NAME)
        # substitution to prevent apps in different spaces from conflicting.
        #
        # An optional second property 'gatewayName' can set which Istio Gateway
        # corresponding routes will assign to themselves. The 'gatewayName' field
        # is a string of the form 'kf/some-gateway', where `some-gateway' is a
        # Gateway resource in the 'kf' Namespace.
        #
        # If 'gatewayName' is not set, the default 'kf/external-gateway' is used.
        spaceClusterDomains:
          - domain: $(SPACE_NAME).prod.example.com
          - domain: $(SPACE_NAME).kf.us-east1.prod.example.com
          - domain: $(SPACE_NAME).$(CLUSTER_INGRESS_IP).nip.io
          - domain: $(SPACE_NAME)-apps.internal
            gatewayName: kf/internal-gateway

        # BuildpacksV2LifecycleImage is the image URL for the V2 buildpack
        # lifecycle binaries. It is expected to contain the `launcher` and
        # `builder` binaries AND to self extract those binaries into /workspace.
        buildpacksV2LifecycleImage: "ko://code.cloudfoundry.org/buildpackapplifecycle/installer"

        # spaceBuildpacksV2 contains an ordered list of default buildpacks to be
        # used for CF compatible builds. The value must be a valid JSON or YAML
        # string.
        #
        # Each entry in the list must be an object with `name` and `url` propreties
        # indicating the human readable name of the buildpack and the URL to
        # fetch it from at runtime. An additional `disabled` property can be used
        # to disable a single buildpack.
        spaceBuildpacksV2:
          - name: name-of-buildpack
            url:  https://github.com/cloudfoundry/name-of-buildpack
            disabled: false

        # spaceStacksV2 contains list of default stacks to be used for CF compatible
        # builds. The value must be a valid JSON or YAML string.
        #
        # Each entry in the list must be an object with `name` and `image`
        # propreties indicating the human readable name of the stack and the docker
        # image that will be used by the apps/buildpacks that run on it.
        #
        # Use images tagged with SHAs to improve build caching.
        spaceStacksV2:
          - name:  cflinuxfs3
            image: cloudfoundry/cflinuxfs3

        # spaceStacksV3 contains list of default stacks to be used for cloud native
        # buildpack builds. The value must be a valid JSON or YAML string.
        #
        # Additional stacks can be discovered using `pack suggest-stacks`
        #
        # Each entry in the list must be an object with the following properties:
        # - `name` - the name of the stack to be specified in the app manifest
        # - `description` - a description of the stack
        # - `buildImage` - the buildpack builder image
        # - `runImage` - the base image of the produced application
        # - `nodeSelector` - list of nodeSelectors
        spaceStacksV3:
          - name: heroku-18
            description: The official Heroku stack based on Ubuntu 18.04
            buildImage: heroku/pack:18-build
            runImage: heroku/pack:18
            nodeSelector:
              kubernetes.io/os: windows

        # spaceDefaultToV3Stack will make spaces use v3 stacks by default if set to
        # true. This will only affect apps without a stack specified in the manifest.
        spaceDefaultToV3Stack: "true"

        # routeServiceProxyImage is the container image used in the PodSpec of the K8s Deployment
        # created by Kf for every Route Service instance. This deployment acts as a proxy for the route
        # service. It adds the `X-Cf-Forwarded-URL` header to each request before forwarding to the route service.
        routeServiceProxyImage: "ko://github.com/google/kf/v2/route-service-proxy-src"

        # featureFlags allow certain features to be toggled on or off.
        # Feature flag names that are not supported by Kf will be ignored.
        # disable_custom_builds - Prevents builds with a kind other than "built-in" from being submitted.
        featureFlags:
          disable_custom_builds: false
          enable_dockerfile_builds: true
          enable_custom_buildpacks: true
          enable_custom_stacks: true
          enable_some_feature: true

        # The following images are used to execute builds. They SHOULD NOT be
        # modified except in rare circumstances.
        buildHelpersImage: "ko://github.com/google/kf/v2/cmd/build-helpers"
        buildKanikoExecutorImage: "gcr.io/kaniko-project/executor:latest"
        buildInfoImage: "kf-release-repository/build-info:kf-version"
        buildTokenDownloadImage: "gcr.io/google.com/cloudsdktool/cloud-sdk:slim"
