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

lazyload support update wormhole ports by itself #198

Merged
merged 4 commits into from
Oct 31, 2022
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ staging/src/slime.io/slime/modules/*/.idea/*
.qz/*

### module helm chats ###
boot/helm-charts/slimeboot/templates/modules/*
boot/helm-charts/slimeboot/templates/modules/*

3 changes: 3 additions & 0 deletions boot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ FROM quay.io/operator-framework/helm-operator:v1.10.0

COPY watches.yaml ${HOME}/watches.yaml
COPY helm-charts/ ${HOME}/helm-charts/

Entrypoint ["/usr/local/bin/helm-operator", "run", "--watches-file=./watches.yaml", "--reconcile-period=0"]

7 changes: 6 additions & 1 deletion boot/publish.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/usr/bin/env bash

set -x
mkdir -p ./helm-charts/slimeboot/templates/modules
MODS=${MODS:-"lazyload limiter plugin"}
for m in $MODS; do
rm -rf "./helm-charts/slimeboot/templates/modules/$m"
cp -r "../staging/src/slime.io/slime/modules/$m/charts/" "./helm-charts/slimeboot/templates/modules/$m"
done
find ./helm-charts/slimeboot/templates/modules -type f | grep -v ".yaml" | xargs --no-run-if-empty rm -f
for e in Chart.yaml values.yaml; do
find ./helm-charts/slimeboot/templates/modules -type f -name "$e" -delete
done

export MOD=boot
export ALL_ACTIONS="image image-push"
Expand Down
52 changes: 20 additions & 32 deletions framework/go.sum

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions staging/src/slime.io/slime/modules/lazyload/charts/charts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package charts

import (
"embed"
)

const GlobalSidecar = "global-sidecar"

//go:embed all:global-sidecar
var GlobalSidecarFS embed.FS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v2
version: 0.1.0
name: global-sidecar
type: application
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
{{ if .Values.component }}
{{ if .Values.component.globalSidecar }}
{{ if .Values.component.globalSidecar.enable }}
{{ $gs := .Values.component.globalSidecar }}
{{ $gsPort := $gs.port | default 80 }}
{{ range $.Values.module }}
{{ if or (eq (default "" .name) "lazyload") (eq (default "" .kind) "lazyload") }}
{{ if .global }}
{{ if .global.misc }}
{{ if .global.misc.globalSidecarMode }}
{{ if eq .global.misc.globalSidecarMode "cluster" }}
{{ $f := .general }}
{{ if .fence }}
{{ $f = .fence }}
{{- end -}}
{{ $g := .global }}
{{ $name := .name }}
{{ $gsSvcPorts := list }}
{{ $hasGsPort := false }}
{{- range $f.wormholePort }}
{{- if eq (int .) $gsPort }}
{{ $hasGsPort = true }}
{{- end -}}
{{ $gsSvcPorts = append $gsSvcPorts . }}
{{- end -}}
{{- if not $hasGsPort }}
{{ $gsSvcPorts = append $gsSvcPorts $gsPort }}
{{- end -}}
{{- if and .Values.component .Values.component.globalSidecar .Values.component.globalSidecar.enable }}
{{ $gs := .Values.component.globalSidecar }}
{{ $gsPort := $gs.port | default 80 }}
{{- range $.Values.module }}
{{- if or (eq (default "" .name) "lazyload") (eq (default "" .kind) "lazyload") }}
{{- if and .global .global.misc }}
{{- if eq .global.misc.globalSidecarMode "cluster" }}
{{ $f := .general }}
{{ if .fence }}
{{ $f = .fence }}
{{- end -}}
{{ $g := .global }}
{{ $name := .name }}
{{ $gsSvcPorts := list }}
{{ $hasGsPort := false }}
{{ $autoPort := .general.autoPort }}
{{- range $f.wormholePort }}
{{- if eq (int .) (int $gsPort) }}
{{ $hasGsPort = true }}
{{- end -}}
{{ $gsSvcPorts = append $gsSvcPorts . }}
{{- end -}}
{{- if not $hasGsPort }}
{{ $gsSvcPorts = append $gsSvcPorts $gsPort }}
{{- end -}}

{{- /*
Now, we will render all the resources of the global-sidecar, reset indentation for readability.
*/}}
{{- if or (not $autoPort) (eq $g.misc.render "lazyload") }}
---
apiVersion: v1
kind: Service
Expand All @@ -48,6 +50,7 @@ spec:
app: global-sidecar
sessionAffinity: None
type: ClusterIP
{{- end }}
---
apiVersion: v1
kind: ServiceAccount
Expand All @@ -57,6 +60,51 @@ metadata:
labels:
account: global-sidecar
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: global-sidecar
namespace: {{ $.Values.namespace }}
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: global-sidecar
namespace: {{ $.Values.namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: global-sidecar
subjects:
- kind: ServiceAccount
name: global-sidecar
namespace: {{ $.Values.namespace }}
{{- if or (not $autoPort) (eq $g.misc.render "lazyload") }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: global-sidecar
namespace: {{ $.Values.namespace }}
labels:
lazyload.slime.io/config: global-sidecar
data:
cfg: |-
wormholePorts:
{{- range $gsSvcPorts }}
- {{ . }}
{{- end }}
{{- end }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -78,27 +126,23 @@ spec:
LAZYLOAD_GLOBAL_SIDECAR
ISTIO_META_ISTIO_VERSION:
"999.0.0"
{{- if $g }}
{{- if $g.misc }}
{{- if $g.misc.metricSourceType }}
{{- if (eq $g.misc.metricSourceType "accesslog") }}
sidecar.istio.io/bootstrapOverride: "lazyload-accesslog-source"
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if $gs.sidecarInject }}
{{- if $gs.sidecarInject.enable }}
{{- with $gs.sidecarInject.annotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}
# {{- if $f.globalSidecar }}
# {{- if $f.globalSidecar.excludeInbounds }}
# traffic.sidecar.istio.io/excludeInboundPorts: {{ $f.globalSidecar.excludeInboundPorts }}
# {{- end }}
# {{- end }}
{{- /*
{{- if $f.globalSidecar }}
{{- if $f.globalSidecar.excludeInbounds }}
traffic.sidecar.istio.io/excludeInboundPorts: {{ $f.globalSidecar.excludeInboundPorts }}
{{- end }}
{{- end }}
*/}}
labels:
app: global-sidecar
{{- if $gs.sidecarInject }}
Expand All @@ -122,9 +166,15 @@ spec:
- name: PROBE_PORT
value: {{ default 18181 $gs.probePort | quote }}
- name: LOG_LEVEL
{{- if $g.log }}
value: {{ default "info" $g.log.logLevel }}
- name: WORMHOLE_PORTS
value: {{ join "," $gsSvcPorts | quote }}
{{- else }}
value: "info"
{{- end }}
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- if $gs.image.tag }}
image: "{{ $gs.image.repository }}:{{ $gs.image.tag}}"
{{- else }}
Expand Down Expand Up @@ -160,8 +210,8 @@ spec:
{{- toYaml $gs.resources | nindent 12 }}
securityContext:
privileged: true
{{- if or (not $g) (not $g.misc) (eq (default "prometheus" $g.misc.metricSourceType) "prometheus") }}
---
{{- if or (not $g) (not $g.misc) (eq (default "prometheus" $g.misc.metricSourceType) "prometheus") }}
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
Expand Down Expand Up @@ -211,7 +261,8 @@ spec:
name: istio.metadata_exchange
patch:
operation: REMOVE
{{- end }}
{{- end }}
{{- if or (not $autoPort) (eq $g.misc.render "lazyload") }}
---
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
Expand Down Expand Up @@ -348,11 +399,9 @@ spec:
route:
cluster: PassthroughCluster
{{- end }}
---
{{- if $g }}
{{- if $g.misc }}
{{- if $g.misc.metricSourceType }}
{{- end }}
{{- if (eq $g.misc.metricSourceType "accesslog") }}
---
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
Expand Down Expand Up @@ -388,16 +437,12 @@ spec:
transport_api_version: "V3"
grpc_service:
envoy_grpc:
#cluster_name: outbound|{{$.Values.service.logSourcePort}}||{{$.Values.name}}.{{$.Values.namespace}}.svc.cluster.local
{{- /*
cluster_name: outbound|{{$.Values.service.logSourcePort}}||{{$.Values.name}}.{{$.Values.namespace}}.svc.cluster.local
*/}}
cluster_name: lazyload-accesslog-source
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
---
{{- if $g }}
{{- if $g.misc }}
{{- if $g.misc.metricSourceType }}
{{- if (eq $g.misc.metricSourceType "accesslog") }}
apiVersion: v1
kind: ConfigMap
Expand Down Expand Up @@ -434,15 +479,12 @@ data:
}
}
{{- end }}
{{- /*
Now that we've rendered all the resources for the global-sidecar, restore the indentation.
*/}}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}

Loading