Skip to content

Commit

Permalink
Refactor using Kustomize to deploy VPA
Browse files Browse the repository at this point in the history
  • Loading branch information
DebakelOrakel committed Oct 17, 2024
1 parent 00b4566 commit 916b0b1
Show file tree
Hide file tree
Showing 65 changed files with 1,466 additions and 1,941 deletions.
3 changes: 1 addition & 2 deletions .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ ignore: |
vendor/
compiled/
.cache/
tests/golden/defaults/vertical-pod-autoscaler/vertical-pod-autoscaler/10_crds/*
tests/golden/full/vertical-pod-autoscaler/vertical-pod-autoscaler/10_crds/*
tests/golden/*/vertical-pod-autoscaler/vertical-pod-autoscaler/10_kustomize/*
4 changes: 4 additions & 0 deletions class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ parameters:
=_metadata: {}
namespace: syn-vertical-pod-autoscaler

manifestVersion: vertical-pod-autoscaler-1.2.1
kustomizeInput:
namespace: ${vertical_pod_autoscaler:namespace}

images:
vpa_admission_controller:
registry: registry.k8s.io
Expand Down
20 changes: 12 additions & 8 deletions class/vertical-pod-autoscaler.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
parameters:
kapitan:
dependencies:
- type: https
source: https://raw.githubusercontent.com/kubernetes/autoscaler/vertical-pod-autoscaler-${vertical_pod_autoscaler:images:vpa_recommender:tag}/vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml
output_path: ${_base_directory}/dependencies/vertical-pod-autoscaler/vpa-v1-crd-gen.yaml

compile:
- input_paths:
- ${_base_directory}/component/app.jsonnet
Expand All @@ -14,7 +9,16 @@ parameters:
- ${_base_directory}/component/main.jsonnet
input_type: jsonnet
output_path: vertical-pod-autoscaler/
# kustomize
- input_paths:
- ${_base_directory}/dependencies/vertical-pod-autoscaler/vpa-v1-crd-gen.yaml
input_type: copy
output_path: vertical-pod-autoscaler/10_crds/
- ${_base_directory}/component/vpa.jsonnet
input_type: jsonnet
output_path: ${_base_directory}/manifests/vpa
- input_paths:
- ${_kustomize_wrapper}
input_type: external
output_path: .
env_vars:
INPUT_DIR: ${_base_directory}/manifests/vpa
args:
- \${compiled_target_dir}/${_instance}/10_kustomize/vpa
93 changes: 0 additions & 93 deletions component/adm_controller.jsonnet

This file was deleted.

45 changes: 32 additions & 13 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,37 @@ local namespacedName(name, namespace='') = {
name: if std.length(namespacedName) > 1 then namespacedName[1] else namespacedName[0],
};

local cert_manager_issuer = {
apiVersion: 'cert-manager.io/v1',
kind: 'Issuer',
metadata: {
name: 'vpa-admission-controller',
namespace: params.namespace,
},
spec: {
selfSigned: {},
},
};

local cert_manager_cert = {
apiVersion: 'cert-manager.io/v1',
kind: 'Certificate',
metadata: {
name: 'vpa-admission-controller',
},
spec: {
secretName: 'vpa-tls-certs',
dnsNames: [
'%(service)s.%(namespace)s.svc' % { service: 'vpa-webhook', namespace: params.namespace },
],
issuerRef: {
name: 'vpa-admission-controller',
kind: 'Issuer',
group: 'cert-manager.io',
},
},
};

local vpa_resources() = [
local vpa = std.get(params.autoscaler, name);
{
Expand All @@ -48,22 +79,10 @@ local vpa_resources() = [
for name in std.objectFields(params.autoscaler)
];

local adm_controller = import 'adm_controller.jsonnet';
local recommender = import 'recommender.jsonnet';
local updater = import 'updater.jsonnet';
local rbac = import 'rbac.jsonnet';

// Define outputs below
{
'00_namespace': namespace,

'20_recommender': recommender.deployment,
[if params.allow_autoscaling then '30_adm_controller']: adm_controller.deployment,
[if params.allow_autoscaling then '40_updater']: updater.deployment,

'50_cluster_roles': rbac.cluster_roles,
'50_aggregated_cluster_roles': rbac.aggregated_cluster_roles,
'50_cluster_role_bindings': rbac.cluster_role_bindings,

[if params.allow_autoscaling then '50_vpa_certs']: [ cert_manager_issuer, cert_manager_cert ],
[if std.length(params.autoscaler) > 0 then '60_vpa_resources']: vpa_resources(),
}
Loading

0 comments on commit 916b0b1

Please sign in to comment.