Skip to content

Commit c8dc4a9

Browse files
Merge branch 'devfile:main' into contribute
2 parents a53f8d8 + 10771f2 commit c8dc4a9

File tree

184 files changed

+11485
-1287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+11485
-1287
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Code Coverage Report
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches: [ main ]
9+
10+
jobs:
11+
coverage-report:
12+
name: Check Code Coverage
13+
runs-on: ubuntu-20.04
14+
steps:
15+
-
16+
name: Set up Go 1.x
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: 1.16.6
20+
-
21+
name: Set up Python 3.8
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: 3.8
25+
-
26+
name: Check out code into the Go module directory
27+
uses: actions/checkout@v2
28+
-
29+
name: Cache go modules
30+
id: cache-mod
31+
uses: actions/cache@v2
32+
with:
33+
path: ~/go/pkg/mod
34+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
35+
restore-keys: |
36+
${{ runner.os }}-go-
37+
-
38+
name: Download dependencies
39+
run: go mod download
40+
if: steps.cache-mod.outputs.cache-hit != 'true'
41+
-
42+
name: Run Go Tests
43+
run: |
44+
python -m pip install --upgrade pip yq
45+
make test
46+
-
47+
name: Build Codecov report
48+
uses: codecov/codecov-action@v1
49+
with:
50+
files: cover.out

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export PROJECT_CLONE_IMG ?= quay.io/devfile/project-clone:next
2929
export PULL_POLICY ?= Always
3030
export DEFAULT_ROUTING ?= basic
3131
export KUBECONFIG ?= ${HOME}/.kube/config
32-
export DEVWORKSPACE_API_VERSION ?= 32cae1f8e42c22035138ef6ee93080bc47d751c6
32+
export DEVWORKSPACE_API_VERSION ?= fe7c10eaa530b12b19cfb0e22e221e753391304c
3333

3434
# Enable using Podman instead of Docker
3535
export DOCKER ?= docker

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Dev Workspace Operator
22

3+
[![codecov](https://codecov.io/gh/devfile/devworkspace-operator/branch/main/graph/badge.svg)](https://codecov.io/gh/devfile/devworkspace-operator)
4+
35
Dev Workspace operator repository that contains the controller for the DevWorkspace Custom Resource. The Kubernetes API of the DevWorkspace is defined in the https://github.com/devfile/api repository.
46

57
## DevWorkspace CR
@@ -79,7 +81,7 @@ In order to build a custom bundle, the following env vars should be set:
7981

8082
To build the index image and register its catalogsource to the cluster, run
8183
```
82-
make generate_olm_bundle_yaml build_bundle_image build_index_image register_catalogsource
84+
make generate_olm_bundle_yaml build_bundle_and_index register_catalogsource
8385
```
8486
8587
Note that setting `DEFAULT_DWO_IMG` while generating sources will result in local changes to the repo which should be `git restored` before committing. This can also be done by unsetting the `DEFAULT_DWO_IMG` env var and re-running `make generate_olm_bundle_yaml`
@@ -180,3 +182,5 @@ This will delete all custom resource definitions created for the controller, as
180182
#### GitHub actions
181183

182184
- [Next Dockerimage](https://github.com/devfile/devworkspace-operator/blob/main/.github/workflows/dockerimage-next.yml) action builds main branch and pushes it to [quay.io/devfile/devworkspace-controller:next](https://quay.io/repository/devfile/devworkspace-controller?tag=latest&tab=tags)
185+
186+
- [Code Coverage Report](./.github/workflows/code-coverage.yml) action creates a code coverage report using [codecov.io](https://about.codecov.io/).

apis/controller/v1alpha1/devworkspaceoperatorconfig_types.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ type StorageSizes struct {
7979
PerWorkspace *resource.Quantity `json:"perWorkspace,omitempty"`
8080
}
8181

82+
type ServiceAccountConfig struct {
83+
// ServiceAccountName defines a fixed name to be used for all DevWorkspaces. If set, the DevWorkspace
84+
// Operator will not generate a separate ServiceAccount for each DevWorkspace, and will instead create
85+
// a ServiceAccount with the specified name in each namespace where DevWorkspaces are created. If specified,
86+
// the created ServiceAccount will not be removed when DevWorkspaces are deleted and must be cleaned up manually.
87+
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
88+
// +kubebuilder:validation:MaxLength=63
89+
ServiceAccountName string `json:"serviceAccountName,omitempty"`
90+
// Disable creation of DevWorkspace ServiceAccounts by the DevWorkspace Operator. If set to true, the serviceAccountName
91+
// field must also be set. If ServiceAccount creation is disabled, it is assumed that the specified ServiceAccount already
92+
// exists in any namespace where a workspace is created. If a suitable ServiceAccount does not exist, starting DevWorkspaces
93+
// will fail.
94+
DisableCreation *bool `json:"disableCreation,omitempty"`
95+
}
96+
8297
type WorkspaceConfig struct {
8398
// ImagePullPolicy defines the imagePullPolicy used for containers in a DevWorkspace
8499
// For additional information, see Kubernetes documentation for imagePullPolicy. If
@@ -95,6 +110,9 @@ type WorkspaceConfig struct {
95110
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
96111
// +kubebuilder:validation:MaxLength=63
97112
PVCName string `json:"pvcName,omitempty"`
113+
// ServiceAccount defines configuration options for the ServiceAccount used for
114+
// DevWorkspaces.
115+
ServiceAccount *ServiceAccountConfig `json:"serviceAccount,omitempty"`
98116
// StorageClassName defines an optional storageClass to use for persistent
99117
// volume claims created to support DevWorkspaces
100118
StorageClassName *string `json:"storageClassName,omitempty"`
@@ -124,10 +142,13 @@ type WorkspaceConfig struct {
124142
// but the objects will be left on the cluster). The default value is false.
125143
CleanupOnStop *bool `json:"cleanupOnStop,omitempty"`
126144
// PodSecurityContext overrides the default PodSecurityContext used for all workspace-related
127-
// pods created by the DevWorkspace Operator when running on Kubernetes. On OpenShift, this
128-
// configuration option is ignored. If set, the entire pod security context is overridden;
129-
// values are not merged.
145+
// pods created by the DevWorkspace Operator. If set, defined values are merged into the default
146+
// configuration
130147
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
148+
// ContainerSecurityContext overrides the default ContainerSecurityContext used for all
149+
// workspace-related containers created by the DevWorkspace Operator. If set, defined
150+
// values are merged into the default configuration
151+
ContainerSecurityContext *corev1.SecurityContext `json:"containerSecurityContext,omitempty"`
131152
// DefaultTemplate defines an optional DevWorkspace Spec Template which gets applied to the workspace
132153
// if the workspace's Template Spec Components are not defined. The DefaultTemplate will overwrite the existing
133154
// Template Spec, with the exception of Projects (if any are defined).

apis/controller/v1alpha1/zz_generated.deepcopy.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515

1616
# https://access.redhat.com/containers/?tab=tags#/registry.access.redhat.com/ubi8/go-toolset
17-
FROM registry.access.redhat.com/ubi8/go-toolset:1.17.7-13.1655148239 as builder
17+
FROM registry.access.redhat.com/ubi8/go-toolset:1.17.12-11 as builder
1818
ENV GOPATH=/go/
1919
USER root
2020
WORKDIR /devworkspace-operator
@@ -34,7 +34,7 @@ RUN make compile-devworkspace-controller
3434
RUN make compile-webhook-server
3535

3636
# https://access.redhat.com/containers/?tab=tags#/registry.access.redhat.com/ubi8-minimal
37-
FROM registry.access.redhat.com/ubi8-minimal:8.6-751.1655117800
37+
FROM registry.access.redhat.com/ubi8-minimal:8.6-994
3838
RUN microdnf -y update && microdnf clean all && rm -rf /var/cache/yum && echo "Installed Packages" && rpm -qa | sort -V && echo "End Of Installed Packages"
3939
WORKDIR /
4040
COPY --from=builder /devworkspace-operator/_output/bin/devworkspace-controller /usr/local/bin/devworkspace-controller

build/make/deploy.mk

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ _store_tls_cert:
6767
$(K8S_CLI) get secret devworkspace-webhookserver-tls -n $(NAMESPACE) -o json | jq -r '.data["tls.key"]' | base64 -d > /tmp/k8s-webhook-server/serving-certs/tls.key
6868
endif
6969

70+
_check_controller_running:
71+
REPLICAS=$$($(K8S_CLI) get deploy devworkspace-controller-manager -n $(NAMESPACE) -o=json | jq -r '.spec.replicas')
72+
if [ "$$REPLICAS" != "0" ]; then \
73+
echo "Controller is already running in cluster, cannot run locally. Scale controller to 0 first." ;\
74+
exit 1 ;\
75+
fi
76+
7077
### install: Install controller in the configured Kubernetes cluster in ~/.kube/config
7178
install: _print_vars _check_cert_manager _init_devworkspace_crds _create_namespace generate_deployment
7279
ifeq ($(PLATFORM),kubernetes)
@@ -124,9 +131,15 @@ _check_cert_manager:
124131
endif
125132

126133
_login_with_devworkspace_sa:
127-
$(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" == "$(DEVWORKSPACE_CTRL_SA)")][0].data.token' | base64 --decode ))
128-
echo "Logging as controller's SA in $(NAMESPACE)"
129-
oc login --token=$(SA_TOKEN) --kubeconfig=$(BUMPED_KUBECONFIG)
134+
# Kubernetes 1.23 and below: get SA token from service-account-token secret; Kubernetes 1.24 and above, use `kubectl create token`
135+
SA_TOKEN=$$($(K8S_CLI) get secrets -o=json -n $(NAMESPACE) \
136+
| jq -r '[.items[] | select (.type == "kubernetes.io/service-account-token" and .metadata.annotations."kubernetes.io/service-account.name" == "$(DEVWORKSPACE_CTRL_SA)")][0].data.token' \
137+
| base64 --decode ); \
138+
if [[ "$$SA_TOKEN" == $$(echo 'null' | base64 -d) ]]; then \
139+
SA_TOKEN=$$($(K8S_CLI) create token -n "$(NAMESPACE)" "$(DEVWORKSPACE_CTRL_SA)"); \
140+
fi; \
141+
echo "Logging as controller's SA in $(NAMESPACE)"; \
142+
oc login --token="$$SA_TOKEN" --kubeconfig=$(BUMPED_KUBECONFIG)
130143

131144
### install_cert_manager: Installs Cert Mananger v1.5.4 on the cluster
132145
install_cert_manager:
@@ -143,15 +156,15 @@ _bump_kubeconfig:
143156
cp $(CONFIG_FILE) $(BUMPED_KUBECONFIG)
144157

145158
### run: Runs against the configured Kubernetes cluster in ~/.kube/config
146-
run: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa _store_tls_cert
159+
run: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa _store_tls_cert _check_controller_running
147160
source $(CONTROLLER_ENV_FILE)
148161
export KUBECONFIG=$(BUMPED_KUBECONFIG)
149162
CONTROLLER_SERVICE_ACCOUNT_NAME=$(DEVWORKSPACE_CTRL_SA) \
150163
WATCH_NAMESPACE=$(NAMESPACE) \
151164
go run ./main.go
152165

153166
### debug: Runs the controller locally with debugging enabled, watching cluster defined in ~/.kube/config
154-
debug: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa _store_tls_cert
167+
debug: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa _store_tls_cert _check_controller_running
155168
source $(CONTROLLER_ENV_FILE)
156169
export KUBECONFIG=$(BUMPED_KUBECONFIG)
157170
CONTROLLER_SERVICE_ACCOUNT_NAME=$(DEVWORKSPACE_CTRL_SA) \

catalog-source.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ spec:
1010
displayName: DevWorkspace Operator Catalog
1111
updateStrategy:
1212
registryPoll:
13-
interval: 1d
13+
interval: 5m

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github_checks:
2+
annotations: false

controllers/controller/devworkspacerouting/solvers/basic_solver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func (s *BasicSolver) Finalize(*controllerv1alpha1.DevWorkspaceRouting) error {
5757
func (s *BasicSolver) GetSpecObjects(routing *controllerv1alpha1.DevWorkspaceRouting, workspaceMeta DevWorkspaceMetadata) (RoutingObjects, error) {
5858
routingObjects := RoutingObjects{}
5959

60-
routingSuffix := config.Routing.ClusterHostSuffix
60+
// TODO: Use workspace-scoped ClusterHostSuffix to allow overriding
61+
routingSuffix := config.GetGlobalConfig().Routing.ClusterHostSuffix
6162
if routingSuffix == "" {
6263
return routingObjects, &RoutingInvalid{"basic routing requires .config.routing.clusterHostSuffix to be set in operator config"}
6364
}

0 commit comments

Comments
 (0)