Skip to content

Commit

Permalink
feat: add checkAPIServiceLabels function to OLM cleanup logic to rewr…
Browse files Browse the repository at this point in the history
…ite APIService owner label
  • Loading branch information
exdx committed Dec 5, 2019
1 parent ef2e6bc commit 78f2809
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
33 changes: 33 additions & 0 deletions cmd/olm/cleanup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -54,6 +55,10 @@ func cleanup(logger *logrus.Logger, c operatorclient.ClientInterface, crc versio
if err := cleanupOwnerReferences(c, crc); err != nil {
logger.WithError(err).Fatal("couldn't cleanup cross-namespace ownerreferences")
}

if err := checkAPIServiceLabels(c); err != nil {
logger.WithError(err).Fatal("couldn't set APIService labels")
}
}

func waitForDelete(checkResource checkResourceFunc, deleteResource deleteResourceFunc) error {
Expand Down Expand Up @@ -250,3 +255,31 @@ func crossNamespaceOwnerReferenceRemoval(kind string, uidNamespaces map[types.UI
return
}
}

// checkAPIServiceLabels checks the labels of existing APIService objects to ensure ownership
// solves a potential contention issues for packageservers (which own the same APIService) during upgrades
func checkAPIServiceLabels(c operatorclient.ClientInterface) error {
listOpts := metav1.ListOptions{FieldSelector: "metadata.name=v1.packages.operators.coreos.com"}
apiServices, err := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().List(listOpts)
if err != nil && !errors.IsNotFound(err) {
return err
}

for _, apiService := range apiServices.Items {
existingLabels := apiService.GetLabels()
if existingLabels[ownerutil.OwnerKey] != ownerutil.OwnerPackageServer {
// existing APIService ownership label name does not correspond to expected packageserver owner
// update APIService with correct label
apiService.Labels[ownerutil.OwnerKey] = ownerutil.OwnerPackageServer
update := func() error {
_, err := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().Update(&apiService)
return err
}
if err := retry.RetryOnConflict(retry.DefaultBackoff, update); err != nil {
return err
}
}
}

return nil
}
7 changes: 4 additions & 3 deletions pkg/lib/ownerutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
)

const (
OwnerKey = "olm.owner"
OwnerNamespaceKey = "olm.owner.namespace"
OwnerKind = "olm.owner.kind"
OwnerKey = "olm.owner"
OwnerNamespaceKey = "olm.owner.namespace"
OwnerKind = "olm.owner.kind"
OwnerPackageServer = "packageserver"
)

var (
Expand Down

0 comments on commit 78f2809

Please sign in to comment.