Skip to content

Commit 4705a99

Browse files
committed
feat(controller): add globalproxysettings crd
Signed-off-by: Oliver Bähler <[email protected]>
1 parent 67b34ac commit 4705a99

File tree

17 files changed

+712
-137
lines changed

17 files changed

+712
-137
lines changed

Makefile

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,14 @@ helm-destroy:
129129
.PHONY: e2e
130130
e2e: e2e-build e2e-install e2e-exec
131131

132-
.PHONY: e2e-exec
133-
e2e-exec:
132+
.PHONY: e2e-legacy-exec
133+
e2e-legacy-exec:
134134
@./e2e/run.bash $${CLIENT_TEST:-kubectl}-$${CAPSULE_PROXY_MODE:-https}
135135

136+
.PHONY: e2e-exec
137+
e2e-exec: ginkgo
138+
$(GINKGO) -v -tags e2e ./e2e
139+
136140
.PHONY: e2e-build
137141
e2e-build:
138142
@echo "Building kubernetes env using Kind $${KIND_K8S_VERSION:-v1.27.0}..."
@@ -151,7 +155,7 @@ e2e-install: install-capsule install-capsule-proxy rbac-fix
151155
.PHONY: e2e-load-image
152156
e2e-load-image: ko-build-all
153157
@echo "Loading Docker image..."
154-
@kind load docker-image --name capsule --nodes capsule-worker $(CAPSULE_PROXY_IMG):$(VERSION)
158+
@kind load docker-image --name capsule $(CAPSULE_PROXY_IMG):$(VERSION)
155159

156160
.PHONY: e2e-destroy
157161
e2e-destroy:
@@ -185,7 +189,8 @@ ifeq ($(CAPSULE_PROXY_MODE),http)
185189
--set "kind=DaemonSet" \
186190
--set "daemonset.hostNetwork=true" \
187191
--set "serviceMonitor.enabled=false" \
188-
--set "options.generateCertificates=false"
192+
--set "options.generateCertificates=false" \
193+
--set "options.extraArgs={--feature-gates=ProxyClusterScoped=true,--feature-gates=ProxyAllNamespaced=true}"
189194
else
190195
@echo "Running in HTTPS mode"
191196
@echo "capsule proxy certificates..."
@@ -194,19 +199,19 @@ else
194199
&& kubectl --namespace capsule-system create secret generic capsule-proxy --from-file=tls.key=./127.0.0.1-key.pem --from-file=tls.crt=./127.0.0.1.pem --from-literal=ca=$$(cat $(ROOTCA) | base64 |tr -d '\n')
195200
@echo "kubeconfig configurations..."
196201
@cd hack \
197-
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- alice oil capsule.clastix.io \
202+
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- alice oil projectcapsule.dev,capsule.clastix.io \
198203
&& mv alice-oil.kubeconfig alice.kubeconfig \
199204
&& KUBECONFIG=alice.kubeconfig kubectl config set clusters.kind-capsule.certificate-authority-data $$(cat $(ROOTCA) | base64 |tr -d '\n') \
200205
&& KUBECONFIG=alice.kubeconfig kubectl config set clusters.kind-capsule.server https://127.0.0.1:9001 \
201-
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- bob gas capsule.clastix.io \
206+
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- bob gas projectcapsule.dev,capsule.clastix.io \
202207
&& mv bob-gas.kubeconfig bob.kubeconfig \
203208
&& KUBECONFIG=bob.kubeconfig kubectl config set clusters.kind-capsule.certificate-authority-data $$(cat $(ROOTCA) | base64 |tr -d '\n') \
204209
&& KUBECONFIG=bob.kubeconfig kubectl config set clusters.kind-capsule.server https://127.0.0.1:9001 \
205-
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- joe gas capsule.clastix.io,foo.clastix.io \
210+
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- joe gas projectcapsule.dev,capsule.clastix.io,foo.clastix.io \
206211
&& mv joe-gas.kubeconfig foo.clastix.io.kubeconfig \
207212
&& KUBECONFIG=foo.clastix.io.kubeconfig kubectl config set clusters.kind-capsule.certificate-authority-data $$(cat $(ROOTCA) | base64 |tr -d '\n') \
208213
&& KUBECONFIG=foo.clastix.io.kubeconfig kubectl config set clusters.kind-capsule.server https://127.0.0.1:9001 \
209-
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- dave soil capsule.clastix.io,bar.clastix.io \
214+
&& curl -s https://raw.githubusercontent.com/projectcapsule/capsule/main/hack/create-user.sh | bash -s -- dave soil projectcapsule.dev,capsule.clastix.io,bar.clastix.io \
210215
&& mv dave-soil.kubeconfig dave.kubeconfig \
211216
&& kubectl --kubeconfig=dave.kubeconfig config set clusters.kind-capsule.certificate-authority-data $$(cat $(ROOTCA) | base64 |tr -d '\n') \
212217
&& kubectl --kubeconfig=dave.kubeconfig config set clusters.kind-capsule.server https://127.0.0.1:9001
@@ -219,8 +224,10 @@ else
219224
--set "service.nodePort=" \
220225
--set "kind=DaemonSet" \
221226
--set "daemonset.hostNetwork=true" \
222-
--set "serviceMonitor.enabled=false"
227+
--set "serviceMonitor.enabled=false" \
228+
--set "options.extraArgs={--feature-gates=ProxyClusterScoped=true,--feature-gates=ProxyAllNamespaced=true}"
223229
endif
230+
@kubectl rollout restart ds capsule-proxy -n capsule-system || true
224231

225232
rbac-fix:
226233
@echo "RBAC customization..."
@@ -258,6 +265,11 @@ CONTROLLER_GEN_VERSION = v0.8.0
258265
controller-gen: ## Download controller-gen locally if necessary.
259266
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION))
260267

268+
GINKGO := $(shell pwd)/bin/ginkgo
269+
GINKGO_VERSION = 2.19.0
270+
ginkgo: ## Download ginkgo locally if necessary.
271+
$(call go-install-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION))
272+
261273
MKCERT = $(shell pwd)/bin/mkcert
262274
MKCERT_VERSION = v1.4.4
263275
mkcert: ## Download mkcert locally if necessary.

PROJECT

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: clastix.io
26
layout:
37
- go.kubebuilder.io/v3
@@ -16,4 +20,11 @@ resources:
1620
kind: ProxySettings
1721
path: github.com/projectcapsule/capsule-proxy/api/v1beta1
1822
version: v1beta1
23+
- api:
24+
crdVersion: v1
25+
domain: clastix.io
26+
group: capsule
27+
kind: GlobalProxySettings
28+
path: github.com/projectcapsule/capsule-proxy/api/v1beta1
29+
version: v1beta1
1930
version: "3"

api/v1beta1/clusterresoure.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ type ClusterResource struct {
2626
Operations []ClusterResourceOperation `json:"operations"`
2727

2828
// Select all cluster scoped resources with the given label selector.
29+
// Defining a selector which does not match any resources is considered not selectable (eg. using operation NotExists).
2930
Selector *metav1.LabelSelector `json:"selector"`
3031
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2020-2023 Project Capsule Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1beta1
5+
6+
import (
7+
"github.com/projectcapsule/capsule/api/v1beta2"
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
)
10+
11+
// GlobalProxySettingsSpec defines the desired state of GlobalProxySettings.
12+
type GlobalProxySettingsSpec struct {
13+
// Subjects that should receive additional permissions.
14+
// The subjects are selected based on the oncoming requests. They don't have to relate to an existing tenant.
15+
// However they must be part of the capsule-user groups.
16+
// +kubebuilder:validation:MinItems=1
17+
Rules []GlobalSubjectSpec `json:"rules"`
18+
}
19+
20+
type GlobalSubjectSpec struct {
21+
// Subjects that should receive additional permissions.
22+
// The subjects are selected based on the oncoming requests. They don't have to relate to an existing tenant.
23+
// However they must be part of the capsule-user groups.
24+
Subjects []GlobalSubject `json:"subjects"`
25+
// Cluster Resources for tenant Owner.
26+
ClusterResources []ClusterResource `json:"clusterResources,omitempty"`
27+
}
28+
29+
type GlobalSubject struct {
30+
// Kind of tenant owner. Possible values are "User", "Group", and "ServiceAccount".
31+
Kind v1beta2.OwnerKind `json:"kind"`
32+
// Name of tenant owner.
33+
Name string `json:"name"`
34+
}
35+
36+
//+kubebuilder:object:root=true
37+
//+kubebuilder:subresource:status
38+
//+kubebuilder:resource:scope=Cluster
39+
40+
// GlobalProxySettings is the Schema for the globalproxysettings API.
41+
type GlobalProxySettings struct {
42+
metav1.TypeMeta `json:",inline"`
43+
metav1.ObjectMeta `json:"metadata,omitempty"`
44+
45+
Spec GlobalProxySettingsSpec `json:"spec,omitempty"`
46+
}
47+
48+
//+kubebuilder:object:root=true
49+
50+
// GlobalProxySettingsList contains a list of GlobalProxySettings.
51+
type GlobalProxySettingsList struct {
52+
metav1.TypeMeta `json:",inline"`
53+
metav1.ListMeta `json:"metadata,omitempty"`
54+
Items []GlobalProxySettings `json:"items"`
55+
}
56+
57+
//nolint:gochecknoinits
58+
func init() {
59+
SchemeBuilder.Register(&GlobalProxySettings{}, &GlobalProxySettingsList{})
60+
}

api/v1beta1/zz_generated.deepcopy.go

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

charts/capsule-proxy/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ If you only need to make minor customizations, you can specify them on the comma
7979

8080
| Key | Type | Default | Description |
8181
|-----|------|---------|-------------|
82-
| crds.install | bool | `false` | Install the CustomResourceDefinitions (This also manages the lifecycle of the CRDs for update operations) |
82+
| crds.annnotations | object | `{}` | Extra Annotations for CRDs |
83+
| crds.install | bool | `true` | Install the CustomResourceDefinitions (This also manages the lifecycle of the CRDs for update operations) |
8384
| crds.keep | bool | `true` | Keep the CustomResourceDefinitions (when the chart is deleted) |
85+
| crds.labels | object | `{}` | Extra Labels for CRDs |
8486

8587
### Global Parameters
8688

@@ -121,8 +123,10 @@ If you only need to make minor customizations, you can specify them on the comma
121123
| Key | Type | Default | Description |
122124
|-----|------|---------|-------------|
123125
| affinity | object | `{}` | Set affinity rules for the capsule-proxy pod. |
124-
| crds.install | bool | `false` | Install the CustomResourceDefinitions (This also manages the lifecycle of the CRDs for update operations) |
126+
| crds.annnotations | object | `{}` | Extra Annotations for CRDs |
127+
| crds.install | bool | `true` | Install the CustomResourceDefinitions (This also manages the lifecycle of the CRDs for update operations) |
125128
| crds.keep | bool | `true` | Keep the CustomResourceDefinitions (when the chart is deleted) |
129+
| crds.labels | object | `{}` | Extra Labels for CRDs |
126130
| daemonset.hostNetwork | bool | `false` | Use the host network namespace for capsule-proxy pod. |
127131
| daemonset.hostPort | bool | `false` | Binding the capsule-proxy listening port to the host port. |
128132
| env | list | `[]` | Additional environment variables |

0 commit comments

Comments
 (0)