Skip to content

Commit

Permalink
Merge pull request #22 from dnvgl/image-automation
Browse files Browse the repository at this point in the history
Image automation
  • Loading branch information
areicher authored Mar 19, 2023
2 parents ab5137d + 52f502d commit a8844d4
Show file tree
Hide file tree
Showing 10 changed files with 421 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ helm dependency update
This will download a versioned tgz file into a charts subfolder.

*The requirements.lock and tgz files should be added to source control

## Development

### Testing

The current test approach involves generating output results with various inputs, and then manually validating the results against previous runs. Separate results are created for different test cases. New behavior should include additional test cases. Test cases are listed in the /testing/generate-reults.sh script.

Please run /testing/generate-results.sh and compare results to previous before submitting PR. Include the result output with the commit/PR.

### Version

The chart version is currently manually managed. Update the `version` in /charts/platform-service/Charts.yaml
2 changes: 1 addition & 1 deletion charts/platform-service/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
appVersion: "1.1"
description: Platform service chart
name: platform-service
version: 1.1.2
version: 1.2.0
10 changes: 10 additions & 0 deletions charts/platform-service/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ If release name contains chart name it will be used as a full name.
{{ include "platform-service.name" . }}.{{ .Release.Namespace }}.svc.cluster.local
{{- end -}}

{{- define "platform-service.imageRepository" -}}
{{- if .Values.image.full -}}
{{ fail "image automation is incompatible with full image format" }}
{{- else if .Values.image.registry -}}
{{ .Values.image.registry }}/{{ .Values.image.repository }}
{{- else -}}
{{ .Values.image.repository }}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
Expand Down
13 changes: 13 additions & 0 deletions charts/platform-service/templates/image-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.image.fluxAutomation.enabled -}}
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImagePolicy
metadata:
name: {{ include "platform-service.name" . }}
spec:
imageRepositoryRef:
name: {{ include "platform-service.name" . }}
{{- if .Values.image.fluxAutomation.filterTags }}
filterTags: {{ .Values.image.fluxAutomation.filterTags | toYaml | nindent 4 }}
{{- end }}
policy: {{ (required "policy is required when fluxAutomation is enabled" .Values.image.fluxAutomation.policy) | toYaml | nindent 4 }}
{{- end }}
9 changes: 9 additions & 0 deletions charts/platform-service/templates/image-repository.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- if .Values.image.fluxAutomation.enabled -}}
apiVersion: image.toolkit.fluxcd.io/v1beta1
kind: ImageRepository
metadata:
name: {{ include "platform-service.name" . }}
spec:
image: "{{ include "platform-service.imageRepository" . }}"
interval: {{ .Values.image.fluxAutomation.interval }}
{{- end }}
9 changes: 9 additions & 0 deletions charts/platform-service/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ image:
pullSecret:
containerPort: 80

fluxAutomation:
enabled: false
interval: 1m0s
#filterTags:
# pattern: '^dev-(?P<build>.*)'
# extract: '$build'
policy:
numerical:
order: asc
# deploymentOnly -- This workload is an addon to another for the same app - only create the deployment and destination rule
deploymentOnly: false

Expand Down
11 changes: 11 additions & 0 deletions testing/generate-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ helm template test-release ../charts/platform-service -n test-ns -f values.yaml
--show-only templates/deployment.yaml \
> results/full-image-syntax.yaml

helm template test-release ../charts/platform-service -n test-ns -f values.yaml \
--set image.fluxAutomation.enabled=true \
--debug \
> results/default-image-automation.yaml

helm template test-release ../charts/platform-service -n test-ns -f values.yaml \
--set image.fluxAutomation.enabled=true,image.fluxAutomation.filterTags.pattern='^dev-(?P<build>.*)',image.fluxAutomation.filterTags.extract='$build',image.fluxAutomation.policy.numerical.order=asc \
--show-only templates/image-policy.yaml \
--show-only templates/image-repository.yaml \
--debug \
> results/image-automation-options.yaml

echo " *** kubeval results ***"
kubeval --ignore-missing-schemas results/*.yaml
Expand Down
Loading

0 comments on commit a8844d4

Please sign in to comment.