imago icon indicating copy to clipboard operation
imago copied to clipboard

How to filter deployments by kubernetes labels

Open martin-schaefer opened this issue 3 years ago • 4 comments

Hi,

I want to use a label on my kubernetes deployments, so imago will only update the ones which a marked. But I a m not sure how the correct syntax for the command is, and several tries did not work. The label I want to use is:

continous-deployment: true

I've deployed imago as cronjob and in my spec I gave the following args, but this did not work. Imago does not update anything.

                        "containers": [
                            {
                                "args": [
                                    "--update",
                                    "--l=continous-deployment=true"
                                ],
                                "image": "philpep/imago:latest",
                                "imagePullPolicy": "Always",
                                "name": "imago"
                            }

Is this supported and what are the correct args for this? Thanks for any help.

martin-schaefer avatar May 06 '21 15:05 martin-schaefer

Hi, as described by imago --help:

  -l string
        Kubernetes labels selectors
        Warning: applies to Deployment, DaemonSet, StatefulSet and CronJob, not pods !

In your deployment you probably assign pod labels in spec.template.metadata.labels, these are pods labels and imago wont match them. It will match labels in metadata.labels of the deployment.

philpep avatar May 06 '21 18:05 philpep

I placed the labels on the deployment resource, not on the pod. Probably it's just a minor syntaxt error on my args section:. e.g I am not sure if two equal signs are correct or there must be one or two dashes before 'update' and 'l'. I found no exact example for my case. Can you give me a working example?

                                "args": [
                                    "--update",
                                    "--l=continous-deployment=true"
                                ],

martin-schaefer avatar May 06 '21 18:05 martin-schaefer

Would this be correct?

                            "args": [
                                "--update",
                                "-l metadata.labels.continous-deployment=true"
                            ],

martin-schaefer avatar May 06 '21 18:05 martin-schaefer

@martin-schaefer

I think you want to use "field-selector" instead of label selector?

Usage of imago-linux-amd64:
....
  -field-selector string
        Kubernetes field-selector
        example: metadata.name=myapp

Or: use label selectors -l continous-deployment=true (without the metadata boilerplate)

derjohn avatar Jul 02 '21 06:07 derjohn