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

There is a problem with the data type of Attributes and pods in class Selector. It should be a dictionary instead of a list. #6

Open
Benxiaohai001 opened this issue Nov 22, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Benxiaohai001
Copy link

Describe the bug

There is a problem with the data type of Attributes and pods in class Selector. It should be a dictionary instead of a list.

Reproduction steps

I follow the official documentation to inject faults into the service. The script is as follows:

import uuid
from chaosmesh.client import Client, Experiment
from chaosmesh.k8s.selector import Selector

# creating the ChaosMesh client
client = Client(version="v1alpha1")

# target pods selector; by labelSector or by pods in specified namespaces
selector = Selector(labelSelectors=None, pods=["my-cnosdb-meta-0"], namespaces=["cnosdb-community-latest-3meta-2querytskv"])
print(selector);

exp_name = str(uuid.uuid4())

# starting up the pod kill experiment
client.start_experiment(Experiment.POD_KILL, namespace="cnosdb-community-latest-3meta-2querytskv", name=exp_name, selector=selector)

but the result as follow:

admission webhook "mpodchaos.kb.io" denied the request: json: cannot unmarshal array into Go struct field PodSelectorSpec.spec.selector.pods of type map[string][]string",

Later, I changed the type of pods and wrote it as a dictionary. I found that the injection failure was normal as follows:

import uuid
from chaosmesh.client import Client, Experiment
from chaosmesh.k8s.selector import Selector

# creating the ChaosMesh client
client = Client(version="v1alpha1")

# target pods selector; by labelSector or by pods in specified namespaces
selector = Selector(labelSelectors=None, pods={"cnosdb-community-latest-3meta-2querytskv":   ["my-cnosdb-meta-0"]}, namespaces=["cnosdb-community-latest-3meta-2querytskv"])
print(selector);

exp_name = str(uuid.uuid4())

# starting up the pod kill experiment
client.start_experiment(Experiment.POD_KILL, namespace="cnosdb-community-latest-3meta-2querytskv", name=exp_name, selector=selector)

the result:

root@ubuntu:/home/bca/code/python3# python3 test_chaos_mesh.py
Selector(namespaces=['cnosdb-community-latest-3meta-2querytskv'], labelSelectors=None, pods={'cnosdb-community-latest-3meta-2querytskv': ['my-cnosdb-meta-0']})
INFO:chaosmesh:starting POD_KILL experiment bbe09fd5-cd7d-4db6-8d0a-53ab85c57f0c in cnosdb-community-latest-3meta-2querytskv namespace
INFO:chaosmesh:chaosmesh experiment bbe09fd5-cd7d-4db6-8d0a-53ab85c57f0c got applied
root@ubuntu:/home/bca/code/python3# python3 test_chaos_mesh.py

...

Expected behavior

1

Additional context

1

@Benxiaohai001 Benxiaohai001 added the bug Something isn't working label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant