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: kill k8s pod with multi labels not work #174

Merged
merged 1 commit into from
Sep 5, 2022

Conversation

Icesource
Copy link
Contributor

@Icesource Icesource commented Aug 26, 2022

Signed-off-by: Icesource gonghuajian.ghj@alibaba-inc.com

Describe what this PR does / why we need it

Fix chaosblade-io/chaosblade#770

Does this pull request fix one issue?

Fixes chaosblade-io/chaosblade#770

Describe how you did it

之前,匹配用的 标签都保存在一个Map中,这会导致如果指定了同key的多个标签,后来的value会覆盖原来的value。
例如,指定 app=a , app=b ,那么只有app=b会 生效

修改为直接使用 labels.Requirement 保存标签可以做到不覆盖,且可调用Selector.In来实现多个value值的或匹配

Describe how to verify it

修改代码后使用以下pod进行验证

default       my-nginx-deployment-586df48455-c5str                       1/1     Running                  0          7m50s   app=mynginx,pod-template-hash=586df48455
default       my-nginx-deployment-586df48455-jlkmn                       1/1     Running                  0          14m     app=mynginx,pod-template-hash=586df48455
default       my2-nginx-deployment-6c67c949d9-kmzgw                      1/1     Running                  0          3d17h   app=mynginx2,pod-template-hash=6c67c949d9
default       my2-nginx-deployment-6c67c949d9-w66hf                      1/1     Running                  0          3d18h   app=mynginx2,pod-template-hash=6c67c949d9
default       nginx-deployment-66b6c48dd5-4khhx                          0/1     ContainerStatusUnknown   1          15d     app=nginx,pod-template-hash=66b6c48dd5
default       nginx-deployment-66b6c48dd5-8jvvr                          1/1     Running                  0          14m     app=nginx,pod-template-hash=66b6c48dd5
default       nginx-deployment-66b6c48dd5-q92jr                          1/1     Running                  0          14m     app=nginx,pod-template-hash=66b6c48dd5

以delete_pod为例
指定标签

- name: labels
      value:
      - "app=nginx"
      - "app=mynginx"

可以删除标签nginx和mynginx下的所有的pod

同时指定name和标签,如果name能匹配上任意一个标签,那么删除该name的pod,如果所有标签都没匹配上,则不删除


例如指定的pod没有匹配上任意对应的标签

    - name: names
      value:
      - "my-nginx-deployment-586df48455-c5str"
    - name: labels
      value:
      - "app=nginx2"
      - "app=mynginx2"

该pod不会被删除


例如,指定的pod匹配上了标签中的app=nginx标签

    - name: names
      value:
      - "my-nginx-deployment-586df48455-c5str"
    - name: labels
      value:
      - "app=nginx"
      - "app=mynginx2"

该pod会被删除

@MandssS MandssS added this to the v1.7.0 milestone Sep 5, 2022
Signed-off-by: Icesource <gonghuajian.ghj@alibaba-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

blade kill k8s pod with multi labels not work
2 participants