open-cluster-management-io / policy-generator-plugin

A Kustomize generator plugin to generate Open Cluster Management policies
Apache License 2.0
29 stars 31 forks source link

placement section issues #124

Closed luiscachog closed 1 year ago

luiscachog commented 1 year ago

Hi, I'm trying to generate a policy that affects two (or more envs) using the next stanza:

  placement:
    clusterSelectors:
      matchExpressions:
      - key: environment
        operator: In
        values:
        - prd
        - non-prd

However, when I run the command:

kustomize build --enable-alpha-plugins > install-operator-policy.yaml

I'm having the next output:

error processing the PolicyGenerator file '/var/folders/l0/vvhr89r17f170c_737kjmny40000z8/T/kust-plugin-config-2887398890': the PolicyGenerator configuration file is invalid: yaml: unmarshal errors:
  line 24: cannot unmarshal !!seq into string
Error: failure in plugin configured via /var/folders/l0/vvhr89r17f170c_737kjmny40000z8/T/kust-plugin-config-2887398890; exit status 1: exit status 1

I also tried this way, that works when I set one environment:

  placement:
    clusterSelectors:
      environment: "prd"

But when I add a second environment like:

  placement:
    clusterSelectors:
      environment: 
        - "prd"
        - "non-prd"

I received the same message:

error processing the PolicyGenerator file '/var/folders/l0/vvhr89r17f170c_737kjmny40000z8/T/kust-plugin-config-2180361478': the PolicyGenerator configuration file is invalid: yaml: unmarshal errors:
  line 24: cannot unmarshal !!seq into string
Error: failure in plugin configured via /var/folders/l0/vvhr89r17f170c_737kjmny40000z8/T/kust-plugin-config-2180361478; exit status 1: exit status 1

Could you help me with the correct stanza for placement to use 2 or more labels?

dhaiducek commented 1 year ago

@luiscachog Thanks for the question!

For the matchExpressions, it looks good and I used what you provided with the latest code and it worked to generate the PlacementRule, so maybe you need to update to the latest version? There was a fix in v1.11.0 to address a bug around the placement generation, so maybe that could help here.

For providing key: value pairs directly under clusterSelector, that is available for backward compatibility and has to be provided as a map with 1-to-1 keys and values, so that won't work for this use case.

Let me know whether an update might work to resolve this!

luiscachog commented 1 year ago

Hello @dhaiducek!

You are right, I upgrade from v1.10.0 to v1.12.2 and now is working!

Closing this one!