小编k_v*_*ath的帖子

使用此关键字作为 Jenkins 文件中类构造函数的参数

我最近在 Jenkinsfile 中遇到了以下几行

def obj = new Foo(this, params)
obj.someMethod()
Run Code Online (Sandbox Code Playgroud)

this 关键字作为类构造函数的参数有什么用?

java groovy jenkins jenkins-pipeline

5
推荐指数
1
解决办法
1158
查看次数

Kubernetes CronJob - 如果上一个作业仍在运行,则跳过作业并等待下一个计划时间

我已安排 K8s cron 每 30 分钟运行一次。

如果当前作业仍在运行并且已达到下一个 cron 计划,则不应创建新作业,而是等待下一个计划。

如果上一个作业仍处于运行状态,则重复相同的过程。

cron kubernetes kubernetes-cronjob

5
推荐指数
2
解决办法
3074
查看次数

对于非本地类型,如何在 Golang 中使用类型从字符串转换为整数来解码 JSON?

下面是 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)

json go unmarshalling amazon-web-services

4
推荐指数
1
解决办法
6325
查看次数

如何访问groovy类文件中的全局变量?

我有以下目录结构

(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)

我在以下文件中有以下代码行

  1. 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)
  2. 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文件夹级别?

groovy global-variables jenkins jenkins-pipeline

4
推荐指数
1
解决办法
2278
查看次数

我们可以使用单个ad-hoc命令在ansible中运行多个模块吗?

我知道可以为每个模块一个接一个地运行多个即席命令,并使用剧本。

剧本:


- 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)

我希望以上内容在一行中使用即席执行。有可能这样做吗?

ansible ansible-ad-hoc

3
推荐指数
1
解决办法
1543
查看次数

如果 java 堆内存限制与 kubernetes 中的 pod 资源限制不同,会发生什么?

我正在使用以下配置在 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)
  1. 如果 java 进程已达到其最大堆限制(即 1600m (Xmx1600m))会发生什么
  2. 如果Xmx对pod内部的java进程没有影响,可以上到pod limit right(即内存:limits段的2500Mi)
  3. 如果以上配置正确,那我们就浪费了900Mi的内存权(2500-1600=900)

java heap-memory kubernetes

3
推荐指数
1
解决办法
2859
查看次数

AWS 中的加权流量文档未按预期工作?

我在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。

这是默认行为吗?

amazon-web-services amazon-route53

1
推荐指数
1
解决办法
1630
查看次数

如何将bash变量作为jq的键传递?

这是示例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而不是值。实现此目的的正确语法是什么?

bash shell jq

1
推荐指数
1
解决办法
1257
查看次数

为什么gcloud API不像gcloud cli那样成熟?

列出项目中的实例

使用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​​列出所有实例吗?

google-compute-engine google-cloud-platform gcloud

1
推荐指数
1
解决办法
62
查看次数

如何从另一个 VPC 中的实例连接到 GKE Private 集群?

我在 GCP 平台中有以下资源

  1. xyz VPC 中带有私有端点的 GKE 私有集群
  2. 与集群 (xyz VPC) 位于同一 VPC 中的私有实例,例如 ubuntu-vm-xyz

  3. 另一个 VPC (lmn VPC) 中的私有实例,比如 ubuntu-vm-lmn

由于自动创建了 Google 和 xyz VPC 之间的 VPC 对等互连,我能够从 ubuntu-vm-xyz 连接到集群。

而且我无法从 ubuntu-vm-lmn 连接到集群,因为必须手动创建 Google 和 lmn VPC 之间的 VPC 对等互连。我可以创建从我这边到 Google 网络的对等互连设置。

我们如何从 Google 端对 lmn VPC 进行对等连接?

networking vpc google-kubernetes-engine

0
推荐指数
1
解决办法
1058
查看次数