小编lib*_*bzz的帖子

如何在 Kubernetes 的容器中设置环境变量?

我想ENV_VAR_VALUE在通过 Kubernetes 部署期间为容器设置一个环境变量(我只是命名)。

我在 pod yaml 配置中有以下内容:

...
...
    spec:
      containers:
      - name: appname-service
        image: path/to/registry/image-name
        ports:
        - containerPort: 1234
        env:
        - name: "ENV_VAR_VALUE"
          value: "some.important.value"
...
...
Run Code Online (Sandbox Code Playgroud)

容器需要使用ENV_VAR_VALUE的值。
但是在容器的应用程序日志中,它的值总是为空。
所以,我尝试从容器内部检查它的值:

$ kubectl exec -it appname-service bash
root@appname-service:/# echo $ENV_VAR_VALUE
some.important.value
root@appname-service:/# 
Run Code Online (Sandbox Code Playgroud)

因此,该值已成功设置。

我想这是因为在容器已经初始化之后设置了从 Kubernetes 定义的环境变量。

因此,我尝试从 pod yaml 配置中覆盖容器的 CMD:

...
...
    spec:
      containers:
      - name: appname-service
        image: path/to/registry/image-name
        ports:
        - containerPort: 1234
        env:
        - name: "ENV_VAR_VALUE"
          value: "some.important.value"
        command: ["/bin/bash"]
        args: ["-c", …
Run Code Online (Sandbox Code Playgroud)

kubernetes kubernetes-pod

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

洪水填充实施

这是我基于堆栈的泛洪填充算法的C#实现(我基于维基百科的定义).在编码之前,我只想看到它的工作原理.它确实如此.然后,我想知道实际填充的像素数.所以在我的代码中,我将返回类型更改为int并返回"ctr"变量.但是后来ctr大约是实际填充像素数的两倍(我制作了一个单独的函数,其唯一目的是计算这些像素 - 只是为了确定).

任何人都可以启发变量"ctr"如何以及为什么增加两倍应该有的话?

*Pixel类仅用作位图像素的x,y和颜色值的容器.

public Bitmap floodfill(Bitmap image, int x, int y, Color newColor)
{
    Bitmap result = new Bitmap(image.Width, image.Height);
    Stack<Pixel> pixels = new Stack<Pixel>();
    Color oldColor = image.GetPixel(x, y);
    int ctr = 0;

    pixels.Push(new Pixel(x, y, oldColor));

    while (pixels.Count > 0)
    {
        Pixel popped = pixels.Pop();

        if (popped.color == oldColor)
        {
            ctr++;
            result.SetPixel(popped.x, popped.y, newColor);

            pixels.Push(new Pixel(popped.x - 1, popped.y, image.GetPixel(x - 1, y));
            pixels.Push(new Pixel(popped.x + …
Run Code Online (Sandbox Code Playgroud)

c# flood-fill

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

如何使用包含文件数据的 JSON 正文发送 Invoke-WebRequest

问题:
如何将文件内容放入 Invoke-WebRequest 的 JSON 正文中,而不包含不需要的文件元数据?

我的目标是发送一个 HTTP 请求,如下所示:

Invoke-WebRequest -Uri http://localhost:4321/updatefile `
    -ContentType 'application/json' `
    -Method POST `
    -Body $Body
Run Code Online (Sandbox Code Playgroud)

在哪里:

PS C:\Users\User1234> $Body = ConvertTo-Json @(
    @{filename='file1.txt';filecontent=$file1},
    @{filename='file2.txt';filecontent=$file2}
)

PS C:\Users\User1234> $file1 = Get-Content "C:\path\to\file1.txt"
PS C:\Users\User1234> $file2 = Get-Content "C:\path\to\file2.txt"
Run Code Online (Sandbox Code Playgroud)

当我打印变量时:

PS C:\Users\User1234> echo $file1
aaaaa
PS C:\Users\User1234> echo $file2
bbbbb
Run Code Online (Sandbox Code Playgroud)

...它按照我的预期打印文件的内容。
但是打印文件内容显示$Body了更多我不需要的信息:

PS C:\Users\User1234> echo $Body
{
    "filename":  "file1.txt",
    "filecontent":  {
                        "value":  "aaaaa",
                        "PSPath":  "C:\\path\\to\\file1.txt",
                        "PSParentPath":  "C:\\path\\to",
                        "PSChildName":  "file1.txt",
                        "PSDrive":  {
                                        "CurrentLocation":  "Users\\User1234",
                                        "Name": …
Run Code Online (Sandbox Code Playgroud)

powershell invoke-webrequest

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

如何在 Node-RED 中合并来自多个有效负载的数据?

我想合并来自 3 个不同来源的数据(来自 HTTP msg.payload)。

但是,这些 HTTP 请求可能会被多次调用,因此可以多次接收来自同一来源的数据。

在此处输入图片说明

[{"id":"7ed13b41.131b14","type":"join","z":"246eac57.42ec74","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"index","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1370,"y":1160,"wires":[["d941ca6e.0e1aa8"]]},{"id":"d941ca6e.0e1aa8","type":"debug","z":"246eac57.42ec74","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1490,"y":1120,"wires":[]},{"id":"b04a312.d6c40d","type":"function","z":"246eac57.42ec74","name":"part 1","func":"msg.parts = {};\nmsg.parts.id = 12345;\nmsg.parts.index = 0;\nmsg.parts.count = 3;\nreturn msg;","outputs":1,"noerr":0,"x":1210,"y":1120,"wires":[["7ed13b41.131b14"]]},{"id":"30cec12.e2fc13e","type":"function","z":"246eac57.42ec74","name":"part 2","func":"msg.parts = {};\nmsg.parts.id = 12345;\nmsg.parts.index = 1;\nmsg.parts.count = 3;\nreturn msg;","outputs":1,"noerr":0,"x":1210,"y":1160,"wires":[["7ed13b41.131b14"]]},{"id":"8902f2d5.ea688","type":"function","z":"246eac57.42ec74","name":"part 3","func":"msg.parts = {};\nmsg.parts.id = 12345;\nmsg.parts.index = 2;\nmsg.parts.count = 3;\nreturn msg;","outputs":1,"noerr":0,"x":1210,"y":1200,"wires":[["7ed13b41.131b14"]]},{"id":"814f25b6.dd3958","type":"http in","z":"246eac57.42ec74","name":"source 1","url":"/source1","method":"get","upload":false,"swaggerDoc":"","x":1060,"y":1120,"wires":[["b04a312.d6c40d"]]},{"id":"cab634ac.5d9df8","type":"http in","z":"246eac57.42ec74","name":"source 2","url":"/source 2","method":"get","upload":false,"swaggerDoc":"","x":1060,"y":1160,"wires":[["30cec12.e2fc13e"]]},{"id":"98f89b04.9b5bb8","type":"http in","z":"246eac57.42ec74","name":"source 3","url":"/source3","method":"get","upload":false,"swaggerDoc":"","x":1060,"y":1200,"wires":[["8902f2d5.ea688"]]}]
Run Code Online (Sandbox Code Playgroud)

此流程中发生的情况是,当加入节点从源 1 接收 3 条消息时,它认为已msg.parts完成。我想要实现的行为是,只有当收到来自 3 个来源的数据时,流程才会继续。如果从同一来源接收数据,它只会覆盖以前的数据。

有没有办法在 Node-RED 中实现这一点?

node-red

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

为什么 helm 不使用部署模板中定义的名称?

即从name: {{ .Chart.Name }}-{{ .Values.module5678.name }}-pod下面

# deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ template "project1234.name" . }}
    chart: {{ template "project1234.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  name: {{ template "project1234.module5678.fullname" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "project1234.name" . }}
  template:
    metadata:
      labels:
        app: {{ template "project1234.name" . }}
    spec:
      containers:
      - image: "{{ .Values.image.name }}:{{ .Values.image.tag }}"
        name: {{ .Chart.Name }}-{{ .Values.module5678.name }}-pod
        ports: …
Run Code Online (Sandbox Code Playgroud)

kubernetes-helm

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