argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
18.04k stars 5.51k forks source link

Panic due to un-exported field #19583

Open sivchari opened 3 months ago

sivchari commented 3 months ago

Checklist:

Describe the bug

ApplicationDestination field has private field named isServerInferred. So if we use this spec to compare the old spec and new one, the code must fail due to following error.

panic: an unexported field was encountered, nested like this:  [recovered]
    panic: an unexported field was encountered, nested like this: bool [recovered]
    panic: an unexported field was encountered, nested like this: v1alpha1.ApplicationDestination -> bool [recovered]
    panic: an unexported field was encountered, nested like this: v1alpha1.ApplicationSpec -> v1alpha1.ApplicationDestination -> bool [recovered]
    panic: an unexported field was encountered, nested like this: v1alpha1.Application -> v1alpha1.ApplicationSpec -> v1alpha1.ApplicationDestination -> bool [recovered]
    panic: an unexported field was encountered, nested like this: *v1alpha1.Application -> v1alpha1.Application -> v1alpha1.ApplicationSpec -> v1alpha1.ApplicationDestination -> bool [recovered]
    panic: an unexported field was encountered, nested like this: *v1alpha1.Application -> v1alpha1.Application -> v1alpha1.ApplicationSpec -> v1alpha1.ApplicationDestination -> bool

https://github.com/argoproj/argo-cd/pull/2808 has implemented this field and this error is caused by this.

To Reproduce

app := &argocdv1.Application{}
app.SetName("test")
app.SetNamespace("test")

if _, err := ctrl.CreateOrUpdate(ctx, client, app, func() error {
        return nil
}

if err != nil {
        panic(err)
}

Expected behavior

Can compare this spec.

Screenshots

Version

Paste the output from `argocd version` here.

Logs

Paste any relevant application logs here.
pazepaze commented 1 month ago

I encountered this in my operator code that imports the module github.com/argoproj/argo-cd/v2 as well when I tried to create the ApplicationSet with CreateOrUpdate from controllerruntime.

What I did as a workaround was to add an equality function:

equality.Semantic.AddFunc(func(a, b argov1alpha1.ApplicationDestination) bool {
    return a.Name == b.Name && a.Namespace == b.Namespace && a.Server == b.Server
})

This is documented in the DeepEquals function from apimachinery:

...
// Unexported field members cannot be compared and will cause an informative panic; you must add an Equality
// function for these types.
func (e Equalities) DeepEqual(a1, a2 interface{}) bool {
...
}
andrii-korotkov-verkada commented 2 weeks ago

What's your argocd version?

pgaxatte commented 3 days ago

Hello,

I have this exact same issue with the helm chart v7.6.12 => argo-cd v2.12.6