Skip to content

Migrate to devfile/api v1alpha2 and add conversion webhooks. #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b62c112
Update scripts to grab devfile/api DevWorkspaceTemplates
amisevsk Nov 9, 2020
34e8837
Update project latest devfile/api
amisevsk Nov 9, 2020
42d3506
Update Makefile to generate v1 CRDs and add a few rules
amisevsk Nov 10, 2020
c65655e
Update go code to use v1alpha2 devfile/api
amisevsk Nov 10, 2020
db8edf4
Regenerate deepcopy, crds after updating to v1alpha2
amisevsk Nov 10, 2020
0b213fe
Clean up unused templates kustomize directories
amisevsk Nov 12, 2020
b4bcc9e
Add yaml templates for generating certs using cert-manager
amisevsk Nov 12, 2020
c2e6c41
Add templates for deploying controller with cert-manager on k8s
amisevsk Nov 12, 2020
7837690
Rename config/devel to config/base
amisevsk Nov 12, 2020
d37dc52
Update webhooks server to create conversion webhooks
amisevsk Nov 13, 2020
3cd22e7
Workaround: uninstall CRDs when running make install
amisevsk Nov 16, 2020
145e464
Make webhooks handle both v1alpha1 and v1alpha2 DevWorkspaces
amisevsk Nov 17, 2020
a41126b
Fix deployment templates TODOs around namespace and service name
amisevsk Nov 17, 2020
5593e46
Fix rest APIs generator to manually set v1alpha2 defaults
amisevsk Nov 17, 2020
c2ccf22
fixup namespace for certificates
amisevsk Nov 17, 2020
453e5fe
Add support for Service CA operator on OpenShift
amisevsk Nov 24, 2020
54f05a4
fixup go.mod
amisevsk Nov 24, 2020
2c8c08a
Test fix for running locally on minikube
amisevsk Nov 24, 2020
28a8107
Adapt code to use new format for Attributes
davidfestal Nov 16, 2020
4367041
Update the samples to use v1alpha2
davidfestal Nov 18, 2020
ee92eb6
Add the all-in-one sample to validate plugins
davidfestal Nov 18, 2020
10f5a7d
Use the initContainer library
davidfestal Nov 19, 2020
51e99fb
Update subresource CRDs
amisevsk Nov 24, 2020
8b2dbb8
Adapt to attributes + fix endpoints
davidfestal Nov 19, 2020
ed9335e
Additional small fixes
davidfestal Nov 20, 2020
f3a91d1
Add "get devworkspaces" permission to workspace SA rbac
amisevsk Nov 24, 2020
b3a6596
Update to the latest changes ...
davidfestal Nov 23, 2020
f436169
Add gitignore entry for binary debug file
amisevsk Nov 24, 2020
a824a02
Format all files and regenerate CRDs
amisevsk Nov 24, 2020
41bbd3f
Restore old samples to v1alpha1 state
amisevsk Nov 24, 2020
c4a4a2a
Adapt initContainer library tests to use v1alpha2
amisevsk Nov 24, 2020
347a494
Fixups from review: cleanup Makefile, constant names, error message
amisevsk Nov 25, 2020
402dd32
Fix default DEVWORKSPACE_API_VERSION in Makefile
amisevsk Nov 25, 2020
6c382c6
Remove workaround for kubectl hang when updating resources
amisevsk Nov 25, 2020
d07a663
Fix variable redeclaration issue
amisevsk Nov 25, 2020
8d0ce24
Add loglines for which certs are used for serving webhooks
amisevsk Nov 25, 2020
7cdb46e
Fixups from review
amisevsk Nov 25, 2020
e442355
Update devfile/api dependency and clean up related scripts
amisevsk Nov 25, 2020
cedfe3d
Rework how initContainer components are added to a workspace
amisevsk Nov 25, 2020
ef02001
Fix name prefixing issue for cert-manager deployment
amisevsk Nov 25, 2020
fbb2adc
Fix openshift-oauth after v1alpha2 changes
sleshchenko Nov 26, 2020
e44d34e
Reorganize config directory and add a bit of documentation
amisevsk Nov 26, 2020
d1c3aab
Remove rules for bundling from Makefile as they are out of date
amisevsk Nov 26, 2020
9485a2b
Remove installing CRDs from e2e test as that rule has been removed
amisevsk Nov 27, 2020
e7e788d
Fix detecting the type of devfile/api version
sleshchenko Nov 27, 2020
933cd78
Fix _init_devworkspace_crds in CI
amisevsk Nov 27, 2020
0a612c6
Make sure defaulted fields are set in the default dockerimage component
amisevsk Nov 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
devworkspace-crds
config/crd/bases/workspace.devfile.io_devworkspaces.yaml
config/crd/bases/workspace.devfile.io_devworkspacetemplates.yaml
testbin
.vscode
__debug_bin

# Binaries for programs and plugins
*.exe
Expand Down
83 changes: 48 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ SHELL := bash
.SHELLFLAGS = -ec
.ONESHELL:

ifndef VERBOSE
MAKEFLAGS += --silent
endif

export NAMESPACE ?= devworkspace-controller
export IMG ?= quay.io/devfile/devworkspace-controller:next
export ROUTING_SUFFIX ?= 192.168.99.100.nip.io
export PULL_POLICY ?= Always
export WEBHOOK_ENABLED ?= true
export DEFAULT_ROUTING ?= basic
REGISTRY_ENABLED ?= true
DEVWORKSPACE_API_VERSION ?= v1alpha1
DEVWORKSPACE_API_VERSION ?= aeda60d4361911da85103f224644bfa792498499

#internal params
INTERNAL_TMP_DIR=/tmp/devworkspace-controller
Expand Down Expand Up @@ -64,7 +68,7 @@ endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
CRD_OPTIONS ?= "crd:crdVersions=v1,trivialVersions=true"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand All @@ -89,9 +93,12 @@ _print_vars:
_create_namespace:
$(K8S_CLI) create namespace $(NAMESPACE) || true

_generate_related_images_env:
@mkdir -p $(INTERNAL_TMP_DIR)
_gen_configuration_env:
mkdir -p $(INTERNAL_TMP_DIR)
echo "export RELATED_IMAGE_devworkspace_webhook_server=$(IMG)" > $(RELATED_IMAGES_FILE)
ifeq ($(PLATFORM),kubernetes)
echo "export WEBHOOK_SECRET_NAME=devworkspace-operator-webhook-cert" >> $(RELATED_IMAGES_FILE)
endif
cat ./config/components/manager/manager.yaml \
| yq -r \
'.spec.template.spec.containers[]?.env[] | select(.name | startswith("RELATED_IMAGE")) | "export \(.name)=\"$${\(.name):-\(.value)}\""' \
Expand Down Expand Up @@ -131,7 +138,7 @@ manager: generate fmt vet

# it's easier to bump whole kubeconfig instead of grabbing cluster URL from the current context
_bump_kubeconfig:
@mkdir -p $(INTERNAL_TMP_DIR)
mkdir -p $(INTERNAL_TMP_DIR)
ifndef KUBECONFIG
$(eval CONFIG_FILE = ${HOME}/.kube/config)
else
Expand All @@ -140,20 +147,20 @@ endif
cp $(CONFIG_FILE) $(BUMPED_KUBECONFIG)

_login_with_devworkspace_sa:
@$(eval SA_TOKEN := $(shell $(K8S_CLI) get secrets -o=json -n $(NAMESPACE) | jq -r '[.items[] | select (.type == "kubernetes.io/service-account-token" and .metadata.annotations."kubernetes.io/service-account.name" == "default")][0].data.token' | base64 --decode ))
@echo "Logging as controller's SA in $(NAMESPACE)"
$(eval SA_TOKEN := $(shell $(K8S_CLI) get secrets -o=json -n $(NAMESPACE) | jq -r '[.items[] | select (.type == "kubernetes.io/service-account-token" and .metadata.annotations."kubernetes.io/service-account.name" == "default")][0].data.token' | base64 --decode ))
echo "Logging as controller's SA in $(NAMESPACE)"
oc login --token=$(SA_TOKEN) --kubeconfig=$(BUMPED_KUBECONFIG)

### run: Run against the configured Kubernetes cluster in ~/.kube/config
run: _print_vars _generate_related_images_env _bump_kubeconfig _login_with_devworkspace_sa
run: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa
source $(RELATED_IMAGES_FILE)
export KUBECONFIG=$(BUMPED_KUBECONFIG)
CONTROLLER_SERVICE_ACCOUNT_NAME=default \
WATCH_NAMESPACE=$(NAMESPACE) \
go run ./main.go


debug: _print_vars _generate_related_images_env _bump_kubeconfig _login_with_devworkspace_sa
debug: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa
source $(RELATED_IMAGES_FILE)
export KUBECONFIG=$(BUMPED_KUBECONFIG)
CONTROLLER_SERVICE_ACCOUNT_NAME=default \
Expand All @@ -166,23 +173,34 @@ install_crds: _kustomize _init_devworkspace_crds

### install: Install controller in the configured Kubernetes cluster in ~/.kube/config
install: _print_vars _kustomize _init_devworkspace_crds _create_namespace deploy_registry
mv config/devel/kustomization.yaml config/devel/kustomization.yaml.bak
mv config/devel/config.properties config/devel/config.properties.bak
mv config/devel/manager_image_patch.yaml config/devel/manager_image_patch.yaml.bak

envsubst < config/devel/kustomization.yaml.bak > config/devel/kustomization.yaml
envsubst < config/devel/config.properties.bak > config/devel/config.properties
envsubst < config/devel/manager_image_patch.yaml.bak > config/devel/manager_image_patch.yaml
$(KUSTOMIZE) build config/devel | $(K8S_CLI) apply -f - || true
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

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
ifeq ($(PLATFORM),kubernetes)
$(KUSTOMIZE) build config/cert-manager | $(K8S_CLI) apply -f - || true
else
$(KUSTOMIZE) build config/service-ca | $(K8S_CLI) apply -f - || true
endif

mv config/devel/kustomization.yaml.bak config/devel/kustomization.yaml
mv config/devel/config.properties.bak config/devel/config.properties
mv config/devel/manager_image_patch.yaml.bak config/devel/manager_image_patch.yaml
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

### restart: Restart devworkspace-controller deployment
restart:
$(K8S_CLI) rollout restart -n $(NAMESPACE) deployment/devworkspace-controller-manager

### restart_webhook: Restart devworkspace-controller webhook deployment
restart_webhook:
$(K8S_CLI) rollout restart -n $(NAMESPACE) deployment/devworkspace-webhook-server

### uninstall: Remove controller resources from the cluster
uninstall: _kustomize
# It's safer to delete all workspaces before deleting the controller; otherwise we could
Expand All @@ -191,7 +209,11 @@ uninstall: _kustomize
$(K8S_CLI) delete devworkspacetemplates.workspace.devfile.io --all-namespaces --all | true
# Have to wait for routings to be deleted in case there are finalizers
$(K8S_CLI) delete workspaceroutings.controller.devfile.io --all-namespaces --all --wait | true
kustomize build config/devel | $(K8S_CLI) delete --ignore-not-found -f -
ifeq ($(PLATFORM),kubernetes)
$(KUSTOMIZE) build config/cert-manager | $(K8S_CLI) delete --ignore-not-found -f -
else
$(KUSTOMIZE) build config/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
$(K8S_CLI) delete validatingwebhookconfigurations.admissionregistration.k8s.io controller.devfile.io --ignore-not-found
Expand Down Expand Up @@ -227,7 +249,7 @@ endif
fmt_license:
ifneq ($(shell command -v addlicense 2> /dev/null),)
@echo 'addlicense -v -f license_header.txt **/*.go'
@addlicense -v -f license_header.txt $$(find . -name '*.go')
addlicense -v -f license_header.txt $$(find . -name '*.go')
else
$(error addlicense must be installed for this rule: go get -u github.com/google/addlicense)
endif
Expand Down Expand Up @@ -268,6 +290,10 @@ else
CONTROLLER_GEN=$(shell which controller-gen)
endif

### install_cert_manager: install Cert Mananger v1.0.4 on the cluster
install_cert_manager:
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v1.0.4/cert-manager.yaml

_kustomize:
ifeq (, $(shell which kustomize))
@{ \
Expand All @@ -289,19 +315,6 @@ ifneq ($(shell operator-sdk version | cut -d , -f 1 | cut -d : -f 2 | cut -d \"
@echo 'WARN: Please use the recommended operator-sdk if you face any issue.'
endif

# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests _operator_sdk
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle

# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: help
### help: print this message
help: Makefile
Expand Down
2 changes: 1 addition & 1 deletion apis/controller/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package v1alpha1

import (
devworkspace "github.com/devfile/api/pkg/apis/workspaces/v1alpha1"
devworkspace "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
)

// Description of a devfile component's workspace additions
Expand Down
4 changes: 3 additions & 1 deletion apis/controller/v1alpha1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package v1alpha1

import (
devworkspace "github.com/devfile/api/pkg/apis/workspaces/v1alpha1"
devworkspace "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -26,6 +26,8 @@ type WorkspaceComponentSpec struct {
Components []devworkspace.Component `json:"components"`
// Commands from devfile, to be matched to components
Commands []devworkspace.Command `json:"commands,omitempty"`
// Events
Events *devworkspace.Events `json:"events,omitempty"`
}

// ComponentStatus defines the observed state of Component
Expand Down
2 changes: 1 addition & 1 deletion apis/controller/v1alpha1/workspacerouting_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package v1alpha1

import (
devworkspace "github.com/devfile/api/pkg/apis/workspaces/v1alpha1"
devworkspace "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
15 changes: 10 additions & 5 deletions apis/controller/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
25 changes: 25 additions & 0 deletions config/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
bases:
- ../components/manager
- ../components/rbac
- ../crd

generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- name: configmap
envs:
- config.properties

patchesStrategicMerge:
- manager_image_patch.yaml

vars:
- name: OPERATOR_NAMESPACE
objref:
kind: Deployment
group: apps
version: v1
name: manager
fieldref:
fieldpath: metadata.namespace
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This patch sets the image used for deployment according to environment variables.
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -11,5 +12,5 @@ spec:
image: ${IMG}
imagePullPolicy: Always
env:
- name: RELATED_IMAGE_devworkspace_webhook_server
value: ${IMG}
- name: RELATED_IMAGE_devworkspace_webhook_server
value: ${IMG}
41 changes: 41 additions & 0 deletions config/cert-manager/crd_webhooks_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Add webhooks to the devfile/api CRDs
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: devworkspaces.workspace.devfile.io
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
spec:
conversion:
strategy: Webhook
webhook:
conversionReviewVersions: ["v1"]
clientConfig:
service:
namespace: system
# Note: service name is hard-coded in pkg/webhook/server/server.go
name: devworkspace-webhookserver
path: /convert
# caBundle will be filled by cert-manager on creation
caBundle: Cg==
---
# Add webhooks to the devfile/api CRDs
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: devworkspacetemplates.workspace.devfile.io
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
spec:
conversion:
strategy: Webhook
webhook:
conversionReviewVersions: ["v1"]
clientConfig:
service:
namespace: system
# Note: service name is hard-coded in pkg/webhook/server/server.go
name: devworkspace-webhookserver
path: /convert
# caBundle will be filled by cert-manager on creation
caBundle: Cg==
42 changes: 42 additions & 0 deletions config/cert-manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Adds namespace to all resources.
namespace: ${NAMESPACE}

# Prefix for names of all resources created by this kustomization
namePrefix: devworkspace-controller-

# Labels to add to all resources and selectors.
commonLabels:
app.kubernetes.io/name: devworkspace-controller
app.kubernetes.io/part-of: devworkspace-operator

bases:
- ../base
- ../components/cert-manager

patchesStrategicMerge:
- manager_certmanager_patch.yaml
- crd_webhooks_patch.yaml

vars:
- name: WEBHOOK_CA_SECRET_NAME
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert
fieldref:
fieldpath: spec.secretName
- name: CERTIFICATE_NAMESPACE
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert
fieldref:
fieldpath: metadata.namespace
- name: CERTIFICATE_NAME
objref:
kind: Certificate
group: cert-manager.io
version: v1
name: serving-cert
Loading