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

Enable OLM to update CRD when there is only one owner of that CRD #878

Merged

Conversation

dinhxuanvu
Copy link
Member

Signed-off-by: Vu Dinh vdinh@redhat.com

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 31, 2019
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 4, 2019
@dinhxuanvu
Copy link
Member Author

/retest

@dinhxuanvu
Copy link
Member Author

/retest

@dinhxuanvu dinhxuanvu force-pushed the update-crd-one branch 3 times, most recently from d6590c3 to dbe3059 Compare June 11, 2019 08:35
@dinhxuanvu
Copy link
Member Author

Ready for final review and approval for merging :)

Copy link
Member

@njhale njhale left a comment

Choose a reason for hiding this comment

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

Looking really good! Have a few comments that are mostly non-blocking.

pkg/controller/operators/catalog/operator.go Outdated Show resolved Hide resolved
func ProvidedAPIsIndexFunc(obj interface{}) ([]string, error) {
indicies := []string{}

csv, ok := obj.(*v1alpha1.ClusterServiceVersion)
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking: this is probably a good place to use OLM's internal versions. If #881 merges first, that could look like:

import (
// ...
       "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators"
       "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/install"
// ...
)

// ...

var scheme = runtime.NewScheme()

func init() {
	// Register internal types and conversion funcs
        install.Install(scheme)
}

// ...

func ProvidedAPIsIndexFunc(obj interface{}) ([]string, error) {
        var indices []string

	csv := &operators.ClusterServiceVersion{}
	if err := scheme.Convert(obj, csv, nil); err != nil {
		return indices, fmt.Errorf("cannot generate indices for object of type %T", obj)
	}

         // ...
}

// ...

@@ -0,0 +1,66 @@
package indexer
Copy link
Member

Choose a reason for hiding this comment

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

Not-blocking: we should probably move all of the OLM specific stuff out of lib.

pkg/lib/index/api.go Show resolved Hide resolved
if len(parts) < 2 {
return indicies, fmt.Errorf("couldn't parse plural.group from crd name: %s", crd.Name)
}
indicies = append(indicies, fmt.Sprintf("provided=%s/%s/%s", parts[1], crd.Version, crd.Kind))
Copy link
Member

Choose a reason for hiding this comment

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

nit: I don't think "provided=" is necessary.

}

// APIsIndexValues returns the names of CSVs that own the given CRD
func APIsIndexValues(indexers map[string]cache.Indexer, crd v1beta1ext.CustomResourceDefinition) (map[string]struct{}, error) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: CRDProviderNames(...)?

expectedCRDVersions[key] = struct{}{}
}

mainCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{mainCRD}, nil, mainNamedStrategy)
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to build a catalog with both CRDs and have the new CSV replace the original instead of deleting/recreating the subscription?

@@ -641,6 +642,176 @@ func TestCreateInstallPlanWithPreExistingCRDOwners(t *testing.T) {
})
}

func TestUpdateInstallPlan(t *testing.T) {
defer cleaner.NotifyTestComplete(t, true)
t.Run("UpdateSingleExistingCRDOwner", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice! I think we also want a negative test-case; i.e. CRD upgrade is blocked from a pre-existing owner.

@dinhxuanvu dinhxuanvu force-pushed the update-crd-one branch 4 times, most recently from 8d37369 to dad2344 Compare June 17, 2019 10:50
fetchedCRD, err := c.ApiextensionsV1beta1Interface().ApiextensionsV1beta1().CustomResourceDefinitions().Get(crdName, metav1.GetOptions{})
require.NoError(t, err)

for _, version := range fetchedCRD.Spec.Versions {
Copy link
Member

Choose a reason for hiding this comment

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

This checks that every version in fectchedCRD is in expectedCRDVersions, but it doesn't check that every version in expectedCRDVersions is in fechedCRD.

(in particulur, both mainCRD and updatedCRD will pass this check since they both contain v1alpha1)

I think you could probably just do require.Equal(t, updatedCRD.Spec.Versions, fetchedCRD.Spec.Versions) to ensure the lists are equal

Copy link
Member

Choose a reason for hiding this comment

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

require.EqualElements ignores ordering if that's needed.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 17, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 17, 2019
@dinhxuanvu dinhxuanvu force-pushed the update-crd-one branch 2 times, most recently from 595e920 to 61f9566 Compare June 17, 2019 20:55
@dinhxuanvu
Copy link
Member Author

/retest

@dinhxuanvu
Copy link
Member Author

/retest

1 similar comment
@dinhxuanvu
Copy link
Member Author

/retest

Signed-off-by: Vu Dinh <vdinh@redhat.com>
Signed-off-by: Vu Dinh <vdinh@redhat.com>
@dinhxuanvu dinhxuanvu force-pushed the update-crd-one branch 3 times, most recently from 18703fc to fededd3 Compare June 18, 2019 22:00
Signed-off-by: Vu Dinh <vdinh@redhat.com>
@dinhxuanvu
Copy link
Member Author

/retest

@jpeeler
Copy link

jpeeler commented Jun 20, 2019

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 20, 2019
@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dinhxuanvu, jpeeler

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 20, 2019
@openshift-merge-robot openshift-merge-robot merged commit b234fe7 into operator-framework:master Jun 20, 2019
@senorhesles
Copy link

Which release did this fix initially make it into?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants