文件未被正确导入 Helm
来源:stackoverflow
时间:2024-02-15 14:51:23 163浏览 收藏
本篇文章向大家介绍《文件未被正确导入 Helm》,主要包括,具有一定的参考价值,需要的朋友可以参考一下。
问题内容
我正在创建 helm chart,但在导入文件时遇到问题:
apiversion: v1
kind: configmap
metadata:
name: vcl-template
namespace: {{.release.namespace}}
data:
{{- (.files.glob "config/varnish/default.vcl.tmpl").asconfig | nindent 2 }}
{{- (.files.glob "config/varnish/nginx.conf").asconfig | nindent 2 }}
这会导入文件 config/varnish/nginx.conf ,但是文件 config/varnish/default.vcl.tmpl 是使用 \n 而不是换行符导入的,因此 configmap 上的数据都会出现错误: p>
apiversion: v1
kind: configmap
metadata:
name: vcl-template
namespace: default
data:
default.vcl.tmpl: "vcl 4.0;\n\nimport std;\nimport directors;\n\n{{ range .frontends
}}\nbackend {{ .name }} {\n .host = \"{{ .host }}\";\n .port = \"{{ .port
}}\";\n}\n{{- end }}\n\n{{ range .backends }}\nbackend be-{{ .name }} {\n .host
= \"{{ .host }}\";\n .port = \"{{ .port }}\";\n}\n{{- end }}\n\nacl purge {\n
\ \"127.0.0.1\";\n \"localhost\";\n \"::1\";\n {{- range .frontends }}\n
\ \"{{ .host }}\";\n {{- end }}\n {{- range .backends }}\n \"{{ .host
}}\";\n {{- end }}\n}\n\nsub vcl_init {\n new cluster = directors.hash();\n\n
\ {{ range .frontends -}}\n cluster.add_backend({{ .name }}, 1);\n {{ end
}}\n\n new lb = directors.round_robin();\n\n {{ range .backends -}}\n lb.add_backend(be-{{
.name }});\n {{ end }}\n}\n\nsub vcl_recv {\n\n unset req.http.x-cache;\n
\ set req.backend_hint = cluster.backend(req.url);\n set req.http.x-shard =
req.backend_hint;\n if (req.http.x-shard != server.identity) {\n return(pass);\n
\ }\n set req.backend_hint = lb.backend();\n\n if (req.method == \"purge\")
{\n if (client.ip !~ purge) {\n return (synth(405, \"method not
allowed\"));\n }\n # to use the x-pool header for purging varnish
during automated deployments, make sure the x-pool header\n # has been added
to the response in your backend server config. this is used, for example, by the\n
\ # capistrano-magento2 gem for purging old content from varnish during it's
deploy routine.\n if (!req.http.x-magento-tags-pattern && !req.http.x-pool)
{\n return (synth(400, \"x-magento-tags-pattern or x-pool header required\"));\n
\ }\n if (req.http.x-magento-tags-pattern) {\n ban(\"obj.http.x-magento-tags
~ \" + req.http.x-magento-tags-pattern);\n }\n if (req.http.x-pool)
{\n ban(\"obj.http.x-pool ~ \" + req.http.x-pool);\n }\n return
(synth(200, \"purged\"));\n }\n\n if (req.method != \"get\" &&\n req.method
!= \"head\" &&\n req.method != \"put\" &&\n req.method != \"post\"
&&\n req.method != \"trace\" &&\n req.method != \"options\" &&\n req.method
!= \"delete\") {\n /* non-rfc2616 or connect which is weird. */\n return
(pipe);\n }\n\n # we only deal with get and head by default\n if (req.method
!= \"get\" && req.method != \"head\") {\n return (pass);\n }\n\n #
bypass shopping cart, checkout and search requests\n if (req.url ~ \"/checkout\"
|| req.url ~ \"/catalogsearch\") {\n return (pass);\n }\n\n # bypass
admin\n if (req.url ~ \"^/admin($|/.*)\") {\n return (pass);\n }\n\n
\ # bypass health check requests\n if (req.url ~ \"/pub/health_check.php\")
{\n return (pass);\n }\n\n # set initial grace period usage status\n
\ set req.http.grace = \"none\";\n\n # normalize url in case of leading http
scheme and domain\n set req.url = regsub(req.url, \"^http[s]?://\", \"\");\n\n
\ # collect all cookies\n std.collect(req.http.cookie);\n\n # compression
filter. see https://www.varnish-cache.org/trac/wiki/faq/compression\n if (req.http.accept-encoding)
{\n if (req.url ~ \"\\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$\")
{\n # no point in compressing these\n unset req.http.accept-encoding;\n
\ } elsif (req.http.accept-encoding ~ \"gzip\") {\n set req.http.accept-encoding
= \"gzip\";\n } elsif (req.http.accept-encoding ~ \"deflate\" && req.http.user-agent
!~ \"msie\") {\n set req.http.accept-encoding = \"deflate\";\n }
else {\n # unknown algorithm\n unset req.http.accept-encoding;\n
\ }\n }\n\n # remove all marketing get parameters to minimize the cache
objects\n if (req.url ~ \"(\\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=\")
{\n set req.url = regsuball(req.url, \"(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_a-z0-9+()%.]+&?\",
\"\");\n set req.url = regsub(req.url, \"[?|&]+$\", \"\");\n }\n\n #
static files caching\n if (req.url ~ \"^/(pub/)?(media|static)/\") {\n return
(pass);\n }\n\n return (hash);\n}\n\nsub vcl_hash {\n if (req.http.cookie
~ \"x-magento-vary=\") {\n hash_data(regsub(req.http.cookie, \"^.*?x-magento-vary=([^;]+);*.*$\",
\"\\1\"));\n }\n\n # for multi site configurations to not cache each other's
content\n if (req.http.host) {\n hash_data(req.http.host);\n } else
{\n hash_data(server.ip);\n }\n\n if (req.url ~ \"/graphql\") {\n call
process_graphql_headers;\n }\n\n # to make sure http users don't see ssl warning\n
\ if (req.http.x-forwarded-proto) {\n hash_data(req.http.x-forwarded-proto);\n
\ }\n \n}\n\nsub process_graphql_headers {\n if (req.http.store) {\n hash_data(req.http.store);\n
\ }\n if (req.http.content-currency) {\n hash_data(req.http.content-currency);\n
\ }\n}\n\nsub vcl_backend_response {\n\n set beresp.grace = 3d;\n\n if (beresp.http.content-type
~ \"text\") {\n set beresp.do_esi = true;\n }\n\n if (bereq.url ~ \"\\.js$\"
|| beresp.http.content-type ~ \"text\") {\n set beresp.do_gzip = true;\n
\ }\n\n if (beresp.http.x-magento-debug) {\n set beresp.http.x-magento-cache-control
= beresp.http.cache-control;\n }\n\n # cache only successfully responses and
404s\n if (beresp.status != 200 && beresp.status != 404) {\n set beresp.ttl
= 0s;\n set beresp.uncacheable = true;\n return (deliver);\n }
elsif (beresp.http.cache-control ~ \"private\") {\n set beresp.uncacheable
= true;\n set beresp.ttl = 86400s;\n return (deliver);\n }\n\n
\ # validate if we need to cache it and prevent from setting cookie\n if (beresp.ttl
> 0s && (bereq.method == \"get\" || bereq.method == \"head\")) {\n unset
beresp.http.set-cookie;\n }\n\n # if page is not cacheable then bypass varnish
for 2 minutes as hit-for-pass\n if (beresp.ttl <= 0s ||\n beresp.http.surrogate-control
~ \"no-store\" ||\n (!beresp.http.surrogate-control &&\n beresp.http.cache-control
~ \"no-cache|no-store\") ||\n beresp.http.vary == \"*\") {\n # mark
as hit-for-pass for the next 2 minutes\n set beresp.ttl = 120s;\n set
beresp.uncacheable = true;\n }\n\n return (deliver);\n}\n\nsub vcl_deliver
{\n if (resp.http.x-magento-debug) {\n if (resp.http.x-varnish ~ \" \")
{\n set resp.http.x-magento-cache-debug = \"hit\";\n set resp.http.grace
= req.http.grace;\n } else {\n set resp.http.x-magento-cache-debug
= \"miss\";\n }\n } else {\n unset resp.http.age;\n }\n\n #
not letting browser to cache non-static files.\n if (resp.http.cache-control
!~ \"private\" && req.url !~ \"^/(pub/)?(media|static)/\") {\n set resp.http.pragma
= \"no-cache\";\n set resp.http.expires = \"-1\";\n set resp.http.cache-control
= \"no-store, no-cache, must-revalidate, max-age=0\";\n }\n\n unset resp.http.x-magento-debug;\n
\ unset resp.http.x-magento-tags;\n unset resp.http.x-powered-by;\n unset
resp.http.server;\n unset resp.http.x-varnish;\n unset resp.http.via;\n unset
resp.http.link;\n}\n\nsub vcl_hit {\n if (obj.ttl >= 0s) {\n # hit within
ttl period\n return (deliver);\n }\n if (std.healthy(req.backend_hint))
{\n if (obj.ttl + 300s > 0s) {\n # hit after ttl expiration, but
within grace period\n set req.http.grace = \"normal (healthy server)\";\n
\ return (deliver);\n } else {\n # hit after ttl and
grace expiration\n return (miss);\n }\n } else {\n #
server is not healthy, retrieve from cache\n set req.http.grace = \"unlimited
(unhealthy server)\";\n return (deliver);\n }\n}\n"
nginx.conf: |
worker_processes auto;
events {
worker_connections 1024;
}
pcre_jit on;
error_log /var/log/nginx/error.log warn;
include /etc/nginx/modules/*.conf;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
client_max_body_size 15m;
keepalive_timeout 30;
sendfile on;
tcp_nodelay on;
gzip_vary on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
include /etc/nginx/conf.d/*.conf;
}
nginx.conf:
worker_processes auto;
events {
worker_connections 1024;
}
pcre_jit on;
error_log /var/log/nginx/error.log warn;
include /etc/nginx/modules/*.conf;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
client_max_body_size 15m;
keepalive_timeout 30;
sendfile on;
tcp_nodelay on;
gzip_vary on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
include /etc/nginx/conf.d/*.conf;
}
default.vcl.tmpl:
vcl 4.0;
import std;
import directors;
{{ range .Frontends }}
backend {{ .Name }} {
.host = "{{ .Host }}";
.port = "{{ .Port }}";
}
{{- end }}
{{ range .Backends }}
backend be-{{ .Name }} {
.host = "{{ .Host }}";
.port = "{{ .Port }}";
}
{{- end }}
acl purge {
"127.0.0.1";
"localhost";
"::1";
{{- range .Frontends }}
"{{ .Host }}";
{{- end }}
{{- range .Backends }}
"{{ .Host }}";
{{- end }}
}
sub vcl_init {
new cluster = directors.hash();
{{ range .Frontends -}}
cluster.add_backend({{ .Name }}, 1);
{{ end }}
new lb = directors.round_robin();
{{ range .Backends -}}
lb.add_backend(be-{{ .Name }});
{{ end }}
}
sub vcl_recv {
unset req.http.x-cache;
set req.backend_hint = cluster.backend(req.url);
set req.http.x-shard = req.backend_hint;
if (req.http.x-shard != server.identity) {
return(pass);
}
set req.backend_hint = lb.backend();
if (req.method == "PURGE") {
if (client.ip !~ purge) {
return (synth(405, "Method not allowed"));
}
# To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
# has been added to the response in your backend server config. This is used, for example, by the
# capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
}
if (req.http.X-Magento-Tags-Pattern) {
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
}
if (req.http.X-Pool) {
ban("obj.http.X-Pool ~ " + req.http.X-Pool);
}
return (synth(200, "Purged"));
}
if (req.method != "GET" &&
req.method != "HEAD" &&
req.method != "PUT" &&
req.method != "POST" &&
req.method != "TRACE" &&
req.method != "OPTIONS" &&
req.method != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
# We only deal with GET and HEAD by default
if (req.method != "GET" && req.method != "HEAD") {
return (pass);
}
# Bypass shopping cart, checkout and search requests
if (req.url ~ "/checkout" || req.url ~ "/catalogsearch") {
return (pass);
}
# Bypass admin
if (req.url ~ "^/admin($|/.*)") {
return (pass);
}
# Bypass health check requests
if (req.url ~ "/pub/health_check.php") {
return (pass);
}
# Set initial grace period usage status
set req.http.grace = "none";
# normalize url in case of leading HTTP scheme and domain
set req.url = regsub(req.url, "^http[s]?://", "");
# collect all cookies
std.collect(req.http.Cookie);
# Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
# No point in compressing these
unset req.http.Accept-Encoding;
} elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
set req.http.Accept-Encoding = "deflate";
} else {
# unknown algorithm
unset req.http.Accept-Encoding;
}
}
# Remove all marketing get parameters to minimize the cache objects
if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
set req.url = regsub(req.url, "[?|&]+$", "");
}
# Static files caching
if (req.url ~ "^/(pub/)?(media|static)/") {
return (pass);
}
return (hash);
}
sub vcl_hash {
if (req.http.cookie ~ "X-Magento-Vary=") {
hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
}
# For multi site configurations to not cache each other's content
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
if (req.url ~ "/graphql") {
call process_graphql_headers;
}
# To make sure http users don't see ssl warning
if (req.http.X-Forwarded-Proto) {
hash_data(req.http.X-Forwarded-Proto);
}
}
sub process_graphql_headers {
if (req.http.Store) {
hash_data(req.http.Store);
}
if (req.http.Content-Currency) {
hash_data(req.http.Content-Currency);
}
}
sub vcl_backend_response {
set beresp.grace = 3d;
if (beresp.http.content-type ~ "text") {
set beresp.do_esi = true;
}
if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") {
set beresp.do_gzip = true;
}
if (beresp.http.X-Magento-Debug) {
set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
}
# cache only successfully responses and 404s
if (beresp.status != 200 && beresp.status != 404) {
set beresp.ttl = 0s;
set beresp.uncacheable = true;
return (deliver);
} elsif (beresp.http.Cache-Control ~ "private") {
set beresp.uncacheable = true;
set beresp.ttl = 86400s;
return (deliver);
}
# validate if we need to cache it and prevent from setting cookie
if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) {
unset beresp.http.set-cookie;
}
# If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass
if (beresp.ttl <= 0s ||
beresp.http.Surrogate-control ~ "no-store" ||
(!beresp.http.Surrogate-Control &&
beresp.http.Cache-Control ~ "no-cache|no-store") ||
beresp.http.Vary == "*") {
# Mark as Hit-For-Pass for the next 2 minutes
set beresp.ttl = 120s;
set beresp.uncacheable = true;
}
return (deliver);
}
sub vcl_deliver {
if (resp.http.X-Magento-Debug) {
if (resp.http.x-varnish ~ " ") {
set resp.http.X-Magento-Cache-Debug = "HIT";
set resp.http.Grace = req.http.grace;
} else {
set resp.http.X-Magento-Cache-Debug = "MISS";
}
} else {
unset resp.http.Age;
}
# Not letting browser to cache non-static files.
if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") {
set resp.http.Pragma = "no-cache";
set resp.http.Expires = "-1";
set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
}
unset resp.http.X-Magento-Debug;
unset resp.http.X-Magento-Tags;
unset resp.http.X-Powered-By;
unset resp.http.Server;
unset resp.http.X-Varnish;
unset resp.http.Via;
unset resp.http.Link;
}
sub vcl_hit {
if (obj.ttl >= 0s) {
# Hit within TTL period
return (deliver);
}
if (std.healthy(req.backend_hint)) {
if (obj.ttl + 300s > 0s) {
# Hit after TTL expiration, but within grace period
set req.http.grace = "normal (healthy server)";
return (deliver);
} else {
# Hit after TTL and grace expiration
return (miss);
}
} else {
# server is not healthy, retrieve from cache
set req.http.grace = "unlimited (unhealthy server)";
return (deliver);
}
}
为什么第二个文件没有正确导入?最新的 helm 版本和最新的 go 版本。
有人有什么想法吗?这两个文件在 vscode 上的编码显示为 utf8。
正确答案
它们实际上与 yaml 的 pov 等效,只是不那么漂亮,但对于您的具体情况来说最重要的是,因为 yaml 无法在不引用它的情况下表示 尾随 空白,这就是它所做的,因为行164 的 .tmpl 文件,如 \n \n 所示:
\ }\n \n}\n\nsub process_graphql_headers {\n if (req.http.store) {\n hash_data(req.http.store);\n
$ sed -ne 164p default.vcl.tmpl | xxd 00000000: 2020 2020 0a .
在编辑器中打开“去除尾随空格”会有所帮助,或者对于这种特定情况,您可以修复第 164 行
今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~
声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
最新阅读
更多>
-
139 收藏
-
204 收藏
-
325 收藏
-
478 收藏
-
486 收藏
-
439 收藏
-
357 收藏
-
352 收藏
-
101 收藏
-
440 收藏
-
212 收藏
-
143 收藏
课程推荐
更多>
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 485次学习