Skip to content

Conversation

@dgn
Copy link
Collaborator

@dgn dgn commented Oct 7, 2025

This adds a targetRef field to the ZTunnel CRD, allowing users to keep their ZTunnel config in sync with what they already defined in the Istio or IstioRevision CRD.

@dgn dgn requested a review from a team as a code owner October 7, 2025 08:57
@codecov
Copy link

codecov bot commented Oct 7, 2025

Codecov Report

❌ Patch coverage is 49.38272% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.10%. Comparing base (eb2b8c1) to head (926dd12).
⚠️ Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
controllers/ztunnel/ztunnel_controller.go 35.71% 34 Missing and 2 partials ⚠️
pkg/revision/references.go 78.26% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1259       +/-   ##
===========================================
+ Coverage   65.19%   77.10%   +11.90%     
===========================================
  Files          39       44        +5     
  Lines        2497     2878      +381     
===========================================
+ Hits         1628     2219      +591     
+ Misses        721      548      -173     
+ Partials      148      111       -37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dgn dgn force-pushed the ztunnel-targetref branch 5 times, most recently from bcd9f0d to b655b0e Compare October 7, 2025 09:50
@dgn
Copy link
Collaborator Author

dgn commented Oct 7, 2025

This should support most use cases including RevisionBased update strategies already. Another thing we could add is making the IstioRevisionController aware of the link - currently, users have to configure the ZTunnel namespace on their Istio/IstioRevision:

spec:
  values:
    pilot:
      trustedZtunnelNamespace: ztunnel

This could be inferred at install time by looking for a ZTunnel resource that has a targetRef pointing to this IstioRevision and then pulling the spec.namespace value from that ZTunnel.

return fmt.Errorf("failed to apply profile: %w", err)
}

// Apply values from referenced IstioRevision first
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it would make sense to warn users when setting the same config in both ztunnel and Istio to different values?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think we need to warn users - their settings will always take precedence. By default, they should only configure the version and targetRef

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, a warning might imply that something is wrong. Can we add a log message saying that user setting from ztunnel are used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm. as we're just merging the fields I don't think we have the ability to give that sort of granular feedback. or rather, we'd have to add a bunch of logic in order to do that. maybe just documenting the behavior is enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, works for me.

BeforeAll(func() {
common.CreateIstio(k, version.Name, `
values:
global:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be added to samples?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure about the global setting. I will add the targetRef to the sample though

@dgn dgn force-pushed the ztunnel-targetref branch from b655b0e to 88ed7f4 Compare October 8, 2025 15:32
Copy link
Contributor

@sridhargaddam sridhargaddam left a comment

Choose a reason for hiding this comment

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

Thanks @dgn.

State ZTunnelConditionReason `json:"state,omitempty"`

// IstioRevision stores the name of the referenced IstioRevision
IstioRevision string `json:"istioRevision"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to use omitempty here (if users does not specify targetRef in spec)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point, will add

return fmt.Errorf("failed to apply profile: %w", err)
}

// Apply values from referenced IstioRevision first
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, a warning might imply that something is wrong. Can we add a log message saying that user setting from ztunnel are used?

return podAnnotations[constants.IstioRevLabel]
}

func GetIstioRevisionFromTargetReference(ctx context.Context, client client.Client, ref v1.TargetReference) (*v1.IstioRevision, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to include unit tests for this API.

var revisionName string
switch ref.Kind {
case v1.IstioRevisionKind:
revisionName = ref.Name
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add input validation for targetReference?

ztunnels := v1alpha1.ZTunnelList{}
err := r.Client.List(ctx, &ztunnels, &client.ListOptions{})
if err != nil {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we add a log message here when err != nil?

version: %s
namespace: %s
targetRef:
kind: Istio
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we will require a test case without the targetRef?

@sridhargaddam
Copy link
Contributor

This should support most use cases including RevisionBased update strategies already. Another thing we could add is making the IstioRevisionController aware of the link - currently, users have to configure the ZTunnel namespace on their Istio/IstioRevision:

spec:
  values:
    pilot:
      trustedZtunnelNamespace: ztunnel

This could be inferred at install time by looking for a ZTunnel resource that has a targetRef pointing to this IstioRevision and then pulling the spec.namespace value from that ZTunnel.

This is a good idea.


// The Istio control plane that this ZTunnel instance is associated with. Valid references are Istio and IstioRevision resources, Istio resources are always resolved to their current active revision.
// Values relevant for ZTunnel will be copied from the referenced IstioRevision resource, these are `spec.values.global`, `spec.values.meshConfig`, `spec.values.revision`.
TargetRef *v1.TargetReference `json:"targetRef,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we should add a comment here saying that if users specify targetRef along with additional config, the user values will take precedence.

@zmiklank
Copy link
Contributor

Hi @dgn, do you think it could be useful to add info about this API change into ZTunnel CRD docs too?

This adds a `targetRef` field to the ZTunnel CRD, allowing users to keep
their ZTunnel config in sync with what they already defined in the
`Istio` or `IstioRevision` CRD.

Signed-off-by: Daniel Grimm <[email protected]>
@dgn dgn force-pushed the ztunnel-targetref branch from 88ed7f4 to 926dd12 Compare October 21, 2025 14:59
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.

5 participants