Skip to content

Commit

Permalink
Merge pull request #145 from chiayu-su/feat/add-business-id-label
Browse files Browse the repository at this point in the history
feat: add cost tag for simple chart
  • Loading branch information
chiayu-su authored Mar 15, 2024
2 parents 55552af + 55497ae commit 7807f84
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 21 deletions.
2 changes: 1 addition & 1 deletion simple/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
description: Helm chart with simple deployment/service template
name: simple
version: 0.17.2
version: 0.18.0
appVersion: 0.0.1
tillerVersion: ">=2.14.3"
7 changes: 7 additions & 0 deletions simple/templates/_ingress_multiple.tpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{{- define "ingress.ingress_multiple" -}}
{{- if eq .Values.EnableMutilpleIngress true }}
{{- $businessid := .Values.businessid }}
{{- range $ingress_name, $ref := .Values.ingress }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $ingress_name }}
labels:
businessid: {{ $businessid | quote }}
{{- with $ref.labels }}
{{- $labelsYaml := toYaml . | quote}}
{{- $labelsYaml | trim | nindent 4 }}
{{- end }}
annotations:
{{ toYaml $ref.annotations | indent 4 }}
spec:
Expand Down
6 changes: 6 additions & 0 deletions simple/templates/_ingress_single.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Values.name }}
labels:
businessid: {{ .Values.businessid | quote }}
{{- with .Values.ingress.labels }}
{{- $labelsYaml := toYaml . | quote }}
{{- $labelsYaml | trim | nindent 4 }}
{{- end }}
annotations:
{{ toYaml .Values.ingress.annotations | indent 4 }}
spec:
Expand Down
5 changes: 5 additions & 0 deletions simple/templates/_resource_tag_checker.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- define "resource_tag_checker" -}}
{{- if not .Values.businessid }}
{{ fail "businessid is a required field. Please provide a value in your values.yaml." }}
{{- end }}
{{- end -}}
10 changes: 8 additions & 2 deletions simple/templates/_service_multiple.tpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{{- define "service.service_multiple" -}}
{{- $businessid := .Values.businessid }}
{{- range $service_name, $ref := .Values.services }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ $service_name }}
annotations: {{ toYaml $ref.annotations | nindent 4 }}
labels: {{ toYaml $ref.labels | nindent 4 }}
labels:
businessid: {{ $businessid | quote }}
{{- with $ref.labels }}
{{- $labelsYaml := toYaml . | quote}}
{{- $labelsYaml | trim | nindent 4 }}
{{- end }}
spec:
{{- if and (hasKey $ref "type") (eq $ref.type "ExternalName")}}
type: {{ $ref.type}}
Expand All @@ -22,7 +28,7 @@ spec:
type: {{ $ref.type | default "ClusterIP" }}
{{- if hasKey $ref "clusterIP" }}
clusterIP: {{ $ref.clusterIP }}
{{- end }}
{{- end }}
selector:
app: {{ $ref.selector.app | default $service_name }}
{{- end }}
Expand Down
7 changes: 6 additions & 1 deletion simple/templates/_service_single.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ kind: Service
metadata:
name: {{ .Values.name }}
annotations: {{ toYaml .Values.service.annotations | nindent 4 }}
labels: {{ toYaml .Values.service.labels | nindent 4 }}
labels:
businessid: {{ .Values.businessid | quote }}
{{- with .Values.service.labels }}
{{- $labelsYaml := toYaml . }}
{{- $labelsYaml | trim | nindent 4 }}
{{- end }}
spec:
{{- if hasKey .Values.service "type" }}
{{- if eq .Values.service.type "ExternalName" }}
Expand Down
2 changes: 2 additions & 0 deletions simple/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{{ include "resource_tag_checker" . }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.name }}
namespace: {{ .Release.Namespace }}
labels:
businessid: {{ $.Values.businessid | quote}}
app: {{ .Values.name }}
spec:
{{- if not (or .Values.hpa .Values.hpav2 ((.Values.KEDA).ScaledObject)) }}
Expand Down
1 change: 1 addition & 0 deletions simple/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if .Values.ingress }}
{{ include "resource_tag_checker" . }}
{{- if hasKey .Values "EnableMutilpleIngress" }}
{{ template "ingress.ingress_multiple" . }}
{{- else }}
Expand Down
7 changes: 7 additions & 0 deletions simple/templates/rollout.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{{ if .Values.rollout }}
{{ include "resource_tag_checker" . }}
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: {{ .Values.name }}
labels:
businessid: {{ $.Values.businessid | quote }}
annotations:
{{- toYaml .Values.rollout.annotations | nindent 4 }}
spec:
Expand Down Expand Up @@ -65,6 +68,8 @@ apiVersion: v1
kind: Service
metadata:
name: {{ .Values.rollout.strategy.canary.canaryService | default (printf "%s-canary" .Values.name) }}
labels:
businessid: {{ $.Values.businessid | quote}}
spec:
{{- if hasKey .Values.service "type" }}
{{- if eq .Values.service.type "ExternalName" }}
Expand Down Expand Up @@ -103,6 +108,8 @@ metadata:
{{- else }}
name: {{ .Values.rollout.strategy.canary.stableService | default (printf "%s-stable" .Values.name) }}
{{- end }}
labels:
businessid: {{ $.Values.businessid | quote}}
spec:
{{- if hasKey .Values.service "type" }}
{{- if eq .Values.service.type "ExternalName" }}
Expand Down
1 change: 1 addition & 0 deletions simple/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{ include "resource_tag_checker" . }}
{{- if .Values.services }}
{{ template "service.service_multiple" . }}
{{- else if .Values.service }}
Expand Down
37 changes: 20 additions & 17 deletions simple/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ name: app-name

replicaCount: 1

# Required: please quote the businessid as string
# businessid: "xxxxxxxxxxxxxxxxxx"

# Note: Please indicate labels of the specific node you willing to place your pods
# nodeSelector:
# labelName: nodegroup
# labelValue: "ec-eks-db-cpu-node-autoscaling-group"

# tolerations:
# tolerations:
# - key: "shop-callback-node"
# operator: "Equal"
# value: "true"
# effect: "NoSchedule"

# Note: Please indicate security contexts in here
# Note: Please indicate security contexts in here
# securityContextForPod:
# runAsUser: 1000
# runAsGroup: 1000
# fsGroup: 1000

# topologySpreadConstraints:
# topologySpreadConstraints:
# - labelSelector:
# matchLabels:
# app: app-name
Expand All @@ -42,7 +45,7 @@ affinity:

deployment: {}
# deployment example
# deployment:
# deployment:
# annotations:
# checksum/config: checksum
# checksum/config.yml: compute_checksum::configmaps/app-config/data/config.yml # `compute_checksum` will compute the sha256 checksum of the content
Expand Down Expand Up @@ -220,18 +223,18 @@ externalSecrets: {}
# externalSecrets:
# example-env-new:
# secretStore:
# aws:
# aws:
# region: "ap-southeast-1" # optional, default "ap-southeast-1"
# arn: "arn:aws:iam::xxx:role/xxxx" # optional, default use deployment service role
# refreshInterval: 1m # optional, default 1h
# dataFrom:
# - extract:
# key: example-secret
# version: "uuid/VersionId"
# key: example-secret
# version: "uuid/VersionId"

# secrets:
# example-env:
# data:
# data:
# data_name: YW5keWNodWFuZw==
# data_tls: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNxRENDQVpBQ0NRQ3NtSEY1ODZDVTRUQU5CZ2txaGtpRzl3MEJBUXNGQURBV01SUXdFZ1lEVlFRRERBdG0KLi4uCnhjUGFMNEdDZ1VsKzhUaUsKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
# # no need to base64 encode
Expand Down Expand Up @@ -272,7 +275,7 @@ externalSecrets: {}

# rollout: {}
# https://argoproj.github.io/argo-rollouts/features/specification/
# rollout:
# rollout:
# annotations:
# notifications.argoproj.io/subscribe.on-rollout-completed.slack_webhook: ""
# revisionHistoryLimit: 10
Expand All @@ -283,7 +286,7 @@ externalSecrets: {}
# activeService: "app-name" # If uses service, this is an optional value; if uses services, then this is a required value
# previewService: "app-name-preview" # If uses service, this is an optional value; if uses services, then this is a required value
# autoPromotionEnabled: false # Required value. if you don't want auto promotion, type false.
# extra:
# extra:
# prePromotionAnalysis:
# templates:
# - templateName: success-rate
Expand All @@ -300,12 +303,12 @@ externalSecrets: {}
# templates:
# - templateName: success-rate
# - setWeight: 100
# trafficRouting:
# trafficRouting:
# alb: # If choose trafficRouting.alb, remember to modify ingress servicePort: use-annotation
# ingress: ingress
# servicePort: 443
# ingress: ingress
# servicePort: 443
# rootService: "app-name" # origin service name
# extra:
# extra:
# analysis:
# templates:
# - templateName: success-rate
Expand All @@ -315,9 +318,9 @@ externalSecrets: {}

analyses: {}
# https://argoproj.github.io/argo-rollouts/features/analysis
# analyses:
# analyses:
# success-rate:
# spec:
# spec:
# dryRun:
# - metricName: .*
# args:
Expand All @@ -336,4 +339,4 @@ analyses: {}
# )) /
# sum(irate(
# istio_requests_total{reporter="source",destination_service=~"{{args.service-name}}"}[5m]
# ))
# ))

0 comments on commit 7807f84

Please sign in to comment.