-
Notifications
You must be signed in to change notification settings - Fork 2
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: add member conditions in status of KonnectGatewayControlPlane #138
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ func init() { | |
// +kubebuilder:printcolumn:name="OrgID",description="Konnect Organization ID this resource belongs to.",type=string,JSONPath=`.status.organizationID` | ||
// +kubebuilder:validation:XValidation:message="spec.konnect.authRef is immutable when an entity is already Programmed", rule="!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True') ? true : self.spec.konnect.authRef == oldSelf.spec.konnect.authRef" | ||
// +kubebuilder:validation:XValidation:message="spec.konnect.authRef is immutable when an entity refers to a Valid API Auth Configuration", rule="!self.status.conditions.exists(c, c.type == 'APIAuthValid' && c.status == 'True') ? true : self.spec.konnect.authRef == oldSelf.spec.konnect.authRef" | ||
// +kubebuilder:validation:XValidation:message="status.members is only applicable for ControlPlanes that are created as groups", rule="(has(self.spec.cluster_type) && self.spec.cluster_type != 'CLUSTER_TYPE_CONTROL_PLANE_GROUP') ? (!has(self.status) || !has(self.status.members)) : true" | ||
// +apireference:kgo:include | ||
type KonnectGatewayControlPlane struct { | ||
metav1.TypeMeta `json:",inline"` | ||
|
@@ -71,6 +72,10 @@ type KonnectGatewayControlPlaneStatus struct { | |
// +kubebuilder:validation:MaxItems=8 | ||
// +kubebuilder:default={{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}} | ||
Conditions []metav1.Condition `json:"conditions,omitempty"` | ||
|
||
// MemberStatus is the status of each member in the control plane group. | ||
// This field is only applicable for control planes with spec.cluster_type = CLUSTER_TYPE_CONTROL_PLANE_GROUP. | ||
MemberStatus map[string][]metav1.Condition `json:"members,omitempty"` | ||
} | ||
|
||
// GetKonnectLabels gets the Konnect Labels from object's spec. | ||
|
@@ -88,6 +93,18 @@ func (c *KonnectGatewayControlPlane) GetKonnectAPIAuthConfigurationRef() Konnect | |
return c.Spec.KonnectConfiguration.APIAuthConfigurationRef | ||
} | ||
|
||
// SetMemberStatus sets conditions of a member of the control plane group in status. | ||
// REVIEW: is it better to replace it with `SetMemberCondition` to set a single condition of a member? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we see a use case for setting more than 1 condition for a member? I believe at this stage we're OK with setting just 1 (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about not adding another field and having it granular per member, but only populating a When creating Kong/gateway-operator#797 I didn't take that into account, but I think that might be easier to implement and cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 This would already be a nice improvement and as you've mentioned: will be easier, less error prone and more efficient to implement. WDYT @randmonkey ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds good to add a specific condition type in the CP representing the CP group. For further details, we can add fields There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's focus on the CP group condition like suggested by @czeslavo - |
||
func (c *KonnectGatewayControlPlane) SetMemberStatus(name string, conditions []metav1.Condition) { | ||
if c.Status.MemberStatus == nil { | ||
c.Status.MemberStatus = map[string][]metav1.Condition{ | ||
name: conditions, | ||
} | ||
} | ||
|
||
c.Status.MemberStatus[name] = conditions | ||
} | ||
|
||
// KonnectGatewayControlPlaneList contains a list of KonnectGatewayControlPlane. | ||
// +kubebuilder:object:root=true | ||
// +apireference:kgo:include | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add tests here for the added field? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried but it requires "error happens in updating status". This requires more changes in the testing framework. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this change introduces CEL validation, I'd halt merging this until we can figure out what is the cause of this error. We don't want to merge a change that would break updating the CP CRD for any supported use case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if we should validate status fields with CEL rules 🤔 It will only be populated by the controller - that's where we should ensure it's generated valid. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point @czeslavo. This makes a lot of sense. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to allow an extension of this field in the future, I suggest to put the conditions in a struct, which could then have other fields added in the future.