我最近在 Jenkinsfile 中遇到了以下几行
def obj = new Foo(this, params)
obj.someMethod()
Run Code Online (Sandbox Code Playgroud)
this 关键字作为类构造函数的参数有什么用?
我已安排 K8s cron 每 30 分钟运行一次。
如果当前作业仍在运行并且已达到下一个 cron 计划,则不应创建新作业,而是等待下一个计划。
如果上一个作业仍处于运行状态,则重复相同的过程。
下面是 aws go sdk elbv2 包中的实际结构类型。此结构中还有其他参数。为了简单起见,我只保留了必要的。
type CreateTargetGroupInput struct {
_ struct{} `type:"structure"`
Name *string `type:"string" required:"true"`
Port *int64 `min:"1" type:"integer" required:"true"`
Protocol *string `type:"string" required:"true" enum:"ProtocolEnum"`
VpcId *string `type:"string" required:"true"`
}
Run Code Online (Sandbox Code Playgroud)
我需要用整数解码一个 JSON 字符串,例如:
{ "name": "test-tg", "port": "8080", "protocol": "HTTP" ,"vpcId": "vpc-xxxxxx"}
Run Code Online (Sandbox Code Playgroud)
去代码:
func main() {
s := `{ "name": "test-tg", "port": "8080", "protocol": "HTTP" ,"vpcId": "vpc-xxxxxx"}`
targetGroupInput := &elbv2.CreateTargetGroupInput{}
err := json.Unmarshal([]byte(s), targetGroupInput)
if err == nil {
fmt.Printf("%+v\n", targetGroupInput)
}
}
Run Code Online (Sandbox Code Playgroud)
我得到以下输出,(如果我以整数格式传递端口,它会工作)
{
Name: "testTG",
Port: …Run Code Online (Sandbox Code Playgroud) 我有以下目录结构
(root)
+- src # Groovy source files
| +- org
| +- foo
| +- Bar.groovy # for org.foo.Bar class
+- vars
| +- foo.groovy # for global 'foo' variable
Run Code Online (Sandbox Code Playgroud)
我在以下文件中有以下代码行
Bar.groovy
package org.foo
class Bar implements Serializable {
def config
def script
Bar(script, config){
this.script = script
this.config = config
}
def accessGlobalVars(){
this.script.echo "${foo.GlobalVar}" // throws an err
}
}
Run Code Online (Sandbox Code Playgroud)foo.groovy
import groovy.transform.Field
@Field GlobalVar="Hello World!"
Run Code Online (Sandbox Code Playgroud)我能够访问脚本块中Jenkinsfile中的变量
echo "${foo.GlobalVar}"
Run Code Online (Sandbox Code Playgroud)
是否可以访问类中的相同变量,因为vars文件夹位于src文件夹级别?
我知道可以为每个模块一个接一个地运行多个即席命令,并使用剧本。
剧本:
- hosts: webservers
tasks:
- name: create .ssh dir
file: path ~/.ssh state=directory
- name: copy pub key
copy: src:~/.ssh/id.rsa_pub dest=~/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
我希望以上内容在一行中使用即席执行。有可能这样做吗?
我正在使用以下配置在 pod 内运行 spring boot。
Pod 限制:
resources:
limits:
cpu: "1"
memory: 2500Mi
requests:
cpu: "1"
memory: 2500Mi
Run Code Online (Sandbox Code Playgroud)
命令参数:
spec:
containers:
- args:
- -c
- ln -sf /dev/stdout /var/log/access.log;java -Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false -Djava.security.egd=file:/dev/./urandom
-Xms1600m -Xmx1600m -XX:NewSize=420m -XX............
Run Code Online (Sandbox Code Playgroud)
我在AWS中有以下流量策略文档
Weighted Resource Record Set Weighted Resource Record Set
---------------------------- ----------------------------
Name: www.example.com Name: www.example.com
Type: A Type: A
Value: 192.0.2.11 Value: 192.0.2.12
Weight: 1 Weight: 3
Run Code Online (Sandbox Code Playgroud)
根据上述文档,25% 的请求应到达 192.0.2.11,75% 的请求应到达 192.0.2.12。
例如,如果我向 www.example.com 发送 4 个并发请求,则 3 个请求应到达 192.0.2.12,1 个请求应到达 192.0.2.11,但这种情况并未发生。
我观察到,前几个请求只会到达 192.0.2.11,一段时间后它只会到达 192.0.2.12。
这是默认行为吗?
这是示例json
{
"app": "K8s",
"version": "1.8",
"date": "2018-10-10"
}
Run Code Online (Sandbox Code Playgroud)
为了获得应用程序的价值,我可以在jq中这样做
jq '.app'
Run Code Online (Sandbox Code Playgroud)
但是我想要的是,我想将密钥作为bash变量传递给jq,即
bash_var="app"
jq '."${bash_var}"'
Run Code Online (Sandbox Code Playgroud)
我得到的输出为null而不是值。实现此目的的正确语法是什么?
列出项目中的实例
使用CLI,我们可以列出所有实例
gcloud computes instances list --project=<PROJECT-NAME>
Run Code Online (Sandbox Code Playgroud)
使用API,我们可以列出每个区域的实例
https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instances
Run Code Online (Sandbox Code Playgroud)
我们不能使用API列出所有实例吗?
我在 GCP 平台中有以下资源
与集群 (xyz VPC) 位于同一 VPC 中的私有实例,例如 ubuntu-vm-xyz
另一个 VPC (lmn VPC) 中的私有实例,比如 ubuntu-vm-lmn
由于自动创建了 Google 和 xyz VPC 之间的 VPC 对等互连,我能够从 ubuntu-vm-xyz 连接到集群。
而且我无法从 ubuntu-vm-lmn 连接到集群,因为必须手动创建 Google 和 lmn VPC 之间的 VPC 对等互连。我可以创建从我这边到 Google 网络的对等互连设置。
我们如何从 Google 端对 lmn VPC 进行对等连接?
groovy ×2
java ×2
jenkins ×2
kubernetes ×2
ansible ×1
bash ×1
cron ×1
gcloud ×1
go ×1
heap-memory ×1
jq ×1
json ×1
networking ×1
shell ×1
vpc ×1