Skip to content

Commit

Permalink
Reorganize templates for deploying controller
Browse files Browse the repository at this point in the history
Rework file structure from

    config
    ├── <kustomize templates>
    ├── current (untracked; dev environment)
    └── static (static deployment files)
to
    deploy
    ├── current (untracked; dev environment)
    ├── deployment (static deployment files)
    └── templates (templates from which above dirs are generated
        └── <kustomize templates>
and adjust scripts to match.

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
  • Loading branch information
amisevsk committed Feb 4, 2021
1 parent e63bf41 commit ab392ff
Show file tree
Hide file tree
Showing 81 changed files with 48 additions and 57 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ jobs:
-
name: Check manifests
run: |
git reset HEAD --hard
pip install yq
# Note: fmt is necessary after generate since generated sources will
# fail format check by default.
Expand All @@ -73,7 +72,6 @@ jobs:
-
name: Check deployment files
run: |
git reset HEAD --hard
make generate_default_deployment
if [[ ! -z $(git status -s) ]]; then
echo "Generated deployment files are out of date; run make generate_default_deployment"
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
devworkspace-crds
config/crd/bases/workspace.devfile.io_devworkspaces.yaml
config/crd/bases/workspace.devfile.io_devworkspacetemplates.yaml
config/current
deploy/templates/crd/bases/workspace.devfile.io_devworkspaces.yaml
deploy/templates/crd/bases/workspace.devfile.io_devworkspacetemplates.yaml
deploy/current
testbin
.vscode
__debug_bin
Expand Down
28 changes: 12 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ _gen_configuration_env:
ifeq ($(PLATFORM),kubernetes)
echo "export WEBHOOK_SECRET_NAME=devworkspace-operator-webhook-cert" >> $(RELATED_IMAGES_FILE)
endif
cat ./config/components/manager/manager.yaml \
cat ./deploy/templates/components/manager/manager.yaml \
| yq -r \
'.spec.template.spec.containers[]?.env[] | select(.name | startswith("RELATED_IMAGE")) | "export \(.name)=\"$${\(.name):-\(.value)}\""' \
>> $(RELATED_IMAGES_FILE)
Expand Down Expand Up @@ -175,25 +175,21 @@ debug: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworksp
WATCH_NAMESPACE=$(NAMESPACE) \
dlv debug --listen=:2345 --headless=true --api-version=2 ./main.go --

### install_crds: Install CRDs into a cluster
install_crds: _kustomize _init_devworkspace_crds
$(KUSTOMIZE) build config/crd | $(K8S_CLI) apply -f -

### install: Install controller in the configured Kubernetes cluster in ~/.kube/config
install: _print_vars _kustomize _init_devworkspace_crds _create_namespace _eval_plugin_registry_url generate_deployment
ifeq ($(PLATFORM),kubernetes)
$(K8S_CLI) apply -f config/current/kubernetes/combined.yaml || true
$(K8S_CLI) apply -f deploy/current/kubernetes/combined.yaml || true
else
$(K8S_CLI) apply -f config/current/openshift/combined.yaml || true
$(K8S_CLI) apply -f deploy/current/openshift/combined.yaml || true
endif

### generate_deployment: Generate files used for deployment from kustomize templates, using environment variables
generate_deployment:
config/generate-templates.sh
deploy/generate-deployment.sh

### generate_default_deployment: Generate files used for deployment from kustomize templates with default values
generate_default_deployment:
config/generate-templates.sh --use-defaults
deploy/generate-deployment.sh --use-defaults

### install_plugin_templates: Deploy sample plugin templates to namespace devworkspace-plugins:
install_plugin_templates: _print_vars
Expand All @@ -216,9 +212,9 @@ uninstall: _kustomize
$(K8S_CLI) delete devworkspacetemplates.workspace.devfile.io --all-namespaces --all || true
$(K8S_CLI) delete workspaceroutings.controller.devfile.io --all-namespaces --all --wait || true
ifeq ($(PLATFORM),kubernetes)
$(KUSTOMIZE) build config/cert-manager | $(K8S_CLI) delete --ignore-not-found -f -
$(KUSTOMIZE) build deploy/templates/cert-manager | $(K8S_CLI) delete --ignore-not-found -f -
else
$(KUSTOMIZE) build config/service-ca | $(K8S_CLI) delete --ignore-not-found -f -
$(KUSTOMIZE) build deploy/templates/service-ca | $(K8S_CLI) delete --ignore-not-found -f -
endif
$(K8S_CLI) delete all -l "app.kubernetes.io/part-of=devworkspace-operator" --all-namespaces
$(K8S_CLI) delete mutatingwebhookconfigurations.admissionregistration.k8s.io controller.devfile.io --ignore-not-found
Expand All @@ -227,18 +223,18 @@ endif

### deploy_registry: Deploy plugin registry
deploy_registry: _print_vars _create_namespace
$(K8S_CLI) apply -f config/registry/local -n $(NAMESPACE)
$(K8S_CLI) apply -f deploy/templates/registry/local -n $(NAMESPACE)
ifeq ($(PLATFORM),kubernetes)
envsubst < config/registry/local/k8s/ingress.yaml | $(K8S_CLI) apply -n $(NAMESPACE) -f -
envsubst < deploy/templates/registry/local/k8s/ingress.yaml | $(K8S_CLI) apply -n $(NAMESPACE) -f -
else
$(K8S_CLI) apply -f config/registry/local/os -n $(NAMESPACE)
$(K8S_CLI) apply -f deploy/templates/registry/local/os -n $(NAMESPACE)
endif

### manifests: Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=role webhook paths="./..." \
output:crd:artifacts:config=config/crd/bases \
output:rbac:artifacts:config=config/components/rbac
output:crd:artifacts:config=deploy/templates/crd/bases \
output:rbac:artifacts:config=deploy/templates/components/rbac
patch/patch_crds.sh

### fmt: Run go fmt against code
Expand Down
File renamed without changes.
File renamed without changes.
43 changes: 20 additions & 23 deletions config/generate-templates.sh → deploy/generate-deployment.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2012-2018 Red Hat, Inc.
# Copyright (c) 2019-2021 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -9,7 +9,7 @@
#
# This script builds complete deployment files for the DevWorkspace Operator,
# filling all environment variables as appropriate. The output, stored in
# config/static, contains subfolders for OpenShift and Kubernetes. Within each
# deploy/deployment, contains subfolders for OpenShift and Kubernetes. Within each
# is a file, combined.yaml, which stores all the objects involved in deploying
# the operator, and a subfolder, objects, which stores separate yaml files for
# each object in combined.yaml, with the name <object-name>.<object-kind>.yaml
Expand All @@ -26,20 +26,17 @@ set -e

SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)

DEVWORKSPACE_BRANCH=${DEVWORKSPACE_BRANCH:-master}

# If '--use-defaults' is passed, output files to config/static; otherwise
# output files to untracked directory config/current (used for development)
# If '--use-defaults' is passed, output files to deploy/deployment; otherwise
# output files to untracked directory deploy/current (used for development)
USE_DEFAULT_ENV=false
OUTPUT_DIR="${SCRIPT_DIR%/}/current"
if [ "$1" == "--use-defaults" ]; then
echo "Using defaults for environment variables"
USE_DEFAULT_ENV=true
OUTPUT_DIR="${SCRIPT_DIR%/}/static"
OUTPUT_DIR="${SCRIPT_DIR%/}/deployment"
fi

if $USE_DEFAULT_ENV; then
export DEVWORKSPACE_BRANCH=master
export NAMESPACE=devworkspace-controller
export IMG=quay.io/devfile/devworkspace-controller:next
export PULL_POLICY=Always
Expand All @@ -56,7 +53,7 @@ OBJECTS_DIR="objects"

mkdir -p "$KUBERNETES_DIR" "$OPENSHIFT_DIR"

required_vars=(DEVWORKSPACE_BRANCH NAMESPACE IMG PULL_POLICY DEFAULT_ROUTING \
required_vars=(NAMESPACE IMG PULL_POLICY DEFAULT_ROUTING \
DEVWORKSPACE_API_VERSION)
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
Expand All @@ -83,28 +80,28 @@ else
fi

# Create backups of templates with env vars
mv config/cert-manager/kustomization.yaml config/cert-manager/kustomization.yaml.bak
mv config/service-ca/kustomization.yaml config/service-ca/kustomization.yaml.bak
mv config/base/config.properties config/base/config.properties.bak
mv config/base/manager_image_patch.yaml config/base/manager_image_patch.yaml.bak
mv ${SCRIPT_DIR}/templates/cert-manager/kustomization.yaml ${SCRIPT_DIR}/templates/cert-manager/kustomization.yaml.bak
mv ${SCRIPT_DIR}/templates/service-ca/kustomization.yaml ${SCRIPT_DIR}/templates/service-ca/kustomization.yaml.bak
mv ${SCRIPT_DIR}/templates/base/config.properties ${SCRIPT_DIR}/templates/base/config.properties.bak
mv ${SCRIPT_DIR}/templates/base/manager_image_patch.yaml ${SCRIPT_DIR}/templates/base/manager_image_patch.yaml.bak

# Fill env vars in templates
envsubst < config/cert-manager/kustomization.yaml.bak > config/cert-manager/kustomization.yaml
envsubst < config/service-ca/kustomization.yaml.bak > config/service-ca/kustomization.yaml
envsubst < config/base/config.properties.bak > config/base/config.properties
envsubst < config/base/manager_image_patch.yaml.bak > config/base/manager_image_patch.yaml
envsubst < ${SCRIPT_DIR}/templates/cert-manager/kustomization.yaml.bak > ${SCRIPT_DIR}/templates/cert-manager/kustomization.yaml
envsubst < ${SCRIPT_DIR}/templates/service-ca/kustomization.yaml.bak > ${SCRIPT_DIR}/templates/service-ca/kustomization.yaml
envsubst < ${SCRIPT_DIR}/templates/base/config.properties.bak > ${SCRIPT_DIR}/templates/base/config.properties
envsubst < ${SCRIPT_DIR}/templates/base/manager_image_patch.yaml.bak > ${SCRIPT_DIR}/templates/base/manager_image_patch.yaml

# Run kustomize to build yamls
echo "Generating config for Kubernetes"
kustomize build config/cert-manager > "${KUBERNETES_DIR}/${COMBINED_FILENAME}"
kustomize build ${SCRIPT_DIR}/templates/cert-manager > "${KUBERNETES_DIR}/${COMBINED_FILENAME}"
echo "Generating config for OpenShift"
kustomize build config/service-ca > "${OPENSHIFT_DIR}/${COMBINED_FILENAME}"
kustomize build ${SCRIPT_DIR}/templates/service-ca > "${OPENSHIFT_DIR}/${COMBINED_FILENAME}"

# Restore backups to not change templates
mv config/cert-manager/kustomization.yaml.bak config/cert-manager/kustomization.yaml
mv config/service-ca/kustomization.yaml.bak config/service-ca/kustomization.yaml
mv config/base/config.properties.bak config/base/config.properties
mv config/base/manager_image_patch.yaml.bak config/base/manager_image_patch.yaml
mv ${SCRIPT_DIR}/templates/cert-manager/kustomization.yaml.bak ${SCRIPT_DIR}/templates/cert-manager/kustomization.yaml
mv ${SCRIPT_DIR}/templates/service-ca/kustomization.yaml.bak ${SCRIPT_DIR}/templates/service-ca/kustomization.yaml
mv ${SCRIPT_DIR}/templates/base/config.properties.bak ${SCRIPT_DIR}/templates/base/config.properties
mv ${SCRIPT_DIR}/templates/base/manager_image_patch.yaml.bak ${SCRIPT_DIR}/templates/base/manager_image_patch.yaml

# Split the giant files output by kustomize per-object
for dir in "$KUBERNETES_DIR" "$OPENSHIFT_DIR"; do
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
# It should be run by deploy/templates/default
resources:
- bases/controller.devfile.io_components.yaml
- bases/controller.devfile.io_workspaceroutings.yaml
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions config/kustomize.pu → deploy/templates/kustomize.pu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ skinparam Object {
AttributeFontSize 12
}

object "config/cert-manager" as certmanager {
object "templates/cert-manager" as certmanager {
- Patch controller deployment
with webhook secret name
- Patch CRDs with cert-manager
Expand All @@ -27,7 +27,7 @@ object "config/cert-manager" as certmanager {
Controller configured for k8s
and cert-manager
}
object "config/service-ca" as serviceca {
object "templates/service-ca" as serviceca {
- Patch CRDs with service-ca
annotation to inject webhooks
and certificate
Expand All @@ -39,7 +39,7 @@ object "config/service-ca" as serviceca {
and Service CA
}

object "config/base" as base {
object "templates/base" as base {
- Create default configmap for
controller
- Patch image used for controller
Expand All @@ -48,7 +48,7 @@ object "config/base" as base {
Basic controller with no webhooks;
namespace and namePrefix unconfigured
}
object "config/crd" as crd {
object "templates/crd" as crd {
- Combine all defined CRDs
- Set configuration to allow
kustomize to inject namespace,
Expand All @@ -57,20 +57,20 @@ object "config/crd" as crd {
List of CRDs to be deployed
}

object "config/components/manager" as manager {
object "templates/components/manager" as manager {
- Store deployment.yaml for controller
--Output--
deployment spec for controller
}
object "config/components/rbac" as rbac {
object "templates/components/rbac" as rbac {
- Store autogenerated RBAC files for
controller
- Includes aggregated roles for edit/view
--Output--
Cluster roles/rolebindings used by
controller and CRDs
}
object "config/components/cert-manager" as certs {
object "templates/components/cert-manager" as certs {
- Configure a self-signed issuer and
a self-signed certificate on the cluster
- Configure kustomize to allow referencing
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions patch/patch_crds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

set -e

COMPONENTS_CRD_PATH="config/crd/bases/controller.devfile.io_components.yaml"
ROUTINGS_CRD_PATH="config/crd/bases/controller.devfile.io_workspaceroutings.yaml"
COMPONENTS_CRD_PATH="deploy/templates/crd/bases/controller.devfile.io_components.yaml"
ROUTINGS_CRD_PATH="deploy/templates/crd/bases/controller.devfile.io_workspaceroutings.yaml"

# CRD path from root to status field, in jq filter format
STATUS_PATH='.spec.versions[].schema.openAPIV3Schema.properties["status"]'
Expand Down
6 changes: 3 additions & 3 deletions update_devworkspace_crds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fi
SCRIPT_DIR=$(cd "$(dirname "$0")" || exit; pwd)

if [[ ($INIT_ONLY -eq 1) &&
(-f "$SCRIPT_DIR/config/crd/bases/workspace.devfile.io_devworkspaces.yaml") &&
(-f "$SCRIPT_DIR/config/crd/bases/workspace.devfile.io_devworkspacetemplates.yaml")]]; then
(-f "$SCRIPT_DIR/deploy/templates/crd/bases/workspace.devfile.io_devworkspaces.yaml") &&
(-f "$SCRIPT_DIR/deploy/templates/crd/bases/workspace.devfile.io_devworkspacetemplates.yaml")]]; then
echo "CRDs from devfile/api are already initialized"
exit 0
fi
Expand All @@ -58,6 +58,6 @@ else
fi
cp crds/workspace.devfile.io_devworkspaces.yaml \
crds/workspace.devfile.io_devworkspacetemplates.yaml \
$SCRIPT_DIR/config/crd/bases/
$SCRIPT_DIR/deploy/templates/crd/bases/

cd $SCRIPT_DIR

0 comments on commit ab392ff

Please sign in to comment.