Skip to content

Commit

Permalink
Merge branch 'main' into add-policy-schema-mounts
Browse files Browse the repository at this point in the history
# Conflicts:
#	charts/kubechecks/Chart.yaml
  • Loading branch information
djeebus committed Oct 11, 2023
2 parents 2886f8c + c103274 commit 15a3e88
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 121 deletions.
4 changes: 2 additions & 2 deletions .github/ct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
remote: origin
target-branch: main
helm-extra-args: --kube-version v1.24.0
check-version-increment: false
check-version-increment: true
validate-maintainers: false
additional-commands:
- "./.github/kubeconform.sh 1.23.0 {{ .Path }}"
- "./.github/kubeconform.sh 1.24.0 {{ .Path }}"
- "./.github/kubeconform.sh 1.25.0 {{ .Path }}"
- "./.github/kubeconform.sh 1.26.0 {{ .Path }}"
- "./.github/helm-unittest.sh {{ .Path }}"
- "./.github/helm-unittest.sh {{ .Path }}"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ tilt_config.json
localdev/terraform/gitlab/project.url
*.tgz
*.DS_Store
kubechecks
/kubechecks
localdev/terraform/github/project.url
4 changes: 2 additions & 2 deletions charts/kubechecks/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
name: kubechecks
description: A Helm chart for kubechecks
version: 0.3.0
appVersion: "1.0.9"
version: 0.3.1
appVersion: "1.0.10"
type: application
maintainers:
- name: zapier
24 changes: 23 additions & 1 deletion charts/kubechecks/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{{- if .Values.autoscaling.create }}
apiVersion: autoscaling/v2beta1
{{ $apiVersion := "" }}
{{- if .Capabilities.APIVersions.Has "autoscaling/v2" }}
{{ $apiVersion = "autoscaling/v2" }}
{{- else if .Capabilities.APIVersions.Has "autoscaling/v2beta2" }}
{{ $apiVersion = "autoscaling/v2beta2" }}
{{- else if .Capabilities.APIVersions.Has "autoscaling/v2beta1" }}
{{ $apiVersion = "autoscaling/v2beta1" }}
{{- else }}
{{ fail "server has no support for autoscaling" }}
{{- end }}
apiVersion: {{ $apiVersion }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "kubechecks.fullname" . }}
Expand All @@ -17,12 +27,24 @@ spec:
- type: Resource
resource:
name: cpu
{{- if or (eq $apiVersion "autoscaling/v2") (eq $apiVersion "autoscaling/v2beta2") }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- else }}
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
{{- if or (eq $apiVersion "autoscaling/v2") (eq $apiVersion "autoscaling/v2beta2") }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- else }}
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
{{- end }}
121 changes: 121 additions & 0 deletions charts/kubechecks/tests/autoscaling_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
suite: autoscaling tests

templates:
- hpa.yaml

tests:
- it: can have v2beta1
set:
autoscaling:
create: true
targetCPUUtilizationPercentage: 10
targetMemoryUtilizationPercentage: 15
capabilities:
apiVersions:
- autoscaling/v2beta1
asserts:
- equal:
path: apiVersion
value: autoscaling/v2beta1
- equal:
path: spec.metrics[0]
value:
type: Resource
resource:
name: cpu
targetAverageUtilization: 10
- equal:
path: spec.metrics[1]
value:
type: Resource
resource:
name: memory
targetAverageUtilization: 15

- it: can have v2beta2
set:
autoscaling:
create: true
targetCPUUtilizationPercentage: 10
targetMemoryUtilizationPercentage: 15
capabilities:
apiVersions:
- autoscaling/v2beta2
asserts:
- equal:
path: apiVersion
value: autoscaling/v2beta2
- equal:
path: spec.metrics[0]
value:
type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 10
- equal:
path: spec.metrics[1]
value:
type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 15

- it: can have v2
set:
autoscaling:
create: true
targetCPUUtilizationPercentage: 10
targetMemoryUtilizationPercentage: 15
capabilities:
apiVersions:
- autoscaling/v2
asserts:
- equal:
path: apiVersion
value: autoscaling/v2
- equal:
path: spec.metrics[0]
value:
type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 10
- equal:
path: spec.metrics[1]
value:
type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 15

- it: prefers v2
set:
autoscaling:
create: true
capabilities:
apiVersions:
- autoscaling/v2beta1
- autoscaling/v2beta2
- autoscaling/v2
asserts:
- equal:
path: apiVersion
value: autoscaling/v2
- it: renders nothing with no support
set:
autoscaling:
create: true
capabilities:
apiVersions:
- autoscaling/vFake
asserts:
- failedTemplate:
errorMessage: server has no support for autoscaling
5 changes: 4 additions & 1 deletion pkg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,19 @@ func (v2a *VcsToArgoMap) GetAppsInRepo(repoCloneUrl string) *app_directory.AppDi

func (v2a *VcsToArgoMap) AddApp(app v1alpha1.Application) {
if app.Spec.Source == nil {
log.Warn().Msgf("%s/%s: no source, skipping", app.Namespace, app.Name)
return
}

rawRepoUrl := app.Spec.Source.RepoURL
cleanRepoUrl, err := normalizeRepoUrl(rawRepoUrl)
if err != nil {
log.Warn().Err(err).Msgf("failed to parse %s", rawRepoUrl)
log.Warn().Err(err).Msgf("%s/%s: failed to parse %s", app.Namespace, app.Name, rawRepoUrl)
return
}

log.Debug().Msgf("%s/%s: %s => %s", app.Namespace, app.Name, rawRepoUrl, cleanRepoUrl)

appDirectory := v2a.vcsAppStubsByRepo[cleanRepoUrl]
if appDirectory == nil {
appDirectory = app_directory.NewAppDirectory()
Expand Down
Loading

0 comments on commit 15a3e88

Please sign in to comment.