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

Fix invalid vs panic and lazyload supports old istio version #158

Merged
merged 2 commits into from
Jun 21, 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
7 changes: 4 additions & 3 deletions framework/controllers/virtualservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *VirtualServiceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err

// 资源更新
m := parseDestination(instance)
log.Infof("get destination after parse, %+v", m)
log.Debugf("get destination after parse, %+v", m)
for k, v := range m {
HostDestinationMapping.Set(k, v)
}
Expand Down Expand Up @@ -104,8 +104,9 @@ func parseDestination(instance *networkingistioiov1alpha3.VirtualService) map[st
if ds, ok := hr[vsRoute].([]interface{}); ok {
for _, d := range ds {
if route, ok := d.(map[string]interface{}); ok {
destinationHost := route[vsDestination].(map[string]interface{})[vsHost].(string)
dhs[destinationHost] = struct{}{}
if destinationHost, ok := route[vsDestination].(map[string]interface{})[vsHost].(string); ok {
dhs[destinationHost] = struct{}{}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ spec:
{{- 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 }}
Expand All @@ -104,6 +111,10 @@ spec:
{{- end }}
{{- end }}
spec:
{{- with $.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: global-sidecar
containers:
- name: global-sidecar
Expand Down Expand Up @@ -148,7 +159,7 @@ spec:
resources:
{{- toYaml $gs.resources | nindent 12 }}
securityContext:
runAsUser: 1000
privileged: true
---
{{- if or (not $g) (not $g.misc) (eq (default "prometheus" $g.misc.metricSourceType) "prometheus") }}
apiVersion: networking.istio.io/v1alpha3
Expand Down Expand Up @@ -266,9 +277,15 @@ spec:
name: 0.0.0.0_{{ . }}
filterChain:
filter:
{{- if $gs.legacyFilterName }}
name: "envoy.http_connection_manager"
subFilter:
name: "envoy.router"
{{- else }}
name: "envoy.filters.network.http_connection_manager"
subFilter:
name: "envoy.filters.http.router"
{{- end }}
patch:
operation: INSERT_BEFORE
value:
Expand All @@ -277,6 +294,13 @@ spec:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
inline_code: |
-- place holder
# compatiable with istio 1.7+
source_codes:
add.lua:
inline_string: |
function envoy_on_request(request_handle)
request_handle:headers():replace("Slime-Source-Ns", os.getenv("POD_NAMESPACE"))
end
- applyTo: HTTP_ROUTE
match :
context: SIDECAR_OUTBOUND
Expand All @@ -290,11 +314,7 @@ spec:
typed_per_filter_config:
envoy.filters.http.lua:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.LuaPerRoute
source_code:
Copy link
Contributor

Choose a reason for hiding this comment

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

why we move the add-source-ns-header lua code from per-route filter config to filter config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

compatiable with istio 1.7, cause istio 1.7 related envoy does support source_code param

inline_string: |
function envoy_on_request(request_handle)
request_handle:headers():replace("Slime-Source-Ns", os.getenv("POD_NAMESPACE"))
end
name: add.lua
- applyTo: VIRTUAL_HOST
match:
proxy:
Expand Down Expand Up @@ -349,7 +369,11 @@ spec:
listener:
filterChain:
filter:
{{- if $gs.legacyFilterName }}
name: "envoy.http_connection_manager"
{{- else }}
name: "envoy.filters.network.http_connection_manager"
{{- end }}
patch:
operation: MERGE
value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ spec:
{{- 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 }}
Expand All @@ -105,6 +112,10 @@ spec:
{{- end }}
{{- end }}
spec:
{{- with $.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: global-sidecar
containers:
- name: global-sidecar
Expand Down Expand Up @@ -149,7 +160,7 @@ spec:
resources:
{{- toYaml $gs.resources | nindent 12 }}
securityContext:
runAsUser: 1000
privileged: true
---
{{- if or (not $g) (not $g.misc) (eq (default "prometheus" $g.misc.metricSourceType) "prometheus") }}
apiVersion: networking.istio.io/v1alpha3
Expand Down Expand Up @@ -318,7 +329,11 @@ spec:
listener:
filterChain:
filter:
{{- if $gs.legacyFilterName }}
name: "envoy.http_connection_manager"
{{- else }}
name: "envoy.filters.network.http_connection_manager"
{{- end }}
patch:
operation: MERGE
value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,35 @@ type SlimeBoot struct {
}

type SlimeBootSpec struct {
Modules []Module `json:"module" yaml:"module"`
Image *Image `json:"image" yaml:"image"`
Component *Component `json:"component" yaml:"component"`
Namespace string `json:"namespace" yaml:"namespace"`
IstioNamespace string `json:"istioNamespace" yaml:"istioNamespace"`
Resources *Resources `json:"resources" yaml:"resources"`
Modules []Module `json:"module" yaml:"module"`
Image *Image `json:"image" yaml:"image"`
ImagePullSecrets []map[string]string `json:"imagePullSecrets" yaml:"imagePullSecrets"`
Component *Component `json:"component" yaml:"component"`
Namespace string `json:"namespace" yaml:"namespace"`
IstioNamespace string `json:"istioNamespace" yaml:"istioNamespace"`
Resources *Resources `json:"resources" yaml:"resources"`
}

type Component struct {
GlobalSidecar *GlobalSidecar `json:"globalSidecar" yaml:"globalSidecar"`
}

type GlobalSidecar struct {
Enable bool `json:"enable" yaml:"enable"`
Image *Image `json:"image" yaml:"image"`
Port int `json:"port" yaml:"port"`
ProbePort int `json:"probePort" yaml:"probePort"`
Replicas int `json:"replicas" yaml:"replicas"`
Resources *Resources `json:"resources" yaml:"resources"`
SidecarInject *SidecarInject `json:"sidecarInject" yaml:"sidecarInject"`
Enable bool `json:"enable" yaml:"enable"`
Image *Image `json:"image" yaml:"image"`
Port int `json:"port" yaml:"port"`
ProbePort int `json:"probePort" yaml:"probePort"`
Replicas int `json:"replicas" yaml:"replicas"`
Resources *Resources `json:"resources" yaml:"resources"`
SidecarInject *SidecarInject `json:"sidecarInject" yaml:"sidecarInject"`
LegacyFilterName bool `json:"legacyFilterName" yaml:"legacyFilterName"`
}

type SidecarInject struct {
Enable bool `json:"enable" yaml:"enable"`
Mode string `json:"mode" yaml:"mode"`
Labels map[string]string `json:"labels" yaml:"labels"`
Enable bool `json:"enable" yaml:"enable"`
Mode string `json:"mode" yaml:"mode"`
Labels map[string]string `json:"labels" yaml:"labels"`
Annotations map[string]string `json:"annotations" yaml:"annotations"`
}

type Resources struct {
Expand Down