Skip to content

run bundle: OperatorGroup Install modes#3861

Merged
jmrodri merged 24 commits intooperator-framework:masterfrom
jmrodri:install-modes
Sep 22, 2020
Merged

run bundle: OperatorGroup Install modes#3861
jmrodri merged 24 commits intooperator-framework:masterfrom
jmrodri:install-modes

Conversation

@jmrodri
Copy link
Copy Markdown
Member

@jmrodri jmrodri commented Sep 8, 2020

Description of the change:
Handle the run bundle OperatorGroup install mode scenarios.

Motivation for the change:
Support run bundle.

Checklist

If the pull request includes user-facing changes, extra documentation is required:

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 8, 2020
@jmrodri jmrodri requested a review from estroz September 8, 2020 13:53
@jmrodri jmrodri requested review from joelanford, rashmigottipati and theishshah and removed request for theishshah September 8, 2020 13:53
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 9, 2020
@jmrodri jmrodri changed the title WIP: run bundle: OperatorGroup Install modes run bundle: OperatorGroup Install modes Sep 9, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 9, 2020
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 9, 2020
Comment thread internal/olm/operator/bundle/install.go Outdated
Comment thread internal/olm/operator/registry/operator_installer.go
Comment thread internal/olm/operator/registry/operator_installer.go Outdated
Comment thread internal/olm/operator/registry/operator_installer.go Outdated
Comment thread internal/olm/operator/registry/operator_installer.go Outdated
Copy link
Copy Markdown
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

There's a bunch of static validation being added to ensureOperatorGroup() that should be done before anything is created in-cluster. Can we move that elsewhere?

Comment thread internal/olm/operator/registry/operator_installer.go Outdated
Comment thread internal/olm/operator/registry/operator_installer.go
Comment thread internal/olm/operator/registry/operator_installer_test.go Outdated
@jmrodri
Copy link
Copy Markdown
Member Author

jmrodri commented Sep 15, 2020

/cc @estroz @joelanford

Comment thread internal/olm/operator/registry/operator_installer.go Outdated
Copy link
Copy Markdown
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

One question about error checking. Otherwise logic looks good (haven't reviewed the tests yet).

Comment thread internal/olm/operator/registry/operator_installer_test.go Outdated
Comment thread internal/olm/operator/registry/operator_installer_test.go Outdated
Comment thread internal/olm/operator/bundle/install.go Outdated
Copy link
Copy Markdown
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

It. shows are addressing its requirements. So,

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 18, 2020
Copy link
Copy Markdown
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

This is almost ready, just one question about logic locality.

Comment on lines +111 to +116
// single namespace and targetns == opname
if i.InstallModeType == v1alpha1.InstallModeTypeSingleNamespace {
if len(i.TargetNamespaces) < 1 || i.TargetNamespaces[0] == operatorNamespace {
return fmt.Errorf("use install mode %q to watch operator's namespace %q", v1alpha1.InstallModeTypeOwnNamespace, i.TargetNamespaces[0])
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think using the controller's namespace with SingleNamespace is valid. However if we are going to perform this check, move it (and the one above it) below the check for support (line 123) so we make sure the mode is supported first.

Copy link
Copy Markdown
Member

@joelanford joelanford Sep 19, 2020

Choose a reason for hiding this comment

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

I can be invalid. Developing kubectl operator I was noticing some behavior around this that I thought was odd, but I confirmed with @njhale that OLM requires an operator to support OwnNamespace if it is watching the namespace in which it is deployed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, it looks like this is actually checking two different cases, right?

  • len(i.TargetNamespaces) < 1 should be checked in Validate() and error with "SingleNamespace requires exactly one target namespace"
  • i.TargetNamespaces[0] == operatorNamespace is the piece that goes with the error message you return here.

@jmrodri I know we talked about this a bit last week. Can you remind me if (and why) we settled on keeping the check for OwnNamespace having a target namespace list equal to the install namespace, which therefore requires us to set that correctly before calling this check?

I'm kind of thinking that it makes more sense to check OwnNamespace has an empty target namespace list (which we should do in Validate(), and only when we are creating the OperatorGroup in the install namespace do we make the inference that OwnNamespace means to use the install namespace. It also seems logical at that point because we must align the OperatorGroup.metadata.namespace with the OperatorGroup.spec.targetNamespaces. WDYT?

supported := o.SupportedInstallModes

// --install-mode was given
if !o.InstallMode.IsEmpty() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we still checking install mode compatibility in this method? This should all be validated by the time ensureOperatorGroup is called. Is there a reason why you're checking them here and CheckCompatibility?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I agree @estroz, but sanity check me here @jmrodri. There are three main things we need to check, and I think we can do ALL of it before creating any resources in the cluster:

  1. The actual format and content of the --install-mode flag. We can check this during flag parsing with InstallMode.Set().
  2. CSV / --install-mode compatibility:
    • if the --install-mode flag is set, make sure it is supported by the CSV.
    • if the --install-mode flag is not set, make sure the CSV supports one of AllNamespaces or OwnNamespace (SingleNamespace requires an explicit target namespace from the --install-mode flag).
  3. There can only be 0 or 1 operator groups in the namespace. If the namespace has an existing operator group, is it compatible with the intersection of the CSV supported install modes and the --install-mode flag (if set).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@estroz @joelanford you're literally saying do not make these checks in ensureOperatorGroup? I realize they are being done in CheckCompatibility which is the earliest entrypoint where the users input can be checked. But checking it there does not guarantee that some other code can't call ensureOperatorGroup without having gone through CheckCompatibility. Or are we saying that OperatorInstaller does NOT care about the rules it only cares about passing the data that was verified BEFORE it was called?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess it feels weird not doing any checks in ensureOperatorGroup because OperatorInstaller does not know that all its attributes were set correctly, so it seems like it should ensure they're okay before doing something with them.

Copy link
Copy Markdown
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

I think all of my comments can be follow-ups (not positive), but I'll clear my "Request changes" review, so I'm not holding it up.

I would say that if this implements the proposal and works as expected for both bundles and packagemanifests, lets merge it and come back to make some improvements later (but still soon).

@joelanford joelanford self-requested a review September 19, 2020 02:43
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 22, 2020
@jmrodri
Copy link
Copy Markdown
Member Author

jmrodri commented Sep 22, 2020

OWN NAMESPACE

[jesusr@transam operator-sdk{install-modes}]$ k get operatorgroups
No resources found in default namespace.
[jesusr@transam operator-sdk{install-modes}]$ grep -A8 -i installmodes bundle-example-operator/manifests/example-operator.clusterserviceversion.yaml 
  installModes:
  - supported: true
    type: OwnNamespace
  - supported: true
    type: SingleNamespace
  - supported: false
    type: MultiNamespace
  - supported: true
    type: AllNamespaces
[jesusr@transam operator-sdk{install-modes}]$ build/operator-sdk run bundle quay.io/joelanford/example-operator-bundle:0.1.0 --install-mode OwnNamespace
INFO[0002] Successfully created registry pod: quay-io-joelanford-example-operator-bundle-0-1-0 
INFO[0002] Created CatalogSource: example-operator-catalog 
INFO[0003] OperatorGroup "operator-sdk-og" created      
INFO[0003] Created Subscription: example-operator-v0-1-0-sub 
INFO[0011] Approved InstallPlan install-mdwb4 for the Subscription: example-operator-v0-1-0-sub 
INFO[0011] Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to reach 'Succeeded' phase 
INFO[0011]   Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to appear 
INFO[0018]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Pending 
INFO[0019]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Installing 
INFO[0025]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Succeeded 
INFO[0025] OLM has successfully installed "example-operator.v0.1.0" 
[jesusr@transam operator-sdk{install-modes}]$ k get operatorgroup operator-sdk-og -o json  | jq '. | {namespace: .metadata.namespace,  targetNamespaces: .spec.targetNamespaces}'
{
  "namespace": "default",
  "targetNamespaces": [
    "default"
  ]
}

@jmrodri
Copy link
Copy Markdown
Member Author

jmrodri commented Sep 22, 2020

SINGLE NAMESPACE

[jesusr@transam operator-sdk{install-modes}]$ k get operatorgroups
No resources found in default namespace.
[jesusr@transam operator-sdk{install-modes}]$ grep -A8 -i installmodes bundle-example-operator/manifests/example-operator.clusterserviceversion.yaml 
  installModes:
  - supported: true
    type: OwnNamespace
  - supported: true
    type: SingleNamespace
  - supported: false
    type: MultiNamespace
  - supported: true
    type: AllNamespaces
[jesusr@transam operator-sdk{install-modes}]$ k create ns foo
namespace/foo created
[jesusr@transam operator-sdk{install-modes}]$ build/operator-sdk run bundle quay.io/joelanford/example-operator-bundle:0.1.0 --install-mode SingleNamespace=foo
INFO[0003] Successfully created registry pod: quay-io-joelanford-example-operator-bundle-0-1-0 
INFO[0003] Created CatalogSource: example-operator-catalog 
INFO[0003] OperatorGroup "operator-sdk-og" created      
INFO[0003] Created Subscription: example-operator-v0-1-0-sub 
INFO[0011] Approved InstallPlan install-7gs64 for the Subscription: example-operator-v0-1-0-sub 
INFO[0011] Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to reach 'Succeeded' phase 
INFO[0011]   Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to appear 
INFO[0023]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Pending 
INFO[0024]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Installing 
INFO[0030]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Succeeded 
INFO[0030] OLM has successfully installed "example-operator.v0.1.0" 
[jesusr@transam operator-sdk{install-modes}]$ k get operatorgroup operator-sdk-og -o json  | jq '. | {namespace: .metadata.namespace,  targetNamespaces: .spec.targetNamespaces}'
{
  "namespace": "default",
  "targetNamespaces": [
    "foo"
  ]
}

@jmrodri
Copy link
Copy Markdown
Member Author

jmrodri commented Sep 22, 2020

ALL NAMESPACES

[jesusr@transam operator-sdk{install-modes}]$ k get operatorgroups
No resources found in default namespace.
[jesusr@transam operator-sdk{install-modes}]$ grep -A8 -i installmodes bundle-example-operator/manifests/example-operator.clusterserviceversion.yaml 
  installModes:
  - supported: true
    type: OwnNamespace
  - supported: true
    type: SingleNamespace
  - supported: false
    type: MultiNamespace
  - supported: true
    type: AllNamespaces
[jesusr@transam operator-sdk{install-modes}]$ build/operator-sdk run bundle quay.io/joelanford/example-operator-bundle:0.1.0 --install-mode AllNamespaces
INFO[0003] Successfully created registry pod: quay-io-joelanford-example-operator-bundle-0-1-0 
INFO[0003] Created CatalogSource: example-operator-catalog 
INFO[0003] OperatorGroup "operator-sdk-og" created      
INFO[0003] Created Subscription: example-operator-v0-1-0-sub 
INFO[0011] Approved InstallPlan install-74kz4 for the Subscription: example-operator-v0-1-0-sub 
INFO[0011] Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to reach 'Succeeded' phase 
INFO[0011]   Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to appear 
INFO[0023]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Pending 
INFO[0024]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Installing 
INFO[0030]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Succeeded 
INFO[0030] OLM has successfully installed "example-operator.v0.1.0" 
[jesusr@transam operator-sdk{install-modes}]$ k get operatorgroup operator-sdk-og -o json  | jq '. | {namespace: .metadata.namespace,  targetNamespaces: .spec.targetNamespaces}'
{
  "namespace": "default",
  "targetNamespaces": null
}

@jmrodri
Copy link
Copy Markdown
Member Author

jmrodri commented Sep 22, 2020

PRECENDENCE

  • Existing operatorgroup suppolrting single namespace
[jesusr@transam operator-sdk{install-modes}]$ k create ns foo
namespace/foo created
[jesusr@transam operator-sdk{install-modes}]$ k apply -f single-og.yaml 
operatorgroup.operators.coreos.com/operator-sdk-og created
[jesusr@transam operator-sdk{install-modes}]$ k get operatorgroup operator-sdk-og -o json  | jq '. | {namespace: .metadata.namespace,  targetNamespaces: .spec.targetNamespaces}'
{
  "namespace": "default",
  "targetNamespaces": [
    "foo"
  ]
}
[jesusr@transam operator-sdk{install-modes}]$ build/operator-sdk run bundle quay.io/joelanford/example-operator-bundle:0.1.0 
INFO[0003] Successfully created registry pod: quay-io-joelanford-example-operator-bundle-0-1-0 
INFO[0003] Created CatalogSource: example-operator-catalog 
INFO[0003] Created Subscription: example-operator-v0-1-0-sub 
INFO[0011] Approved InstallPlan install-rkhrw for the Subscription: example-operator-v0-1-0-sub 
INFO[0011] Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to reach 'Succeeded' phase 
INFO[0011]   Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to appear 
INFO[0023]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: InstallReady 
INFO[0024]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Installing 
INFO[0029]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Succeeded 
INFO[0029] OLM has successfully installed "example-operator.v0.1.0" 
  • Existing operatorgroup supporting own namespace
[jesusr@transam operator-sdk{install-modes}]$ k apply -f own-og.yaml 
operatorgroup.operators.coreos.com/operator-sdk-og created
[jesusr@transam operator-sdk{install-modes}]$ k get operatorgroup operator-sdk-og -o json  | jq '. | {namespace: .metadata.namespace,  targetNamespaces: .spec.targetNamespaces}'
{
  "namespace": "default",
  "targetNamespaces": [
    "default"
  ]
}
[jesusr@transam operator-sdk{install-modes}]$ build/operator-sdk run bundle quay.io/joelanford/example-operator-bundle:0.1.0 
INFO[0003] Successfully created registry pod: quay-io-joelanford-example-operator-bundle-0-1-0 
INFO[0003] Created CatalogSource: example-operator-catalog 
INFO[0003] Created Subscription: example-operator-v0-1-0-sub 
INFO[0011] Approved InstallPlan install-4fd4c for the Subscription: example-operator-v0-1-0-sub 
INFO[0011] Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to reach 'Succeeded' phase 
INFO[0011]   Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to appear 
INFO[0023]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Pending 
INFO[0024]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Installing 
INFO[0029]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Succeeded 
INFO[0029] OLM has successfully installed "example-operator.v0.1.0" 
  • Existing operatorgroup supporting all namespaces
[jesusr@transam operator-sdk{install-modes}]$ k apply -f all-og.yaml 
operatorgroup.operators.coreos.com/operator-sdk-og created
[jesusr@transam operator-sdk{install-modes}]$ k get operatorgroup operator-sdk-og -o json  | jq '. | {namespace: .metadata.namespace,  targetNamespaces: .spec.targetNamespaces}'
{
  "namespace": "default",
  "targetNamespaces": null
}
[jesusr@transam operator-sdk{install-modes}]$ build/operator-sdk run bundle quay.io/joelanford/example-operator-bundle:0.1.0 
INFO[0003] Successfully created registry pod: quay-io-joelanford-example-operator-bundle-0-1-0 
INFO[0003] Created CatalogSource: example-operator-catalog 
INFO[0003] Created Subscription: example-operator-v0-1-0-sub 
INFO[0011] Approved InstallPlan install-zb5s2 for the Subscription: example-operator-v0-1-0-sub 
INFO[0011] Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to reach 'Succeeded' phase 
INFO[0011]   Waiting for ClusterServiceVersion "default/example-operator.v0.1.0" to appear 
INFO[0022]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Pending 
INFO[0023]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Installing 
INFO[0029]   Found ClusterServiceVersion "default/example-operator.v0.1.0" phase: Succeeded 
INFO[0029] OLM has successfully installed "example-operator.v0.1.0" 

They all had successful operator runs

[jesusr@transam operator-sdk{install-modes}]$ k get all
NAME                                                                  READY   STATUS      RESTARTS   AGE
pod/6c68598feb4a9e5b62e608efafcc1b0f4c13209037d298c8f7041d888d9ms6q   0/1     Completed   0          50s
pod/example-operator-c86659899-56dhv                                  1/1     Running     0          38s
pod/quay-io-joelanford-example-operator-bundle-0-1-0                  1/1     Running     0          60s

NAME                               TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
service/example-operator-metrics   ClusterIP   10.100.208.166   <none>        8383/TCP,8686/TCP   31s
service/kubernetes                 ClusterIP   10.96.0.1        <none>        443/TCP             2m49s

NAME                               READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/example-operator   1/1     1            1           38s

NAME                                         DESIRED   CURRENT   READY   AGE
replicaset.apps/example-operator-c86659899   1         1         1       38s

NAME                                                                        COMPLETIONS   DURATION   AGE
job.batch/6c68598feb4a9e5b62e608efafcc1b0f4c13209037d298c8f7041d888db8386   1/1           6s         50s

Copy link
Copy Markdown
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 22, 2020
@jmrodri jmrodri dismissed joelanford’s stale review September 22, 2020 20:10

Dismissing Joe's review based on #3861 (review)

@jmrodri jmrodri merged commit 7f43289 into operator-framework:master Sep 22, 2020
@jmrodri jmrodri deleted the install-modes branch January 30, 2022 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants