philpep / imago

Ensure kubernetes pods run on latest images builds from the docker registry
Apache License 2.0
96 stars 13 forks source link

How to filter deployments by kubernetes labels #26

Open martin-schaefer opened 3 years ago

martin-schaefer commented 3 years ago

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.

philpep commented 3 years ago

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.

martin-schaefer commented 3 years ago

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 commented 3 years ago

Would this be correct?

                            "args": [
                                "--update",
                                "-l metadata.labels.continous-deployment=true"
                            ],
derjohn commented 3 years ago

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