Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

GH-324 pollicyaffected condition for gateway #433

Closed
wants to merge 1 commit into from

Conversation

maksymvavilov
Copy link
Contributor

@maksymvavilov maksymvavilov commented Aug 17, 2023

closes #324

What

Reporting the state of the DNSPolicy to the Gateway affected by that policy

Verification

  1. Get the MGC running
  2. Create a DNSPolicy
kubectl apply -f - <<EOF
apiVersion: kuadrant.io/v1alpha1
kind: DNSPolicy
metadata:
  name: prod-web
  namespace: multi-cluster-gateways
spec:
  targetRef:
    name: prod-web
    group: gateway.networking.k8s.io
    kind: Gateway
  healthCheck:
    allowInsecureCertificates: true
    endpoint: /
    expectedResponses:
      - 200
      - 201
      - 301
    failureThreshold: 5
    port: 443
    protocol: https
EOF
  1. Watch conditions on the gateway getting updated.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 17, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: makslion
Once this PR has been reviewed and has the lgtm label, please assign sergioifg94 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@maksymvavilov maksymvavilov linked an issue Aug 17, 2023 that may be closed by this pull request
@maksymvavilov
Copy link
Contributor Author

maksymvavilov commented Aug 17, 2023

/hold
I'd like to ensure that this is what we want and how we want.
The "what" part:

  1. We have an annotation on the Gateway referencing policy. The conditions block looks like a glorified annotation with an error message attached in case something goes wrong. In any case, it might be worth discussing with Kuadrant people since they are the ones to implement an annotation.
  2. There is still a discussion on the Gateway side about how this should be done. Since all this is still considered to be "experimental" and aimed to land after the GA should we wait for them to deploy conditions for the DNSPolicy itself?

The "how" part:

  1. We are about to have more stuff that could use those conditions - such as TLS policies. Would it be worth "standardizing" the way we do conditions?
  2. Annotations vs condition blocks - one of them or both?

Also, invite @mikenairn to add more or correct me on this.

@maksymvavilov maksymvavilov temporarily deployed to e2e-internal August 17, 2023 12:30 — with GitHub Actions Inactive
ConditionTypeReady string = "Ready"
ConditionTypeReady ConditionType = "Ready"

DNSPolicyAffected ConditionType = "DNSPolicyAffected"
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm I am wondering if this would be better in the dnspolicy package?

@@ -225,6 +236,49 @@ func (r *DNSPolicyReconciler) readyCondition(targetNetworkObjectectKind string,
return cond
}

func buildGatewayCondition(reason conditions.ConditionReason, err error) *metav1.Condition {
Copy link
Contributor

@maleck13 maleck13 Aug 21, 2023

Choose a reason for hiding this comment

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

prob should name this buildDNSPolicyAffectedCondition ?

Copy link
Contributor

@maleck13 maleck13 Aug 21, 2023

Choose a reason for hiding this comment

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

or we could make it a bit more generic and add it to the conditions package

func buildPolicyAffectedCondition(conditionType conditions.ConditionType, policy metav1.Object, reason conditions.ConditionReason, err error) *metav1.Condition {
	condition := &metav1.Condition{
		Type:    string(conditionType),
		Status:  metav1.ConditionTrue,
		Reason:  string(reason),
		Message: fmt.Sprintf("%s policy affected. policy namespace %s policy name", conditionType, policy.Namespace, policy.Name),
	}

	if err != nil {
		condition.Status = metav1.ConditionFalse
		condition.Message = err.Error()
	}

	return condition
}

return condition
}

func (r *DNSPolicyReconciler) updateGatewayCondition(ctx context.Context, condition *metav1.Condition, gatewayDiff *reconcilers.GatewayDiff) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

These seem like potentially generic for all policy controllers?

if err := r.reconcileDNSRecords(ctx, dnsPolicy, gatewayDiffObj); err != nil {
if err = r.reconcileDNSRecords(ctx, dnsPolicy, gatewayDiffObj); err != nil {
gatewayCondition = buildGatewayCondition(conditions.DNSPolicyReasonInvalid, err)
_ = r.updateGatewayCondition(ctx, gatewayCondition, gatewayDiffObj)
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why we are ignoring the error here?

if err := r.reconcileHealthChecks(ctx, dnsPolicy, gatewayDiffObj); err != nil {
if err = r.reconcileHealthChecks(ctx, dnsPolicy, gatewayDiffObj); err != nil {
gatewayCondition = buildGatewayCondition(conditions.DNSPolicyReasonInvalid, err)
_ = r.updateGatewayCondition(ctx, gatewayCondition, gatewayDiffObj)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here and below. Not much point in returning an error if all we do is ignore it

@@ -357,7 +357,7 @@ var _ = Describe("DNSPolicy", Ordered, func() {
return false
}

return meta.IsStatusConditionTrue(dnsPolicy.Status.Conditions, conditions.ConditionTypeReady)
return meta.IsStatusConditionTrue(dnsPolicy.Status.Conditions, string(conditions.ConditionTypeReady))
Copy link
Contributor

Choose a reason for hiding this comment

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

why did we change the types here out of curiosity

@maleck13
Copy link
Contributor

#436

@maleck13 maleck13 closed this Aug 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add PolicyAffected status condition for gateway
2 participants