Skip to content

Commit 3aad4fd

Browse files
Inplace resize support (#33)
* add new rule in pod mutatingwebhook to cath the updates of the pod's resize subresource * add new function for make overcommit on resize operations * fix overcommit test * check if the request is a resize operation and use his own function for overcommit * add missing SPDX header, update controller gen version in makefile * add test for resize overcommit function * update kuttl version in CI * update kind cluster version to 1.35 for E2E test * fix kind config file * update E2E dependencies * add E2E test for patch resize operation * fix expected requests in resize e2e test * add missing SPDX headers in inplace resize tests
1 parent 8aa7276 commit 3aad4fd

17 files changed

Lines changed: 242 additions & 117 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ jobs:
2222

2323
- name: Install kubectl, helm, kind and kuttl ⬇️
2424
env:
25-
KUTTL_VERSION: '0.20.0'
26-
KUTTL_PLUGIN_FILENAME: 'kubectl-kuttl_0.20.0_linux_x86_64'
25+
KUTTL_VERSION: '0.25.0'
26+
KUTTL_PLUGIN_FILENAME: 'kubectl-kuttl_0.25.0_linux_x86_64'
2727
run: bash hack/install-dependencies.sh
2828

2929
- name: Run kind ⚙️
30-
run: kind create cluster --name kuttl-cluster
30+
run: kind create cluster --name kuttl-cluster --config ./hack/kind-config.yaml
3131

3232
- name: Mount the image in the Kind cluster ⚙️
3333
run: |
@@ -36,7 +36,7 @@ jobs:
3636
- name: Run the tests 🔎
3737
run: |
3838
echo "Running the tests"
39-
kubectl kuttl test test/e2e/ --start-kind=false
39+
kubectl kuttl test --config test/e2e/kuttl-test.yaml test/e2e/kuttl --start-kind=false
4040
4141
- name: Clean up Kind cluster ☠️
4242
if: always()

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ hack/tilt/bin
3131
hack/tilt/chart
3232

3333
*kubeconfig*
34+
35+
e2e.json

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ endif
5959
OPERATOR_SDK_VERSION ?= v1.40.0
6060

6161
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
62-
ENVTEST_K8S_VERSION = 1.31.0
62+
ENVTEST_K8S_VERSION = 1.35.0
6363

6464
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6565
ifeq (,$(shell go env GOBIN))
@@ -217,7 +217,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
217217

218218
## Tool Versions
219219
KUSTOMIZE_VERSION ?= v5.4.3
220-
CONTROLLER_TOOLS_VERSION ?= v0.16.1
220+
CONTROLLER_TOOLS_VERSION ?= v0.17.2
221221
ENVTEST_VERSION ?= release-0.19
222222
GOLANGCI_LINT_VERSION ?= v1.59.1
223223

config/crd/bases/overcommit.inditex.dev_overcommitclasses.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.1
6+
controller-gen.kubebuilder.io/version: v0.17.2
77
name: overcommitclasses.overcommit.inditex.dev
88
spec:
99
group: overcommit.inditex.dev

config/crd/bases/overcommit.inditex.dev_overcommits.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.1
6+
controller-gen.kubebuilder.io/version: v0.17.2
77
name: overcommits.overcommit.inditex.dev
88
spec:
99
group: overcommit.inditex.dev

config/webhook/manifests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ webhooks:
1313
path: /mutate--v1-pod
1414
failurePolicy: Ignore
1515
name: mutating-pod-v1.overcommit.inditex.dev
16+
reinvocationPolicy: IfNeeded
1617
rules:
1718
- apiGroups:
1819
- ""
@@ -23,6 +24,7 @@ webhooks:
2324
- UPDATE
2425
resources:
2526
- pods
27+
- pods/resize
2628
sideEffects: None
2729
---
2830
apiVersion: admissionregistration.k8s.io/v1

docs/e2e-test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Then build the image and install the test chart in the kind cluster
2424
And finally run the tests
2525

2626
```[sh]
27-
kubectl kuttl test code/test/e2e/ --config code/test/e2e/kuttl-tests.yaml --start-kind=false
27+
kubectl kuttl test --config test/e2e/kuttl-test.yaml test/e2e/kuttl --start-kind=false
2828
```

hack/install-dependencies.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
set -e
99

1010
#Kubectl
11-
curl -LO https://dl.k8s.io/release/v1.31.0/bin/linux/amd64/kubectl
11+
curl -LO https://dl.k8s.io/release/v1.35.0/bin/linux/amd64/kubectl
1212
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
1313

1414
#Helm3
@@ -22,6 +22,6 @@ sudo mv ${KUTTL_PLUGIN_FILENAME} /usr/local/bin/kubectl-kuttl
2222
sudo chmod +x /usr/local/bin/kubectl-kuttl
2323

2424
#Kind
25-
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64
25+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.31.0/kind-linux-amd64
2626
chmod +x ./kind
2727
sudo mv ./kind /usr/local/bin/kind

hack/kind-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
4+
featureGates:
5+
InPlacePodVerticalScaling: true
6+
7+
nodes:
8+
- role: control-plane
9+
image: kindest/node:v1.35.0
10+
kubeadmConfigPatches:
11+
- |
12+
kind: ClusterConfiguration
13+
apiServer:
14+
extraArgs:
15+
feature-gates: InPlacePodVerticalScaling=true
16+
controllerManager:
17+
extraArgs:
18+
feature-gates: InPlacePodVerticalScaling=true
19+
scheduler:
20+
extraArgs:
21+
feature-gates: InPlacePodVerticalScaling=true
22+
23+
- role: worker
24+
image: kindest/node:v1.35.0

internal/resources/generate_resources_pod_mutating_webhooks.go

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func getSelectorClassNotExist(label string) *metav1.LabelSelector {
175175
}
176176
}
177177

178-
func getMatchCondition(isDefault bool, name string, excludedNamespaces string, label string) []admissionv1.MatchCondition {
178+
func getMatchCondition(excludedNamespaces string) []admissionv1.MatchCondition {
179179
matchConditions := []admissionv1.MatchCondition{}
180180
matchConditions = append(matchConditions, admissionv1.MatchCondition{
181181
Name: "exclude-namespaces",
@@ -202,11 +202,36 @@ func getObjectSelector(isDefault bool, label string, name string) *metav1.LabelS
202202
}
203203

204204
func CreateMutatingWebhookConfiguration(class overcommit.OvercommitClass, svc corev1.Service, cert certmanager.Certificate, label string) *admissionv1.MutatingWebhookConfiguration {
205-
206205
var path = "/mutate--v1-pod"
207206
var scope = admissionv1.NamespacedScope
208207
var policy = admissionv1.Fail
209208
var sideEffect = admissionv1.SideEffectClassNone
209+
var reinvocationPolicy = admissionv1.IfNeededReinvocationPolicy
210+
211+
rules := []admissionv1.RuleWithOperations{
212+
{
213+
Operations: []admissionv1.OperationType{
214+
admissionv1.Create,
215+
},
216+
Rule: admissionv1.Rule{
217+
APIGroups: []string{""},
218+
APIVersions: []string{"v1"},
219+
Resources: []string{"pods"},
220+
Scope: &scope,
221+
},
222+
},
223+
{
224+
Operations: []admissionv1.OperationType{
225+
admissionv1.Update,
226+
},
227+
Rule: admissionv1.Rule{
228+
APIGroups: []string{""},
229+
APIVersions: []string{"v1"},
230+
Resources: []string{"pods/resize"},
231+
Scope: &scope,
232+
},
233+
},
234+
}
210235

211236
webhookConfig := &admissionv1.MutatingWebhookConfiguration{
212237
ObjectMeta: metav1.ObjectMeta{
@@ -225,23 +250,12 @@ func CreateMutatingWebhookConfiguration(class overcommit.OvercommitClass, svc co
225250
Path: &path,
226251
},
227252
},
228-
Rules: []admissionv1.RuleWithOperations{
229-
{
230-
Operations: []admissionv1.OperationType{
231-
admissionv1.Create,
232-
},
233-
Rule: admissionv1.Rule{
234-
APIGroups: []string{""},
235-
APIVersions: []string{"v1"},
236-
Resources: []string{"pods"},
237-
Scope: &scope,
238-
},
239-
},
240-
},
253+
Rules: rules,
241254
AdmissionReviewVersions: []string{"v1"},
242255
FailurePolicy: &policy,
243256
SideEffects: &sideEffect,
244-
MatchConditions: getMatchCondition(false, class.Name, class.Spec.ExcludedNamespaces, label),
257+
ReinvocationPolicy: &reinvocationPolicy,
258+
MatchConditions: getMatchCondition(class.Spec.ExcludedNamespaces),
245259
ObjectSelector: getObjectSelector(false, label, class.Name),
246260
},
247261
},
@@ -257,25 +271,15 @@ func CreateMutatingWebhookConfiguration(class overcommit.OvercommitClass, svc co
257271
Path: &path,
258272
},
259273
},
260-
Rules: []admissionv1.RuleWithOperations{
261-
{
262-
Operations: []admissionv1.OperationType{
263-
admissionv1.Create,
264-
},
265-
Rule: admissionv1.Rule{
266-
APIGroups: []string{""},
267-
APIVersions: []string{"v1"},
268-
Resources: []string{"pods"},
269-
Scope: &scope,
270-
},
271-
},
272-
},
274+
Rules: rules,
273275
AdmissionReviewVersions: []string{"v1"},
274276
FailurePolicy: &policy,
275277
SideEffects: &sideEffect,
276-
MatchConditions: getMatchCondition(class.Spec.IsDefault, class.Name, class.Spec.ExcludedNamespaces, label),
278+
ReinvocationPolicy: &reinvocationPolicy,
279+
MatchConditions: getMatchCondition(class.Spec.ExcludedNamespaces),
277280
ObjectSelector: getObjectSelector(class.Spec.IsDefault, label, class.Name),
278281
})
279282
}
283+
280284
return webhookConfig
281285
}

0 commit comments

Comments
 (0)