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

Don't process CSVs without operatorgroup #589

Merged

Conversation

ecordell
Copy link
Member

This PR also moves the copying logic into the CSV control loop so that we don't have to requeue operatorgroups every time a CSV changes.

We probably shouldn't merge until there's a default operatorgroup shipping with OLM (otherwise you won't be able to install any operators)

/hold

@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 Nov 28, 2018
@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 28, 2018
@ecordell ecordell requested review from jpeeler and removed request for njhale and alecmerdler November 28, 2018 23:34
@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 28, 2018
@ecordell ecordell requested a review from njhale November 28, 2018 23:34
@ecordell
Copy link
Member Author

/approve
/hold

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ecordell

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 Nov 28, 2018
@ecordell ecordell changed the title [WIP] don't process CSVs without operatorgroup Don't process CSVs without operatorgroup Nov 28, 2018
@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 Nov 28, 2018
return
}

// operatorGroupForCSV returns the operatorgroup for the CSV only if the CSV is active one in the group
func (a *Operator) operatorGroupForActiveCSV(logger *log.Logger, csv *v1alpha1.ClusterServiceVersion) *v1alpha2.OperatorGroup {
Copy link
Member

Choose a reason for hiding this comment

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

Function signature is a bit weird when this takes a log.Logger argument.

@openshift-bot
Copy link
Contributor

@ecordell: PR needs rebase.

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.

@@ -391,6 +391,17 @@ func withAnnotations(obj runtime.Object, annotations map[string]string) runtime.
return meta.(runtime.Object)
}

func addAnnotations(annotations map[string]string, add map[string]string) map[string]string {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@ecordell ecordell force-pushed the copying-in-csv-loop branch from 1b1188c to 7501021 Compare December 3, 2018 16:04
@ecordell
Copy link
Member Author

ecordell commented Dec 3, 2018

/retest

@ecordell ecordell force-pushed the copying-in-csv-loop branch from 7501021 to 7667f79 Compare December 3, 2018 16:33
@ecordell
Copy link
Member Author

ecordell commented Dec 4, 2018

/retest

1 similar comment
@ecordell
Copy link
Member Author

ecordell commented Dec 5, 2018

/retest

@ecordell ecordell force-pushed the copying-in-csv-loop branch 2 times, most recently from d6b9a4e to 72ebb02 Compare December 6, 2018 15:52
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 6, 2018
@ecordell ecordell force-pushed the copying-in-csv-loop branch 2 times, most recently from f12785d to e48a2c1 Compare December 6, 2018 19:56
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 10, 2018
@ecordell ecordell force-pushed the copying-in-csv-loop branch from c360b8f to a0c1f69 Compare December 10, 2018 20:34
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 10, 2018
this commit also moves the copying / rbac logic into the CSV loop, so
that we don't have to requeue operatorgroups frequently
@ecordell ecordell force-pushed the copying-in-csv-loop branch 2 times, most recently from 527c0ba to cc773f8 Compare December 11, 2018 20:55
and aggregate them to operatorgroup clusterroles

this lets us speed up the tests for operatorgroups and in the future can
simplify installplan generation (can remove the clusterrole gen from
installplans)
@ecordell ecordell force-pushed the copying-in-csv-loop branch from cc773f8 to bbc68a9 Compare December 11, 2018 21:00
@ecordell
Copy link
Member Author

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 11, 2018
namespace: {{ .Values.operator_namespace }}
---
apiVersion: operators.coreos.com/v1alpha2
Copy link
Member Author

Choose a reason for hiding this comment

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

Added an operatorgroup for the packages server, since they're required now

sa, err := c.GetServiceAccount(opGroupNamespace, perm.ServiceAccountName)
require.NoError(t, err)
for _, rule := range perm.Rules {
satisfied, err := ruleChecker.RuleSatisfied(sa, otherNamespaceName, rule)
Copy link
Member Author

Choose a reason for hiding this comment

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

added a test to verify RBAC in target namespaces (kinda funky with informers in the test, but it works)

})

// validate provided API clusterroles for the operatorgroup
adminRole, err := c.KubernetesInterface().RbacV1().ClusterRoles().Get(operatorGroup.Name+"-admin", metav1.GetOptions{})
Copy link
Member Author

Choose a reason for hiding this comment

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

This validates both that the operatorgroup clusterrole was created, and that it has correctly aggregated the csv-specific roles

@@ -286,8 +397,4 @@ func TestOperatorGroup(t *testing.T) {
})
require.NoError(t, err)

err = c.KubernetesInterface().CoreV1().Namespaces().Delete(otherNamespaceName, &metav1.DeleteOptions{})
Copy link
Member Author

Choose a reason for hiding this comment

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

these moved into defer blocks further up

@@ -403,7 +404,31 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
"phase": clusterServiceVersion.Status.Phase,
})

operatorNamespace, ok := clusterServiceVersion.GetAnnotations()["olm.operatorNamespace"]
operatorGroup := a.operatorGroupForActiveCSV(logger, clusterServiceVersion)
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the main part of the PR: gating csv processing on whether there are operatorgroups or not

@@ -429,9 +454,67 @@ func (a *Operator) syncClusterServiceVersion(obj interface{}) (syncError error)
}
syncError = fmt.Errorf("error transitioning ClusterServiceVersion: %s and error updating CSV status: %s", syncError, updateErr)
}

// Check if we need to do any copying / annotation for the operatorgroup
if err := a.copyCsvToTargetNamespace(updatedCSV, operatorGroup); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved these three pieces from the operatorgroup control loop to here. The symptom was the e2e test taking a very long time (because csv changes didn't requeue their operatorgroups).

One option would've been to retrigger the owning operatorgroup on CSV change, but then in the operatorgroup side, we reach out and collect up each CSV to perform some of these actions. Moving them here removes all of that processing and lets us treat each CSV in isolation.

}

// Ensure cluster roles exist for using provided apis
if err := a.ensureClusterRolesForCSV(updatedCSV, operatorGroup); err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously we were generating operatorgroup clusterroles directly (e.g. an operatorgroup with permissions on all provided apis in the group).

To speed things up, the operatorgroup control loop just writes out a ClusterRole with aggregation rules, and each individual CSV writes out clusterroles for its provided apis with the correct label to get aggregated to the operatorgroup clusterrole. There's an e2e test to verify the aggregated roles get the correct permissions.

@@ -18,63 +17,137 @@ import (
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
)

const (
operatorGroupAnnotationKey = "olm.operatorGroup"
Copy link

Choose a reason for hiding this comment

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

One of us is going to have to rebase a bit. I ended up pulling this into types so the e2e can also use them in #616. Will finish reviewing this tomorrow.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think #616 will need to change (slightly) anyway - see the operatorGroupForActiveCSV method.

return err
}
}
log.Debug("CSV annotation completed")
for _, owned := range csv.Spec.APIServiceDefinitions.Owned {
namePrefix := fmt.Sprintf("%s-%s-", owned.Name, owned.Version)
Copy link
Member

Choose a reason for hiding this comment

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

Is ownee.Name always set for APIServiceDefinitions?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not, but I want to review all of the current ones, add them, and then go make it required in the json schema

return err
}
}

continue
} else if k8serrors.IsNotFound(err) {
newCSV := csv.DeepCopy()
newCSV.SetNamespace(ns)
newCSV.SetResourceVersion("")
Copy link
Member

@njhale njhale Dec 12, 2018

Choose a reason for hiding this comment

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

ObjectMeta.ResourceVersion is read only so I don't think this needs to be cleared.

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.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 12, 2018
@openshift-merge-robot openshift-merge-robot merged commit 0d5b431 into operator-framework:master Dec 12, 2018
}

// target namespaces don't match
if annotations[operatorGroupTargetsAnnotationKey] != strings.Join(operatorGroup.Status.Namespaces, ",") {
Copy link

Choose a reason for hiding this comment

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

Would this scenario only occur if an operator group was modified after annotations had been previously correct?

ownerutil.AddNonBlockingOwner(clusterRole, csv)
existingCR, err := a.OpClient.KubernetesInterface().RbacV1().ClusterRoles().Create(clusterRole)
if k8serrors.IsAlreadyExists(err) {
if existingCR != nil && reflect.DeepEqual(existingCR.Labels, clusterRole.Labels) && reflect.DeepEqual(existingCR.Rules, clusterRole.Rules) {
Copy link

Choose a reason for hiding this comment

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

Does createPatch not handle a no-op or is this just an optimization?

@ecordell ecordell deleted the copying-in-csv-loop branch January 9, 2019 13:42
ecordell pushed a commit to ecordell/operator-lifecycle-manager that referenced this pull request Mar 8, 2019
…v-loop

Don't process CSVs without operatorgroup
@njhale njhale added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 19, 2019
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants