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 ClustersPerDecisionGroup as optional field #263

Conversation

haoqing0110
Copy link
Member

Summary

Related issue(s)

Fixes #

Signed-off-by: haoqing0110 <qhao@redhat.com>
@haoqing0110
Copy link
Member Author

/assign @serngawy

@@ -137,7 +137,6 @@ type GroupStrategy struct {
// group SHOULD be less than ClustersPerDecisionGroup. Once the number of items exceeds the ClustersPerDecisionGroup,
// the decisionGroups will also be be divided into multiple decisionGroups with same GroupName but different GroupIndex.
//
// +kubebuilder:validation:Required
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing it ? we need to keep the default value 100% exist if the user did not defined the GroupStrategy. With omitempty available it will be empty string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meets below error if this field is required.

➜  placement-strategy git:(master) ✗ cat placement1.yaml
#  clusteradm clusterset bind global --namespace default
apiVersion: cluster.open-cluster-management.io/v1beta1
kind: Placement
metadata:
  name: placement1
  namespace: default
spec:
  clusterSets:
    - global
  tolerations:
  - key: cluster.open-cluster-management.io/unreachable
    operator: Exists
  - key: cluster.open-cluster-management.io/unavailable
    operator: Exists
  decisionStrategy:
    groupStrategy:
      decisionGroups:
      - groupName: prod-canary-west
        groupClusterSelector:
          labelSelector:
            matchExpressions:
              - key: prod-canary-west
                operator: Exists
      - groupName: prod-canary-east
        groupClusterSelector:
          labelSelector:
            matchExpressions:
              - key: prod-canary-east
                operator: Exists
➜  placement-strategy git:(master) ✗ kubectl apply -f placement1.yaml
error: error validating "placement1.yaml": error validating data: ValidationError(Placement.spec.decisionStrategy.groupStrategy): missing required field "clustersPerDecisionGroup" in io.open-cluster-management.cluster.v1beta1.Placement.spec.decisionStrategy.groupStrategy; if you choose to ignore these errors, turn validation off with --validate=false

Even remove it, since it has default value 100%

	// +kubebuilder:default:="100%"
	// +optional

The applied resource will still have a default value 100% generated.

After removing the Required

➜  placement-strategy git:(master) ✗ kubectl apply -f placement1.yaml
placement.cluster.open-cluster-management.io/placement1 created
➜  placement-strategy git:(master) ✗ kubectl get placement placement1 -oyaml | grep spec -A 10
spec:
  clusterSets:
  - global
  decisionStrategy:
    groupStrategy:
      clustersPerDecisionGroup: 100%
      decisionGroups:
      - groupClusterSelector:
          labelSelector:
            matchExpressions:
            - key: prod-canary-west

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, then sounds good to me.

@openshift-ci openshift-ci bot added the lgtm label Aug 22, 2023
@qiujian16
Copy link
Member

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: haoqing0110, qiujian16, serngawy

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 2e8926a into open-cluster-management-io:main Aug 22, 2023
10 checks passed
@haoqing0110 haoqing0110 deleted the br_placement-strategy branch August 23, 2023 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants