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

[vmcluster]: About the HasSpecChanges method and the AnnotationsFiltered method #753

Closed
z-anshun opened this issue Sep 11, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@z-anshun
Copy link

Hi, everyone!
When I read the source code, I had some doubts about vmcluster, they may be bugs:

  1. The HasSpecChanges method does not judge null values, which may cause an error when querying crd for the first time.
    code:
    https://github.com/VictoriaMetrics/operator/blob/master/api/v1beta1/vmcluster_types.go#L947
    error:
1.6944398628889349e+09  ERROR   controller      failed to check if cluster spec changed {"Request.Namespace": "vm", "Request.Name": "example-vmcluster-persistent", "error": "cannot parse last applied cluster spec value:  : unexpected end of JSON input"}
...
  1. annotationFilterPrefixes will filter annotations prefixed by operator.victoriametrics.com/, but in the LastAppliedSpecAsPatch function, the key of annotation is set to operator.victoriametrics/last-applied-spec. I think annotationFilterPrefixes expects to filter it out.
@Haleygo Haleygo self-assigned this Sep 12, 2023
@Haleygo Haleygo added the bug Something isn't working label Sep 12, 2023
@Haleygo
Copy link
Contributor

Haleygo commented Sep 12, 2023

Hello, thanks for the issue!

The HasSpecChanges method does not judge null values, which may cause an error when querying crd for the first time.

That's a nosiy message for new resource, but it also print error if LastAppliedSpecAsPatch wasn't ever success or annotation got lost for some reason, so I think it's ok to leave it there.

annotationFilterPrefixes will filter annotations prefixed by operator.victoriametrics.com/, but in the LastAppliedSpecAsPatch function, the key of annotation is set to operator.victoriametrics/last-applied-spec. I think annotationFilterPrefixes expects to filter it out.

Yeah, should be fixed in #754, please take a look.

@z-anshun
Copy link
Author

Thank you.

That's a nosiy message for new resource, but it also print error if LastAppliedSpecAsPatch wasn't ever success or annotation got lost for some reason, so I think it's ok to leave it there.

By the way, because Reconcile may execute r.Client.Patch at the end, but there is no waitExpanding like creating or updating other components. This may cause the next time the Reconcile method is executed, the VMCluster obtained may not be the latest version, which may cause the error log to be printed twice.

The error log is as follows:

1.694585952956201e+09   ERROR   controller      failed to check if cluster spec changed {"Request.Namespace": "vm", "Request.Name": "example-vmcluster-persistent", "error": "cannot parse last applied cluster spec value:  : unexpected end of JSON input"}
github.com/VictoriaMetrics/operator/controllers.(*VMClusterReconciler).Reconcile
        /github/operator/controllers/vmcluster_controller.go:63
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile
        /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:121
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
        /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:320
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
        /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:273
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
        /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:234
1.69458595818442e+09    INFO    controller      Reconciling VMCluster   {"Request.Namespace": "vm", "Request.Name": "example-vmcluster-persistent"}
1.6945859964140449e+09  ERROR   controller      failed to check if cluster spec changed {"Request.Namespace": "vm", "Request.Name": "example-vmcluster-persistent", "error": "cannot parse last applied cluster spec value:  : unexpected end of JSON input"}
github.com/VictoriaMetrics/operator/controllers.(*VMClusterReconciler).Reconcile
        /github/operator/controllers/vmcluster_controller.go:63
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile
       /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:121
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
        /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:320
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
        /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:273
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
       /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:234
1.694585996437922e+09   ERROR   Reconciler error        {"controller": "vmcluster", "controllerGroup": "operator.victoriametrics.com", "controllerKind": "VMCluster", "VMCluster": {"name":"example-vmcluster-persistent","namespace":"vm"}, "namespace": "vm", "name": "example-vmcluster-persistent", "reconcileID": "367f79fb-01ad-40cd-a3ee-a1c00a16e668", "error": "cannot set expanding status for cluster: Operation cannot be fulfilled on vmclusters.operator.victoriametrics.com \"example-vmcluster-persistent\": the object has been modified; please apply your changes to the latest version and try again"}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
        /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:326
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
        /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:273
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
       /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:234

This isn't a panic mistake, but I feel like there should be a better way to avoid this.

@Haleygo
Copy link
Contributor

Haleygo commented Sep 21, 2023

Hmm, that's right. But there is no pods or other resources for vmcluster to wait or show it's ready, I can only come up the idea to have a hardcode timeout or recheck it's spec, both sound not so good.
Please let me know if you get other idea)

@f41gh7
Copy link
Collaborator

f41gh7 commented Sep 21, 2023

Linked commit must remove misleading error message.

@f41gh7
Copy link
Collaborator

f41gh7 commented Oct 5, 2023

@f41gh7 f41gh7 closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants