Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chart/navi-attractor] chart syncup #519

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions charts/navi-attractor/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v2
name: navi-attractor
description: Attractor Helm chart
type: application
keywords:
- navi
- attractor
version: 0.1.0
appVersion: 7.27.1.2
dependencies:
- name: generic-chart
version: '*'
repository: file://../generic-chart
maintainers:
- name: 2gis
url: https://github.com/2gis
email: [email protected]
200 changes: 200 additions & 0 deletions charts/navi-attractor/README.md

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions charts/navi-attractor/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.grpc.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "generic-chart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.grpc.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "generic-chart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "generic-chart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.grpc.port }}
{{- else if contains "ClusterIP" .Values.service.grpc.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "generic-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}

{{- if .Values.attractor.app_castle_host }}
#################################################################################
###### WARNING: `attractor.app_castle_host` has been deprecated! #####
###### We recommend using `attractor.castleUrl`. #####
#################################################################################
{{- end }}
242 changes: 242 additions & 0 deletions charts/navi-attractor/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
{{/*
Distinguishable main container name
Override generic-chart
TODO: rewrite https://github.com/helm/helm/issues/11291
*/}}
{{- define "generic-chart.containerName" -}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Объявление нового шаблона с именем из чужого домена.
При чтении чарта не понятно где её искать. В этом чарте или в чарте generic-chart

{{- if .Values.dataGroup.enabled }}
{{- .Values.dataGroup.prefix }}-{{ .Chart.Name }}
{{- else }}
{{- .Chart.Name }}
{{- end }}
{{- end -}}

{{- define "config.setCpuNumber" }}
{{- $cpu_divider := 1 }}
{{- $num_threads := 0 }}
{{- $resources := regexSplit "m" (toString .Values.resources.limits.cpu) -1 }}
{{- if eq (len $resources) 2 }}
{{- $cpu_divider = 1000 }}
{{- end }}
{{- $cpu_value := index $resources 0 }}
{{- $num_threads = ceil (divf $cpu_value $cpu_divider) }}
{{- print $num_threads }}
{{- end -}}

{{/*
Renders a value or file that contains rules.
Usage:
{{ include "rules.renderRules" }}
*/}}
{{- define "rules.renderRules" -}}
{{- $rules := list -}}
{{- if ( and .Values.rules (kindIs "slice" .Values.rules )) -}}
{{- $rules = .Values.rules -}}
{{- end -}}
{{ $rules | toPrettyJson | nindent 6 -}}
{{- end -}}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Разное число пустых строк между блоками. Где-то одна, где-то две.
Предлагаю привести к везде к одной.


{{/*
Check if value exists in rule routing section
Usage:
{{ include "rules.inRoutingSection" ( dict "routingValue" "<value>" "context" $) }}
*/}}
{{- define "rules.inRoutingSection" -}}
{{- $found := false -}}
{{- if $.context.Values.rules -}}
{{- range $.context.Values.rules -}}
{{- if eq .name $.context.Values.attractor.app_rule -}}
{{- if (has $.routingValue .routing) -}}
{{- $found = true -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- ternary "true" "" $found -}}
{{- end -}}


{{/*
Check if value exists in rule queries section
Usage:
{{ include "rules.inQueriesSection" ( dict "queriesValue" "<value>" "context" $) }}
*/}}
{{- define "rules.inQueriesSection" -}}
{{- $found := false -}}
{{- if $.context.Values.rules -}}
{{- range $.context.Values.rules -}}
{{- if eq .name $.context.Values.attractor.app_rule -}}
{{- if (has $.queriesValue .queries) -}}
{{- $found = true -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- ternary "true" "" $found -}}
{{- end -}}


{{/*
Set attractor_car parameter in server config section
Usage:
{{ include "config.setAttractorCar" $ }}
*/}}
{{- define "config.setAttractorCar" -}}
{{- ternary
$.Values.attractor.attractor.car
(include "rules.inRoutingSection" (dict "routingValue" "driving" "context" $))
(hasKey $.Values.attractor.attractor "car")
-}}
{{- end -}}


{{/*
Set attractor_pedestrian parameter in server config section
Usage:
{{ include "config.setAttractorPedestrian" $ }}
*/}}
{{- define "config.setAttractorPedestrian" -}}
{{- ternary
$.Values.attractor.attractor.pedestrian
(or (include "rules.inRoutingSection" (dict "routingValue" "ctx" "context" $))
(include "rules.inRoutingSection" (dict "routingValue" "public_transport" "context" $))
(include "rules.inRoutingSection" (dict "routingValue" "pedestrian" "context" $)))
(hasKey $.Values.attractor.attractor "pedestrian")
-}}
{{- end -}}


{{/*
Set attractor_taxi parameter in server config section
Usage:
{{ include "config.setAttractorTaxi" $ }}
*/}}
{{- define "config.setAttractorTaxi" -}}
{{- ternary
$.Values.attractor.attractor.taxi
(include "rules.inRoutingSection" (dict "routingValue" "taxi" "context" $))
(hasKey $.Values.attractor.attractor "taxi")
-}}
{{- end -}}


{{/*
Set attractor_truck parameter in server config section
Usage:
{{ include "config.setAttractorTruck" $ }}
*/}}
{{- define "config.setAttractorTruck" -}}
{{- ternary
$.Values.attractor.attractor.truck
(include "rules.inRoutingSection" (dict "routingValue" "truck" "context" $))
(hasKey $.Values.attractor.attractor "truck")
-}}
{{- end -}}


{{/*
Set attractor_bicycle parameter in server config section
Usage:
{{ include "config.setAttractorBicycle" $ }}
*/}}
{{- define "config.setAttractorBicycle" -}}
{{- ternary
$.Values.attractor.attractor.bicycle
(or (include "rules.inRoutingSection" (dict "routingValue" "bicycle" "context" $))
(include "rules.inRoutingSection" (dict "routingValue" "scooter" "context" $)))
(or (hasKey $.Values.attractor.attractor "bicycle") (hasKey $.Values.attractor.attractor "scooter"))
-}}
{{- end -}}


{{/*
Check if instance is running in truck mode
Usage:
{{ include "config.isTruck" $ }}
*/}}
{{- define "config.isTruck" -}}
{{- $is_enabled_routing := ( eq "true" (include "rules.inRoutingSection" (dict "routingValue" "truck" "context" $))) -}}
{{- ternary "true" "" $is_enabled_routing -}}
{{- end -}}


{{/*
Check if instance is running in ctx mode
Usage:
{{ include "config.isCTX" $ }}
*/}}
{{- define "config.isCTX" -}}
{{- $is_enabled_routing := ( or (eq "true" (include "rules.inRoutingSection" (dict "routingValue" "ctx" "context" $))) (eq "true" (include "rules.inRoutingSection" (dict "routingValue" "public_transport" "context" $)))) -}}
{{- $is_enabled_query := ( or (eq "true" (include "rules.inQueriesSection" (dict "queriesValue" "ctx" "context" $))) (eq "true" (include "rules.inQueriesSection" (dict "queriesValue" "public_transport" "context" $)))) -}}
{{- ternary "true" "" (or $is_enabled_routing $is_enabled_query) -}}
{{- end -}}


{{/*
Check if instance is running in taxi mode
Usage:
{{ include "config.isTaxi" $ }}
*/}}
{{- define "config.isTaxi" -}}
{{- $is_enabled_routing := ( eq "true" (include "rules.inRoutingSection" (dict "routingValue" "taxi" "context" $))) -}}
{{- ternary "true" "" $is_enabled_routing -}}
{{- end -}}

{{/*
Check if map matching is enabled
Usage:
{{ include "config.isMapMatching" $ }}
*/}}
{{- define "config.isMapMatching" -}}
{{- include "rules.inQueriesSection" (dict "queriesValue" "map_matching" "context" $) -}}
{{- end -}}

{{/* vim: set filetype=mustache: */}}

{{/*
Set castle url
If use frozenData return local path
Usage:
{{ include "config.setCastleUrl" $ }}
*/}}
{{- define "config.setCastleUrl" -}}
{{- if .Values.frozenData.enabled -}}
{{- printf "file://{LOCAL_PATH}" -}}
{{- else if .Values.attractor.castleUrl -}}
{{- printf .Values.attractor.castleUrl -}}
{{- else if .Values.attractor.app_castle_host -}}
{{- printf "http://%s" .Values.attractor.app_castle_host -}}
{{- end -}}
{{- end -}}

{{/*
Set restriction url
If rtr enabled return attractor.rtr.url, else return attractor.castleUrl
Usage:
{{ include "config.setRestrictionUrl" $ }}
*/}}
{{- define "config.setRestrictionUrl" -}}
{{- if .Values.attractor.rtr.enabled -}}
{{- printf .Values.attractor.rtr.url -}}
{{- else -}}
{{- printf (include "config.setCastleUrl" $) -}}
{{- end -}}
{{- end -}}

{{/*
Set probe
If mock enable then use http probe, else user grpc probe
Usage:
{{ include "navi-attractor.probe" . }}
*/}}
{{- define "navi-attractor.probe" -}}
{{- if .Values.attractor.mock -}}
httpGet:
path: /about
port: http
{{- else -}}
grpc:
port: {{ .Values.attractor.grpcPort }}
{{- end -}}
{{- end -}}
Loading
Loading