Skip to content

Managing different versions of CRD in the operator-idk controller #6324

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

Closed
akularaja opened this issue Feb 21, 2023 · 5 comments
Closed

Managing different versions of CRD in the operator-idk controller #6324

akularaja opened this issue Feb 21, 2023 · 5 comments
Labels
language/go Issue is related to a Go operator project lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. triage/support Indicates an issue that is a support question.
Milestone

Comments

@akularaja
Copy link

Type of question

General operator-related help

Question

What did you do?

I have setup a new Operator for this CRD called foo. I followed the steps in the Go tutorial, so everything with regards to the Controller is the same as in that tutorial.

foo has two versions, v1alpha1 and v2beta1. There are some drastic changes between these version. v2beta1 has a complete different Spec and Status. Currently, we have another service (another controller that was written from scratch, not using the operator-idk) that operates on the v1alpha version.

I recently added this new v2beta1 version, and I am in the process of setting up the controller using the operator-idk to reconcile on this version.

It seems that the scheme, GroupVersion and all that is setup properly when creating the Manager and setting up the controller.

In the Kube cluster, I have two Foo resources created and deployed, foo1 and foo2. The former is a v1alpha1 version and the latter is v2beta1

In the Reconcile method, when I do the following:

foo := &v2beta1.Foo{}
err := r.Get(ctx, req.NamespacedName, foo)
...

It retrieves foo1 which is of v1alpha1 version. Another weird thing is that when I do

fmt.Println(foo1.APIVersion)

It prints v2beta1.

What did you expect to see?

I expect that in the Reconcile method, when I do:

r.Get(ctx, req.NamespacedName, foo)

I only retrieve the v2beta1 version of the foo resources.

What did you see instead? Under which circumstances?

I am seeing that my Get call is retrieving both v1alpha1 and v2beta1 versions.

Environment

Operator type:

/language go

Kubernetes cluster type:

vanilla

$ operator-sdk version

operator-idk version: "v1.26.0", commit: "cbeec475e4612e19f1047ff7014342afe93f60d2", kubernetes version: "v1.25.0", go version: "go1.19.4", GOOS: "darwin", GOARCH: "arm64"

$ go version (if language is Go)

go version go1.18.10 darwin/arm64

$ kubectl version

Client Version: v1.24.4

Additional context

@openshift-ci openshift-ci bot added the language/go Issue is related to a Go operator project label Feb 21, 2023
@varshaprasad96
Copy link
Member

@akularaja In k8s clusters on creation of a resource, the apiserver stores it on a persistent storage called etcd. Though multiple version are supported, the etcd uses only version when persisting the resources for storage. I suspect that in your case, v1alpha1 is the storage version. You can check if it is so, by looking at the storage: field in CRD. If it is set to true, it means that this is the version in which your resources will be stored in etcd, which is possibly why when you fetch resources you see v1alpha objects.

In general, if you have multiple versions, only one should be marked as storage, the others must be set to storage: false. To be able to use multiple versions you would have to use conversion webhooks such that the apiserver knows how to convert objects between 2 versions. More documentation on the same: https://book.kubebuilder.io/multiversion-tutorial/conversion.html

@varshaprasad96 varshaprasad96 added the triage/support Indicates an issue that is a support question. label Feb 27, 2023
@varshaprasad96 varshaprasad96 added this to the Backlog milestone Feb 27, 2023
@openshift-bot
Copy link

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

@openshift-ci openshift-ci bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 29, 2023
@openshift-bot
Copy link

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

@openshift-ci openshift-ci bot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jun 28, 2023
@openshift-bot
Copy link

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-ci openshift-ci bot closed this as completed Jul 29, 2023
@openshift-ci
Copy link

openshift-ci bot commented Jul 29, 2023

@openshift-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/go Issue is related to a Go operator project lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. triage/support Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

3 participants